int32_t registerService(const std::string& host, const int32_t port) {
   // Your implementation goes here
   printf("registerService\n");
   pair<string,int> host_tuple(host,port);
   boost::shared_ptr<TTransport> socket(new TSocket(host,port));
   boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
   boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
   boost::shared_ptr<RemoteInfixSearchClient> client(new RemoteInfixSearchClient(protocol));
   thrift_container_t container;
   container.host = host;
   container.port = port;
   container.socket = socket;
   container.transport = transport;
   container.protocol = protocol;
   container.client = client;
   bool found = false;
   for(host_list_t::iterator it = host_list.begin();it!=host_list.end();++it){
     thrift_container_t container = *it;
     if(container.host.compare(host)==0 && container.port==port){
       printf("Found a matching entry\n");
       found = true;
       break;
     }
   }
   if(!found) host_list.push_back(container);
   printf("There are now %u workers\n",(uint)host_list.size());
 }
Ejemplo n.º 2
0
    error server_control_executor::validate_host_list(
        const host_list_t&  _irods_hosts,
        const host_list_t&  _cmd_hosts,
        host_list_t&        _valid_hosts ) {

        host_list_t::const_iterator itr;
        for ( itr  = _cmd_hosts.begin();
                itr != _cmd_hosts.end();
                ++itr ) {
            // check host value against list from the icat
            if ( !is_host_in_list(
                        *itr,
                        _irods_hosts ) ) {
                std::string msg( "invalid server hostname [" );
                msg += *itr;
                msg += "]";
                return ERROR(
                           SYS_INVALID_INPUT_PARAM,
                           msg );

            }

            // skip the IES since it is a special case
            // and handled elsewhere
            if ( compare_host_names( icat_host_name_, *itr ) ) {
                continue;
            }

            // skip the local server since it is also a
            // special case and handled elsewhere
            if ( compare_host_names( my_host_name_, *itr ) ) {
                continue;

            }

            // add the host to our newly ordered list
            _valid_hosts.push_back( *itr );

        } // for itr

        return SUCCESS();

    } // validate_host_list
Ejemplo n.º 3
0
    error server_control_executor::get_resource_host_names(
        host_list_t& _host_names ) {
        rodsEnv my_env;
        _reloadRodsEnv( my_env );
        rcComm_t* comm = rcConnect(
                             my_env.rodsHost,
                             my_env.rodsPort,
                             my_env.rodsUserName,
                             my_env.rodsZone,
                             NO_RECONN, 0 );
        if ( !comm ) {
            return ERROR(
                       NULL_VALUE_ERR,
                       "rcConnect failed" );
        }

        int status = clientLogin(
                         comm,
                         0,
                         my_env.rodsAuthScheme );
        if ( status != 0 ) {
            rcDisconnect( comm );
            return ERROR(
                       status,
                       "client login failed" );
        }

        genQueryInp_t  gen_inp;
        genQueryOut_t* gen_out = NULL;
        memset( &gen_inp, 0, sizeof( gen_inp ) );

        addInxIval( &gen_inp.selectInp, COL_R_LOC, 1 );
        gen_inp.maxRows = MAX_SQL_ROWS;

        int cont_idx = 1;
        while ( cont_idx ) {
            int status = rcGenQuery(
                             comm,
                             &gen_inp,
                             &gen_out );
            if ( status < 0 ) {
                rcDisconnect( comm );
                freeGenQueryOut( &gen_out );
                clearGenQueryInp( &gen_inp );
                return ERROR(
                           status,
                           "genQuery failed." );

            } // if

            sqlResult_t* resc_loc = getSqlResultByInx(
                                        gen_out,
                                        COL_R_LOC );
            if ( !resc_loc ) {
                rcDisconnect( comm );
                freeGenQueryOut( &gen_out );
                clearGenQueryInp( &gen_inp );
                return ERROR(
                           UNMATCHED_KEY_OR_INDEX,
                           "getSqlResultByInx for COL_R_LOC failed" );
            }

            for ( int i = 0;
                    i < gen_out->rowCnt;
                    ++i ) {
                const std::string hn( &resc_loc->value[ resc_loc->len * i ] );
                if ( "localhost"    != hn ) {
                    _host_names.push_back( hn );

                }

            } // for i

            cont_idx = gen_out->continueInx;

        } // while

        freeGenQueryOut( &gen_out );
        clearGenQueryInp( &gen_inp );

        status = rcDisconnect( comm );
        if ( status < 0 ) {
            return ERROR(
                       status,
                       "failed in rcDisconnect" );
        }

        return SUCCESS();

    } // get_resource_host_names
Ejemplo n.º 4
0
    error server_control_executor::extract_command_parameters(
        const control_plane_command& _cmd,
        std::string&                 _name,
        std::string&                 _option,
        std::string&                 _wait_option,
        size_t&                      _wait_seconds,
        host_list_t&                 _hosts ) {
        // capture and validate the command parameter
        _name = _cmd.command;
        if ( SERVER_CONTROL_SHUTDOWN != _name &&
                SERVER_CONTROL_PAUSE    != _name &&
                SERVER_CONTROL_RESUME   != _name &&
                SERVER_CONTROL_STATUS   != _name ) {
            std::string msg( "invalid command [" );
            msg += _name;
            msg += "]";
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       msg );
        }

        // capture and validate the option parameter
        std::map<std::string, std::string>::const_iterator itr =
            _cmd.options.find( SERVER_CONTROL_OPTION_KW );
        if ( _cmd.options.end() == itr ) {
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       "option parameter is empty" );

        }

        _option = itr->second;
        if ( SERVER_CONTROL_ALL_OPT   != _option &&
                SERVER_CONTROL_HOSTS_OPT != _option ) {
            std::string msg( "invalid command option [" );
            msg += _option;
            msg += "]";
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       msg );
        }

        // capture and validate the server hosts, skip the option key
        for ( itr  = _cmd.options.begin();
                itr != _cmd.options.end();
                ++itr ) {
            if ( itr->first == SERVER_CONTROL_OPTION_KW ) {
                continue;

            }
            else if ( itr->first == SERVER_CONTROL_FORCE_AFTER_KW ) {
                _wait_option = SERVER_CONTROL_FORCE_AFTER_KW;
                _wait_seconds = boost::lexical_cast< size_t >( itr->second );

            }
            else if ( itr->first == SERVER_CONTROL_WAIT_FOREVER_KW ) {
                _wait_option = SERVER_CONTROL_WAIT_FOREVER_KW;
                _wait_seconds = 0;

            }
            else if ( itr->first.find(
                          SERVER_CONTROL_HOST_KW )
                      != std::string::npos ) {
                _hosts.push_back( itr->second );

            }
            else {
                std::string msg( "invalid option key [" );
                msg += itr->first;
                msg += "]";
                return ERROR(
                           SYS_INVALID_INPUT_PARAM,
                           msg );

            }

        } // for itr

        return SUCCESS();

    } // extract_command_parameters