Example #1
0
StatusWith<ConnectionString> ConnectionString::parse(const std::string& url) {
    const std::string::size_type i = url.find('/');

    // Replica set
    if (i != std::string::npos && i != 0) {
        return ConnectionString(SET, url.substr(i + 1), url.substr(0, i));
    }

    const int numCommas = str::count(url, ',');

    // Single host
    if (numCommas == 0) {
        HostAndPort singleHost;
        Status status = singleHost.initialize(url);
        if (!status.isOK()) {
            return status;
        }

        return ConnectionString(singleHost);
    }

    // Sharding config server
    if (numCommas == 2) {
        return ConnectionString(SYNC, url, "");
    }

    return Status(ErrorCodes::FailedToParse, str::stream() << "invalid url [" << url << "]");
}
Example #2
0
    TEST( Shard, EqualitySync ) {
        ConnectionString cs( ConnectionString::SYNC, "a,b,c" );
        ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "a,b,c" ) ) );
        ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "c,b,a" ) ) );
        ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "c,a,b" ) ) );

        ASSERT( ! cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "d,a,b" ) ) );
    }
Example #3
0
        bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg,
                 BSONObjBuilder& result, bool) {
            Timer t;
            DistributedLock lk(ConnectionString(cmdObj["host"].String(),
                                                ConnectionString::SYNC), "testdistlockwithsync", 0, 0);
            current = &lk;
            count.store(0);
            gotit = 0;
            errors = 0;
            keepGoing = true;

            vector<shared_ptr<boost::thread> > l;
            for (int i = 0; i < 4; i++) {
                l.push_back(
                    shared_ptr<boost::thread> (new boost::thread(runThread)));
            }

            int secs = 10;
            if (cmdObj["secs"].isNumber())
                secs = cmdObj["secs"].numberInt();
            sleepsecs(secs);
            keepGoing = false;

            for (unsigned i = 0; i < l.size(); i++)
                l[i]->join();

            current = 0;

            result.append("count", count.loadRelaxed());
            result.append("gotit", gotit);
            result.append("errors", errors);
            result.append("timeMS", t.millis());

            return errors == 0;
        }
Example #4
0
void Fenfloss::PrepareSimStart(int numProc)
{
	char sNumNodes[30];
	char *startshell = NULL;
	char simStart[255];
	int connMeth;
	int simAppl;

	dprintf(1, "Fenfloss::PrepareSimStart(%d)\n", numProc);
	sprintf(sNumNodes, "%d", numProc);
	startshell = ConnectionString();

	connMeth = p_ConnectionMethod->getValue();
	simAppl = p_simApplication->getValue();

	setUserArg(0, startshell);

	const char *caseString = p_StartupSwitch->getActLabel();

	if (!strcmp(s_ConnectionMethod[connMeth], "echo"))
		sprintf(simStart, "echo -T \"flow_%s\" -e %s start %s %d", caseString, SimBatchString(), caseString, numProc);
#ifdef WIN32
	else if (!strcmp(s_ConnectionMethod[connMeth], "WMI"))
	{
		sprintf(simStart, "\"%s start %s %d\" \" \" \"%s\" \" %s \"",  SimBatchString(), caseString, numProc, p_Hostname->getValue(), p_User->getValue());
		fprintf(stderr,"simStart='%s'\n", simStart);
	}
#endif
	else if (!strcmp(s_ConnectionMethod[connMeth], "rdaemon"))
	{
		sprintf(simStart, "\"%s start %s %d %s\" \" \" \"%s\" \" %s \"",  SimBatchString(), caseString, numProc, s_simApplication[simAppl], p_Hostname->getValue(), p_User->getValue());
           //sprintf(simStart, "\"%s start %s %d\" \" \" \"%s\" \" %s \"",  SimBatchString(), caseString, numProc, p_Hostname->getValue(), p_User->getValue());
		   
		   dprintf(3,"\n\nsimStart='%s'\n\n", simStart);
	}
	else if (!strcmp(s_ConnectionMethod[connMeth], "globus_gram")) {
	   
	   std::string globusrun = coCoviseConfig::getEntry("value","Module.Globus.GlobusRun", "/usr/local/globus-4.0.1/bin/globusrun-ws");
	   std::string jobfactory = coCoviseConfig::getEntry("value","Module.Globus.jobfactory","/wsrf/services/ManagedJobFactoryService");
	   
           printf("globusrun: [%s]\njobfactory: [%s]\n", globusrun.c_str(), jobfactory.c_str());

	   //snprintf(simStart, sizeof(simStart), "%s -s -Ft PBS -F https://%s%s -submit -c %s start %s %d %s", globusrun, p_Hostname->getValue(), jobfactory, SimBatchString(), caseString, numProc, s_simApplication[simAppl]);
           snprintf(simStart, sizeof(simStart), "%s -s -Ft PBS -J -F https://%s%s -submit -c %s start %s %d %s", globusrun.c_str(), p_Hostname->getValue(), jobfactory.c_str(), SimBatchString(), caseString, numProc, s_simApplication[simAppl]);
           printf("simstart: [%s]\n", simStart);
	}
	else if (!strcmp(s_ConnectionMethod[connMeth], "reattach")) {
	   
	   snprintf(simStart, sizeof(simStart), "()"); // FIXME
	}
	// execProcessWMI: commandLine, workingdirectory, host, user, password
	else {
           sprintf(simStart, "%s start %s %d %s", SimBatchString(), caseString, numProc, s_simApplication[simAppl]);
        }

	setUserArg(1,simStart);
	dprintf(3, "\tPrepareSimStart: startshell=%s; simStart=%s\n",
               startshell, simStart);
	if (startshell)   free(startshell);
}
Example #5
0
ConnectionString ConnectionString::parse(const std::string& url, std::string& errmsg) {
    auto status = parse(url);
    if (status.isOK()) {
        errmsg = "";
        return status.getValue();
    }

    errmsg = status.getStatus().toString();
    return ConnectionString();
}
Example #6
0
void Fenfloss::StopSimulation(void)
{
	char *stopshell = NULL;
	char simStop[255];

	stopshell = ConnectionString();
	sprintf(simStop, "%s '%s kill'", stopshell, SimBatchString());
	if(system(simStop)==-1)
           dprintf(1, "Fenfloss::StopSimulation: execution of %s failed\n", simStop);
	if (stopshell) free(stopshell);
}
Example #7
0
    ConnectionString ConnectionString::parse( const string& host , string& errmsg ) {

        string::size_type i = host.find( '/' );
        if ( i != string::npos && i != 0) {
            // replica set
            return ConnectionString( SET , host.substr( i + 1 ) , host.substr( 0 , i ) );
        }

        int numCommas = str::count( host , ',' );

        if( numCommas == 0 )
            return ConnectionString( HostAndPort( host ) );

        if ( numCommas == 1 )
            return ConnectionString( PAIR , host );

        if ( numCommas == 2 )
            return ConnectionString( SYNC , host );

        errmsg = (string)"invalid hostname [" + host + "]";
        return ConnectionString(); // INVALID
    }
intrusive_ptr<DocumentSource> DocumentSourceMergeCursors::createFromBson(
    BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
    massert(17026,
            string("Expected an Array, but got a ") + typeName(elem.type()),
            elem.type() == Array);

    CursorIds cursorIds;
    BSONObj array = elem.embeddedObject();
    BSONForEach(cursor, array) {
        massert(17027,
                string("Expected an Object, but got a ") + typeName(cursor.type()),
                cursor.type() == Object);

        cursorIds.push_back(
            make_pair(ConnectionString(HostAndPort(cursor["host"].String())), cursor["id"].Long()));
    }
Example #9
0
        bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
            DistributedLock lk( ConnectionString( cmdObj["host"].String() , ConnectionString::SYNC ), "testdistlockwithsync" );
            current = &lk;
            count = 0;
            gotit = 0;

            vector<shared_ptr<boost::thread> > l;
            for ( int i=0; i<4; i++ ) {
                l.push_back( shared_ptr<boost::thread>( new boost::thread( runThread ) ) );
            }

            for ( unsigned i=0; i<l.size(); i++ )
                l[i]->join();

            result.append( "count" , count );
            result.append( "gotit" , gotit );
            current = 0;
            return count == gotit * 2000;
        }
Example #10
0
    bool ConfigServer::init( vector<string> configHosts ) {
        uassert( 10187 ,  "need configdbs" , configHosts.size() );

        string hn = getHostName();
        if ( hn.empty() ) {
            sleepsecs(5);
            dbexit( EXIT_BADOPTIONS );
        }

        set<string> hosts;
        for ( size_t i=0; i<configHosts.size(); i++ ) {
            string host = configHosts[i];
            hosts.insert( getHost( host , false ) );
            configHosts[i] = getHost( host , true );
        }

        for ( set<string>::iterator i=hosts.begin(); i!=hosts.end(); i++ ) {
            string host = *i;
            bool ok = false;
            for ( int x=10; x>0; x-- ) {
                if ( ! hostbyname( host.c_str() ).empty() ) {
                    ok = true;
                    break;
                }
                log() << "can't resolve DNS for [" << host << "]  sleeping and trying " << x << " more times" << endl;
                sleepsecs( 10 );
            }
            if ( ! ok )
                return false;
        }

        _config = configHosts;

        string fullString;
        joinStringDelim( configHosts, &fullString, ',' );
        _primary.setAddress( ConnectionString( fullString , ConnectionString::SYNC ) );
        log(1) << " config string : " << fullString << endl;

        return true;
    }
intrusive_ptr<DocumentSource> DocumentSourceMergeCursors::createFromBson(
    BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
    massert(17026,
            string("Expected an Array, but got a ") + typeName(elem.type()),
            elem.type() == Array);

    std::vector<CursorDescriptor> cursorDescriptors;
    BSONObj array = elem.embeddedObject();
    BSONForEach(cursor, array) {
        massert(17027,
                string("Expected an Object, but got a ") + typeName(cursor.type()),
                cursor.type() == Object);

        // The cursor descriptors for the merge cursors stage used to lack an "ns" field; "ns" was
        // understood to be the expression context namespace in that case. For mixed-version
        // compatibility, we accept both the old and new formats here.
        std::string cursorNs = cursor["ns"] ? cursor["ns"].String() : pExpCtx->ns.ns();

        cursorDescriptors.emplace_back(ConnectionString(HostAndPort(cursor["host"].String())),
                                       std::move(cursorNs),
                                       cursor["id"].Long());
    }
Example #12
0
ConnectionString ConnectionString::forReplicaSet(StringData setName,
                                                 std::vector<HostAndPort> servers) {
    return ConnectionString(setName, std::move(servers));
}
Example #13
0
ConnectionString ConnectionString::forLocal() {
    return ConnectionString(LOCAL);
}
Example #14
0
 void Shard::_setAddr( const string& addr ) {
     _addr = addr;
     if ( !_addr.empty() ) {
         _cs = ConnectionString( addr , ConnectionString::SET );
     }
 }
ConnectionString RemoteCommandTargeterStandalone::connectionString() {
    return ConnectionString(_hostAndPort);
}
Example #16
0
    DWORD CALLBACK Thread()
    {
        IMDPROXY_CONNECT_REQ ConnectReq;

        KdPrint(("ImDskSvc: Thread created.%n"));

        if (Overlapped.BufRecv(hPipe, &ConnectReq.request_code,
            sizeof ConnectReq.request_code) !=
            sizeof ConnectReq.request_code)
        {
            KdPrintLastError(("Overlapped.BufRecv() failed"));

            delete this;
            return 0;
        }

        if (ConnectReq.request_code != IMDPROXY_REQ_CONNECT)
        {
            delete this;
            return 0;
        }

        if (Overlapped.BufRecv(hPipe,
            ((PUCHAR)&ConnectReq) +
            sizeof(ConnectReq.request_code),
            sizeof(ConnectReq) -
            sizeof(ConnectReq.request_code)) !=
            sizeof(ConnectReq) -
            sizeof(ConnectReq.request_code))
        {
            KdPrintLastError(("Overlapped.BufRecv() failed"));

            delete this;
            return 0;
        }

        if ((ConnectReq.length == 0) | (ConnectReq.length > 520))
        {
            KdPrint(("ImDskSvc: Bad connection string length received (%1!u!).%n",
                ConnectReq.length));

            delete this;
            return 0;
        }

        WCRTMem<WCHAR> ConnectionString((size_t)ConnectReq.length + 2);
        if (!ConnectionString)
        {
            KdPrintLastError(("malloc() failed"));

            delete this;
            return 0;
        }

        if (Overlapped.BufRecv(hPipe, ConnectionString,
            (DWORD)ConnectReq.length) !=
            ConnectReq.length)
        {
            KdPrintLastError(("Overlapped.BufRecv() failed"));

            
            delete this;
            return 0;
        }

        IMDPROXY_CONNECT_RESP connect_resp = { 0 };

        ConnectionString[ConnectReq.length / sizeof *ConnectionString] = 0;

        // Split server connection string and string that should be sent to server
        // for server side connection to specific image file.

        LPWSTR path_part = wcsstr(ConnectionString, L"://");

        if (path_part != NULL)
        {
            path_part[0] = 0;
            path_part++;
        }

        HANDLE hTarget;
        switch (IMDISK_PROXY_TYPE(ConnectReq.flags))
        {
        case IMDISK_PROXY_TYPE_COMM:
        {
            LPWSTR FileName = wcstok(ConnectionString, L": ");

            KdPrint(("ImDskSvc: Connecting to '%1!ws!'.%n", FileName));

            hTarget = CreateFile(FileName,
                GENERIC_READ | GENERIC_WRITE,
                0,
                NULL,
                OPEN_EXISTING,
                0,
                NULL);

            if (hTarget == INVALID_HANDLE_VALUE)
            {
                connect_resp.error_code = GetLastError();

                KdPrintLastError(("CreateFile() failed"));

                Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

                delete this;
                return 0;
            }

            LPWSTR DCBAndTimeouts = wcstok(NULL, L"");
            if (DCBAndTimeouts != NULL)
            {
                DCB dcb = { 0 };
                COMMTIMEOUTS timeouts = { 0 };

                if (DCBAndTimeouts[0] == L' ')
                    ++DCBAndTimeouts;

                KdPrint(("ImDskSvc: Configuring '%1!ws!'.%n", DCBAndTimeouts));

                GetCommState(hTarget, &dcb);
                GetCommTimeouts(hTarget, &timeouts);
                BuildCommDCBAndTimeouts(DCBAndTimeouts, &dcb, &timeouts);
                SetCommState(hTarget, &dcb);
                SetCommTimeouts(hTarget, &timeouts);
            }

            KdPrint(("ImDskSvc: Connected to '%1!ws!' and configured.%n",
                FileName));

            break;
        }

        case IMDISK_PROXY_TYPE_TCP:
        {
            LPWSTR ServerName = wcstok(ConnectionString, L":");
            LPWSTR PortName = wcstok(NULL, L"");

            if (PortName == NULL)
                PortName = L"9000";

            KdPrint(("ImDskSvc: Connecting to '%1!ws!:%2!ws!'.%n",
                ServerName, PortName));

            hTarget = (HANDLE)ConnectTCP(ServerName, PortName);
            if (hTarget == INVALID_HANDLE_VALUE)
            {
                connect_resp.error_code = GetLastError();

                KdPrintLastError(("ConnectTCP() failed"));
                

                Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

                delete this;
                return 0;
            }

            bool b = true;
            setsockopt((SOCKET)hTarget, IPPROTO_TCP, TCP_NODELAY, (LPCSTR)&b,
                sizeof b);

            KdPrint(("ImDskSvc: Connected to '%1!ws!:%2!ws!' and configured.%n",
                ServerName, PortName));

            break;
        }

        default:
            KdPrint(("ImDskSvc: Unsupported connection type (%1!#x!).%n",
                IMDISK_PROXY_TYPE(ConnectReq.flags)));

            connect_resp.error_code = (ULONGLONG)-1;
            Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

            
            delete this;
            return 0;
        }

        // Connect to requested server side image path

        if (path_part != NULL)
        {
            size_t path_size = wcslen(path_part) << 1;

            size_t req_size = sizeof(IMDPROXY_CONNECT_REQ) +
                path_size;

            WCRTMem<IMDPROXY_CONNECT_REQ> open_request(req_size);

            if (!open_request)
            {
                KdPrintLastError(("malloc() failed"));

                connect_resp.error_code = (ULONGLONG)-1;
                Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

                delete this;
                return 0;
            }

            ZeroMemory(open_request, req_size);

            open_request->request_code = IMDPROXY_REQ_CONNECT;
            open_request->length = path_size;

            memcpy(open_request + 1, path_part, path_size);

            if (!Overlapped.BufSend(hTarget, open_request, (DWORD)req_size))
            {
                KdPrintLastError(("Failed to send connect request to server"));

                connect_resp.error_code = (ULONGLONG)-1;
                Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

                delete this;
                return 0;
            }

            open_request.Free();

            if (Overlapped.BufRecv(hTarget, &connect_resp, sizeof connect_resp) !=
                sizeof connect_resp)
            {
                connect_resp.object_ptr = NULL;
                if (connect_resp.error_code == 0)
                {
                    connect_resp.error_code = (ULONGLONG)-1;
                }

                Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);
                
                delete this;
                return 0;
            }
        }
        
        ConnectionString.Free();

        HANDLE hDriver = CreateFile(IMDISK_CTL_DOSDEV_NAME,
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL,
            OPEN_EXISTING,
            0,
            NULL);

        if (hDriver == INVALID_HANDLE_VALUE)
        {
            connect_resp.error_code = GetLastError();

            KdPrintLastError(("Opening ImDiskCtl device failed"));
            CloseHandle(hTarget);

            Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

            delete this;
            return 0;
        }

        DWORD dw;
        if (!DeviceIoControl(hDriver,
            IOCTL_IMDISK_REFERENCE_HANDLE,
            &hTarget,
#pragma warning(suppress: 28132)
            sizeof hTarget,
            &connect_resp.object_ptr,
            sizeof connect_resp.object_ptr,
            &dw,
            NULL))
        {
            connect_resp.error_code = GetLastError();

            KdPrintLastError(("IOCTL_IMDISK_REFERENCE_HANDLE failed"));
            CloseHandle(hDriver);
            CloseHandle(hTarget);

            Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

            delete this;
            return 0;
        }

        CloseHandle(hDriver);

        Overlapped.BufSend(hPipe, &connect_resp, sizeof connect_resp);

        // This will fail when driver closes the pipe, but that just indicates that
        // we should shut down this connection.
        Overlapped.BufRecv(hPipe, &dw, sizeof dw);

        KdPrint(("ImDskSvc: Cleaning up.%n"));

        CloseHandle(hTarget);

        delete this;
        return 1;
    }