// get overall queue where project will be queued
private OverallBuildQueue getOverallBuildQueue( int projectId, int typeOfQueue, List<BuildQueue> buildQueues )
throws BuildManagerException
{
OverallBuildQueue whereToBeQueued = null;
synchronized ( overallBuildQueues )
{
if ( overallBuildQueues == null || overallBuildQueues.isEmpty() )
{
throw new BuildManagerException( "No build queues configured." );
}
int size = 0;
int idx = 0;
int allowedBuilds = configurationService.getNumberOfBuildsInParallel();
try
{
int count = 1;
for ( BuildQueue buildQueue : buildQueues )
{
if( count <= allowedBuilds )
{
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( buildQueue.getId() );
if ( overallBuildQueue != null )
{
TaskQueue taskQueue = null;
if ( typeOfQueue == BUILD_QUEUE )
{
taskQueue = overallBuildQueue.getBuildQueue();
}
else if ( typeOfQueue == CHECKOUT_QUEUE )
{
taskQueue = overallBuildQueue.getCheckoutQueue();
}
if ( idx == 0 )
{
size = taskQueue.getQueueSnapshot().size();
whereToBeQueued = overallBuildQueue;
}
if ( taskQueue.getQueueSnapshot().size() < size )
{
whereToBeQueued = overallBuildQueue;
size = taskQueue.getQueueSnapshot().size();
}
idx++;
}
else
{
log.error( "Build queue not found." );
}
count++;
}
else
{
break;
}
}
}
catch ( TaskQueueException e )
{
throw new BuildManagerException( "Error occurred while retrieving task quueue: " + e.getMessage() );
}
}
// use default overall build queue if none is configured
if ( whereToBeQueued == null )
{
Set<Integer> keySet = overallBuildQueues.keySet();
for( Integer key : keySet )
{
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
if( overallBuildQueue.getName().equals( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) )
{
return overallBuildQueue;
}
}
}