// get overall queue where project will be queued
private OverallBuildQueue getOverallBuildQueue( 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;
TaskQueueExecutor taskQueueExecutor = null;
int tempSize = 0;
if ( typeOfQueue == BUILD_QUEUE )
{
taskQueue = overallBuildQueue.getBuildQueue();
taskQueueExecutor = overallBuildQueue.getBuildTaskQueueExecutor();
}
else if ( typeOfQueue == CHECKOUT_QUEUE )
{
taskQueue = overallBuildQueue.getCheckoutQueue();
taskQueueExecutor = overallBuildQueue.getCheckoutTaskQueueExecutor();
}
else if ( typeOfQueue == PREPARE_BUILD_QUEUE )
{
taskQueue = overallBuildQueue.getPrepareBuildQueue();
taskQueueExecutor = overallBuildQueue.getPrepareBuildTaskQueueExecutor();
}
tempSize = taskQueue.getQueueSnapshot().size();
if ( taskQueueExecutor.getCurrentTask() != null )
{
tempSize++;
}
if ( idx == 0 )
{
whereToBeQueued = overallBuildQueue;
size = tempSize;
}
if ( tempSize < size )
{
whereToBeQueued = overallBuildQueue;
size = tempSize;
}
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;
}
}
}