continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r926873 - 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-core/src/main/java/org/apache/continuum/re...
Date Wed, 24 Mar 2010 00:04:49 GMT
Author: ctan
Date: Wed Mar 24 00:04:49 2010
New Revision: 926873

URL: http://svn.apache.org/viewvc?rev=926873&view=rev
Log:
also add the check if agent is available during releases

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-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManagerTest.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=926873&r1=926872&r2=926873&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
Wed Mar 24 00:04:49 2010
@@ -82,4 +82,7 @@ public interface DistributedBuildManager
 
     void removeFromBuildQueue( List<String> hashCodes )
         throws ContinuumException;
+
+    boolean isAgentAvailable( String buildAgentUrl )
+        throws ContinuumException;
 }
\ No newline at end of file

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=926873&r1=926872&r2=926873&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
Wed Mar 24 00:04:49 2010
@@ -32,6 +32,7 @@ import org.apache.continuum.builder.dist
 import org.apache.continuum.builder.utils.ContinuumBuildConstant;
 import org.apache.continuum.configuration.BuildAgentConfiguration;
 import org.apache.continuum.configuration.BuildAgentGroupConfiguration;
+import org.apache.continuum.configuration.ContinuumConfigurationException;
 import org.apache.continuum.dao.BuildDefinitionDao;
 import org.apache.continuum.dao.BuildResultDao;
 import org.apache.continuum.dao.ProjectDao;
@@ -44,6 +45,7 @@ import org.apache.continuum.utils.Projec
 import org.apache.continuum.utils.build.BuildTrigger;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.configuration.ConfigurationStoringException;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
@@ -1135,8 +1137,8 @@ public class DefaultDistributedBuildMana
         return new BuildProjectTask( projectId, buildDefinitionId, buildTrigger, null, buildDefinitionLabel,
null, projectGroupId );
     }
 
-    private boolean isAgentAvailable( String buildAgentUrl )
-        throws Exception
+    public boolean isAgentAvailable( String buildAgentUrl )
+        throws ContinuumException
     {
         try
         {
@@ -1161,7 +1163,7 @@ public class DefaultDistributedBuildMana
     }
 
     private void disableBuildAgent( String buildAgentUrl )
-        throws Exception
+        throws ContinuumException
     {
         List<BuildAgentConfiguration> agents = configurationService.getBuildAgents();
 
@@ -1171,7 +1173,15 @@ public class DefaultDistributedBuildMana
             {
                 agent.setEnabled( false );
                 configurationService.updateBuildAgent( agent );
-                configurationService.store();
+
+                try
+                {
+                    configurationService.store();
+                }
+                catch ( Exception e )
+                {
+                    throw new ContinuumException( "Unable to disable build agent: " + buildAgentUrl,
e );
+                }
 
                 removeDistributedBuildQueueOfAgent( buildAgentUrl );
             }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java?rev=926873&r1=926872&r2=926873&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/release/distributed/manager/DefaultDistributedReleaseManager.java
Wed Mar 24 00:04:49 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;
@@ -79,6 +80,11 @@ public class DefaultDistributedReleaseMa
      */
     ConfigurationService configurationService;
 
+    /**
+     * @plexus.requirement
+     */
+    DistributedBuildManager distributedBuildManager;
+
     private Map<String, Map<String, Object>> releasesInProgress;
 
     public Map getReleasePluginParameters( int projectId, String pomFilename )
@@ -95,8 +101,13 @@ 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 );
+            }
+
+            throw new ContinuumReleaseException( "Failed to retrieve release plugin parameters
because build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -124,8 +135,13 @@ 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
);
+            }
+
+            throw new ContinuumReleaseException( "Failed to process project for releasing
because build agent " + buildAgentUrl + " is unavailable" );
         }
         catch ( MalformedURLException e )
         {
@@ -154,17 +170,22 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            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 );
+            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;
+            }
 
-            return releaseId;
+            throw new ContinuumReleaseException( "Failed to prepare release project because
the build agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -190,16 +211,22 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            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 ) );
+            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;
+            }
 
-            return releaseResult;
+            throw new ContinuumReleaseException( "Failed to get release result of " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -225,8 +252,14 @@ 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 );
+            }
+
+            throw new ContinuumReleaseException( "Failed to get listener for " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -252,8 +285,14 @@ 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 );
+            }
+
+            throw new ContinuumReleaseException( "Failed to remove listener of " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -280,8 +319,14 @@ 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 );
+            }
+
+            throw new ContinuumReleaseException( "Failed to get prepared release name of
" + releaseId + 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -338,10 +383,16 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new
URL( buildAgentUrl ) );
-            client.releasePerform( releaseId, goals, arguments, useReleaseProfile, map, username
);
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient(
new URL( buildAgentUrl ) );
+                client.releasePerform( releaseId, goals, arguments, useReleaseProfile, map,
username );
+    
+                addReleaseInProgress( releaseId, "perform", projectId, username );
+            }
 
-            addReleaseInProgress( releaseId, "perform", projectId, username );
+            throw new ContinuumReleaseException( "Failed to perform release of " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -389,15 +440,20 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            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 );
+            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;
+            }
 
-            return releaseId;
+            throw new ContinuumReleaseException( "Failed to perform release because the build
agent " + buildAgentUrl + " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -423,8 +479,14 @@ 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 );
+            }
+
+            throw new ContinuumReleaseException( "Unable to rollback release " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -450,13 +512,19 @@ public class DefaultDistributedReleaseMa
 
         try
         {
-            SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient( new
URL( buildAgentUrl ) );
-            String result = client.releaseCleanup( releaseId );
-
-            removeFromReleaseInProgress( releaseId );
-            removeFromPreparedReleases( releaseId );
+            if ( distributedBuildManager.isAgentAvailable( buildAgentUrl ) )
+            {
+                SlaveBuildAgentTransportClient client = new SlaveBuildAgentTransportClient(
new URL( buildAgentUrl ) );
+                String result = client.releaseCleanup( releaseId );
+    
+                removeFromReleaseInProgress( releaseId );
+                removeFromPreparedReleases( releaseId );
+    
+                return result;
+            }
 
-            return result;
+            throw new ContinuumReleaseException( "Failed to cleanup release of " + releaseId
+ 
+                                                 " because the build agent " + buildAgentUrl
+ " is not available" );
         }
         catch ( MalformedURLException e )
         {
@@ -465,8 +533,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 );
         }
     }
 
@@ -491,19 +559,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 )

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManagerTest.java?rev=926873&r1=926872&r2=926873&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManagerTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManagerTest.java
Wed Mar 24 00:04:49 2010
@@ -92,11 +92,49 @@ public class DefaultDistributedBuildMana
     {
         setUpMockOverallDistributedBuildQueues();
 
+        recordDisableOfBuildAgent();
+
+        Map<String, List<PrepareBuildProjectsTask>> prepareBuildQueues = distributedBuildManager.getProjectsInPrepareBuildQueue();
+        Map<String, List<BuildProjectTask>> buildQueues = distributedBuildManager.getProjectsInBuildQueue();
+        Map<String, PrepareBuildProjectsTask> currentPrepareBuild = distributedBuildManager.getProjectsCurrentlyPreparingBuild();
+        Map<String, BuildProjectTask> currentBuild = distributedBuildManager.getProjectsCurrentlyBuilding();
+
+        assertEquals( prepareBuildQueues.size(), 0 );
+        assertEquals( buildQueues.size(), 0 );
+        assertEquals( currentPrepareBuild.size(), 0 );
+        assertEquals( currentBuild.size(), 0 );
+
+        context.assertIsSatisfied();
+    }
+
+    public void testDisableBuildAgentWhenUnavailableToPing()
+        throws Exception
+    {
+        setUpMockOverallDistributedBuildQueues();
+
+        recordDisableOfBuildAgent();
+
+        distributedBuildManager.isAgentAvailable( TEST_BUILD_AGENT );
+
+        context.assertIsSatisfied();
+    }
+
+    private void setUpMockOverallDistributedBuildQueues()
+    {
+        Map<String, OverallDistributedBuildQueue> overallDistributedBuildQueues =
+            Collections.synchronizedMap( new HashMap<String, OverallDistributedBuildQueue>()
);
+        overallDistributedBuildQueue = context.mock( OverallDistributedBuildQueue.class );
+
+        overallDistributedBuildQueues.put( TEST_BUILD_AGENT, overallDistributedBuildQueue
);
+        distributedBuildManager.setOverallDistributedBuildQueues( overallDistributedBuildQueues
);
+    }
+
+    private void recordDisableOfBuildAgent()
+        throws Exception
+    {
         context.checking( new Expectations()
         {
             {
-                //one( configurationService ).addBuildAgent( buildAgent );
-
                 one( configurationService ).getBuildAgents();
                 will( returnValue( buildAgents )  );
 
@@ -119,28 +157,6 @@ public class DefaultDistributedBuildMana
 
                 one( distributedBuildTaskQueueExecutor ).stop();
             }
-        });
-
-        Map<String, List<PrepareBuildProjectsTask>> prepareBuildQueues = distributedBuildManager.getProjectsInPrepareBuildQueue();
-        Map<String, List<BuildProjectTask>> buildQueues = distributedBuildManager.getProjectsInBuildQueue();
-        Map<String, PrepareBuildProjectsTask> currentPrepareBuild = distributedBuildManager.getProjectsCurrentlyPreparingBuild();
-        Map<String, BuildProjectTask> currentBuild = distributedBuildManager.getProjectsCurrentlyBuilding();
-
-        assertEquals( prepareBuildQueues.size(), 0 );
-        assertEquals( buildQueues.size(), 0 );
-        assertEquals( currentPrepareBuild.size(), 0 );
-        assertEquals( currentBuild.size(), 0 );
-
-        context.assertIsSatisfied();
-    }
-
-    private void setUpMockOverallDistributedBuildQueues()
-    {
-        Map<String, OverallDistributedBuildQueue> overallDistributedBuildQueues =
-            Collections.synchronizedMap( new HashMap<String, OverallDistributedBuildQueue>()
);
-        overallDistributedBuildQueue = context.mock( OverallDistributedBuildQueue.class );
-
-        overallDistributedBuildQueues.put( TEST_BUILD_AGENT, overallDistributedBuildQueue
);
-        distributedBuildManager.setOverallDistributedBuildQueues( overallDistributedBuildQueues
);
+        } );
     }
 }



Mime
View raw message