checkManageQueuesAuthorization();
try
{
if ( continuum.getConfiguration().isDistributedBuildEnabled() )
{
DistributedBuildManager dbm = continuum.getDistributedBuildManager();
String buildAgentUrl = dbm.getBuildAgentUrl( projectId, buildDefinitionId );
if ( dbm.isProjectInAnyPrepareBuildQueue( projectId, buildDefinitionId ) )
{
if ( buildAgentUrl != null )
{
org.apache.continuum.model.project.ProjectScmRoot scmRoot =
continuum.getProjectScmRootByProject( projectId );
dbm.removeFromPrepareBuildQueue( buildAgentUrl, scmRoot.getProjectGroup().getId(),
scmRoot.getId() );
}
}
// wait if already preparing
else if ( dbm.isProjectCurrentlyPreparingBuild( projectId, buildDefinitionId ) )
{
while ( dbm.isProjectCurrentlyPreparingBuild( projectId, buildDefinitionId ) )
{
try
{
Thread.sleep( 1000 );
}
catch ( InterruptedException e )
{
// do nothing
}
}
}
if ( dbm.isProjectInAnyBuildQueue( projectId, buildDefinitionId ) )
{
dbm.removeFromBuildQueue( buildAgentUrl, projectId, buildDefinitionId );
}
else if ( dbm.isProjectCurrentlyBuilding( projectId, buildDefinitionId ) )
{
if ( buildAgentUrl != null )
{
dbm.cancelDistributedBuild( buildAgentUrl );
}
}
return true;
}