continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1082448 - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/ continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/ continuum-xmlrpc/continuum-xmlrpc-api/src/main/java...
Date Thu, 17 Mar 2011 11:46:30 GMT
Author: ctan
Date: Thu Mar 17 11:46:30 2011
New Revision: 1082448

URL: http://svn.apache.org/viewvc?rev=1082448&view=rev
Log:
[CONTINUUM-2617] cancel a project build for distributed builds

Submitted By: John Michael Luy

Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
    continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-api/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumService.java
    continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/ContinuumXmlRpcClient.java
    continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java?rev=1082448&r1=1082447&r2=1082448&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
Thu Mar 17 11:46:30 2011
@@ -103,4 +103,7 @@ public interface DistributedBuildManager
 
     boolean isProjectCurrentlyBuilding( int projectId, int buildDefinitionId )
         throws ContinuumException;
+        
+    String getBuildAgentUrl( int projectId )
+        throws ContinuumException;
 }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java?rev=1082448&r1=1082447&r2=1082448&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
Thu Mar 17 11:46:30 2011
@@ -1055,6 +1055,54 @@ public class DefaultDistributedBuildMana
         return agentUrl;
     }
 
+    public String getBuildAgentUrl( int projectId )
+        throws ContinuumException
+    {
+        String agentUrl = null;
+
+        synchronized( overallDistributedBuildQueues )
+        {
+            for ( String buildAgentUrl : overallDistributedBuildQueues.keySet() )
+            {
+                OverallDistributedBuildQueue overallDistributedBuildQueue = 
+                    overallDistributedBuildQueues.get( buildAgentUrl );
+    
+                if ( overallDistributedBuildQueue != null )
+                {
+                    try
+                    {
+                        if ( isAgentAvailable( buildAgentUrl ) )
+                        {
+                            SlaveBuildAgentTransportService client = createSlaveBuildAgentTransportClientConnection(
buildAgentUrl );
+                            
+                            if ( client.isProjectGroupCurrentlyPreparingBuild( projectId
) ||
+                                client.isProjectCurrentlyBuilding( projectId ) ||
+                                client.isProjectGroupInPrepareBuildQueue( projectId ) ||
+                                client.isProjectInBuildQueue( projectId ) )
+                            {
+                                agentUrl = buildAgentUrl;
+                                break;
+                            }
+                        }
+                    }
+                    catch ( MalformedURLException e )
+                    {
+                        log.warn( "Unable to check if project " + projectId + " is currently
queued or processed in agent: Invalid build agent url" + buildAgentUrl );
+                    }
+                    catch ( Exception e )
+                    {
+                        log.warn( "Unable to check if project " + projectId + " is currently
queued or processed in agent", e );
+                    }
+                }
+            }
+        }
+
+        // call reload in case we disable a build agent
+        reload();
+
+        return agentUrl;
+    }
+
     private void createDistributedBuildQueueForAgent( String buildAgentUrl )
         throws ComponentLookupException
     {
@@ -1521,4 +1569,4 @@ public class DefaultDistributedBuildMana
         this.container = container;
     }
 
-}
\ No newline at end of file
+}

Modified: continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-api/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-api/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumService.java?rev=1082448&r1=1082447&r2=1082448&view=diff
==============================================================================
--- continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-api/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumService.java
(original)
+++ continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-api/src/main/java/org/apache/maven/continuum/xmlrpc/ContinuumService.java
Thu Mar 17 11:46:30 2011
@@ -1189,6 +1189,16 @@ public interface ContinuumService
     boolean cancelCurrentBuild()
         throws Exception;
 
+    /**
+     * Cancel a project build
+     * 
+     * @param projectId the project id
+     * @return
+     * @throws Exception
+     */
+    boolean cancelBuild( int projectId )
+        throws Exception;
+
     // ----------------------------------------------------------------------
     // TODO:Users
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/ContinuumXmlRpcClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/ContinuumXmlRpcClient.java?rev=1082448&r1=1082447&r2=1082448&view=diff
==============================================================================
--- continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/ContinuumXmlRpcClient.java
(original)
+++ continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-client/src/main/java/org/apache/maven/continuum/xmlrpc/client/ContinuumXmlRpcClient.java
Thu Mar 17 11:46:30 2011
@@ -583,6 +583,12 @@ public class ContinuumXmlRpcClient
         return continuum.cancelCurrentBuild();
     }
 
+    public boolean cancelBuild( int projectId )
+        throws Exception
+    {
+        return continuum.cancelBuild( projectId );
+    }
+
     // ----------------------------------------------------------------------
     // Release Result
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java?rev=1082448&r1=1082447&r2=1082448&view=diff
==============================================================================
--- continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
(original)
+++ continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
Thu Mar 17 11:46:30 2011
@@ -40,6 +40,7 @@ import org.apache.continuum.configuratio
 import org.apache.continuum.configuration.BuildAgentGroupConfiguration;
 import org.apache.continuum.configuration.ContinuumConfigurationException;
 import org.apache.continuum.dao.SystemConfigurationDao;
+import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.purge.ContinuumPurgeManagerException;
 import org.apache.continuum.purge.PurgeConfigurationServiceException;
 import org.apache.continuum.repository.RepositoryServiceException;
@@ -102,7 +103,7 @@ public class ContinuumServiceImpl
     private static final MapperIF mapper = DozerBeanMapperSingletonWrapper.getInstance();
 
     private final Logger logger = LoggerFactory.getLogger( ContinuumServiceImpl.class );
-    
+
     /**
      * @plexus.requirement
      */
@@ -658,7 +659,7 @@ public class ContinuumServiceImpl
     {
         ProjectSummary ps = getProjectSummary( projectId );
         checkBuildProjectInGroupAuthorization( ps.getProjectGroup().getName() );
-        
+
         buildProjectWithBuildDefinition( projectId, buildDefinitionId,
                                          new org.apache.continuum.utils.build.BuildTrigger(
ContinuumProjectState.TRIGGER_SCHEDULED, "" ) );
         return 0;
@@ -675,7 +676,7 @@ public class ContinuumServiceImpl
         continuum.buildProject( projectId, buildTrigger );
         return 0;
     }
-    
+
     public int buildProject( int projectId, int buildDefinitionId, BuildTrigger xmlrpcBuildTrigger
)
         throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException
     {
@@ -684,7 +685,7 @@ public class ContinuumServiceImpl
 
         org.apache.continuum.utils.build.BuildTrigger buildTrigger = populateBuildTrigger(
xmlrpcBuildTrigger );
         buildProjectWithBuildDefinition( projectId, buildDefinitionId, buildTrigger );
-        
+
         return 0;
     }
 
@@ -859,7 +860,7 @@ public class ContinuumServiceImpl
 
         return populateAddingResult( result );
     }
-    
+
     public AddingResult addMavenTwoProject( String url, int projectGroupId, boolean checkProtocol,
                                             boolean useCredentialsCache, boolean recursiveProjects,
                                             boolean checkoutInSingleDirectory )
@@ -1269,7 +1270,7 @@ public class ContinuumServiceImpl
         try
         {
             Map<String, List<org.apache.continuum.taskqueue.BuildProjectTask>>
buildTasks;
-            
+
             if ( continuum.getConfiguration().isDistributedBuildEnabled() )
             {
                 buildTasks = distributedBuildManager.getProjectsInBuildQueue();
@@ -1278,7 +1279,7 @@ public class ContinuumServiceImpl
             {
                 buildTasks = parallelBuildsManager.getProjectsInBuildQueues();
             }
-                
+
             Set<String> keys = buildTasks.keySet();
             List<org.apache.continuum.taskqueue.BuildProjectTask> convertedTasks =
                 new ArrayList<org.apache.continuum.taskqueue.BuildProjectTask>();
@@ -1324,6 +1325,105 @@ public class ContinuumServiceImpl
         }
     }
 
+    public boolean cancelBuild( int projectId )
+        throws ContinuumException
+    {
+        checkManageQueuesAuthorization();
+        try
+        {
+            if ( continuum.getConfiguration().isDistributedBuildEnabled() )
+            {
+                DistributedBuildManager dbm = continuum.getDistributedBuildManager();
+
+                String buildAgentUrl = dbm.getBuildAgentUrl( projectId );
+
+                // wait if already preparing
+                if ( dbm.isProjectCurrentlyPreparingBuild( projectId, -1 ) )
+                {
+                    while ( dbm.isProjectCurrentlyPreparingBuild( projectId, -1 ) )
+                    {
+                        try
+                        {
+                            Thread.sleep( 1000 );
+                        }
+                        catch ( InterruptedException e )
+                        {
+                            // do nothing
+                        }
+                    }
+                }
+
+                if ( dbm.isProjectInAnyPrepareBuildQueue( projectId, -1 ) )
+                {
+                    if ( buildAgentUrl != null )
+                    {
+                        ProjectScmRoot scmRoot = continuum.getProjectScmRootByProject( projectId
);
+                        dbm.removeFromPrepareBuildQueue( buildAgentUrl, scmRoot.getProjectGroup().getId(),
+                                                         scmRoot.getId() );
+                    }
+                }
+                else if ( dbm.isProjectInAnyBuildQueue( projectId, -1 ) )
+                {
+                    dbm.removeFromBuildQueue( buildAgentUrl, projectId, -1 );
+                }
+                else if ( dbm.isProjectCurrentlyBuilding( projectId, -1 ) )
+                {
+                    if ( buildAgentUrl != null )
+                    {
+                        dbm.cancelDistributedBuild( buildAgentUrl );
+                    }
+                }
+
+                return true;
+            }
+            else
+            {
+                // if currently preparing build or being checked out, wait until done
+                if ( parallelBuildsManager.isProjectCurrentlyPreparingBuild( projectId )
||
+                    parallelBuildsManager.isProjectCurrentlyBeingCheckedOut( projectId )
)
+                {
+                    while ( parallelBuildsManager.isProjectCurrentlyPreparingBuild( projectId
) ||
+                        parallelBuildsManager.isProjectCurrentlyBeingCheckedOut( projectId
) )
+                    {
+                        try
+                        {
+                            Thread.sleep( 1000 );
+                        }
+                        catch ( InterruptedException e )
+                        {
+                            // do nothing
+                        }
+                    }
+                }
+
+                if ( parallelBuildsManager.isInPrepareBuildQueue( projectId ) )
+                {
+                    ProjectScmRoot scmRoot = continuum.getProjectScmRootByProject( projectId
);
+                    parallelBuildsManager.removeProjectFromPrepareBuildQueue( scmRoot.getProjectGroup().getId(),
+                                                                              scmRoot.getId()
);
+                }
+                else if ( parallelBuildsManager.isInAnyCheckoutQueue( projectId ) )
+                {
+                    parallelBuildsManager.removeProjectFromCheckoutQueue( projectId );
+                }
+                else if ( parallelBuildsManager.isInAnyBuildQueue( projectId ) )
+                {
+                    parallelBuildsManager.removeProjectFromBuildQueue( projectId );
+                }
+                else if ( parallelBuildsManager.isProjectInAnyCurrentBuild( projectId ) )
+                {
+                    return parallelBuildsManager.cancelBuild( projectId );
+                }
+
+                return true;
+            }
+        }
+        catch ( BuildManagerException e )
+        {
+            throw new ContinuumException( e.getMessage(), e );
+        }
+    }
+
     // ----------------------------------------------------------------------
     // Release Results
     // ----------------------------------------------------------------------
@@ -1994,7 +2094,7 @@ public class ContinuumServiceImpl
         {
             bd.setSchedule( null );
         }
-        
+
         if ( StringUtils.isNotEmpty( buildDef.getDescription() ) )
         {
             bd.setDescription( buildDef.getDescription() );
@@ -2002,7 +2102,7 @@ public class ContinuumServiceImpl
 
         return bd;
     }
-    
+
     protected void buildProjectWithBuildDefinition( int projectId, int buildDefinitionId,
org.apache.continuum.utils.build.BuildTrigger buildTrigger )
         throws ContinuumException, NoBuildAgentException, NoBuildAgentInGroupException
     {
@@ -2730,7 +2830,7 @@ public class ContinuumServiceImpl
     {
         return serializeObject( this.addMavenTwoProjectAsSingleProject( url, projectGroupId
) );
     }
-    
+
     public Map<String, Object> addMavenTwoProjectRPC( String url, int projectGroupId,
boolean checkProtocol,
                                                       boolean useCredentialsCache, boolean
recursiveProjects,
                                                       boolean checkoutInSingleDirectory )



Mime
View raw message