continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1153358 [1/2] - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/buildmanager/ continuum-api/src/main/java/org/apache/continuum/taskqueue/ continuum-api/src/main/java/org/apache/maven/continuum/ continuum-core/src/main...
Date Wed, 03 Aug 2011 06:37:03 GMT
Author: ctan
Date: Wed Aug  3 06:37:01 2011
New Revision: 1153358

URL: http://svn.apache.org/viewvc?rev=1153358&view=rev
Log:
[CONTINUUM-2286] run prepare builds in parallel

Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/buildmanager/BuildsManager.java
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components-fragment.xml
    continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/scm/queue/PrepareBuildProjectsTaskExecutorTest.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/QueuesAction.java
    continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
    continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/buildQueueView.jsp

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/buildmanager/BuildsManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/buildmanager/BuildsManager.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/buildmanager/BuildsManager.java (original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/buildmanager/BuildsManager.java Wed Aug  3 06:37:01 2011
@@ -149,10 +149,34 @@ public interface BuildsManager
 
     // public boolean cancelPrepareBuild(int projectId) throws BuildManagerException;
 
+    /**
+     * Cancels all the prepare builds in all overall queues
+     */
     boolean cancelAllPrepareBuilds()
         throws BuildManagerException;
 
     /**
+     * Cancels the specified project group prepare build
+     * 
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     * @throws BuildManagerException
+     */
+    boolean cancelPrepareBuild( int projectGroupId, int scmRootId )
+        throws BuildManagerException;
+
+    /**
+     * Cancels the specified project prepare build
+     * 
+     * @param projectId
+     * @return
+     * @throws BuildManagerException
+     */
+    boolean cancelPrepareBuild( int projectId )
+        throws BuildManagerException;
+
+    /**
      * Removes the project from the build queue.
      *
      * @param projectId
@@ -294,6 +318,17 @@ void removeProjectsFromPrepareBuildQueue
         throws BuildManagerException;
 
     /**
+     * Checks where the project group is already in the prepare-build queue
+     * 
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     * @throws BuildManagerException
+     */
+    boolean isInPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws BuildManagerException;
+
+    /**
      * Checks whether the project is currently being built.
      *
      * @param projectId
@@ -303,6 +338,15 @@ void removeProjectsFromPrepareBuildQueue
     boolean isProjectInAnyCurrentBuild( int projectId )
         throws BuildManagerException;
 
+    /**
+     * Checks if at least one of the projects is currently preparing build
+     * @param projectIds
+     * @return
+     * @throws BuildManagerException
+     */
+    boolean isAnyProjectCurrentlyPreparingBuild( int[] projectIds )
+        throws BuildManagerException;
+
     // needed in QueuesAction
 
     /**
@@ -378,11 +422,21 @@ void removeProjectsFromPrepareBuildQueue
         throws BuildManagerException;
 
     /**
+     * Checks whether project group is currently preparing build
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     * @throws BuildManagerException
+     */
+    boolean isProjectGroupCurrentlyPreparingBuild( int projectGroupId, int scmRootId )
+        throws BuildManagerException;
+
+    /**
      * Return currently preparing build project.
      * @return
      * @throws BuildManagerException
      */
-    PrepareBuildProjectsTask getCurrentProjectInPrepareBuild()
+    Map<String, PrepareBuildProjectsTask> getCurrentProjectInPrepareBuild()
         throws BuildManagerException;
 
     /**
@@ -390,7 +444,7 @@ void removeProjectsFromPrepareBuildQueue
      * @return
      * @throws BuildManagerException
      */
-    List<PrepareBuildProjectsTask> getProjectsInPrepareBuildQueue()
+    Map<String, List<PrepareBuildProjectsTask>> getProjectsInPrepareBuildQueue()
         throws BuildManagerException;
 
     /**

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java (original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/taskqueue/OverallBuildQueue.java Wed Aug  3 06:37:01 2011
@@ -138,6 +138,125 @@ public interface OverallBuildQueue
     void removeTasksFromCheckoutQueueWithHashCodes( int[] hashCodes )
         throws TaskQueueException;
 
+    /* Prepare Build Queue */
+
+    /**
+     * Returns the prepare build queue.
+     *
+     * @return
+     */
+    TaskQueue getPrepareBuildQueue();
+
+    /**
+     * Add the prepare build task to the prepare build queue.
+     *
+     * @param prepareBuildTask
+     * @throws Exception
+     */
+    void addToPrepareBuildQueue( PrepareBuildProjectsTask prepareBuildTask )
+        throws TaskQueueException;
+
+    /**
+     * Add the prepare build tasks to the prepare build queue.
+     *
+     * @param prepareBuildTasks
+     * @throws TaskQueueException TODO
+     */
+    void addToPrepareBuildQueue( List<PrepareBuildProjectsTask> prepareBuildTasks )
+        throws TaskQueueException;
+
+    /**
+     * Returns the prepare build tasks in the prepare build queue.
+     *
+     * @return
+     * @throws TaskQueueException TODO
+     */
+    List<PrepareBuildProjectsTask> getProjectsInPrepareBuildQueue()
+        throws TaskQueueException;
+
+    /**
+     * Checks if the specified project is in the prepare build queue.
+     *
+     * @param projectId
+     * @return
+     * @throws TaskQueueException TODO
+     */
+    boolean isInPrepareBuildQueue( int projectId )
+        throws TaskQueueException;
+
+    /**
+     * Checks if the specified project group and scm root is in the prepare build queue.
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     * @throws TaskQueueException
+     */
+    boolean isInPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws TaskQueueException;
+
+    /**
+     * Checks if the specified project group and scm root is in the prepare build queue.
+     * @param projectGroupId
+     * @param scmRootAddress
+     * @return
+     * @throws TaskQueueException
+     */
+    boolean isInPrepareBuildQueue( int projectGroupId, String scmRootAddress )
+        throws TaskQueueException;
+
+    /**
+     * Cancel the prepare build task of the corresponding project group and scm root.
+     *
+     * @param projectId
+     * @param scmRootId
+     */
+    void cancelPrepareBuildTask( int projectGroupId, int scmRootId );
+
+    /**
+     * Cancel the prepare build task of the corresponding project
+     * 
+     * @param projectId
+     */
+    void cancelPrepareBuildTask( int projectId );
+
+    /**
+     * Cancel the current prepare build.
+     *
+     * @return
+     */
+    boolean cancelCurrentPrepareBuild();
+
+    /**
+     * Remove the project group matching the specified id, and scm root id from the prepare build queue.
+     *
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     * @throws TaskQueueException TODO
+     */
+    boolean removeProjectFromPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws TaskQueueException;
+
+    /**
+     * Remove the project group matching the specified id and scm root address from the prepare build queue.
+     *
+     * @param projectId
+     * @param scmRootAddress
+     * @return
+     * @throws TaskQueueException TODO
+     */
+    boolean removeProjectFromPrepareBuildQueue( int projectGroupId, String scmRootAddress )
+        throws TaskQueueException;
+
+    /**
+     * Remove the projects matching the specified hashcodes from the prepare build queue.
+     *
+     * @param hashCodes
+     * @throws TaskQueueException TODO
+     */
+    void removeProjectsFromPrepareBuildQueueWithHashCodes( int[] hashCodes )
+        throws TaskQueueException;
+
     /* Build Queue */
 
     /**
@@ -221,7 +340,7 @@ public interface OverallBuildQueue
      * @throws TaskQueueException TODO
      */
     boolean removeProjectFromBuildQueue( int projectId, int buildDefinitionId, BuildTrigger buildTrigger,
-    		                             String projectName, int projectGroupId )
+                                         String projectName, int projectGroupId )
         throws TaskQueueException;
 
     /**
@@ -266,4 +385,11 @@ public interface OverallBuildQueue
      * @return
      */
     TaskQueueExecutor getCheckoutTaskQueueExecutor();
+
+    /**
+     * Returns the prepare build task queue executor used.
+     * 
+     * @return
+     */
+    TaskQueueExecutor getPrepareBuildTaskQueueExecutor();
 }

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java (original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java Wed Aug  3 06:37:01 2011
@@ -163,9 +163,6 @@ public interface Continuum
     void buildProjects( BuildTrigger buildTrigger )
         throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException;
 
-    void buildProjects( BuildTrigger buildTrigger, int buildDefinitionId )
-        throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException;
-
     void buildProjects( Schedule schedule )
         throws ContinuumException;
 

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=1153358&r1=1153357&r2=1153358&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 Wed Aug  3 06:37:01 2011
@@ -20,6 +20,7 @@ package org.apache.continuum.buildmanage
  */
 
 import java.io.File;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -28,7 +29,6 @@ import java.util.Set;
 
 import javax.annotation.Resource;
 
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.continuum.buildqueue.BuildQueueService;
 import org.apache.continuum.buildqueue.BuildQueueServiceException;
 import org.apache.continuum.dao.BuildDefinitionDao;
@@ -53,7 +53,6 @@ import org.codehaus.plexus.context.Conte
 import org.codehaus.plexus.context.ContextException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
-import org.codehaus.plexus.taskqueue.Task;
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
 import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
@@ -80,14 +79,14 @@ public class ParallelBuildsManager
 
     private static final int CHECKOUT_QUEUE = 2;
 
+    private static final int PREPARE_BUILD_QUEUE = 3;
+
     @Resource
     private BuildDefinitionDao buildDefinitionDao;
 
     @Resource
     private ProjectDao projectDao;
 
-    private TaskQueue prepareBuildQueue;
-
     @Resource
     private ConfigurationService configurationService;
 
@@ -410,6 +409,94 @@ public class ParallelBuildsManager
         return true;
     }
 
+    public boolean cancelPrepareBuild( int projectGroupId, int scmRootId )
+        throws BuildManagerException
+    {
+        try
+        {
+            OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectGroupIsQueued( projectGroupId, scmRootId );
+
+            if ( overallBuildQueue != null )
+            {
+                overallBuildQueue.cancelPrepareBuildTask( projectGroupId, scmRootId );
+            }
+            else
+            {
+                synchronized ( overallBuildQueues )
+                {
+                    Set<Integer> keySet = overallBuildQueues.keySet();
+                    for ( Integer key : keySet )
+                    {
+                        overallBuildQueue = overallBuildQueues.get( key );
+                        PrepareBuildProjectsTask task =
+                            (PrepareBuildProjectsTask) overallBuildQueue.getPrepareBuildTaskQueueExecutor().getCurrentTask();
+                        if ( task != null && task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+                        {
+                            overallBuildQueue.cancelPrepareBuildTask( projectGroupId, scmRootId );
+                            return true;
+                        }
+                    }
+                    log.error( "Project group '{}' with scm root '{}' not found in any of the builds queues.", projectGroupId, scmRootId );
+                }
+            }
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Error occurred while cancelling build: " + e.getMessage() );
+        }
+
+        return true;
+    }
+
+    public boolean cancelPrepareBuild( int projectId )
+        throws BuildManagerException
+    {
+        try
+        {
+            OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectIsQueued( projectId, PREPARE_BUILD_QUEUE );
+
+            if ( overallBuildQueue != null )
+            {
+                overallBuildQueue.cancelPrepareBuildTask( projectId );
+            }
+            else
+            {
+                synchronized ( overallBuildQueues )
+                {
+                    Set<Integer> keySet = overallBuildQueues.keySet();
+                    for ( Integer key : keySet )
+                    {
+                        overallBuildQueue = overallBuildQueues.get( key );
+                        PrepareBuildProjectsTask task =
+                            (PrepareBuildProjectsTask) overallBuildQueue.getPrepareBuildTaskQueueExecutor().getCurrentTask();
+                        if ( task != null )
+                        {
+                            Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
+
+                            if ( map.size() > 0 )
+                            {
+                                Set<Integer> projectIds = map.keySet();
+
+                                if ( projectIds.contains( new Integer( projectId ) ) )
+                                {
+                                    overallBuildQueue.cancelPrepareBuildTask( projectId );
+                                    return true;
+                                }
+                            }
+                        }
+                    }
+                    log.error( "Project '{}' not found in any of the builds queues.", projectId );
+                }
+            }
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Error occurred while cancelling build: " + e.getMessage() );
+        }
+
+        return true;
+    }
+
     /**
      * @see BuildsManager#checkoutProject(int, String, File, String, String, String, BuildDefinition, List)
      */
@@ -536,32 +623,60 @@ public class ParallelBuildsManager
     {
         try
         {
-            List<PrepareBuildProjectsTask> queue = prepareBuildQueue.getQueueSnapshot();
-            for ( PrepareBuildProjectsTask task : queue )
+            synchronized ( overallBuildQueues )
             {
-                if ( task != null )
+                Set<Integer> keySet = overallBuildQueues.keySet();
+                for ( Integer key : keySet )
                 {
-                    Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
-
-                    if ( map.size() > 0 )
+                    OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+    
+                    if ( overallBuildQueue.isInPrepareBuildQueue( projectId ) )
                     {
-                        Set<Integer> projectIds = map.keySet();
-
-                        if ( projectIds.contains( new Integer( projectId ) ) )
-                        {
-                            log.info( "Project " + projectId + " is in prepare build queue" );
-                            return true;
-                        }
+                        return true;
                     }
                 }
+    
+                return false;
             }
         }
         catch ( TaskQueueException e )
         {
-            throw new BuildManagerException( e.getMessage() );
+            throw new BuildManagerException( "Unable to check if projectId " + projectId + " is in prepare build queue", e );
         }
+    }
 
-        return false;
+    /**
+     * @see BuildsManager#isInPrepareBuildQueue(int, int)
+     * @param projectGroupId
+     * @param scmRootId
+     * @return
+     */
+    public boolean isInPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws BuildManagerException
+    {
+        try
+        {
+            synchronized ( overallBuildQueues )
+            {
+                Set<Integer> keySet = overallBuildQueues.keySet();
+                for ( Integer key : keySet )
+                {
+                    OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+    
+                    if ( overallBuildQueue.isInPrepareBuildQueue( projectGroupId, scmRootId ) )
+                    {
+                        return true;
+                    }
+                }
+    
+                return false;
+            }
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Unable to check if projectGroupId " + projectGroupId + " with scmRootId " + scmRootId 
+                                             + " is in prepare build queue", e );
+        }
     }
 
     /**
@@ -596,19 +711,50 @@ public class ParallelBuildsManager
                                       int scmRootId )
         throws BuildManagerException
     {
+        if ( isInPrepareBuildQueue( projectGroupId, scmRootId ) )
+        {
+            log.warn( "Project group {} with scm root id {} is already in prepare build queue. Will not queue anymore." );
+            return;
+        }
+
+        Collection<Integer> buildDefs = projectsBuildDefinitionsMap.values();
+        BuildDefinition buildDef = null;
+
+        // get the first build definition
         try
         {
-            PrepareBuildProjectsTask task =
-            	new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, buildTrigger, projectGroupId, projectGroupName,
-                                              scmRootAddress, scmRootId );
+            for ( Integer buildDefId : buildDefs )
+            {
+                buildDef = buildDefinitionDao.getBuildDefinition( buildDefId );
+            }
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new BuildManagerException( "Error occurred while retrieving build definition of project group " + projectGroupId, e );
+        }
+
+        OverallBuildQueue overallBuildQueue =
+            getOverallBuildQueue( PREPARE_BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
+
+        PrepareBuildProjectsTask task =
+            new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, buildTrigger, projectGroupId, projectGroupName,
+                                          scmRootAddress, scmRootId );
 
-            log.info( "Queueing prepare-build-project task '" + task + "' to prepare-build queue." );
-            prepareBuildQueue.put( task );
+        try
+        {
+            if ( overallBuildQueue != null )
+            {
+                log.info( "Project group '{}' added to overall build queue '{}'", projectGroupId, overallBuildQueue.getName() );
+                overallBuildQueue.addToPrepareBuildQueue( task );
+            }
+            else
+            {
+                throw new BuildManagerException( "Unable to add project to prepare build queue. No overall build queue configured." );
+            }
         }
         catch ( TaskQueueException e )
         {
-            throw new BuildManagerException(
-                "Error occurred while creating prepare-build-project task: " + e.getMessage() );
+            throw new BuildManagerException( "Error occurred while adding project to prepare build queue: " + e.getMessage() );
         }
     }
 
@@ -796,22 +942,23 @@ public class ParallelBuildsManager
     {
         try
         {
-            List<PrepareBuildProjectsTask> queue = prepareBuildQueue.getQueueSnapshot();
-
-            for ( PrepareBuildProjectsTask task : queue )
+            OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectGroupIsQueued( projectGroupId, scmRootAddress );
+            if ( overallBuildQueue != null )
             {
-                if ( task != null && task.getProjectGroupId() == projectGroupId &&
-                    task.getScmRootAddress().equals( scmRootAddress ) )
-                {
-                    return prepareBuildQueue.remove( task );
-                }
+                overallBuildQueue.removeProjectFromPrepareBuildQueue( projectGroupId, scmRootAddress );
+            }
+            else
+            {
+                log.info( "Project group '{}' with scm '{}' not found in any of the build queues.", projectGroupId, scmRootAddress );
             }
-            return false;
         }
         catch ( TaskQueueException e )
         {
-            throw new BuildManagerException( "Error while getting the prepare build projects task in queue", e );
+            throw new BuildManagerException(
+                "Error occurred while removing project group from prepare build queue: " + e.getMessage() );
         }
+
+        return true;
     }
 
     /**
@@ -853,6 +1000,7 @@ public class ParallelBuildsManager
     {
         List<BuildProjectTask> tasks;
         List<CheckOutTask> checkoutTasks;
+        List<PrepareBuildProjectsTask> prepareBuildTasks;
 
         synchronized ( overallBuildQueues )
         {
@@ -865,19 +1013,23 @@ public class ParallelBuildsManager
             try
             {
                 if ( overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask() != null ||
-                    overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask() != null )
+                    overallBuildQueue.getCheckoutTaskQueueExecutor().getCurrentTask() != null ||
+                    overallBuildQueue.getPrepareBuildTaskQueueExecutor().getCurrentTask() != null )
                 {
                     throw new BuildManagerException( "Cannot remove build queue. A task is currently executing." );
                 }
 
                 tasks = overallBuildQueue.getProjectsInBuildQueue();
                 checkoutTasks = overallBuildQueue.getProjectsInCheckoutQueue();
+                prepareBuildTasks = overallBuildQueue.getProjectsInPrepareBuildQueue();
 
                 overallBuildQueue.getBuildQueue().removeAll( tasks );
                 overallBuildQueue.getCheckoutQueue().removeAll( checkoutTasks );
+                overallBuildQueue.getPrepareBuildQueue().removeAll( prepareBuildTasks );
 
                 ( (ParallelBuildsThreadedTaskQueueExecutor) overallBuildQueue.getBuildTaskQueueExecutor() ).stop();
                 ( (ParallelBuildsThreadedTaskQueueExecutor) overallBuildQueue.getCheckoutTaskQueueExecutor() ).stop();
+                ( (ParallelBuildsThreadedTaskQueueExecutor) overallBuildQueue.getPrepareBuildTaskQueueExecutor() ).stop();
                 container.release( overallBuildQueue );
             }
             catch ( TaskQueueException e )
@@ -931,6 +1083,12 @@ public class ParallelBuildsManager
                 log.error( "Unable to queue checkout task for project '" + task.getProjectName() + "'" );
             }
         }
+
+        for ( PrepareBuildProjectsTask prepareTask : prepareBuildTasks )
+        {
+            prepareBuildProjects( prepareTask.getProjectsBuildDefinitionsMap(), prepareTask.getBuildTrigger(), prepareTask.getProjectGroupId(),
+                                  prepareTask.getProjectGroupName(), prepareTask.getScmRootAddress(), prepareTask.getProjectScmRootId() );
+        }
     }
 
     public Map<Integer, OverallBuildQueue> getOverallBuildQueues()
@@ -1047,22 +1205,18 @@ public class ParallelBuildsManager
     public boolean cancelAllPrepareBuilds()
         throws BuildManagerException
     {
-        try
+        synchronized ( overallBuildQueues )
         {
-            TaskQueueExecutor executor =
-                (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
-            Task task = executor.getCurrentTask();
-            if ( task != null )
+            Set<Integer> keySet = overallBuildQueues.keySet();
+            OverallBuildQueue overallBuildQueue = null;
+            for ( Integer key : keySet )
             {
-                executor.cancelTask( task );
+                overallBuildQueue = overallBuildQueues.get( key );
+                overallBuildQueue.cancelCurrentPrepareBuild();
             }
-        }
-        catch ( ComponentLookupException e )
-        {
-            throw new BuildManagerException( "Error looking up prepare-build-queue.", e );
-        }
 
-        return false;
+            return true;
+        }
     }
 
     /**
@@ -1088,20 +1242,23 @@ public class ParallelBuildsManager
     public boolean isProjectCurrentlyPreparingBuild( int projectId )
         throws BuildManagerException
     {
-        PrepareBuildProjectsTask task = getCurrentProjectInPrepareBuild();
+        Map<String, PrepareBuildProjectsTask> tasks = getCurrentProjectInPrepareBuild();
 
-        if ( task != null )
+        if ( tasks != null )
         {
-            Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
-
-            if ( map.size() > 0 )
+            for ( PrepareBuildProjectsTask task : tasks.values() )
             {
-                Set<Integer> projectIds = map.keySet();
-
-                if ( projectIds.contains( new Integer( projectId ) ) )
+                Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
+    
+                if ( map.size() > 0 )
                 {
-                    log.info( "Project " + projectId + " is currently preparing build" );
-                    return true;
+                    Set<Integer> projectIds = map.keySet();
+    
+                    if ( projectIds.contains( new Integer( projectId ) ) )
+                    {
+                        log.info( "Project '{}' is currently preparing build", projectId );
+                        return true;
+                    }
                 }
             }
         }
@@ -1109,68 +1266,115 @@ public class ParallelBuildsManager
         return false;
     }
 
-    public PrepareBuildProjectsTask getCurrentProjectInPrepareBuild()
+    public boolean isProjectGroupCurrentlyPreparingBuild( int projectGroupId, int scmRootId )
         throws BuildManagerException
     {
-        Task task = getPrepareBuildTaskQueueExecutor().getCurrentTask();
+        Map<String, PrepareBuildProjectsTask> tasks = getCurrentProjectInPrepareBuild();
 
-        if ( task != null )
-        {
-            return (PrepareBuildProjectsTask) task;
-        }
-        else
+        if ( tasks != null )
         {
-            return null;
+            for ( PrepareBuildProjectsTask task : tasks.values() )
+            {
+                if ( task != null && task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+                {
+                    log.info( "Project group '{}' with scm root '{}' is currently preparing build", projectGroupId, scmRootId );
+                    return true;
+                }
+            }
         }
+
+        return false;
     }
 
-    public List<PrepareBuildProjectsTask> getProjectsInPrepareBuildQueue()
+    public Map<String,PrepareBuildProjectsTask> getCurrentProjectInPrepareBuild()
         throws BuildManagerException
     {
-        try
+        synchronized ( overallBuildQueues )
         {
-            return getPrepareBuildQueue().getQueueSnapshot();
+            Map<String, PrepareBuildProjectsTask> currentBuilds = new HashMap<String, PrepareBuildProjectsTask>();
+            Set<Integer> keys = overallBuildQueues.keySet();
+            for ( Integer key : keys )
+            {
+                OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+                PrepareBuildProjectsTask task =
+                    (PrepareBuildProjectsTask) overallBuildQueue.getPrepareBuildTaskQueueExecutor().getCurrentTask();
+                if ( task != null )
+                {
+                    currentBuilds.put( overallBuildQueue.getName(), task );
+                }
+            }
+            return currentBuilds;
         }
-        catch ( TaskQueueException e )
+    }
+
+    public Map<String, List<PrepareBuildProjectsTask>> getProjectsInPrepareBuildQueue()
+        throws BuildManagerException
+    {
+        synchronized ( overallBuildQueues )
         {
-            throw new BuildManagerException( "Error occurred while retrieving projects in prepare build queue", e );
+            Map<String, List<PrepareBuildProjectsTask>> queuedPrepareBuilds = new HashMap<String, List<PrepareBuildProjectsTask>>();
+            Set<Integer> keySet = overallBuildQueues.keySet();
+            for ( Integer key : keySet )
+            {
+                OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+                try
+                {
+                    queuedPrepareBuilds.put( overallBuildQueue.getName(), overallBuildQueue.getProjectsInPrepareBuildQueue() );
+                }
+                catch ( TaskQueueException e )
+                {
+                    throw new BuildManagerException(
+                        "Error occurred while getting projects in prepare build queue '" + overallBuildQueue.getName() + "'.",
+                        e );
+                }
+            }
+            return queuedPrepareBuilds;
         }
     }
 
     public boolean removeProjectFromPrepareBuildQueue( int projectGroupId, int scmRootId )
         throws BuildManagerException
     {
-        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
-
-        if ( tasks != null )
+        try
         {
-            for ( PrepareBuildProjectsTask task : tasks )
+            OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectGroupIsQueued( projectGroupId, scmRootId );
+            if ( overallBuildQueue != null )
             {
-                if ( task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
-                {
-                    return getPrepareBuildQueue().remove( task );
-                }
+                overallBuildQueue.removeProjectFromPrepareBuildQueue( projectGroupId, scmRootId );
+            }
+            else
+            {
+                log.info( "Project group '{}' with scm '{}' not found in any of the build queues.", projectGroupId, scmRootId );
             }
         }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException(
+                "Error occurred while removing project group from prepare build queue: " + e.getMessage() );
+        }
 
-        return false;
+        return true;
     }
 
     public void removeProjectsFromPrepareBuildQueueWithHashCodes( int[] hashCodes )
         throws BuildManagerException
     {
-        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
-
-        if ( tasks != null )
+        try
         {
-            for ( PrepareBuildProjectsTask task : tasks )
+            synchronized ( overallBuildQueues )
             {
-                if ( ArrayUtils.contains( hashCodes, task.getHashCode() ) )
+                Set<Integer> keySet = overallBuildQueues.keySet();
+                for ( Integer key : keySet )
                 {
-                    getPrepareBuildQueue().remove( task );
+                    OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+                    overallBuildQueue.removeProjectsFromPrepareBuildQueueWithHashCodes( hashCodes );
                 }
             }
         }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Error encountered while removing project group(s) from build queue.", e );
+        }
     }
 
     private boolean isInQueue( int projectId, int typeOfQueue, int buildDefinitionId )
@@ -1243,6 +1447,14 @@ public class ParallelBuildsManager
                         break;
                     }
                 }
+                else if ( typeOfQueue == PREPARE_BUILD_QUEUE )
+                {
+                    if ( overallBuildQueue.isInPrepareBuildQueue( projectId ) )
+                    {
+                        whereQueued = overallBuildQueue;
+                        break;
+                    }
+                }
             }
 
             return whereQueued;
@@ -1288,6 +1500,11 @@ public class ParallelBuildsManager
                                 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 )
@@ -1383,34 +1600,65 @@ public class ParallelBuildsManager
         return whereToBeQueued;
     }
 
-    private OverallBuildQueue getOverallBuildQueueWhereProjectIsBuilding( int projectId )
+    private OverallBuildQueue getOverallBuildQueueWhereProjectGroupIsQueued( int projectGroupId, int scmRootId )
+        throws TaskQueueException
     {
         synchronized ( overallBuildQueues )
         {
-            for ( Integer key : overallBuildQueues.keySet() )
+            OverallBuildQueue whereQueued = null;
+            Set<Integer> keySet = overallBuildQueues.keySet();
+
+            for ( Integer key : keySet )
             {
                 OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
-                BuildProjectTask task =
-                    (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
-                if ( task != null && task.getProjectId() == projectId )
+
+                if ( overallBuildQueue.isInPrepareBuildQueue( projectGroupId, scmRootId ) )
                 {
-                    return overallBuildQueue;
+                    whereQueued = overallBuildQueue;
                 }
             }
-            return null;
+
+            return whereQueued;
         }
     }
 
-    public TaskQueueExecutor getPrepareBuildTaskQueueExecutor()
-        throws BuildManagerException
+    private OverallBuildQueue getOverallBuildQueueWhereProjectGroupIsQueued( int projectGroupId, String scmRootAddress )
+        throws TaskQueueException
     {
-        try
+        synchronized ( overallBuildQueues )
         {
-            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
+            OverallBuildQueue whereQueued = null;
+            Set<Integer> keySet = overallBuildQueues.keySet();
+    
+            for ( Integer key : keySet )
+            {
+                OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+    
+                if ( overallBuildQueue.isInPrepareBuildQueue( projectGroupId, scmRootAddress ) )
+                {
+                    whereQueued = overallBuildQueue;
+                }
+            }
+    
+            return whereQueued;
         }
-        catch ( ComponentLookupException e )
+    }
+
+    private OverallBuildQueue getOverallBuildQueueWhereProjectIsBuilding( int projectId )
+    {
+        synchronized ( overallBuildQueues )
         {
-            throw new BuildManagerException( e.getMessage(), e );
+            for ( Integer key : overallBuildQueues.keySet() )
+            {
+                OverallBuildQueue overallBuildQueue = overallBuildQueues.get( key );
+                BuildProjectTask task =
+                    (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
+                if ( task != null && task.getProjectId() == projectId )
+                {
+                    return overallBuildQueue;
+                }
+            }
+            return null;
         }
     }
 
@@ -1444,6 +1692,20 @@ public class ParallelBuildsManager
         return false;
     }
 
+    public boolean isAnyProjectCurrentlyPreparingBuild( int[] projectIds )
+        throws BuildManagerException
+    {
+        for ( int i = 0; i < projectIds.length; i++ )
+        {
+            if ( isProjectCurrentlyPreparingBuild( projectIds[i] ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public void contextualize( Context context )
         throws ContextException
     {
@@ -1493,16 +1755,6 @@ public class ParallelBuildsManager
         overallBuildQueues.put( overallBuildQueue.getId(), overallBuildQueue );
     }
 
-    public TaskQueue getPrepareBuildQueue()
-    {
-        return prepareBuildQueue;
-    }
-
-    public void setPrepareBuildQueue( TaskQueue prepareBuildQueue )
-    {
-        this.prepareBuildQueue = prepareBuildQueue;
-    }
-
     // for unit tests.. 
 
     public void setOverallBuildQueues( Map<Integer, OverallBuildQueue> overallBuildQueues )

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=1153358&r1=1153357&r2=1153358&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 Wed Aug  3 06:37:01 2011
@@ -21,6 +21,8 @@ package org.apache.continuum.taskqueue;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.annotation.Resource;
 
@@ -56,6 +58,8 @@ public class DefaultOverallBuildQueue
 
     private TaskQueueExecutor checkoutTaskQueueExecutor;
 
+    private TaskQueueExecutor prepareBuildTaskQueueExecutor;
+
     private int id;
 
     private String name;
@@ -426,6 +430,221 @@ public class DefaultOverallBuildQueue
         }
     }
 
+    /* Prepare Build */
+
+    /**
+     * @see OverallBuildQueue#addToPrepareBuildQueue(PrepareBuildProjectsTask)
+     */
+    public void addToPrepareBuildQueue( PrepareBuildProjectsTask prepareBuildTask )
+        throws TaskQueueException
+    {
+        getPrepareBuildQueue().put( prepareBuildTask );
+    }
+
+    /**
+     * @see OverallBuildQueue#addToPrepareBuildQueue(List)
+     */
+    public void addToPrepareBuildQueue( List<PrepareBuildProjectsTask> prepareBuildTasks )
+        throws TaskQueueException
+    {
+        for ( PrepareBuildProjectsTask prepareBuildTask : prepareBuildTasks )
+        {
+            getPrepareBuildQueue().put( prepareBuildTask );
+        }
+    }
+
+    /**
+     * @see OverallBuildQueue#getProjectsInPrepareBuildQueue()
+     */
+    public List<PrepareBuildProjectsTask> getProjectsInPrepareBuildQueue()
+        throws TaskQueueException
+    {
+        return getPrepareBuildQueue().getQueueSnapshot();
+    }
+
+    /**
+     * @see OverallBuildQueue#isInPrepareBuildQueue(int)
+     */
+    public boolean isInPrepareBuildQueue( int projectId )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> queue = getProjectsInPrepareBuildQueue();
+        for ( PrepareBuildProjectsTask task : queue )
+        {
+            if ( task != null )
+            {
+                Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
+
+                if ( map.size() > 0 )
+                {
+                    Set<Integer> projectIds = map.keySet();
+
+                    if ( projectIds.contains( new Integer( projectId ) ) )
+                    {
+                        log.info( "Project {} is already in prepare build queue", projectId );
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#isInPrepareBuildQueue(int, int)
+     */
+    public boolean isInPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> queue = getProjectsInPrepareBuildQueue();
+        for ( PrepareBuildProjectsTask task : queue )
+        {
+            if ( task != null && task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+            {
+                log.info( "Project group {} with scm root {} is in prepare build queue {}", new Object[] { projectGroupId, scmRootId, task } );
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#isInPrepareBuildQueue(int, String)
+     */
+    public boolean isInPrepareBuildQueue( int projectGroupId, String scmRootAddress )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> queue = getProjectsInPrepareBuildQueue();
+        for ( PrepareBuildProjectsTask task : queue )
+        {
+            if ( task != null && task.getProjectGroupId() == projectGroupId && task.getScmRootAddress().equals( scmRootAddress ) )
+            {
+                log.info( "Project group {} with scm root {} is in prepare build queue {}", new Object[] { projectGroupId, scmRootAddress, task } );
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#cancelPrepareBuildTask(int, int)
+     */
+    public void cancelPrepareBuildTask( int projectGroupId, int scmRootId )
+    {
+        PrepareBuildProjectsTask task = (PrepareBuildProjectsTask) prepareBuildTaskQueueExecutor.getCurrentTask();
+        if ( task != null && task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+        {
+            log.info(
+                "Cancelling prepare build task for project group '{}' with scmRootId '{}' in task executor '{}'", 
+                new Object[] { projectGroupId, scmRootId, prepareBuildTaskQueueExecutor } );
+            prepareBuildTaskQueueExecutor.cancelTask( task );
+        }
+    }
+
+    /**
+     * @see OverallBuildQueue#cancelPrepareBuildTask(int)
+     */
+    public void cancelPrepareBuildTask( int projectId )
+    {
+        PrepareBuildProjectsTask task = (PrepareBuildProjectsTask) prepareBuildTaskQueueExecutor.getCurrentTask();
+        if ( task != null )
+        {
+            Map<Integer, Integer> map = task.getProjectsBuildDefinitionsMap();
+
+            if ( map.size() > 0 )
+            {
+                Set<Integer> projectIds = map.keySet();
+
+                if ( projectIds.contains( new Integer( projectId ) ) )
+                {
+                    log.info(
+                             "Cancelling prepare build task for project '{}' in task executor '{}'", projectId, prepareBuildTaskQueueExecutor );
+                    prepareBuildTaskQueueExecutor.cancelTask( task );
+                }
+            }
+        }
+    }
+
+    /**
+     * @see OverallBuildQueue#cancelCurrentPrepareBuild()
+     */
+    public boolean cancelCurrentPrepareBuild()
+    {
+        Task task = prepareBuildTaskQueueExecutor.getCurrentTask();
+        if ( task != null )
+        {
+            return prepareBuildTaskQueueExecutor.cancelTask( task );
+        }
+
+        log.info( "No prepare build task currently executing on build executor: {}", buildTaskQueueExecutor );
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#removeProjectFromPrepareBuildQueue(int, int)
+     */
+    public boolean removeProjectFromPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
+
+        if ( tasks != null )
+        {
+            for ( PrepareBuildProjectsTask task : tasks )
+            {
+                if ( task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+                {
+                    return getPrepareBuildQueue().remove( task );
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#removeProjectFromPrepareBuildQueue(int, String)
+     */
+    public boolean removeProjectFromPrepareBuildQueue( int projectGroupId, String scmRootAddress )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> queue = getProjectsInPrepareBuildQueue();
+
+        for ( PrepareBuildProjectsTask task : queue )
+        {
+            if ( task != null && task.getProjectGroupId() == projectGroupId &&
+                task.getScmRootAddress().equals( scmRootAddress ) )
+            {
+                return getPrepareBuildQueue().remove( task );
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @see OverallBuildQueue#removeProjectsFromPrepareBuildQueueWithHashCodes(int[])
+     */
+    public void removeProjectsFromPrepareBuildQueueWithHashCodes( int[] hashCodes )
+        throws TaskQueueException
+    {
+        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
+
+        if ( tasks != null )
+        {
+            for ( PrepareBuildProjectsTask task : tasks )
+            {
+                if ( ArrayUtils.contains( hashCodes, task.getHashCode() ) )
+                {
+                    getPrepareBuildQueue().remove( task );
+                }
+            }
+        }
+    }
+
     /**
      * @see OverallBuildQueue#getCheckoutQueue()
      */
@@ -443,6 +662,14 @@ public class DefaultOverallBuildQueue
     }
 
     /**
+     * @see OverallBuildQueue#getPrepareBuildQueue()
+     */
+    public TaskQueue getPrepareBuildQueue()
+    {
+        return ( (ParallelBuildsThreadedTaskQueueExecutor) prepareBuildTaskQueueExecutor ).getQueue();
+    }
+
+    /**
      * @see OverallBuildQueue#getBuildTaskQueueExecutor()
      */
     public TaskQueueExecutor getBuildTaskQueueExecutor()
@@ -458,6 +685,14 @@ public class DefaultOverallBuildQueue
         return checkoutTaskQueueExecutor;
     }
 
+    /**
+     * @see OverallBuildQueue#getPrepareBuildTaskQueueExecutor()
+     */
+    public TaskQueueExecutor getPrepareBuildTaskQueueExecutor()
+    {
+        return prepareBuildTaskQueueExecutor;
+    }
+
     public void setBuildDefinitionDao( BuildDefinitionDao buildDefinitionDao )
     {
         this.buildDefinitionDao = buildDefinitionDao;
@@ -472,4 +707,9 @@ public class DefaultOverallBuildQueue
     {
         this.checkoutTaskQueueExecutor = checkoutTaskQueueExecutor;
     }
+
+    public void setPrepareBuildTaskQueueExecutor( TaskQueueExecutor prepareBuildTaskQueueExecutor )
+    {
+        this.prepareBuildTaskQueueExecutor = prepareBuildTaskQueueExecutor;
+    }
 }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java Wed Aug  3 06:37:01 2011
@@ -398,6 +398,12 @@ public class DefaultContinuum
                         "Unable to delete group. At least one project in group is still being checked out." );
                 }
 
+                if ( parallelBuildsManager.isAnyProjectCurrentlyPreparingBuild( projectIds ) )
+                {
+                    throw new ContinuumException(
+                        "Unable to delete group. The project group is still preparing build." );
+                }
+
                 if ( parallelBuildsManager.isAnyProjectCurrentlyBuilding( projectIds ) )
                 {
                     throw new ContinuumException(
@@ -780,12 +786,6 @@ public class DefaultContinuum
     	buildProjects( new BuildTrigger( ContinuumProjectState.TRIGGER_FORCED, username ) );
     }
 
-    public void buildProjectsWithBuildDefinition( int buildDefinitionId )
-        throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException
-    {
-    	buildProjects( new BuildTrigger( ContinuumProjectState.TRIGGER_FORCED, "" ), buildDefinitionId );
-    }
-
     public void buildProjectsWithBuildDefinition( List<Project> projects, List<BuildDefinition> bds )
         throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException
     {
@@ -820,23 +820,6 @@ public class DefaultContinuum
     }
 
     /**
-     * fire of the builds of all projects across all project groups using the group build definition
-     *
-     * @param buildTrigger
-     * @param buildDefinitionId
-     * @throws ContinuumException
-     */
-    public void buildProjects( BuildTrigger buildTrigger, int buildDefinitionId )
-        throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException
-    {
-        Collection<Project> projectsList = getProjectsInBuildOrder();
-
-        Collection<Project> filteredProjectsList = getProjectsNotInReleaseStage( projectsList );
-
-        prepareBuildProjects( filteredProjectsList, buildDefinitionId, buildTrigger );
-    }
-
-    /**
      * fire off a build for all of the projects in a project group using their default builds
      *
      * @param projectGroupId

Modified: continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components-fragment.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components-fragment.xml?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components-fragment.xml (original)
+++ continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components-fragment.xml Wed Aug  3 06:37:01 2011
@@ -138,14 +138,14 @@
       <role-hint>prepare-build-project</role-hint>
       <implementation>org.codehaus.plexus.taskqueue.DefaultTaskQueue</implementation>
       <lifecycle-handler>plexus-configurable</lifecycle-handler>
-      <instantiation-strategy>singleton</instantiation-strategy>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
     </component>
     
     <component>
       <role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
       <role-hint>prepare-build-project</role-hint>
-      <implementation>org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor</implementation>
-      <instantiation-strategy>singleton</instantiation-strategy>
+      <implementation>org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
       <requirements>
         <requirement>
           <role>org.codehaus.plexus.taskqueue.execution.TaskExecutor</role>

Modified: continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml (original)
+++ continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml Wed Aug  3 06:37:01 2011
@@ -34,13 +34,12 @@
   </bean>
   
   <bean name="buildsManager#parallel" 
-  		class="org.apache.continuum.buildmanager.ParallelBuildsManager" autowire="byName">
-     <property name="prepareBuildQueue" ref="taskQueue#prepare-build-project"/>
-  </bean>
+  		class="org.apache.continuum.buildmanager.ParallelBuildsManager" autowire="byName"/>
     
   <bean name="overallBuildQueue" 
   		class="org.apache.continuum.taskqueue.DefaultOverallBuildQueue" scope="prototype" autowire="byName">
      <property name="buildTaskQueueExecutor" ref="taskQueueExecutor#build-project"/>
      <property name="checkoutTaskQueueExecutor" ref="taskQueueExecutor#check-out-project"/>
+     <property name="prepareBuildTaskQueueExecutor" ref="taskQueueExecutor#prepare-build-project"/>
   </bean>
 </beans>

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java (original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java Wed Aug  3 06:37:01 2011
@@ -32,6 +32,7 @@ import org.apache.continuum.dao.ProjectD
 import org.apache.continuum.taskqueue.BuildProjectTask;
 import org.apache.continuum.taskqueue.CheckOutTask;
 import org.apache.continuum.taskqueue.OverallBuildQueue;
+import org.apache.continuum.taskqueue.PrepareBuildProjectsTask;
 import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor;
 import org.apache.continuum.utils.build.BuildTrigger;
 import org.apache.maven.continuum.configuration.ConfigurationService;
@@ -74,12 +75,16 @@ public class ParallelBuildsManagerTest
 
     private TaskQueue checkoutQueue;
 
+    private TaskQueue prepareBuildQueue;
+
     private List<Project> projects;
 
     private TaskQueueExecutor buildTaskQueueExecutor;
 
     private TaskQueueExecutor checkoutTaskQueueExecutor;
 
+    private TaskQueueExecutor prepareBuildTaskQueueExecutor;
+
     @Override
     public void setUp()
         throws Exception
@@ -95,10 +100,6 @@ public class ParallelBuildsManagerTest
 
         buildsManager.setBuildDefinitionDao( buildDefinitionDao );
 
-        TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
-
-        buildsManager.setPrepareBuildQueue( prepareBuildQueue );
-
         configurationService = context.mock( ConfigurationService.class );
 
         buildsManager.setConfigurationService( configurationService );
@@ -111,6 +112,8 @@ public class ParallelBuildsManagerTest
 
         checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" );
 
+        prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+
         projectDao = context.mock( ProjectDao.class );
 
         buildsManager.setProjectDao( projectDao );
@@ -118,6 +121,8 @@ public class ParallelBuildsManagerTest
         buildTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "build-task-queue" );
 
         checkoutTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "checkout-task-queue" );
+
+        prepareBuildTaskQueueExecutor = context.mock( TaskQueueExecutor.class, "prepare-build-task-queue" );
     }
 
     @Override
@@ -291,6 +296,67 @@ public class ParallelBuildsManagerTest
             }} );
     }
 
+    // prepare build project recordings
+    private void recordStartOfPrepareBuildProjectSequence()
+        throws TaskQueueException, ContinuumStoreException
+    {
+        final BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setId( 1 );
+        buildDef.setSchedule( getSchedule( 1, 1, 2 ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                exactly( 5 ).of( overallBuildQueue ).isInPrepareBuildQueue( with( any( int.class ) ), with( any( int.class ) ) );
+                will( returnValue( false ) );
+
+                one( buildDefinitionDao ).getBuildDefinition( 1 );
+                will( returnValue( buildDef ) );
+
+                one( configurationService ).getNumberOfBuildsInParallel();
+                will( returnValue( 2 ) );
+    
+                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildQueue();
+                will( returnValue( prepareBuildQueue ) );
+    
+                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
+                will( returnValue( prepareBuildTaskQueueExecutor ) );
+            }} );
+    }
+
+    private void recordPrepareBuildProjectPrepareBuildQueuesAreEmpty()
+        throws TaskQueueException, ContinuumStoreException
+    {
+        recordStartOfPrepareBuildProjectSequence();
+    
+        final List<Task> tasks = new ArrayList<Task>();
+        context.checking( new Expectations()
+        {
+            {
+                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+                
+                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( null ) );
+    
+                one( overallBuildQueue ).getName();
+                will( returnValue( "BUILD_QUEUE_2" ) );
+            }} );
+    
+        recordAddToPrepareBuildQueue();
+    }
+
+    private void recordAddToPrepareBuildQueue()
+        throws TaskQueueException
+    {
+        context.checking( new Expectations()
+        {
+            {
+                one( overallBuildQueue ).addToPrepareBuildQueue( with( any( PrepareBuildProjectsTask.class ) ) );
+            }
+        } );
+    }
+
     // start of test cases..
 
     public void testContainer()
@@ -606,6 +672,8 @@ public class ParallelBuildsManagerTest
         final TaskQueueExecutor buildQueueExecutor = context.mock( TaskQueueExecutor.class, "build-queue-executor" );
         final TaskQueueExecutor checkoutQueueExecutor =
             context.mock( TaskQueueExecutor.class, "checkout-queue-executor" );
+        final TaskQueueExecutor prepareBuildQueueExecutor =
+            context.mock( TaskQueueExecutor.class, "prepare-build-queue-executor" );
 
         final List<Task> buildTasks = new ArrayList<Task>();
         buildTasks.add( new BuildProjectTask( 2, 1, new BuildTrigger( 1, "test-user" ), "continuum-project-test-2", "BUILD_DEF", null, 2 ) );
@@ -615,10 +683,18 @@ public class ParallelBuildsManagerTest
             new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2",
             			"dummy", "dummypass", null, null ) );
 
+        final List<Task> prepareBuildTasks = new ArrayList<Task>();
+        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 1, 1 );
+        prepareBuildTasks.add( new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1,
+                                                             "Project Group A", "http://scm.root.address", 2 ) );
+
         final ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor =
             context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-build-task-executor" );
         final ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor =
             context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-checkout-task-executor" );
+        final ParallelBuildsThreadedTaskQueueExecutor prepareBuildTaskQueueExecutor =
+            context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-prepare-build-task-executor" );
 
         final List<Task> tasks = new ArrayList<Task>();
 
@@ -642,6 +718,12 @@ public class ParallelBuildsManagerTest
                 will( returnValue( null ) );
                 //will( returnValue( checkoutTask ) );
 
+                // check if there is any prepare build task currently being executed
+                one( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
+                will( returnValue( prepareBuildQueueExecutor ) );
+                one( prepareBuildQueueExecutor ).getCurrentTask();
+                will( returnValue( null ) );
+
                 // get all queued build tasks & remove them
                 one( overallBuildQueue ).getProjectsInBuildQueue();
                 will( returnValue( buildTasks ) );
@@ -656,14 +738,24 @@ public class ParallelBuildsManagerTest
                 will( returnValue( checkoutQueue ) );
                 one( checkoutQueue ).removeAll( checkoutTasks );
 
+                // get all queued prepare build tasks & remove them
+                one( overallBuildQueue ).getProjectsInPrepareBuildQueue();
+                will( returnValue( prepareBuildTasks ) );
+                one( overallBuildQueue ).getPrepareBuildQueue();
+                will( returnValue( prepareBuildQueue ) );
+                one( prepareBuildQueue ).removeAll( prepareBuildTasks );
+
                 // stop the build & checkout task queue executors
                 one( overallBuildQueue ).getBuildTaskQueueExecutor();
                 will( returnValue( buildTaskQueueExecutor ) );
                 one( overallBuildQueue ).getCheckoutTaskQueueExecutor();
                 will( returnValue( checkoutTaskQueueExecutor ) );
+                one( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
+                will( returnValue( prepareBuildTaskQueueExecutor ) );
 
                 one( buildTaskQueueExecutor ).stop();
                 one( checkoutTaskQueueExecutor ).stop();
+                one( prepareBuildTaskQueueExecutor ).stop();
 
                 // TODO: test scenario when there are no longer build queues configured aside from the one removed?
                 //      - the behaviour should be that the default build queue will be used!
@@ -729,6 +821,33 @@ public class ParallelBuildsManagerTest
                 will( returnValue( "BUILD_QUEUE_2" ) );
 
                 recordAddToCheckoutQueue();
+
+                // re-queue projects in the prepare build queue of the deleted overall build queue
+                exactly( 4 ).of( overallBuildQueue ).isInPrepareBuildQueue( with( any( int.class ) ), with( any( int.class ) ) );
+                will( returnValue( false ) );
+
+                one( buildDefinitionDao ).getBuildDefinition( 1 );
+                will( returnValue( buildDef ) );
+
+                one( configurationService ).getNumberOfBuildsInParallel();
+                will( returnValue( 2 ) );
+
+                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                exactly( 2 ).of( overallBuildQueue ).getPrepareBuildTaskQueueExecutor();
+                will( returnValue( prepareBuildQueueExecutor ) );
+
+                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                exactly( 2 ).of( prepareBuildQueueExecutor ).getCurrentTask();
+                will( returnValue( null ) );
+
+                one( overallBuildQueue ).getName();
+                will( returnValue( "BUILD_QUEUE_2" ) );
+
+                recordAddToPrepareBuildQueue();
             }} );
 
         buildsManager.removeOverallBuildQueue( 5 );
@@ -879,6 +998,126 @@ public class ParallelBuildsManagerTest
         context.assertIsSatisfied();
     }
 
+    // prepare build queue
+    public void testPrepareBuildProjectNoProjectQueuedInAnyOverallBuildQueues()
+        throws Exception
+    {
+        setupMockOverallBuildQueues();
+
+        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 1, 1 );
+
+        recordPrepareBuildProjectPrepareBuildQueuesAreEmpty();
+
+        buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, 
+                                            "Project Group A", "http://scm.root.address", 1 );
+        context.assertIsSatisfied();
+    }
+
+    public void testPrepareBuildProjectsAlreadyQueued()
+        throws Exception
+    {
+        setupMockOverallBuildQueues();
+
+        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 1, 1 );
+
+        //queue second project - 1st queue is not empty, 2nd queue is empty 
+        recordStartOfPrepareBuildProjectSequence();
+
+        // the first prepare build queue already has a task queued
+        final List<Task> tasks = new ArrayList<Task>();
+        final List<Task> tasksOfFirstPrepareBuildQueue = new ArrayList<Task>();
+        tasksOfFirstPrepareBuildQueue.add(
+                new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 1,
+                                              "Project Group B", "http://scm.root.address2", 2 ) );
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasksOfFirstPrepareBuildQueue ) );
+
+                // the second prepare build queue has no tasks queued, so it should return 0
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( null ) );
+
+                one( overallBuildQueue ).getName();
+                will( returnValue( "BUILD_QUEUE_3" ) );
+            }} );
+
+        recordAddToPrepareBuildQueue();
+
+        buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, 
+                                            "Project Group A", "http://scm.root.address", 1 );
+        context.assertIsSatisfied();
+
+        // queue third project - both queues have 1 task queued each
+        recordStartOfPrepareBuildProjectSequence();
+
+        // both queues have 1 task each        
+        context.checking( new Expectations()
+        {
+            {
+                exactly( 2 ).of( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasksOfFirstPrepareBuildQueue ) );
+
+                exactly( 2 ).of( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( null ) );
+                
+                one( overallBuildQueue ).getName();
+                will( returnValue( "BUILD_QUEUE_2" ) );
+            }} );
+
+        recordAddToPrepareBuildQueue();
+
+        buildsManager.prepareBuildProjects( map, new BuildTrigger( 1, "test-user" ), 1, 
+                                            "Project Group A", "http://scm.root.address", 1 );
+        context.assertIsSatisfied();
+    }
+
+    public void testGetProjectsInPrepareBuildQueue()
+        throws Exception
+    {
+        setupMockOverallBuildQueues();
+
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 1,
+                                                 "Project Group A", "http://scm.root.address", 2  ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                exactly( 5 ).of( overallBuildQueue ).getName();
+                will( returnValue( "PREPARE_BUILD_QUEUE" ) );
+
+                exactly( 5 ).of( overallBuildQueue ).getProjectsInPrepareBuildQueue();
+                will( returnValue( tasks ) );
+            }} );
+
+        buildsManager.getProjectsInPrepareBuildQueue();
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectFromPrepareBuildQueue()
+        throws Exception
+    {
+        setupMockOverallBuildQueues();
+        context.checking( new Expectations()
+        {
+            {
+                exactly( 5 ).of( overallBuildQueue ).isInPrepareBuildQueue( 1, 2 );
+                will( returnValue( true ) );
+
+                one( overallBuildQueue ).removeProjectFromPrepareBuildQueue( 1, 2 );
+            }} );
+
+        buildsManager.removeProjectFromPrepareBuildQueue( 1, 2 );
+        context.assertIsSatisfied();
+    }
+
     /*
     public void testNumOfAllowedParallelBuildsIsLessThanConfiguredBuildQueues()
         throws Exception

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java?rev=1153358&r1=1153357&r2=1153358&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java (original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueueTest.java Wed Aug  3 06:37:01 2011
@@ -21,7 +21,9 @@ package org.apache.continuum.taskqueue;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.continuum.dao.BuildDefinitionDao;
 import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor;
@@ -53,6 +55,8 @@ public class DefaultOverallBuildQueueTes
 
     private ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor;
 
+    private ParallelBuildsThreadedTaskQueueExecutor prepareBuildTaskQueueExecutor;
+
     @Override
     protected void setUp()
         throws Exception
@@ -71,11 +75,16 @@ public class DefaultOverallBuildQueueTes
         checkoutTaskQueueExecutor =
             context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "checkout-queue-executor" );
 
+        prepareBuildTaskQueueExecutor = 
+            context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "prepare-build-queue-executor" );
+
         overallQueue.setBuildDefinitionDao( buildDefinitionDao );
 
         overallQueue.setBuildTaskQueueExecutor( buildTaskQueueExecutor );
 
         overallQueue.setCheckoutTaskQueueExecutor( checkoutTaskQueueExecutor );
+
+        overallQueue.setPrepareBuildTaskQueueExecutor( prepareBuildTaskQueueExecutor );
     }
 
     // checkout queue
@@ -334,4 +343,254 @@ public class DefaultOverallBuildQueueTes
         overallQueue.removeProjectFromBuildQueue( 1 );
         context.assertIsSatisfied();
     }
+
+    // prepare build queue
+
+    public void testAddToPrepareBuildQueue()
+        throws Exception
+    {
+        final PrepareBuildProjectsTask prepareBuildTask =
+            new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 1, 
+                                          "Project Group A", "http://scmRootAddress", 1 );
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).put( prepareBuildTask );
+            }} );
+
+        overallQueue.addToPrepareBuildQueue( prepareBuildTask );
+        context.assertIsSatisfied();
+    }
+
+    public void testCancelCurrentPrepareBuild()
+        throws Exception
+    {
+        final Task prepareBuildTask = 
+            new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 1, 
+                                          "Project Group A", "http://scm.root.address", 1 );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( prepareBuildTask ) );
+
+                one( prepareBuildTaskQueueExecutor ).cancelTask( prepareBuildTask );
+            }} );
+
+        overallQueue.cancelCurrentPrepareBuild();
+        context.assertIsSatisfied();
+    }
+
+    public void testCancelPrepareBuildTaskByProject()
+        throws Exception
+    {
+        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 1, 1 );
+
+        final Task prepareBuildTask = 
+            new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1, 
+                                          "Project Group A", "http://scm.root.address", 1 );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( prepareBuildTask ) );
+
+                one( prepareBuildTaskQueueExecutor ).cancelTask( prepareBuildTask );
+            }} );
+
+        overallQueue.cancelPrepareBuildTask( 1 );
+        context.assertIsSatisfied();
+    }
+
+    public void testCancelPrepareBuildTaskByProjectGroup()
+        throws Exception
+    {
+        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 1, 1 );
+
+        final Task prepareBuildTask = 
+            new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1, 
+                                          "Project Group A", "http://scm.root.address", 2 );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getCurrentTask();
+                will( returnValue( prepareBuildTask ) );
+
+                one( prepareBuildTaskQueueExecutor ).cancelTask( prepareBuildTask );
+            }} );
+
+        overallQueue.cancelPrepareBuildTask( 1, 2 );
+        context.assertIsSatisfied();
+    }
+
+    public void testGetProjectsFromPrepareBuildQueue()
+        throws Exception
+    {
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 2, 
+                                                 "Project Group A", "http://scm.root.address", 2 ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }} );
+
+        List<PrepareBuildProjectsTask> returnedTasks = overallQueue.getProjectsInPrepareBuildQueue();
+        context.assertIsSatisfied();
+
+        assertNotNull( returnedTasks );
+        assertEquals( 1, returnedTasks.size() );
+    }
+
+    public void testIsInPrepareBuildQueueByProject()
+        throws Exception
+    {
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+
+        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 2, 1 );
+
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A", 
+                                                 "http://scm.root.address", 2 ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }} );
+
+        assertTrue( overallQueue.isInPrepareBuildQueue( 2 ) );
+        context.assertIsSatisfied();
+    }
+
+    public void testIsInPrepareBuildQueueByProjectGroupAndScmRootId()
+        throws Exception
+    {
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+
+        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 2, 1 );
+
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A", 
+                                                 "http://scm.root.address", 2 ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }} );
+
+        assertTrue( overallQueue.isInPrepareBuildQueue( 1, 2 ) );
+        context.assertIsSatisfied();
+    }
+
+    public void testIsInPrepareBuildQueueByProjectGroupAndScmRootAddress()
+        throws Exception
+    {
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+
+        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+        map.put( 2, 1 );
+
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( new PrepareBuildProjectsTask( map, new BuildTrigger( 1, "test-user" ), 1, "Project Group A", 
+                                                 "http://scm.root.address", 2 ) );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+            }} );
+
+        assertTrue( overallQueue.isInPrepareBuildQueue( 1, "http://scm.root.address" ) );
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectsFromPrepareBuildQueueByProjectGroupAndScmRootId()
+        throws Exception
+    {
+        final Task prepareBuildTask = new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 
+                                                                    1, "Project Group A", "http://scm.root.address", 1 );
+
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( prepareBuildTask );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).remove( prepareBuildTask );
+            }} );
+
+        overallQueue.removeProjectFromPrepareBuildQueue( 1, 1 );
+        context.assertIsSatisfied();
+    }
+
+    public void testRemoveProjectsFromPrepareBuildQueueByProjectGroupAndScmRootAddress()
+        throws Exception
+    {
+        final Task prepareBuildTask = new PrepareBuildProjectsTask( new HashMap<Integer, Integer>(), new BuildTrigger( 1, "test-user" ), 
+                                                                    1, "Project Group A", "http://scm.root.address", 1 );
+
+        final TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" );
+        final List<Task> tasks = new ArrayList<Task>();
+        tasks.add( prepareBuildTask );
+
+        context.checking( new Expectations()
+        {
+            {
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).getQueueSnapshot();
+                will( returnValue( tasks ) );
+
+                one( prepareBuildTaskQueueExecutor ).getQueue();
+                will( returnValue( prepareBuildQueue ) );
+
+                one( prepareBuildQueue ).remove( prepareBuildTask );
+            }} );
+
+        overallQueue.removeProjectFromPrepareBuildQueue( 1, "http://scm.root.address" );
+        context.assertIsSatisfied();
+    }
 }



Mime
View raw message