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());
 }
 int32_t deregisterService(const std::string& host, const int32_t port) {
   // Your implementation goes here
   printf("deregisterService\n");
   pair<string,int> host_tuple(host,port);
   host_list_t::iterator it = host_list.begin();
   while(it!=host_list.end()){
     thrift_container_t container = *it;
     if(container.host.compare(host)==0 && container.port==port){
       printf("Found a matching entry\n");
       it = host_list.erase(it);
     }else{
       ++it;
     }
   }
   printf("There are now %u workers\n",(uint)host_list.size());
 }
Ejemplo n.º 3
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
  void findMatches(std::vector<std::string> & _return, const std::string& key) {
    // Your implementation goes here
    printf("findMatches\n");
    if(service_type ==  TYPE_SLAVE){
      search.find_path(key,_return);
      for(int i=0;i<_return.size();++i){
        _return[i] = search.extract_row(_return[i]);
      }
    }else{
      if(host_list.size()>0){
        _return.clear();
        list<delegator_t *> delegator_list;
        for(host_list_t::iterator it = host_list.begin();it!=host_list.end();++it){
          thrift_container_t container = *it;
          delegator_t * delegator = new delegator_t(container,key);
          delegator_list.push_back(delegator);
        }
        findMatchesThreaded(_return,key,delegator_list);
        for(list<delegator_t *>::iterator it = delegator_list.begin();
        it!=delegator_list.end();++it){
          delegator_t * delegator = *it;
          for(vector<string>::iterator it = delegator->matches.begin();
          it!=delegator->matches.end();++it){
             _return.push_back(*it);
          }
          delete(delegator);
//          try {
//            printf("Trying host %s port %d\n",container.host.data(),container.port);
//            container.transport->open();
//            vector<string> matches;
//            container.client->findMatches(matches,key);
//            container.transport->close();
//            for(vector<string>::iterator it = matches.begin();it!=matches.end();++it){
//              _return.push_back(*it);
//            }
//          }catch(TException & tx){
//            cout<<"ERROR: "<<tx.what()<<endl;
//          }
        }
      }
    }
  }
Ejemplo n.º 5
0
    error server_control_executor::process_host_list(
        const std::string& _cmd_name,
        const std::string& _wait_option,
        const size_t&      _wait_seconds,
        const host_list_t& _hosts,
        std::string&       _output ) {
        if ( _hosts.empty() ) {
            return SUCCESS();

        }

        error fwd_err = SUCCESS();
        host_list_t::const_iterator itr;
        for ( itr  = _hosts.begin();
                itr != _hosts.end();
                ++itr ) {
            if ( "localhost" == *itr ) {
                continue;

            }

            std::string output;
            if ( compare_host_names(
                        *itr,
                        my_host_name_ ) ) {
                error ret = op_map_[ _cmd_name ](
                                _wait_option,
                                _wait_seconds,
                                output );
                if ( !ret.ok() ) {
                    fwd_err = PASS( ret );

                }

                _output += output;

            }
            else {
                error ret = forward_command(
                                _cmd_name,
                                *itr,
                                port_prop_,
                                _wait_option,
                                _wait_seconds,
                                output );
                if ( !ret.ok() ) {
                    log( PASS( ret ) );
                    fwd_err = PASS( ret );

                }
                else {
                    _output += output;

                }

            }

        } // for itr

        return fwd_err;

    } // process_host_list