You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ev...@apache.org on 2009/03/09 23:02:36 UTC
svn commit: r751864 [3/4] - in /continuum/trunk:
continuum-api/src/main/java/org/apache/continuum/dao/
continuum-api/src/main/java/org/apache/continuum/taskqueue/
continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/
continuum-api/src/mai...
Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java?rev=751864&r1=751863&r2=751864&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java (original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java Mon Mar 9 22:02:34 2009
@@ -59,12 +59,12 @@
import org.slf4j.LoggerFactory;
/**
- * Parallel builds manager.
- *
+ * Parallel builds manager.
+ *
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version $Id$
*/
-public class ParallelBuildsManager
+public class ParallelBuildsManager
implements BuildsManager, Contextualizable
{
private Logger log = LoggerFactory.getLogger( ParallelBuildsManager.class );
@@ -84,16 +84,17 @@
@Resource
private ConfigurationService configurationService;
-
+
@Resource
private BuildQueueService buildQueueService;
private PlexusContainer container;
-
+
/**
* @see BuildsManager#buildProject(int, BuildDefinition, String, int, ScmResult)
*/
- public void buildProject( int projectId, BuildDefinition buildDefinition, String projectName, int trigger, ScmResult scmResult )
+ public void buildProject( int projectId, BuildDefinition buildDefinition, String projectName, int trigger,
+ ScmResult scmResult )
throws BuildManagerException
{
try
@@ -106,10 +107,10 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while checking if the project is already in queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while checking if the project is already in queue: " + e.getMessage() );
}
-
+
OverallBuildQueue overallBuildQueue =
getOverallBuildQueue( projectId, BUILD_QUEUE, buildDefinition.getSchedule().getBuildQueues() );
@@ -120,10 +121,12 @@
}
Task buildTask =
- new BuildProjectTask( projectId, buildDefinition.getId(), trigger, projectName, buildDefinitionLabel, scmResult );
+ new BuildProjectTask( projectId, buildDefinition.getId(), trigger, projectName, buildDefinitionLabel,
+ scmResult );
try
{
- log.info( "Project '" + projectName + "' added to overall build queue '" + overallBuildQueue.getName() + "'." );
+ log.info(
+ "Project '" + projectName + "' added to overall build queue '" + overallBuildQueue.getName() + "'." );
overallBuildQueue.addToBuildQueue( buildTask );
}
catch ( TaskQueueException e )
@@ -160,17 +163,18 @@
if ( firstProjectId != 0 )
{
- BuildDefinition buildDef = projectsBuildDefinitionsMap.get( firstProjectId );
+ BuildDefinition buildDef = projectsBuildDefinitionsMap.get( firstProjectId );
OverallBuildQueue overallBuildQueue =
getOverallBuildQueue( firstProjectId, BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
if ( overallBuildQueue != null )
- {
+ {
for ( Project project : projects )
{
try
{
- if ( isInQueue( project.getId(), BUILD_QUEUE, projectsBuildDefinitionsMap.get( project.getId() ).getId() ) )
+ if ( isInQueue( project.getId(), BUILD_QUEUE,
+ projectsBuildDefinitionsMap.get( project.getId() ).getId() ) )
{
log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
"' is already in build queue." );
@@ -200,13 +204,13 @@
{
log.info( "Project '" + project.getId() + "' - '" + project.getName() +
"' added to overall build queue '" + overallBuildQueue.getName() + "'." );
-
+
overallBuildQueue.addToBuildQueue( buildTask );
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while adding project to build queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while adding project to build queue: " + e.getMessage() );
}
}
}
@@ -226,7 +230,7 @@
{
synchronized ( overallBuildQueues )
{
- OverallBuildQueue overallBuildQueue = null;
+ OverallBuildQueue overallBuildQueue = null;
overallBuildQueue = overallBuildQueues.get( buildQueueId );
if ( overallBuildQueue != null )
{
@@ -296,14 +300,15 @@
}
else
{
- synchronized( overallBuildQueues )
+ synchronized ( overallBuildQueues )
{
Set<Integer> keySet = overallBuildQueues.keySet();
- for( Integer key : keySet )
+ for ( Integer key : keySet )
{
overallBuildQueue = overallBuildQueues.get( key );
- BuildProjectTask buildTask = (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
- if( buildTask != null && buildTask.getProjectId() == projectId )
+ BuildProjectTask buildTask =
+ (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
+ if ( buildTask != null && buildTask.getProjectId() == projectId )
{
overallBuildQueue.cancelBuildTask( projectId );
return true;
@@ -317,7 +322,7 @@
{
throw new BuildManagerException( "Error occurred while cancelling build: " + e.getMessage() );
}
-
+
return true;
}
@@ -336,14 +341,15 @@
}
else
{
- synchronized( overallBuildQueues )
+ synchronized ( overallBuildQueues )
{
Set<Integer> keySet = overallBuildQueues.keySet();
- for( Integer key : keySet )
+ for ( Integer key : keySet )
{
overallBuildQueue = overallBuildQueues.get( key );
- CheckOutTask checkoutTask = (CheckOutTask) overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask();
- if( checkoutTask != null && checkoutTask.getProjectId() == projectId )
+ CheckOutTask checkoutTask =
+ (CheckOutTask) overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask();
+ if ( checkoutTask != null && checkoutTask.getProjectId() == projectId )
{
overallBuildQueue.cancelCheckoutTask( projectId );
return true;
@@ -378,8 +384,8 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while checking if the project is already in queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while checking if the project is already in queue: " + e.getMessage() );
}
OverallBuildQueue overallBuildQueue =
@@ -388,19 +394,22 @@
new CheckOutTask( projectId, workingDirectory, projectName, scmUsername, scmPassword );
try
{
- if( overallBuildQueue != null )
+ if ( overallBuildQueue != null )
{
- log.info( "Project '" + projectName + "' added to overall build queue '" + overallBuildQueue.getName() + "'." );
+ log.info( "Project '" + projectName + "' added to overall build queue '" + overallBuildQueue.getName() +
+ "'." );
overallBuildQueue.addToCheckoutQueue( checkoutTask );
}
else
{
- throw new BuildManagerException( "Unable to add project to checkout queue. No overall build queue configured." );
+ throw new BuildManagerException(
+ "Unable to add project to checkout queue. No overall build queue configured." );
}
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while adding project to checkout queue: " + e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while adding project to checkout queue: " + e.getMessage() );
}
}
@@ -457,15 +466,15 @@
*/
public boolean isAnyProjectCurrentlyBeingCheckedOut( int[] projectIds )
throws BuildManagerException
- {
- for( int i = 0; i < projectIds.length; i++ )
+ {
+ for ( int projectId : projectIds )
{
Map<String, Task> checkouts = getCurrentCheckouts();
Set<String> keySet = checkouts.keySet();
- for( String key : keySet )
+ for ( String key : keySet )
{
CheckOutTask task = (CheckOutTask) checkouts.get( key );
- if( task.getProjectId() == projectIds[i] )
+ if ( task.getProjectId() == projectId )
{
return true;
}
@@ -473,6 +482,7 @@
}
return false;
}
+
/**
* @see BuildsManager#isInPrepareBuildQueue(int)
*/
@@ -514,14 +524,15 @@
public boolean isProjectInAnyCurrentBuild( int projectId )
throws BuildManagerException
{
- synchronized( overallBuildQueues )
+ synchronized ( overallBuildQueues )
{
Set<Integer> keys = overallBuildQueues.keySet();
- for( Integer key : keys )
+ for ( Integer key : keys )
{
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
- BuildProjectTask task = (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
- if( task != null && task.getProjectId() == projectId )
+ BuildProjectTask task =
+ (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
+ if ( task != null && task.getProjectId() == projectId )
{
return true;
}
@@ -533,21 +544,24 @@
/**
* @see BuildsManager#prepareBuildProjects(Map, int, int, String, String, int)
*/
- public void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, int trigger, int projectGroupId, String projectGroupName, String scmRootAddress, int scmRootId )
+ public void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, int trigger,
+ int projectGroupId, String projectGroupName, String scmRootAddress,
+ int scmRootId )
throws BuildManagerException
{
try
- {
+ {
PrepareBuildProjectsTask task =
- new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, trigger, projectGroupId, projectGroupName, scmRootAddress, scmRootId );
-
+ new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, trigger, projectGroupId, projectGroupName,
+ scmRootAddress, scmRootId );
+
log.info( "Queueing prepare-build-project task '" + task + "' to prepare-build queue." );
prepareBuildQueue.put( task );
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while creating prepare-build-project task: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while creating prepare-build-project task: " + e.getMessage() );
}
}
@@ -571,8 +585,8 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while removing project from build queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while removing project from build queue: " + e.getMessage() );
}
}
@@ -596,8 +610,8 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while removing project from build queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while removing project from build queue: " + e.getMessage() );
}
}
@@ -621,8 +635,8 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while removing project from checkout queue: " +
- e.getMessage() );
+ throw new BuildManagerException(
+ "Error occurred while removing project from checkout queue: " + e.getMessage() );
}
}
@@ -631,25 +645,25 @@
*/
public void removeProjectsFromBuildQueue( int[] projectIds )
{
- for ( int i = 0; i < projectIds.length; i++ )
+ for ( int projectId : projectIds )
{
try
{
- OverallBuildQueue overallBuildQueue =
- getOverallBuildQueueWhereProjectIsQueued( projectIds[i], BUILD_QUEUE );
+ OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectIsQueued( projectId, BUILD_QUEUE )
+ ;
if ( overallBuildQueue != null )
{
- overallBuildQueue.removeProjectFromBuildQueue( projectIds[i] );
+ overallBuildQueue.removeProjectFromBuildQueue( projectId );
}
else
{
- log.error( "Project '" + projectIds[i] + "' not found in any of the build queues." );
+ log.error( "Project '" + projectId + "' not found in any of the build queues." );
continue;
}
}
catch ( TaskQueueException e )
{
- log.error( "Error occurred while removing project '" + projectIds[i] + "' from build queue." );
+ log.error( "Error occurred while removing project '" + projectId + "' from build queue." );
continue;
}
}
@@ -660,25 +674,25 @@
*/
public void removeProjectsFromCheckoutQueue( int[] projectIds )
{
- for ( int i = 0; i < projectIds.length; i++ )
+ for ( int projectId : projectIds )
{
try
{
OverallBuildQueue overallBuildQueue =
- getOverallBuildQueueWhereProjectIsQueued( projectIds[i], CHECKOUT_QUEUE );
+ getOverallBuildQueueWhereProjectIsQueued( projectId, CHECKOUT_QUEUE );
if ( overallBuildQueue != null )
{
- overallBuildQueue.removeProjectFromCheckoutQueue( projectIds[i] );
+ overallBuildQueue.removeProjectFromCheckoutQueue( projectId );
}
else
{
- log.error( "Project '" + projectIds[i] + "' not found in any of the checkout queues." );
+ log.error( "Project '" + projectId + "' not found in any of the checkout queues." );
continue;
}
}
catch ( TaskQueueException e )
{
- log.error( "Error occurred while removing project '" + projectIds[i] + "' from checkout queue." );
+ log.error( "Error occurred while removing project '" + projectId + "' from checkout queue." );
continue;
}
}
@@ -698,7 +712,7 @@
for ( Integer key : keySet )
{
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
- overallBuildQueue.removeTasksFromCheckoutQueueWithHashCodes( hashcodes );
+ overallBuildQueue.removeTasksFromCheckoutQueueWithHashCodes( hashcodes );
}
}
}
@@ -731,7 +745,7 @@
throw new BuildManagerException( "Error encountered while removing project(s) from build queue.", e );
}
}
-
+
public boolean removeProjectGroupFromPrepareBuildQueue( int projectGroupId, String scmRootAddress )
throws BuildManagerException
{
@@ -754,7 +768,7 @@
throw new BuildManagerException( "Error while getting the prepare build projects task in queue", e );
}
}
-
+
/**
* @see BuildsManager#addOverallBuildQueue(BuildQueue)
*/
@@ -768,7 +782,7 @@
OverallBuildQueue overallBuildQueue = (OverallBuildQueue) container.lookup( OverallBuildQueue.class );
overallBuildQueue.setId( buildQueue.getId() );
overallBuildQueue.setName( buildQueue.getName() );
-
+
if ( overallBuildQueues.get( buildQueue.getId() ) == null )
{
log.info( "Adding overall build queue to map : " + overallBuildQueue.getName() );
@@ -780,7 +794,7 @@
}
}
catch ( ComponentLookupException e )
- {
+ {
throw new BuildManagerException( "Error creating overall build queue.", e );
}
}
@@ -796,7 +810,7 @@
List<CheckOutTask> checkoutTasks = null;
synchronized ( overallBuildQueues )
- {
+ {
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( overallBuildQueueId );
if ( overallBuildQueue.getName().equals( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) )
{
@@ -805,8 +819,8 @@
try
{
- if( overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask() != null ||
- overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask() != null )
+ if ( overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask() != null ||
+ overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask() != null )
{
throw new BuildManagerException( "Cannot remove build queue. A task is currently executing." );
}
@@ -824,34 +838,32 @@
catch ( TaskQueueException e )
{
throw new BuildManagerException(
- "Cannot remove build queue. An error occurred while retrieving queued tasks." );
+ "Cannot remove build queue. An error occurred while retrieving queued tasks." );
}
catch ( ComponentLifecycleException e )
{
throw new BuildManagerException(
- "Cannot remove build queue. An error occurred while destroying the build queue: " +
- e.getMessage() );
+ "Cannot remove build queue. An error occurred while destroying the build queue: " +
+ e.getMessage() );
}
catch ( StoppingException e )
{
throw new BuildManagerException(
- "Cannot remove build queue. An error occurred while stopping the build queue: " +
- e.getMessage() );
+ "Cannot remove build queue. An error occurred while stopping the build queue: " + e.getMessage() );
}
this.overallBuildQueues.remove( overallBuildQueueId );
log.info( "Removed overall build queue '" + overallBuildQueueId + "' from build queues map." );
}
-
for ( Task task : tasks )
- {
+ {
BuildProjectTask buildTask = (BuildProjectTask) task;
try
{
BuildDefinition buildDefinition =
buildDefinitionDao.getBuildDefinition( buildTask.getBuildDefinitionId() );
-
+
buildProject( buildTask.getProjectId(), buildDefinition, buildTask.getProjectName(),
buildTask.getTrigger(), buildTask.getScmResult() );
}
@@ -868,14 +880,14 @@
{
BuildDefinition buildDefinition = buildDefinitionDao.getDefaultBuildDefinition( task.getProjectId() );
checkoutProject( task.getProjectId(), task.getProjectName(), task.getWorkingDirectory(),
- task.getScmUserName(), task.getScmPassword(), buildDefinition );
+ task.getScmUserName(), task.getScmPassword(), buildDefinition );
}
catch ( ContinuumStoreException e )
{
log.error( "Unable to queue checkout task for project '" + task.getProjectName() + "'" );
continue;
}
- }
+ }
}
public Map<Integer, OverallBuildQueue> getOverallBuildQueues()
@@ -889,19 +901,19 @@
public Map<String, Task> getCurrentBuilds()
throws BuildManagerException
{
- synchronized( overallBuildQueues )
+ synchronized ( overallBuildQueues )
{
- Map<String, Task> currentBuilds = new HashMap<String, Task>();
+ Map<String, Task> currentBuilds = new HashMap<String, Task>();
Set<Integer> keys = overallBuildQueues.keySet();
- for( Integer key : keys )
+ for ( Integer key : keys )
{
- OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+ OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
Task task = overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
- if( task != null )
+ if ( task != null )
{
currentBuilds.put( overallBuildQueue.getName(), task );
- }
- }
+ }
+ }
return currentBuilds;
}
}
@@ -912,20 +924,20 @@
public Map<String, Task> getCurrentCheckouts()
throws BuildManagerException
{
- synchronized( overallBuildQueues )
+ synchronized ( overallBuildQueues )
{
Map<String, Task> currentCheckouts = new HashMap<String, Task>();
Set<Integer> keys = overallBuildQueues.keySet();
- for( Integer key : keys )
+ for ( Integer key : keys )
{
- OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+ OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
Task task = overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask();
- if( task != null )
+ if ( task != null )
{
currentCheckouts.put( overallBuildQueue.getName(), task );
- }
- }
- return currentCheckouts;
+ }
+ }
+ return currentCheckouts;
}
}
@@ -948,8 +960,9 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while getting projects in build queue '" +
- overallBuildQueue.getName() + "'.", e );
+ throw new BuildManagerException(
+ "Error occurred while getting projects in build queue '" + overallBuildQueue.getName() + "'.",
+ e );
}
}
return queuedBuilds;
@@ -975,24 +988,27 @@
}
catch ( TaskQueueException e )
{
- throw new BuildManagerException( "Error occurred while getting projects in build queue '" +
- overallBuildQueue.getName() + "'.", e );
+ throw new BuildManagerException(
+ "Error occurred while getting projects in build queue '" + overallBuildQueue.getName() + "'.",
+ e );
}
}
return queuedCheckouts;
}
}
-
+
/**
* @see BuildsManager#cancelAllPrepareBuilds()
*/
- public boolean cancelAllPrepareBuilds() throws BuildManagerException
+ public boolean cancelAllPrepareBuilds()
+ throws BuildManagerException
{
try
{
- TaskQueueExecutor executor = ( TaskQueueExecutor ) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
- Task task = executor.getCurrentTask();
- if( task != null )
+ TaskQueueExecutor executor =
+ (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
+ Task task = executor.getCurrentTask();
+ if ( task != null )
{
executor.cancelTask( task );
}
@@ -1001,7 +1017,7 @@
{
throw new BuildManagerException( "Error looking up prepare-build-queue.", e );
}
-
+
return false;
}
@@ -1009,14 +1025,14 @@
* @see BuildsManager#isBuildInProgress()
*/
public boolean isBuildInProgress()
- {
- synchronized( overallBuildQueues )
+ {
+ synchronized ( overallBuildQueues )
{
Set<Integer> keySet = overallBuildQueues.keySet();
- for( Integer key : keySet )
+ for ( Integer key : keySet )
{
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
- if( overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask() != null )
+ if ( overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask() != null )
{
return true;
}
@@ -1111,16 +1127,16 @@
}
int size = 0;
- int idx = 0;
+ int idx = 0;
int allowedBuilds = configurationService.getNumberOfBuildsInParallel();
-
+
try
{
int count = 1;
for ( BuildQueue buildQueue : buildQueues )
- {
- if( count <= allowedBuilds )
- {
+ {
+ if ( count <= allowedBuilds )
+ {
OverallBuildQueue overallBuildQueue = overallBuildQueues.get( buildQueue.getId() );
if ( overallBuildQueue != null )
{
@@ -1133,31 +1149,31 @@
{
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." );
+ log.error( "Build queue not found." );
}
count++;
}
else
{
break;
- }
+ }
}
}
catch ( TaskQueueException e )
@@ -1168,12 +1184,12 @@
// use default overall build queue if none is configured
if ( whereToBeQueued == null )
- {
+ {
Set<Integer> keySet = overallBuildQueues.keySet();
- for( Integer key : keySet )
+ for ( Integer key : keySet )
{
- OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
- if( overallBuildQueue.getName().equals( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) )
+ OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+ if ( overallBuildQueue.getName().equals( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) )
{
return overallBuildQueue;
}
@@ -1182,26 +1198,26 @@
return whereToBeQueued;
}
-
+
public void contextualize( Context context )
throws ContextException
{
- container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-
+ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+
synchronized ( overallBuildQueues )
{
try
{
// create all the build queues configured in the database, not just the default!
List<BuildQueue> buildQueues = buildQueueService.getAllBuildQueues();
- for( BuildQueue buildQueue : buildQueues )
- {
+ for ( BuildQueue buildQueue : buildQueues )
+ {
createOverallBuildQueue( buildQueue );
- }
+ }
// add default overall build queue if not yet added to the map
BuildQueue defaultBuildQueue = configurationService.getDefaultBuildQueue();
- if( overallBuildQueues.get( defaultBuildQueue.getId() ) == null )
+ if ( overallBuildQueues.get( defaultBuildQueue.getId() ) == null )
{
createOverallBuildQueue( defaultBuildQueue );
}
@@ -1221,32 +1237,31 @@
{
this.container = container;
}
-
+
private OverallBuildQueue createOverallBuildQueue( BuildQueue defaultBuildQueue )
throws ComponentLookupException
{
- OverallBuildQueue overallBuildQueue =
- (OverallBuildQueue) container.lookup( OverallBuildQueue.class );
+ OverallBuildQueue overallBuildQueue = (OverallBuildQueue) container.lookup( OverallBuildQueue.class );
overallBuildQueue.setId( defaultBuildQueue.getId() );
overallBuildQueue.setName( defaultBuildQueue.getName() );
-
+
overallBuildQueues.put( overallBuildQueue.getId(), overallBuildQueue );
-
+
return overallBuildQueue;
}
-
+
public TaskQueue getPrepareBuildQueue()
{
return prepareBuildQueue;
}
-
+
public void setPrepareBuildQueue( TaskQueue prepareBuildQueue )
{
this.prepareBuildQueue = prepareBuildQueue;
}
-
+
// for unit tests..
-
+
public void setOverallBuildQueues( Map<Integer, OverallBuildQueue> overallBuildQueues )
{
this.overallBuildQueues = overallBuildQueues;
@@ -1261,7 +1276,7 @@
{
this.buildQueueService = buildQueueService;
}
-
+
public void setBuildDefinitionDao( BuildDefinitionDao buildDefinitionDao )
{
this.buildDefinitionDao = buildDefinitionDao;
Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java?rev=751864&r1=751863&r2=751864&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java (original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java Mon Mar 9 22:02:34 2009
@@ -41,26 +41,26 @@
/**
* "Overall" build queue which has a checkout queue and a build queue.
- *
+ *
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version $Id$
*/
-public class DefaultOverallBuildQueue
+public class DefaultOverallBuildQueue
implements OverallBuildQueue
{
@Resource
private BuildDefinitionDao buildDefinitionDao;
-
+
private TaskQueueExecutor buildTaskQueueExecutor;
-
+
private TaskQueueExecutor checkoutTaskQueueExecutor;
private int id;
private String name;
-
+
private Logger log = LoggerFactory.getLogger( DefaultOverallBuildQueue.class );
-
+
public int getId()
{
return id;
@@ -175,11 +175,7 @@
}
}
}
- if ( !tasks.isEmpty() )
- {
- return getCheckoutQueue().removeAll( tasks );
- }
- return false;
+ return !tasks.isEmpty() && getCheckoutQueue().removeAll( tasks );
}
/**
@@ -244,7 +240,7 @@
public boolean isInBuildQueue( int projectId, int buildDefinitionId )
throws TaskQueueException
{
- List<Task> queue = getProjectsInBuildQueue();
+ List<Task> queue = getProjectsInBuildQueue();
for ( Task task : queue )
{
BuildProjectTask buildTask = (BuildProjectTask) task;
@@ -259,7 +255,8 @@
}
else
{
- if ( buildTask.getProjectId() == projectId && buildTask.getBuildDefinitionId() == buildDefinitionId )
+ if ( buildTask.getProjectId() == projectId &&
+ buildTask.getBuildDefinitionId() == buildDefinitionId )
{
return true;
}
@@ -275,14 +272,14 @@
public void cancelBuildTask( int projectId )
{
BuildProjectTask task = (BuildProjectTask) buildTaskQueueExecutor.getCurrentTask();
- if( task != null && task.getProjectId() == projectId )
+ if ( task != null && task.getProjectId() == projectId )
{
- log.info( "Cancelling build task for project '" + projectId + "' in task executor '" +
- buildTaskQueueExecutor );
+ log.info(
+ "Cancelling build task for project '" + projectId + "' in task executor '" + buildTaskQueueExecutor );
buildTaskQueueExecutor.cancelTask( task );
- }
+ }
}
-
+
/**
* @see OverallBuildQueue#cancelCheckoutTask(int)
*/
@@ -290,12 +287,12 @@
throws TaskQueueException
{
CheckOutTask task = (CheckOutTask) checkoutTaskQueueExecutor.getCurrentTask();
- if( task != null && task.getProjectId() == projectId )
+ if ( task != null && task.getProjectId() == projectId )
{
log.info( "Cancelling checkout task for project '" + projectId + "' in task executor '" +
- checkoutTaskQueueExecutor );
- checkoutTaskQueueExecutor.cancelTask( task );
- }
+ checkoutTaskQueueExecutor );
+ checkoutTaskQueueExecutor.cancelTask( task );
+ }
}
/**
@@ -304,26 +301,26 @@
public boolean cancelCurrentBuild()
{
Task task = buildTaskQueueExecutor.getCurrentTask();
- if( task != null )
+ if ( task != null )
{
return buildTaskQueueExecutor.cancelTask( task );
}
-
+
log.info( "No build task currently executing on build executor: " + buildTaskQueueExecutor );
return false;
}
-
+
/**
* @see OverallBuildQueue#cancelCurrentCheckout()
*/
public boolean cancelCurrentCheckout()
{
Task task = checkoutTaskQueueExecutor.getCurrentTask();
- if( task != null )
+ if ( task != null )
{
return checkoutTaskQueueExecutor.cancelTask( task );
}
-
+
log.info( "No checkout task currently executing on checkout task executor: " + checkoutTaskQueueExecutor );
return false;
}
@@ -392,12 +389,8 @@
{
log.info( "cancel build for project " + buildProjectTask.getProjectId() );
}
- if ( !tasks.isEmpty() )
- {
- return getBuildQueue().removeAll( tasks );
- }
- return false;
+ return !tasks.isEmpty() && getBuildQueue().removeAll( tasks );
}
/**
@@ -435,12 +428,12 @@
}
}
- /**
+ /**
* @see OverallBuildQueue#getCheckoutQueue()
*/
public TaskQueue getCheckoutQueue()
{
- return ( ( ParallelBuildsThreadedTaskQueueExecutor ) checkoutTaskQueueExecutor ).getQueue();
+ return ( (ParallelBuildsThreadedTaskQueueExecutor) checkoutTaskQueueExecutor ).getQueue();
}
/**
@@ -448,7 +441,7 @@
*/
public TaskQueue getBuildQueue()
{
- return ( ( ParallelBuildsThreadedTaskQueueExecutor ) buildTaskQueueExecutor ).getQueue();
+ return ( (ParallelBuildsThreadedTaskQueueExecutor) buildTaskQueueExecutor ).getQueue();
}
/**
Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java?rev=751864&r1=751863&r2=751864&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java (original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java Mon Mar 9 22:02:34 2009
@@ -58,7 +58,7 @@
public class DefaultTaskQueueManager
implements TaskQueueManager, Contextualizable
{
- private Logger log = LoggerFactory.getLogger( DefaultTaskQueueManager.class );
+ private Logger log = LoggerFactory.getLogger( DefaultTaskQueueManager.class );
/**
* @plexus.requirement role-hint="distributed-build-project"
@@ -74,12 +74,12 @@
* @plexus.requirement role-hint="prepare-release"
*/
private TaskQueue prepareReleaseQueue;
-
+
/**
* @plexus.requirement role-hint="perform-release"
*/
private TaskQueue performReleaseQueue;
-
+
/**
* @plexus.requirement
*/
@@ -89,12 +89,12 @@
* @plexus.requirement
*/
private PurgeConfigurationService purgeConfigurationService;
-
+
/**
- * @plexus.requirement role-hint="parallel"
+ * @plexus.requirement role-hint="parallel"
*/
private BuildsManager buildsManager;
-
+
private PlexusContainer container;
public TaskQueue getDistributedBuildQueue()
@@ -131,7 +131,8 @@
{
if ( task != null )
{
- if ( task.getProjectGroupId() == projectGroupId && task.getScmRootAddress().equals( scmRootAddress ) )
+ if ( task.getProjectGroupId() == projectGroupId &&
+ task.getScmRootAddress().equals( scmRootAddress ) )
{
return true;
}
@@ -145,12 +146,12 @@
throw new TaskQueueManagerException( "Error while getting the tasks in distributed build queue", e );
}
}
-
+
public boolean isInPurgeQueue( int purgeConfigId )
throws TaskQueueManagerException
{
List<PurgeTask> queue = getAllPurgeConfigurationsInPurgeQueue();
-
+
for ( PurgeTask task : queue )
{
if ( task != null && task.getPurgeConfigurationId() == purgeConfigId )
@@ -160,13 +161,13 @@
}
return false;
}
-
+
public boolean isRepositoryInPurgeQueue( int repositoryId )
throws TaskQueueManagerException
{
List<RepositoryPurgeConfiguration> repoPurgeConfigs =
purgeConfigurationService.getRepositoryPurgeConfigurationsByRepository( repositoryId );
-
+
for ( RepositoryPurgeConfiguration repoPurge : repoPurgeConfigs )
{
if ( isInPurgeQueue( repoPurge.getId() ) )
@@ -176,53 +177,53 @@
}
return false;
}
-
+
public boolean isRepositoryInUse( int repositoryId )
throws TaskQueueManagerException
{
- try
- {
- Map<String, Task> currentBuilds = buildsManager.getCurrentBuilds();
- Set<String> keys = currentBuilds.keySet();
-
- for( String key : keys )
- {
- Task task = currentBuilds.get( key );
- if ( task != null && task instanceof BuildProjectTask )
+ try
+ {
+ Map<String, Task> currentBuilds = buildsManager.getCurrentBuilds();
+ Set<String> keys = currentBuilds.keySet();
+
+ for ( String key : keys )
+ {
+ Task task = currentBuilds.get( key );
+ if ( task != null && task instanceof BuildProjectTask )
{
int projectId = ( (BuildProjectTask) task ).getProjectId();
-
+
Project project = projectDao.getProject( projectId );
LocalRepository repository = project.getProjectGroup().getLocalRepository();
-
+
if ( repository != null && repository.getId() == repositoryId )
{
return true;
}
}
- }
+ }
return false;
- }
- catch ( BuildManagerException e )
- {
- log.error( "Error occured while getting current builds: " + e.getMessage() );
- throw new TaskQueueManagerException( e.getMessage(), e );
- }
- catch ( ContinuumStoreException e )
- {
- log.error( "Error occured while getting project details: " + e.getMessage() );
- throw new TaskQueueManagerException( e.getMessage(), e );
- }
+ }
+ catch ( BuildManagerException e )
+ {
+ log.error( "Error occured while getting current builds: " + e.getMessage() );
+ throw new TaskQueueManagerException( e.getMessage(), e );
+ }
+ catch ( ContinuumStoreException e )
+ {
+ log.error( "Error occured while getting project details: " + e.getMessage() );
+ throw new TaskQueueManagerException( e.getMessage(), e );
+ }
}
-
+
public boolean isProjectInReleaseStage( String releaseId )
throws TaskQueueManagerException
{
- Task prepareTask = getCurrentTask( "prepare-release" );
- if( prepareTask != null && prepareTask instanceof PrepareReleaseProjectTask )
+ Task prepareTask = getCurrentTask( "prepare-release" );
+ if ( prepareTask != null && prepareTask instanceof PrepareReleaseProjectTask )
{
- if( ( ( PrepareReleaseProjectTask ) prepareTask ).getReleaseId().equals( releaseId ) )
+ if ( ( (PrepareReleaseProjectTask) prepareTask ).getReleaseId().equals( releaseId ) )
{
return true;
}
@@ -232,9 +233,9 @@
{
// check if in queue
List<Task> tasks = prepareReleaseQueue.getQueueSnapshot();
- for( Task prepareReleaseTask : tasks )
+ for ( Task prepareReleaseTask : tasks )
{
- if( ( ( PrepareReleaseProjectTask) prepareReleaseTask ).getReleaseId().equals( releaseId ) )
+ if ( ( (PrepareReleaseProjectTask) prepareReleaseTask ).getReleaseId().equals( releaseId ) )
{
return true;
}
@@ -246,11 +247,11 @@
}
}
}
-
- Task performTask = getCurrentTask( "perform-release" );
- if( performTask != null && performTask instanceof PerformReleaseProjectTask )
+
+ Task performTask = getCurrentTask( "perform-release" );
+ if ( performTask != null && performTask instanceof PerformReleaseProjectTask )
{
- if( ( ( PerformReleaseProjectTask ) performTask ).getReleaseId().equals( releaseId ) )
+ if ( ( (PerformReleaseProjectTask) performTask ).getReleaseId().equals( releaseId ) )
{
return true;
}
@@ -260,9 +261,9 @@
{
// check if in queue
List<Task> tasks = performReleaseQueue.getQueueSnapshot();
- for( Task performReleaseTask : tasks )
+ for ( Task performReleaseTask : tasks )
{
- if( ( ( PerformReleaseProjectTask) performReleaseTask ).getReleaseId().equals( releaseId ) )
+ if ( ( (PerformReleaseProjectTask) performReleaseTask ).getReleaseId().equals( releaseId ) )
{
return true;
}
@@ -274,7 +275,7 @@
}
}
}
-
+
return false;
}
@@ -282,20 +283,15 @@
throws TaskQueueManagerException
{
Task task = getCurrentTask( "perform-release" );
-
- if ( task != null && task instanceof PerformReleaseProjectTask )
- {
- return true;
- }
-
- return false;
+
+ return task != null && task instanceof PerformReleaseProjectTask;
}
public void removeFromDistributedBuildQueue( int projectGroupId, String scmRootAddress )
throws TaskQueueManagerException
{
List<PrepareBuildProjectsTask> queue = getDistributedBuildProjectsInQueue();
-
+
for ( PrepareBuildProjectsTask task : queue )
{
if ( task.getProjectGroupId() == projectGroupId && task.getScmRootAddress().equals( scmRootAddress ) )
@@ -309,7 +305,7 @@
throws TaskQueueManagerException
{
List<PurgeTask> queue = getAllPurgeConfigurationsInPurgeQueue();
-
+
for ( PurgeTask task : queue )
{
if ( task != null && task.getPurgeConfigurationId() == purgeConfigId )
@@ -327,16 +323,16 @@
{
return false;
}
-
+
if ( purgeConfigIds.length < 1 )
{
return false;
}
-
+
List<PurgeTask> queue = getAllPurgeConfigurationsInPurgeQueue();
-
+
List<PurgeTask> tasks = new ArrayList<PurgeTask>();
-
+
for ( PurgeTask task : queue )
{
if ( task != null )
@@ -347,21 +343,16 @@
}
}
}
-
- if ( !tasks.isEmpty() )
- {
- return purgeQueue.removeAll( tasks );
- }
-
- return false;
+
+ return !tasks.isEmpty() && purgeQueue.removeAll( tasks );
}
-
+
public void removeRepositoryFromPurgeQueue( int repositoryId )
throws TaskQueueManagerException
{
List<RepositoryPurgeConfiguration> repoPurgeConfigs =
purgeConfigurationService.getRepositoryPurgeConfigurationsByRepository( repositoryId );
-
+
for ( RepositoryPurgeConfiguration repoPurge : repoPurgeConfigs )
{
removeFromPurgeQueue( repoPurge.getId() );
@@ -372,7 +363,7 @@
throws TaskQueueManagerException
{
List<PrepareBuildProjectsTask> queue = getDistributedBuildProjectsInQueue();
-
+
for ( PrepareBuildProjectsTask task : queue )
{
if ( ArrayUtils.contains( hashCodes, task.hashCode() ) )
@@ -381,13 +372,13 @@
}
}
}
-
+
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
-
+
private List<PurgeTask> getAllPurgeConfigurationsInPurgeQueue()
throws TaskQueueManagerException
{
@@ -400,7 +391,7 @@
throw new TaskQueueManagerException( "Error while getting the purge configs in purge queue", e );
}
}
-
+
private Task getCurrentTask( String task )
throws TaskQueueManagerException
{