Exemple #1
0
static void remove_from_list(HostList& hl, HostPList& ht) 
{
    for(HostList_iter hl_iter = hl.begin(); hl_iter != hl.end(); hl_iter++) 
	if(contains(ht, &(*hl_iter)))
	    hl_iter->unused = true;
	
}
void
ConnectionPool::setup_broker_connection(const HostList &brokers) throw(KafkaError) {
    boost::mutex::scoped_lock lock(m_data->m_sockets_mutex);
    for(HostList::const_iterator host = brokers.begin(); host != brokers.end(); ++host ){
        std::ostringstream sout;
        sout<<(*host)->port();
        boost::asio::ip::tcp::resolver::query query(
                                (*host)->host(), sout.str().c_str(),
                                boost::asio::ip::resolver_query_base::numeric_service);
        boost::asio::ip::tcp::resolver resolver(m_io_service);
        boost::system::error_code error = boost::asio::error::host_not_found;
        for(boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);
                            i != boost::asio::ip::tcp::resolver::iterator(); ++i) {
            boost::asio::ip::tcp::endpoint end = *i;
            m_meta_channel = Socket( new boost::asio::ip::tcp::socket(m_io_service) );
            m_meta_channel->connect(end, error);
            if(!error) {
                //std::cout<<"BROKER CONNECTION INITIALIZED"<<std::endl;
                break; //Connection established
            }
        }
        if(error) {
            //TODO::Error?
        }
    }
}
HostList StorageList::createHostList(std::string controllerName) {
    HostList l;
    for (HostStorageVector::iterator it = hosts.begin(); it != hosts.end(); it++) {
        HostStorage* s = (HostStorage*) *it;
        if (s->isConnected()) {
            l.addHost(s->getName());
        }
    }
    return l;
}
void ControllerStorageReceiver::setHostName(std::string hostName) {
    HostList ls = StorageList::createHostList(storage->getName());
    if (!hostName.empty() && std::find(ls.getHosts().begin(), ls.getHosts().end(), hostName) != ls.getHosts().end()) {
        HostStorage* store = (HostStorage*) StorageList::findHostStorageByName(hostName);
        storage->setHostStorage(store);
        ControllerData dat = storage->createControllerData();
        storage->sendMessage(&dat);
    }
    if (hostName.empty()) {
        if (storage->getHostStorage() && storage == ((HostStorage*)storage->getHostStorage())->getOwner()) {
            setWantControl(false, false);
        }
        storage->setHostStorage(NULL);
        storage->sendMessage(&ls);
    }
}
Exemple #5
0
HostClass* get_hostclass(const string& ip, int firstnode) 
{
    if(HostClass* hc = find_host(hostlist, ip)) 
	return hc;

    HostClass hc(ip, firstnode);
    hostlist.push_back(hc);

    return find_host(hostlist, ip);
}
Exemple #6
0
/**
 * 保持中のホストリストからグループリストを取得する。
 * @retval グループリスト
 */
std::vector<GroupItem>
HostList::GetGroupList()
{
	IPMSG_FUNC_ENTER( "std::vector<GroupItem> HostList::GetGroupList()" );
	std::vector<GroupItem> ret;
	HostList tmp = *this;
	tmp.sort( new IpMsgGetGroupListComparator() );
	std::string hostName = "", encodingName = "";
	for( std::vector<HostListItem>::iterator ixhost = tmp.begin(); ixhost != tmp.end(); ixhost++ ) {
		if ( hostName != ixhost->HostName() || encodingName != ixhost->EncodingName() ){
			GroupItem item;
			item.setGroupName( ixhost->GroupName() );
			item.setEncodingName( ixhost->EncodingName() );
			ret.push_back( item );
		}
		hostName = ixhost->HostName();
		encodingName = ixhost->EncodingName();
	}
	IPMSG_FUNC_RETURN( ret );
}
Exemple #7
0
string create_unknown_node(const string& prev_node) 
{
    static HostClass* prev_res = 0;

    if(prev_res && prev_res->ip == prev_node) {
	
	prev_res->unknown_hosts++;
	return prev_node;
    }
    
    HostClass hu;
    hostlist.push_back(hu);

    prev_res = find_host(hostlist, hu.ip);
    if(!prev_res)
	cout << "BIGMISTAKE" << endl;

    return hu.name();
}
bool Mapping::map( bool forceUnmount, QString * errMsg )
{
	Host h = host();
	LOG_5( "Mapping::map" );
	// If there is a group of hosts, pick the one with the lowest load
	if( !h.isRecord() ) {
		
		HostList hl = hostMappings().hosts();
		LOG_5( "Got " + QString::number( hl.size() ) + " hosts for this mapping" );
		hl.reload();
		LOG_5( "Got " + QString::number( hl.size() ) + " hosts after reload" );
		hl = hl.filter( "online", 1 );
		LOG_5( "Got " + QString::number( hl.size() ) + " hosts after online filter" );
		float bestLoad = std::numeric_limits<double>::max();
		foreach( Host hit, hl ) {
			HostLoad hl = hit.hostLoad();
			float computedAvg = hl.loadAvg() + hl.loadAvgAdjust(); 
			LOG_5( "Checking host " + hit.name() + "  Load: " + QString::number( computedAvg ) + " Online: " + QString::number(hit.online()) );
			if( hit.online() && computedAvg < bestLoad ) {
				bestLoad = computedAvg;
				h = hit;
			}
		}
JobAssignmentList Host::activeAssignments(HostList hosts)
{
	return JobAssignment::select( QString("WHERE fkeyhost IN (%1) AND fkeyjobassignmentstatus IN (SELECT keyjobassignmentstatus FROM jobassignmentstatus WHERE status IN ('ready','copy','busy'))").arg(hosts.keyString()) );
}