You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by oc...@apache.org on 2009/01/05 11:13:30 UTC

svn commit: r731514 - /continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java

Author: oching
Date: Mon Jan  5 02:13:30 2009
New Revision: 731514

URL: http://svn.apache.org/viewvc?rev=731514&view=rev
Log:
o respect the number of allowed builds in parallel each time a build is triggered
o create the default over build queue when starting up the parallel builds manager

Modified:
    continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java

Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java?rev=731514&r1=731513&r2=731514&view=diff
==============================================================================
--- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java (original)
+++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java Mon Jan  5 02:13:30 2009
@@ -94,7 +94,7 @@
     private BuildQueueDao buildQueueDao;
 
     private PlexusContainer container;
-
+    
     /**
      * @see BuildsManager#buildProject(int, BuildDefinition, String, int)
      */
@@ -1023,47 +1023,53 @@
             }
 
             int size = 0;
-            int idx = 0;
-            
-            // TODO: 
-            // - the number of build queues to be used should respect the number of allowed builds in parallel!
-            // - what to do when the number of allowed builds in parallel is reduced and there are queued tasks?
+            int idx = 0;            
+            int allowedBuilds = configurationService.getNumberOfBuildsInParallel();
             
             try
-            {   
+            {
+                int count = 1;             
                 for ( BuildQueue buildQueue : buildQueues )
-                {                                        
-                    OverallBuildQueue overallBuildQueue = overallBuildQueues.get( buildQueue.getId() );
-                    if ( overallBuildQueue != null )
-                    {
-                        TaskQueue taskQueue = null;
-                        if ( typeOfQueue == BUILD_QUEUE )
+                {            
+                    if( count <= allowedBuilds )
+                    {   
+                        OverallBuildQueue overallBuildQueue = overallBuildQueues.get( buildQueue.getId() );
+                        if ( overallBuildQueue != null )
                         {
-                            taskQueue = overallBuildQueue.getBuildQueue();
-                        }
-                        else if ( typeOfQueue == CHECKOUT_QUEUE )
-                        {
-                            taskQueue = overallBuildQueue.getCheckoutQueue();
-                        }
-                        
-                        if ( idx == 0 )
-                        {
-                            size = taskQueue.getQueueSnapshot().size();
-                            whereToBeQueued = overallBuildQueue;
+                            TaskQueue taskQueue = null;
+                            if ( typeOfQueue == BUILD_QUEUE )
+                            {
+                                taskQueue = overallBuildQueue.getBuildQueue();
+                            }
+                            else if ( typeOfQueue == CHECKOUT_QUEUE )
+                            {
+                                taskQueue = overallBuildQueue.getCheckoutQueue();
+                            }
+                            
+                            if ( idx == 0 )
+                            {
+                                size = taskQueue.getQueueSnapshot().size();
+                                whereToBeQueued = overallBuildQueue;
+                            }
+    
+                            if ( taskQueue.getQueueSnapshot().size() < size )
+                            {
+                                whereToBeQueued = overallBuildQueue;
+                                size = taskQueue.getQueueSnapshot().size();
+                            }
+    
+                            idx++;
                         }
-
-                        if ( taskQueue.getQueueSnapshot().size() < size )
+                        else
                         {
-                            whereToBeQueued = overallBuildQueue;
-                            size = taskQueue.getQueueSnapshot().size();
+                            log.error( "Build queue not found." );                            
                         }
-
-                        idx++;
+                        count++;
                     }
                     else
                     {
-                        log.error( "Build queue not found." );
-                    }
+                        break;
+                    }   
                 }
             }
             catch ( TaskQueueException e )
@@ -1085,32 +1091,6 @@
                     found = true;
                     return overallBuildQueue;
                 }
-            }            
-            
-            // no default "overall" build queue configured
-            if( !found )
-            {
-                try
-                {
-                    // add the default build queue to the map                    
-                    BuildQueue defaultBuildQueue = buildQueueDao.getBuildQueueByName( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME );
-                    if( defaultBuildQueue != null )
-                    {
-                        return createOverallBuildQueue( defaultBuildQueue );                        
-                    }
-                    else
-                    {
-                        throw new BuildManagerException( "No default build queue configured." );
-                    }
-                }
-                catch ( ContinuumStoreException e )
-                {
-                    throw new BuildManagerException( "Error encountered while retrieving default build queue from the database." );
-                }
-                catch ( ComponentLookupException e )
-                {
-                    throw new BuildManagerException( "Error occurred while creating default build queue." );
-                }
             }
         }
 
@@ -1137,7 +1117,13 @@
                 {   
                     createOverallBuildQueue( buildQueue );
                 }               
-                //BuildQueue defaultBuildQueue = configurationService.getDefaultBuildQueue();
+
+                // add default overall build queue if not yet added to the map
+                BuildQueue defaultBuildQueue = configurationService.getDefaultBuildQueue();
+                if( overallBuildQueues.get( defaultBuildQueue.getId() ) == null )
+                {
+                    createOverallBuildQueue( defaultBuildQueue );
+                }
             }
             catch ( ComponentLookupException e )
             {