Example #1
0
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;
			}
		}