continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r941625 [7/24] - in /continuum/branches/continuum-flat-multi-module: ./ continuum-api/ continuum-api/src/main/java/org/apache/continuum/builder/distributed/ continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/ conti...
Date Thu, 06 May 2010 09:23:34 GMT
Modified: continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java?rev=941625&r1=941624&r2=941625&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/buildmanager/ParallelBuildsManager.java Thu May  6 09:23:13 2010
@@ -28,14 +28,17 @@ 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;
+import org.apache.continuum.dao.ProjectDao;
 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;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildQueue;
@@ -80,6 +83,9 @@ public class ParallelBuildsManager
     @Resource
     private BuildDefinitionDao buildDefinitionDao;
 
+    @Resource
+    private ProjectDao projectDao;
+
     private TaskQueue prepareBuildQueue;
 
     @Resource
@@ -89,12 +95,12 @@ public class ParallelBuildsManager
     private BuildQueueService buildQueueService;
 
     private PlexusContainer container;
-        
+
     /**
-     * @see BuildsManager#buildProject(int, BuildDefinition, String, int, ScmResult)
+     * @see BuildsManager#buildProject(int, BuildDefinition, String, BuildTrigger, ScmResult, int)
      */
-    public void buildProject( int projectId, BuildDefinition buildDefinition, String projectName, int trigger,
-                              ScmResult scmResult )
+    public void buildProject( int projectId, BuildDefinition buildDefinition, String projectName, BuildTrigger buildTrigger,
+                              ScmResult scmResult, int projectGroupId )
         throws BuildManagerException
     {
         try
@@ -104,6 +110,11 @@ public class ParallelBuildsManager
                 log.warn( "Project already queued." );
                 return;
             }
+            else if ( isProjectInAnyCurrentBuild( projectId ) )
+            {
+                log.warn( "Project is already building." );
+                return;
+            }
         }
         catch ( TaskQueueException e )
         {
@@ -111,35 +122,47 @@ public class ParallelBuildsManager
                 "Error occurred while checking if the project is already in queue: " + e.getMessage() );
         }
 
-        OverallBuildQueue overallBuildQueue =
-            getOverallBuildQueue( BUILD_QUEUE, buildDefinition.getSchedule().getBuildQueues() );
+        OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectsInGroupAreQueued( projectGroupId );
 
-        String buildDefinitionLabel = buildDefinition.getDescription();
-        if ( StringUtils.isEmpty( buildDefinitionLabel ) )
+        if ( overallBuildQueue == null )
         {
-            buildDefinitionLabel = buildDefinition.getGoals();
+            overallBuildQueue = getOverallBuildQueue( BUILD_QUEUE, buildDefinition.getSchedule().getBuildQueues() );
         }
 
-        BuildProjectTask buildTask =
-            new BuildProjectTask( projectId, buildDefinition.getId(), trigger, projectName, buildDefinitionLabel,
-                                  scmResult );
-        try
+        if ( overallBuildQueue != null )
         {
-            log.info(
-                "Project '" + projectName + "' added to overall build queue '" + overallBuildQueue.getName() + "'." );
-            overallBuildQueue.addToBuildQueue( buildTask );
+            String buildDefinitionLabel = buildDefinition.getDescription();
+
+            if ( StringUtils.isEmpty( buildDefinitionLabel ) )
+            {
+                buildDefinitionLabel = buildDefinition.getGoals();
+            }
+    
+            BuildProjectTask buildTask =
+            	new BuildProjectTask( projectId, buildDefinition.getId(), buildTrigger, projectName, buildDefinitionLabel,
+                                      scmResult, projectGroupId );
+            try
+            {
+                log.info(
+                    "Project '" + projectName + "' 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() );
+            }
         }
-        catch ( TaskQueueException e )
+        else
         {
-            throw new BuildManagerException( "Error occurred while adding project to build queue: " + e.getMessage() );
+            log.warn( "No build queue configured. Not building." );
         }
     }
 
     /**
-     * @see BuildsManager#buildProjects(List, Map, int, Map)
+     * @see BuildsManager#buildProjects(List, Map, BuildTrigger, Map, int)
      */
     public void buildProjects( List<Project> projects, Map<Integer, BuildDefinition> projectsBuildDefinitionsMap,
-                               int trigger, Map<Integer, ScmResult> scmResultMap )
+    		                   BuildTrigger buildTrigger, Map<Integer, ScmResult> scmResultMap, int projectGroupId )
         throws BuildManagerException
     {
         int firstProjectId = 0;
@@ -148,7 +171,7 @@ public class ParallelBuildsManager
         {
             try
             {
-                if ( !isInQueue( project.getId(), BUILD_QUEUE, -1 ) )
+                if ( !isInQueue( project.getId(), BUILD_QUEUE, -1 ) && !isProjectInAnyCurrentBuild( project.getId() ) )
                 {
                     firstProjectId = project.getId();
                     break;
@@ -163,8 +186,12 @@ public class ParallelBuildsManager
         if ( firstProjectId != 0 )
         {
             BuildDefinition buildDef = projectsBuildDefinitionsMap.get( firstProjectId );
-            OverallBuildQueue overallBuildQueue =
-                getOverallBuildQueue( BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
+            OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectsInGroupAreQueued( projectGroupId );
+
+            if ( overallBuildQueue == null )
+            {
+                overallBuildQueue = getOverallBuildQueue( BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
+            }
 
             if ( overallBuildQueue != null )
             {
@@ -179,6 +206,12 @@ public class ParallelBuildsManager
                                 "' is already in build queue." );
                             continue;
                         }
+                        else if ( isProjectInAnyCurrentBuild( project.getId() ) )
+                        {
+                            log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
+                                      "' is already building." );
+                            continue;
+                        }
                     }
                     catch ( TaskQueueException e )
                     {
@@ -195,8 +228,8 @@ public class ParallelBuildsManager
 
                     ScmResult scmResult = scmResultMap.get( project.getId() );
                     BuildProjectTask buildTask =
-                        new BuildProjectTask( project.getId(), buildDefinition.getId(), trigger, project.getName(),
-                                              buildDefinitionLabel, scmResult );
+                    	new BuildProjectTask( project.getId(), buildDefinition.getId(), buildTrigger, project.getName(),
+                                              buildDefinitionLabel, scmResult, projectGroupId );
                     buildTask.setMaxExecutionTime( buildDefinition.getSchedule().getMaxJobExecutionTime() * 1000 );
 
                     try
@@ -213,11 +246,14 @@ public class ParallelBuildsManager
                     }
                 }
             }
+            else
+            {
+                log.warn( "No build queue configured. Not building" );
+            }
         }
         else
         {
             log.error( "Projects are already in build queue." );
-            throw new BuildManagerException( "Projects are already in build queue." );
         }
     }
 
@@ -367,10 +403,10 @@ public class ParallelBuildsManager
     }
 
     /**
-     * @see BuildsManager#checkoutProject(int, String, File, String, String, String, BuildDefinition, List)
+     * @see BuildsManager#checkoutProject(int, String, File, String, String, BuildDefinition)
      */
-    public void checkoutProject( int projectId, String projectName, File workingDirectory, String scmRootUrl,
-                                 String scmUsername, String scmPassword, BuildDefinition defaultBuildDefinition, List<Project> subProjects )
+    public void checkoutProject( int projectId, String projectName, File workingDirectory, String scmUsername,
+                                 String scmPassword, BuildDefinition defaultBuildDefinition )
         throws BuildManagerException
     {
         try
@@ -390,7 +426,7 @@ public class ParallelBuildsManager
         OverallBuildQueue overallBuildQueue =
             getOverallBuildQueue( CHECKOUT_QUEUE, defaultBuildDefinition.getSchedule().getBuildQueues() );
         CheckOutTask checkoutTask =
-            new CheckOutTask( projectId, workingDirectory, projectName, scmUsername, scmPassword, scmRootUrl, subProjects );
+            new CheckOutTask( projectId, workingDirectory, projectName, scmUsername, scmPassword );
         try
         {
             if ( overallBuildQueue != null )
@@ -475,6 +511,7 @@ public class ParallelBuildsManager
                 CheckOutTask task = checkouts.get( key );
                 if ( task.getProjectId() == projectId )
                 {
+                    log.info( "Project " + projectId + " is currently being checked out" );
                     return true;
                 }
             }
@@ -503,6 +540,7 @@ public class ParallelBuildsManager
 
                         if ( projectIds.contains( new Integer( projectId ) ) )
                         {
+                            log.info( "Project " + projectId + " is in prepare build queue" );
                             return true;
                         }
                     }
@@ -533,6 +571,7 @@ public class ParallelBuildsManager
                     (BuildProjectTask) overallBuildQueue.getBuildTaskQueueExecutor().getCurrentTask();
                 if ( task != null && task.getProjectId() == projectId )
                 {
+                    log.info( "Project " + projectId + " is currently building in " + overallBuildQueue.getName() );
                     return true;
                 }
             }
@@ -541,9 +580,9 @@ public class ParallelBuildsManager
     }
 
     /**
-     * @see BuildsManager#prepareBuildProjects(Map, int, int, String, String, int)
+     * @see BuildsManager#prepareBuildProjects(Map, BuildTrigger, int, String, String, int)
      */
-    public void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, int trigger,
+    public void prepareBuildProjects( Map<Integer, Integer> projectsBuildDefinitionsMap, BuildTrigger buildTrigger,
                                       int projectGroupId, String projectGroupName, String scmRootAddress,
                                       int scmRootId )
         throws BuildManagerException
@@ -551,7 +590,7 @@ public class ParallelBuildsManager
         try
         {
             PrepareBuildProjectsTask task =
-                new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, trigger, projectGroupId, projectGroupName,
+            	new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, buildTrigger, projectGroupId, projectGroupName,
                                               scmRootAddress, scmRootId );
 
             log.info( "Queueing prepare-build-project task '" + task + "' to prepare-build queue." );
@@ -590,9 +629,10 @@ public class ParallelBuildsManager
     }
 
     /**
-     * @see BuildsManager#removeProjectFromBuildQueue(int, int, int, String)
+     * @see BuildsManager#removeProjectFromBuildQueue(int, int, BuildTrigger, String, int)
      */
-    public void removeProjectFromBuildQueue( int projectId, int buildDefinitionId, int trigger, String projectName )
+    public void removeProjectFromBuildQueue( int projectId, int buildDefinitionId, BuildTrigger buildTrigger,
+    		                                 String projectName, int projectGroupId )
         throws BuildManagerException
     {
         try
@@ -600,7 +640,8 @@ public class ParallelBuildsManager
             OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectIsQueued( projectId, BUILD_QUEUE );
             if ( overallBuildQueue != null )
             {
-                overallBuildQueue.removeProjectFromBuildQueue( projectId, buildDefinitionId, trigger, projectName );
+            	overallBuildQueue.removeProjectFromBuildQueue( projectId, buildDefinitionId, buildTrigger, projectName,
+                                                               projectGroupId );
             }
             else
             {
@@ -859,7 +900,7 @@ public class ParallelBuildsManager
                     buildDefinitionDao.getBuildDefinition( buildTask.getBuildDefinitionId() );
 
                 buildProject( buildTask.getProjectId(), buildDefinition, buildTask.getProjectName(),
-                              buildTask.getTrigger(), buildTask.getScmResult() );
+                		      buildTask.getBuildTrigger(), buildTask.getScmResult(), buildTask.getProjectGroupId() );
             }
             catch ( ContinuumStoreException e )
             {
@@ -871,9 +912,9 @@ public class ParallelBuildsManager
         {
             try
             {
-                BuildDefinition buildDefinition = buildDefinitionDao.getDefaultBuildDefinition( task.getProjectId() );                
+                BuildDefinition buildDefinition = buildDefinitionDao.getDefaultBuildDefinition( task.getProjectId() );
                 checkoutProject( task.getProjectId(), task.getProjectName(), task.getWorkingDirectory(),
-                                 task.getScmRootUrl(), task.getScmUserName(), task.getScmPassword(), buildDefinition, task.getProjectsWithCommonScmRoot() );
+                                 task.getScmUserName(), task.getScmPassword(), buildDefinition );
             }
             catch ( ContinuumStoreException e )
             {
@@ -1034,6 +1075,94 @@ public class ParallelBuildsManager
         }
     }
 
+    public boolean isProjectCurrentlyPreparingBuild( int projectId )
+        throws BuildManagerException
+    {
+        PrepareBuildProjectsTask task = getCurrentProjectInPrepareBuild();
+
+        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 " + projectId + " is currently preparing build" );
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public PrepareBuildProjectsTask getCurrentProjectInPrepareBuild()
+        throws BuildManagerException
+    {
+        Task task = getPrepareBuildTaskQueueExecutor().getCurrentTask();
+
+        if ( task != null )
+        {
+            return (PrepareBuildProjectsTask) task;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    public List<PrepareBuildProjectsTask> getProjectsInPrepareBuildQueue()
+        throws BuildManagerException
+    {
+        try
+        {
+            return getPrepareBuildQueue().getQueueSnapshot();
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Error occurred while retrieving projects in prepare build queue", e );
+        }
+    }
+
+    public boolean removeProjectFromPrepareBuildQueue( int projectGroupId, int scmRootId )
+        throws BuildManagerException
+    {
+        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
+
+        if ( tasks != null )
+        {
+            for ( PrepareBuildProjectsTask task : tasks )
+            {
+                if ( task.getProjectGroupId() == projectGroupId && task.getProjectScmRootId() == scmRootId )
+                {
+                    return getPrepareBuildQueue().remove( task );
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public void removeProjectsFromPrepareBuildQueueWithHashCodes( int[] hashCodes )
+        throws BuildManagerException
+    {
+        List<PrepareBuildProjectsTask> tasks = getProjectsInPrepareBuildQueue();
+
+        if ( tasks != null )
+        {
+            for ( PrepareBuildProjectsTask task : tasks )
+            {
+                if ( ArrayUtils.contains( hashCodes, task.getHashCode() ) )
+                {
+                    getPrepareBuildQueue().remove( task );
+                }
+            }
+        }
+    }
+
     private boolean isInQueue( int projectId, int typeOfQueue, int buildDefinitionId )
         throws TaskQueueException
     {
@@ -1049,6 +1178,7 @@ public class ParallelBuildsManager
                     {
                         if ( overallBuildQueue.isInBuildQueue( projectId ) )
                         {
+                            log.info( "Project " + projectId + " is in build queue " + overallBuildQueue.getName() );
                             return true;
                         }
                     }
@@ -1056,6 +1186,7 @@ public class ParallelBuildsManager
                     {
                         if ( overallBuildQueue.isInBuildQueue( projectId, buildDefinitionId ) )
                         {
+                            log.info( "Project " + projectId + " is in build queue " + overallBuildQueue.getName() );
                             return true;
                         }
                     }
@@ -1064,6 +1195,7 @@ public class ParallelBuildsManager
                 {
                     if ( overallBuildQueue.isInCheckoutQueue( projectId ) )
                     {
+                        log.info( "Project " + projectId + " is in checkout queue " + overallBuildQueue.getName() );
                         return true;
                     }
                 }
@@ -1118,14 +1250,14 @@ public class ParallelBuildsManager
             {
                 throw new BuildManagerException( "No build queues configured." );
             }
-            
+
+            int size = 0;
+            int idx = 0;
+            int allowedBuilds = configurationService.getNumberOfBuildsInParallel();
+
             try
-            {     
-                int size = 0;
-                int idx = 0;
-                int allowedBuilds = configurationService.getNumberOfBuildsInParallel();
+            {
                 int count = 1;
-               
                 for ( BuildQueue buildQueue : buildQueues )
                 {
                     if ( count <= allowedBuilds )
@@ -1134,27 +1266,37 @@ public class ParallelBuildsManager
                         if ( overallBuildQueue != null )
                         {
                             TaskQueue taskQueue = null;
+                            TaskQueueExecutor taskQueueExecutor = null;
+                            int tempSize = 0;
                             if ( typeOfQueue == BUILD_QUEUE )
                             {
                                 taskQueue = overallBuildQueue.getBuildQueue();
+                                taskQueueExecutor = overallBuildQueue.getBuildTaskQueueExecutor();
                             }
                             else if ( typeOfQueue == CHECKOUT_QUEUE )
                             {
                                 taskQueue = overallBuildQueue.getCheckoutQueue();
+                                taskQueueExecutor = overallBuildQueue.getCheckoutTaskQueueExecutor();
+                            }
+
+                            tempSize = taskQueue.getQueueSnapshot().size();
+                            if ( taskQueueExecutor.getCurrentTask() != null )
+                            {
+                                tempSize++;
                             }
-       
+
                             if ( idx == 0 )
                             {
-                                size = taskQueue.getQueueSnapshot().size();
                                 whereToBeQueued = overallBuildQueue;
+                                size = tempSize;
                             }
-       
-                            if ( taskQueue.getQueueSnapshot().size() < size )
+
+                            if ( tempSize < size )
                             {
                                 whereToBeQueued = overallBuildQueue;
-                                size = taskQueue.getQueueSnapshot().size();
+                                size = tempSize;
                             }
-       
+
                             idx++;
                         }
                         else
@@ -1172,7 +1314,7 @@ public class ParallelBuildsManager
             catch ( TaskQueueException e )
             {
                 throw new BuildManagerException( "Error occurred while retrieving task quueue: " + e.getMessage() );
-            }         
+            }
         }
 
         // use default overall build queue if none is configured
@@ -1191,7 +1333,107 @@ public class ParallelBuildsManager
 
         return whereToBeQueued;
     }
- 
+
+    public OverallBuildQueue getOverallBuildQueueWhereProjectsInGroupAreQueued( int projectGroupId )
+        throws BuildManagerException
+    {
+        OverallBuildQueue whereToBeQueued = null;
+
+        try
+        {
+            List<Project> projects = projectDao.getProjectsInGroup( projectGroupId );
+
+            if ( projects != null )
+            {
+                for ( Project project : projects )
+                {
+                    whereToBeQueued = getOverallBuildQueueWhereProjectIsQueued( project.getId(), BUILD_QUEUE );
+
+                    if ( whereToBeQueued == null )
+                    {
+                        whereToBeQueued = getOverallBuildQueueWhereProjectIsBuilding( project.getId() );
+                    }
+
+                    if ( whereToBeQueued != null )
+                    {
+                        break;
+                    }
+                }
+            }
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new BuildManagerException( "Error while retrieving overall build queue for project: " + e.getMessage() );
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new BuildManagerException( "Error while retrieving overall build queue for project: " + e.getMessage() );
+        }
+
+        return whereToBeQueued;
+    }
+
+    private OverallBuildQueue getOverallBuildQueueWhereProjectIsBuilding( int projectId )
+    {
+        synchronized ( overallBuildQueues )
+        {
+            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;
+        }
+    }
+
+    public TaskQueueExecutor getPrepareBuildTaskQueueExecutor()
+        throws BuildManagerException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "prepare-build-project" );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new BuildManagerException( e.getMessage(), e );
+        }
+    }
+
+    public boolean isProjectCurrentlyBeingCheckedOut( int projectId )
+        throws BuildManagerException
+    {
+        Map<String, CheckOutTask> checkouts = getCurrentCheckouts();
+        for( String key : checkouts.keySet() )
+        {
+            CheckOutTask task = checkouts.get( key );
+            if( task.getProjectId() == projectId )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean isAnyProjectCurrentlyBuilding( int[] projectIds )
+        throws BuildManagerException
+    {
+        for ( int i = 0; i < projectIds.length; i++ )
+        {
+            if ( isProjectInAnyCurrentBuild( projectIds[i] ) ) 
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public void contextualize( Context context )
         throws ContextException
     {
@@ -1272,4 +1514,9 @@ public class ParallelBuildsManager
     {
         this.buildDefinitionDao = buildDefinitionDao;
     }
+
+    public void setProjectDao( ProjectDao projectDao )
+    {
+        this.projectDao = projectDao;
+    }
 }

Modified: continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java?rev=941625&r1=941624&r2=941625&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/purge/DefaultContinuumPurgeManager.java Thu May  6 09:23:13 2010
@@ -27,8 +27,13 @@ import org.apache.continuum.model.reposi
 import org.apache.continuum.purge.task.PurgeTask;
 import org.apache.continuum.taskqueue.manager.TaskQueueManager;
 import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.build.settings.DefaultSchedulesActivator;
+import org.apache.maven.continuum.build.settings.SchedulesActivationException;
+import org.apache.maven.continuum.build.settings.SchedulesActivator;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
@@ -43,10 +48,12 @@ import java.util.List;
 public class DefaultContinuumPurgeManager
     implements ContinuumPurgeManager
 {
+    private static final Logger log = LoggerFactory.getLogger( DefaultContinuumPurgeManager.class );
+    
     /**
      * @plexus.requirement
      */
-    private ProjectDao projectDao;
+    private SchedulesActivator schedulesActivator;
 
     /**
      * @plexus.requirement
@@ -69,8 +76,8 @@ public class DefaultContinuumPurgeManage
         List<RepositoryPurgeConfiguration> repoPurgeList = null;
         List<DirectoryPurgeConfiguration> dirPurgeList = null;
 
-        repoPurgeList = purgeConfigurationService.getRepositoryPurgeConfigurationsBySchedule( schedule.getId() );
-        dirPurgeList = purgeConfigurationService.getDirectoryPurgeConfigurationsBySchedule( schedule.getId() );
+        repoPurgeList = purgeConfigurationService.getEnableRepositoryPurgeConfigurationsBySchedule( schedule.getId() );
+        dirPurgeList = purgeConfigurationService.getEnableDirectoryPurgeConfigurationsBySchedule( schedule.getId() );
 
         if ( repoPurgeList != null && repoPurgeList.size() > 0 )
         {
@@ -87,6 +94,20 @@ public class DefaultContinuumPurgeManage
                 purgeDirectory( dirPurge );
             }
         }
+        
+        if ( ( repoPurgeList == null || repoPurgeList.isEmpty() ) && ( dirPurgeList == null || dirPurgeList.isEmpty() ) )
+        {
+            // This purge is not enable for a purge process.
+            try
+            {
+                schedulesActivator.unactivateOrphanPurgeSchedule( schedule );
+            }
+            catch ( SchedulesActivationException e )
+            {
+                log.debug( String.format( "Can't unactivate orphan schedule '%s' for purgeConfiguration",
+                                          schedule.getName() ) );
+            }
+        }
     }
 
     public void purgeRepository( RepositoryPurgeConfiguration repoPurge )

Modified: continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/DistributedReleaseUtil.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/DistributedReleaseUtil.java?rev=941625&r1=941624&r2=941625&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/DistributedReleaseUtil.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/DistributedReleaseUtil.java Thu May  6 09:23:13 2010
@@ -99,6 +99,8 @@ public class DistributedReleaseUtil
     public static final String KEY_RELEASE_GOAL = "release-goal";
 
     public static final String KEY_BUILD_AGENT_URL = "build-agent-url";
+    
+    public static final String KEY_USERNAME = "username";
 
     public static String getScmTag( Map<String, Object> context, String defaultValue )
     {
@@ -209,6 +211,11 @@ public class DistributedReleaseUtil
     {
         return getInteger( context, KEY_PROJECT_ID );
     }
+    
+    public static String getUsername( Map<String, Object> context )
+    {
+        return getString( context, KEY_USERNAME, "" );
+    }
 
     // ----------------------------------------------------------------------
     //

Modified: continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java?rev=941625&r1=941624&r2=941625&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java Thu May  6 09:23:13 2010
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.continuum.builder.distributed.manager.DistributedBuildManager;
 import org.apache.continuum.configuration.BuildAgentConfiguration;
 import org.apache.continuum.configuration.BuildAgentConfigurationException;
 import org.apache.continuum.dao.BuildResultDao;
@@ -48,6 +49,7 @@ import org.apache.maven.continuum.model.
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.release.ContinuumReleaseException;
 import org.apache.maven.shared.release.ReleaseResult;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.slf4j.Logger;
@@ -78,14 +80,17 @@ public class DefaultDistributedReleaseMa
      */
     ConfigurationService configurationService;
 
+    /**
+     * @plexus.requirement
+     */
+    DistributedBuildManager distributedBuildManager;
+
     private Map<String, Map<String, Object>> releasesInProgress;
 
     public Map getReleasePluginParameters( int projectId, String pomFilename )
         throws ContinuumReleaseException, BuildAgentConfigurationException
     {
-        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId );
-
-        String buildAgentUrl = buildResult.getBuildUrl();
+        String buildAgentUrl = getDefaultBuildagent( projectId );
 
         if ( !checkBuildAgent( buildAgentUrl ) )
         {
@@ -94,8 +99,16 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            return client.getReleasePluginParameters( projectId, pomFilename );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                return client.getReleasePluginParameters( projectId, pomFilename );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Failed to retrieve release plugin parameters because build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -123,8 +136,16 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            return client.processProject( projectId, pomFilename, autoVersionSubmodules );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                return client.processProject( projectId, pomFilename, autoVersionSubmodules );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Failed to process project for releasing because build agent " + buildAgentUrl + " is unavailable" );
         }
         catch ( MalformedURLException e )
         {
@@ -139,12 +160,10 @@ public class DefaultDistributedReleaseMa
     }
 
     public String releasePrepare( Project project, Properties releaseProperties, Map<String, String> releaseVersion,
-                                  Map<String, String> developmentVersion, Map<String, String> environments )
+                                  Map<String, String> developmentVersion, Map<String, String> environments, String username )
         throws ContinuumReleaseException, BuildAgentConfigurationException
     {
-        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( project.getId() );
-
-        String buildAgentUrl = buildResult.getBuildUrl();
+        String buildAgentUrl = environments.get( DistributedReleaseUtil.KEY_BUILD_AGENT_URL );
 
         if ( !checkBuildAgent( buildAgentUrl ) )
         {
@@ -153,16 +172,25 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            String releaseId =
-                client.releasePrepare( createProjectMap( project ), createPropertiesMap( releaseProperties ),
-                                       releaseVersion, developmentVersion, environments );
-
-            addReleasePrepare( releaseId, buildAgentUrl, releaseVersion.get( releaseId ) );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+    
+                String releaseId =
+                    client.releasePrepare( createProjectMap( project ), createPropertiesMap( releaseProperties ),
+                                           releaseVersion, developmentVersion, environments, username );
+    
+                addReleasePrepare( releaseId, buildAgentUrl, releaseVersion.get( releaseId ), "prepare" );
+    
+                addReleaseInProgress( releaseId, "prepare", project.getId(), username );
+    
+                return releaseId;
+            }
 
-            addReleaseInProgress( releaseId, "prepare", project.getId() );
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
 
-            return releaseId;
+            throw new ContinuumReleaseException( "Failed to prepare release project because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -188,16 +216,25 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            Map<String, Object> result = client.getReleaseResult( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                Map<String, Object> result = client.getReleaseResult( releaseId );
+    
+                ReleaseResult releaseResult = new ReleaseResult();
+                releaseResult.setStartTime( DistributedReleaseUtil.getStartTime( result ) );
+                releaseResult.setEndTime( DistributedReleaseUtil.getEndTime( result ) );
+                releaseResult.setResultCode( DistributedReleaseUtil.getReleaseResultCode( result ) );
+                releaseResult.getOutputBuffer().append( DistributedReleaseUtil.getReleaseOutput( result ) );
+    
+                return releaseResult;
+            }
 
-            ReleaseResult releaseResult = new ReleaseResult();
-            releaseResult.setStartTime( DistributedReleaseUtil.getStartTime( result ) );
-            releaseResult.setEndTime( DistributedReleaseUtil.getEndTime( result ) );
-            releaseResult.setResultCode( DistributedReleaseUtil.getReleaseResultCode( result ) );
-            releaseResult.getOutputBuffer().append( DistributedReleaseUtil.getReleaseOutput( result ) );
+            // call reload in case we disable a build agent
+            distributedBuildManager.reload();
 
-            return releaseResult;
+            throw new ContinuumReleaseException( "Failed to get release result of " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -223,8 +260,17 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            return client.getListener( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                return client.getListener( releaseId );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Failed to get listener for " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -250,8 +296,17 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            client.removeListener( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                client.removeListener( releaseId );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Failed to remove listener of " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -278,8 +333,17 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            return client.getPreparedReleaseName( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                return client.getPreparedReleaseName( releaseId );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Failed to get prepared release name of " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -294,9 +358,21 @@ public class DefaultDistributedReleaseMa
     }
 
     public void releasePerform( int projectId, String releaseId, String goals, String arguments,
-                                boolean useReleaseProfile, LocalRepository repository )
+                                boolean useReleaseProfile, LocalRepository repository, String username )
         throws ContinuumReleaseException, BuildAgentConfigurationException
     {
+        List<PreparedRelease> releases = getPreparedReleases();
+
+        for ( PreparedRelease release: releases )
+        {
+            if ( release.getReleaseId().equals( releaseId ) )
+            {
+                release.setReleaseType( "perform" );
+                savePreparedReleases( releases );
+                break;
+            }
+        }
+
         String buildAgentUrl = getBuildAgentUrl( releaseId );
 
         if ( !checkBuildAgent( buildAgentUrl ) )
@@ -315,20 +391,28 @@ public class DefaultDistributedReleaseMa
         }
 
         Map<String, String> map = new HashMap<String, String>();
+        map.put( DistributedReleaseUtil.KEY_USERNAME, username );
 
         if ( repository != null )
-        {
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY, repository.getLocation() );
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_NAME, repository.getName() );
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_LAYOUT, repository.getLayout() );
+        {   
+            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_NAME, repository.getName() );         
         }
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            client.releasePerform( releaseId, goals, arguments, useReleaseProfile, map );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                client.releasePerform( releaseId, goals, arguments, useReleaseProfile, map, username );
+    
+                addReleaseInProgress( releaseId, "perform", projectId, username );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
 
-            addReleaseInProgress( releaseId, "perform", projectId );
+            throw new ContinuumReleaseException( "Failed to perform release of " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -342,14 +426,12 @@ public class DefaultDistributedReleaseMa
         }
     }
 
-    public void releasePerformFromScm( int projectId, String goals, String arguments, boolean useReleaseProfile,
-                                       LocalRepository repository, String scmUrl, String scmUsername,
-                                       String scmPassword, String scmTag, String scmTagBase, Map environments )
+    public String releasePerformFromScm( int projectId, String goals, String arguments, boolean useReleaseProfile,
+                                         LocalRepository repository, String scmUrl, String scmUsername,
+                                         String scmPassword, String scmTag, String scmTagBase, Map environments, String username )
         throws ContinuumReleaseException, BuildAgentConfigurationException
     {
-        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId );
-
-        String buildAgentUrl = buildResult.getBuildUrl();
+        String buildAgentUrl = (String) environments.get( DistributedReleaseUtil.KEY_BUILD_AGENT_URL );
 
         if ( !checkBuildAgent( buildAgentUrl ) )
         {
@@ -367,22 +449,32 @@ public class DefaultDistributedReleaseMa
         }
 
         Map<String, String> map = new HashMap<String, String>();
+        map.put( DistributedReleaseUtil.KEY_USERNAME, username );
 
         if ( repository != null )
-        {
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY, repository.getLocation() );
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_NAME, repository.getName() );
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_LAYOUT, repository.getLayout() );
+        {            
+            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_NAME, repository.getName() );         
         }
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            String releaseId =
-                client.releasePerformFromScm( goals, arguments, useReleaseProfile, map, scmUrl, scmUsername,
-                                              scmPassword, scmTag, scmTagBase, environments );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                String releaseId =
+                    client.releasePerformFromScm( goals, arguments, useReleaseProfile, map, scmUrl, scmUsername,
+                                                  scmPassword, scmTag, scmTagBase, environments, username );
+    
+                addReleasePrepare( releaseId, buildAgentUrl, scmTag, "perform" );
+                addReleaseInProgress( releaseId, "perform", projectId, username );
+    
+                return releaseId;
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
 
-            addReleaseInProgress( releaseId, "perform", projectId );
+            throw new ContinuumReleaseException( "Failed to perform release because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -408,8 +500,17 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            client.releaseRollback( releaseId, projectId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                client.releaseRollback( releaseId, projectId );
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
+
+            throw new ContinuumReleaseException( "Unable to rollback release " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -435,11 +536,22 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-            String result = client.releaseCleanup( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                String result = client.releaseCleanup( releaseId );
+    
+                removeFromReleaseInProgress( releaseId );
+                removeFromPreparedReleases( releaseId );
+    
+                return result;
+            }
+
+            // call reload in case we disable the build agent
+            distributedBuildManager.reload();
 
-            removeFromReleaseInProgress( releaseId );
-            return result;
+            throw new ContinuumReleaseException( "Failed to cleanup release of " + releaseId + 
+                                                 " because the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -448,8 +560,8 @@ public class DefaultDistributedReleaseMa
         }
         catch ( Exception e )
         {
-            log.error( "Failed to get prepared release name of " + releaseId, e );
-            throw new ContinuumReleaseException( "Failed to get prepared release name of " + releaseId, e );
+            log.error( "Failed to cleanup release of " + releaseId, e );
+            throw new ContinuumReleaseException( "Failed to cleanup release of " + releaseId, e );
         }
     }
 
@@ -474,19 +586,22 @@ public class DefaultDistributedReleaseMa
 
                     try
                     {
-                        SlaveBuildAgentTransportClient client =
-                            new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
-                        Map map = client.getListener( releaseId );
-
-                        if ( map != null && !map.isEmpty() )
+                        if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
                         {
-                            Map<String, Object> release = releasesInProgress.get( releaseId );
-                            release.put( DistributedReleaseUtil.KEY_RELEASE_ID, releaseId );
-                            release.put( DistributedReleaseUtil.KEY_BUILD_AGENT_URL, buildAgentUrl );
-
-                            releases.add( release );
-
-                            releasesMap.put( releaseId, releasesInProgress.get( releaseId ) );
+                            SlaveBuildAgentTransportClient client =
+                                new SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
+                            Map map = client.getListener( releaseId );
+    
+                            if ( map != null && !map.isEmpty() )
+                            {
+                                Map<String, Object> release = releasesInProgress.get( releaseId );
+                                release.put( DistributedReleaseUtil.KEY_RELEASE_ID, releaseId );
+                                release.put( DistributedReleaseUtil.KEY_BUILD_AGENT_URL, buildAgentUrl );
+    
+                                releases.add( release );
+    
+                                releasesMap.put( releaseId, releasesInProgress.get( releaseId ) );
+                            }
                         }
                     }
                     catch ( MalformedURLException e )
@@ -505,8 +620,25 @@ public class DefaultDistributedReleaseMa
             releasesInProgress = releasesMap;
         }
 
+        try
+        {
+            // call reload in case we disable a build agent
+            distributedBuildManager.reload();
+        }
+        catch ( Exception e )
+        {
+            throw new ContinuumReleaseException( e.getMessage(), e );
+        }
+
         return releases;
     }
+    
+    public String getDefaultBuildagent( int projectId )
+    {
+        BuildResult buildResult = buildResultDao.getLatestBuildResultForProject( projectId );
+        
+        return buildResult != null ? buildResult.getBuildUrl() : null;
+    }
 
     private Map createProjectMap( Project project )
     {
@@ -518,8 +650,8 @@ public class DefaultDistributedReleaseMa
         map.put( DistributedReleaseUtil.KEY_SCM_URL, project.getScmUrl() );
         if ( project.getProjectGroup().getLocalRepository() != null )
         {
-            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY,
-                     project.getProjectGroup().getLocalRepository().getLocation() );
+            map.put( DistributedReleaseUtil.KEY_LOCAL_REPOSITORY_NAME,
+                     project.getProjectGroup().getLocalRepository().getName() );
         }
 
         return map;
@@ -599,10 +731,12 @@ public class DefaultDistributedReleaseMa
 
         if ( file.exists() )
         {
+            FileInputStream fis = null;
             try
             {
+                fis = new FileInputStream( file );
                 ContinuumPrepareReleasesModelXpp3Reader reader = new ContinuumPrepareReleasesModelXpp3Reader();
-                PreparedReleaseModel model = reader.read( new InputStreamReader( new FileInputStream( file ) ) );
+                PreparedReleaseModel model = reader.read( new InputStreamReader( fis ) );
 
                 return model.getPreparedReleases();
             }
@@ -616,25 +750,26 @@ public class DefaultDistributedReleaseMa
                 log.error( e.getMessage(), e );
                 throw new ContinuumReleaseException( e.getMessage(), e );
             }
+            finally
+            {
+                if ( fis != null )
+                {
+                    IOUtil.close( fis );
+                }
+            }
         }
 
         return null;
     }
 
-    private void addReleasePrepare( String releaseId, String buildAgentUrl, String releaseName )
+    private void addReleasePrepare( String releaseId, String buildAgentUrl, String releaseName, String releaseType )
         throws ContinuumReleaseException
     {
-        File file = getPreparedReleasesFile();
-
-        if ( !file.exists() )
-        {
-            file.getParentFile().mkdirs();
-        }
-
         PreparedRelease release = new PreparedRelease();
         release.setReleaseId( releaseId );
         release.setBuildAgentUrl( buildAgentUrl );
         release.setReleaseName( releaseName );
+        release.setReleaseType( releaseType );
 
         List<PreparedRelease> preparedReleases = getPreparedReleases();
 
@@ -642,42 +777,28 @@ public class DefaultDistributedReleaseMa
         {
             preparedReleases = new ArrayList<PreparedRelease>();
         }
-        else
-        {
-            boolean found = false;
 
-            for ( PreparedRelease preparedRelease : preparedReleases )
-            {
-                if ( preparedRelease.getReleaseId().equals( release.getReleaseId() ) &&
-                    preparedRelease.getReleaseName().equals( release.getReleaseName() ) )
-                {
-                    preparedRelease.setBuildAgentUrl( release.getBuildAgentUrl() );
-                    found = true;
-                }
-            }
+        boolean found = false;
 
-            if ( !found )
+        for ( PreparedRelease preparedRelease : preparedReleases )
+        {
+            if ( preparedRelease.getReleaseId().equals( release.getReleaseId() ) &&
+                 preparedRelease.getReleaseName().equals( release.getReleaseName() ) )
             {
-                preparedReleases.add( release );
+                preparedRelease.setBuildAgentUrl( release.getBuildAgentUrl() );
+                found = true;
             }
         }
 
-        PreparedReleaseModel model = new PreparedReleaseModel();
-        model.setPreparedReleases( preparedReleases );
-
-        try
+        if ( !found )
         {
-            ContinuumPrepareReleasesModelXpp3Writer writer = new ContinuumPrepareReleasesModelXpp3Writer();
-            FileWriter fileWriter = new FileWriter( file );
-            writer.write( fileWriter, model );
-        }
-        catch ( IOException e )
-        {
-            throw new ContinuumReleaseException( "Failed to write prepared releases in file", e );
+            preparedReleases.add( release );
         }
+
+        savePreparedReleases( preparedReleases );
     }
 
-    private void addReleaseInProgress( String releaseId, String releaseType, int projectId )
+    private void addReleaseInProgress( String releaseId, String releaseType, int projectId, String username )
     {
         if ( releasesInProgress == null )
         {
@@ -687,6 +808,7 @@ public class DefaultDistributedReleaseMa
         Map<String, Object> map = new HashMap<String, Object>();
         map.put( DistributedReleaseUtil.KEY_RELEASE_GOAL, releaseType );
         map.put( DistributedReleaseUtil.KEY_PROJECT_ID, projectId );
+        map.put( DistributedReleaseUtil.KEY_USERNAME, username );
 
         releasesInProgress.put( releaseId, map );
     }
@@ -733,7 +855,60 @@ public class DefaultDistributedReleaseMa
             return true;
         }
 
-        log.info( "Build agent: " + buildAgentUrl + "is either disabled or removed" );
+        log.info( "Build agent: " + buildAgentUrl + " is either disabled or removed" );
         return false;
     }
+
+    private void removeFromPreparedReleases( String releaseId )
+        throws ContinuumReleaseException
+    {
+        List<PreparedRelease> releases = getPreparedReleases();
+
+        for ( PreparedRelease release : releases )
+        {
+            if ( release.getReleaseId().equals( releaseId ) )
+            {
+                if ( release.getReleaseType().equals( "perform" ) )
+                {
+                    releases.remove( release );
+                    savePreparedReleases( releases );
+                    break;
+                }
+            }
+        }
+    }
+
+    private void savePreparedReleases( List<PreparedRelease> preparedReleases)
+        throws ContinuumReleaseException
+    {
+        File file = getPreparedReleasesFile();
+
+        if ( !file.exists() )
+        {
+            file.getParentFile().mkdirs();
+        }
+
+        PreparedReleaseModel model = new PreparedReleaseModel();
+        model.setPreparedReleases( preparedReleases );
+
+        try
+        {
+            ContinuumPrepareReleasesModelXpp3Writer writer = new ContinuumPrepareReleasesModelXpp3Writer();
+            FileWriter fileWriter = new FileWriter( file );
+            writer.write( fileWriter, model );
+            fileWriter.flush();
+            fileWriter.close();
+        }
+        catch ( IOException e )
+        {
+            throw new ContinuumReleaseException( "Failed to write prepared releases in file", e );
+        }
+    }
+    
+    // for unit test
+    
+    public void setBuildResultDao( BuildResultDao buildResultDao )
+    {
+        this.buildResultDao = buildResultDao;
+    }
 }
\ No newline at end of file

Modified: continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java?rev=941625&r1=941624&r2=941625&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-core/src/main/java/org/apache/continuum/taskqueue/DefaultOverallBuildQueue.java Thu May  6 09:23:13 2010
@@ -27,6 +27,7 @@ import javax.annotation.Resource;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.continuum.dao.BuildDefinitionDao;
 import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor;
+import org.apache.continuum.utils.build.BuildTrigger;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.taskqueue.Task;
@@ -323,9 +324,10 @@ public class DefaultOverallBuildQueue
     }
 
     /**
-     * @see OverallBuildQueue#removeProjectFromBuildQueue(int, int, int, String)
+     * @see OverallBuildQueue#removeProjectFromBuildQueue(int, int, BuildTrigger, String, int)
      */
-    public boolean removeProjectFromBuildQueue( int projectId, int buildDefinitionId, int trigger, String projectName )
+    public boolean removeProjectFromBuildQueue( int projectId, int buildDefinitionId, BuildTrigger buildTrigger,
+    		                                    String projectName, int projectGroupId )
         throws TaskQueueException
     {
         BuildDefinition buildDefinition;
@@ -347,7 +349,8 @@ public class DefaultOverallBuildQueue
         }
 
         BuildProjectTask buildProjectTask =
-            new BuildProjectTask( projectId, buildDefinitionId, trigger, projectName, buildDefinitionLabel, null );
+        	                      new BuildProjectTask( projectId, buildDefinitionId, buildTrigger, projectName, 
+                                  buildDefinitionLabel, null, projectGroupId );
 
         return getBuildQueue().remove( buildProjectTask );
     }



Mime
View raw message