You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@continuum.apache.org by Deng Ching <oc...@apache.org> on 2010/04/13 07:48:44 UTC
Re: svn commit: r933451 [1/2] - in /continuum/trunk:
continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/
continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/
continuum-buildagent/conti
On Tue, Apr 13, 2010 at 8:26 AM, <ct...@apache.org> wrote:
>
> - OverallDistributedBuildQueue overallDistributedBuildQueue =
> getOverallDistributedBuildQueueByGroup( projectGroupId );
> -
> - if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) &&
> overallDistributedBuildQueue == null )
> + OverallDistributedBuildQueue overallDistributedBuildQueue =
> getOverallDistributedBuildQueueByGroup( projectGroupId, scmRoots, scmRootId
> );
> +
> + if ( overallDistributedBuildQueue == null )
> {
> - if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap ) )
> - {
> - log.warn( "No build agent configured in build agent group.
> Not building projects." );
> + log.info( "no overall build queue by group" );
>
> - throw new NoBuildAgentInGroupException( "No build agent
> configured in build agent group" );
> + if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) )
> + {
> + if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap )
> )
> + {
> + log.warn( "No build agent configured in build agent
> group. Not building projects." );
> +
> + throw new NoBuildAgentInGroupException( "No build
> agent configured in build agent group" );
> + }
> + else
> + {
> + // get overall distributed build queue from build
> agent group
> + overallDistributedBuildQueue =
> getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap );
> + log.info( "got overall build queue by agent group" );
> + }
> }
> else
> {
> - // get overall distributed build queue from build agent
> group
> - overallDistributedBuildQueue =
> getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap );
> + // project does not have build agent group
> + overallDistributedBuildQueue =
> getOverallDistributedBuildQueue();
> + log.info( "get overall build queue in all agents" );
>
Can we improve the log.info logs above? It looks like these these got left
out for tracing/debugging purposes :)
> }
> }
> - else if ( overallDistributedBuildQueue == null )
> - {
> - // project does not have build agent group
> - overallDistributedBuildQueue =
> getOverallDistributedBuildQueue();
> - }
>
> if ( overallDistributedBuildQueue != null )
> {
> @@ -329,8 +336,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client =
> - new SlaveBuildAgentTransportClient( new URL(
> buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
>
> List<Map<String, Object>> projects =
> client.getProjectsInPrepareBuildQueue();
>
> @@ -353,6 +359,9 @@ public class DefaultDistributedBuildMana
> }
> }
>
> + // call reload in case we disable a build agent
> + reload();
> +
> return map;
> }
>
> @@ -369,8 +378,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client =
> - new SlaveBuildAgentTransportClient( new URL(
> buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> Map<String, Object> project =
> client.getProjectCurrentlyPreparingBuild();
>
> if ( !project.isEmpty() )
> @@ -389,6 +397,10 @@ public class DefaultDistributedBuildMana
> }
> }
> }
> +
> + // call reload in case we disable a build agent
> + reload();
> +
> return map;
> }
>
> @@ -405,8 +417,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client =
> - new SlaveBuildAgentTransportClient( new URL(
> buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> Map<String, Object> project =
> client.getProjectCurrentlyBuilding();
>
> if ( !project.isEmpty() )
> @@ -426,6 +437,9 @@ public class DefaultDistributedBuildMana
> }
> }
>
> + // call reload in case we disable a build agent
> + reload();
> +
> return map;
> }
>
> @@ -444,8 +458,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client =
> - new SlaveBuildAgentTransportClient( new URL(
> buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> List<Map<String, Object>> projects =
> client.getProjectsInBuildQueue();
>
> for ( Map<String, Object> context : projects )
> @@ -466,6 +479,10 @@ public class DefaultDistributedBuildMana
> }
> }
> }
> +
> + // call reload in case we disable a build agent
> + reload();
> +
> return map;
> }
>
> @@ -494,10 +511,13 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
>
> client.cancelBuild();
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> }
> catch ( MalformedURLException e )
> {
> @@ -515,40 +535,40 @@ public class DefaultDistributedBuildMana
> throws ContinuumException
> {
> Map<String, Object> map = new HashMap<String, Object>();
> -
> +
> String buildAgentUrl = getBuildAgent( projectId );
> -
> +
> if ( buildAgentUrl == null )
> {
> return null;
> }
> -
> +
> try
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> -
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> +
> Map<String, Object> result = client.getBuildResult(
> projectId );
> -
> +
> if ( result != null )
> {
> int buildDefinitionId =
> ContinuumBuildConstant.getBuildDefinitionId( result );
> -
> +
> Project project = projectDao.getProjectWithAllDetails(
> projectId );
> BuildDefinition buildDefinition =
> buildDefinitionDao.getBuildDefinition( buildDefinitionId );
> -
> +
> BuildResult oldBuildResult =
>
> buildResultDao.getLatestBuildResultForBuildDefinition( projectId,
> buildDefinitionId );
> -
> +
> BuildResult buildResult =
> distributedBuildUtil.convertMapToBuildResult( result );
> buildResult.setBuildDefinition( buildDefinition );
> buildResult.setBuildNumber( project.getBuildNumber() +
> 1 );
> buildResult.setModifiedDependencies(
> distributedBuildUtil.getModifiedDependencies( oldBuildResult, result ) );
> buildResult.setScmResult(
> distributedBuildUtil.getScmResult( result ) );
> -
> +
> String buildOutput =
> ContinuumBuildConstant.getBuildOutput( result );
> -
> +
> map.put( ContinuumBuildConstant.KEY_BUILD_RESULT,
> buildResult );
> map.put( ContinuumBuildConstant.KEY_BUILD_OUTPUT,
> buildOutput );
> }
> @@ -562,7 +582,10 @@ public class DefaultDistributedBuildMana
> {
> throw new ContinuumException( "Error while retrieving build
> result for project" + projectId, e );
> }
> -
> +
> + // call reload in case we disable the build agent
> + reload();
> +
> return map;
> }
>
> @@ -570,15 +593,15 @@ public class DefaultDistributedBuildMana
> throws ContinuumException
> {
> List<Installation> installations = new ArrayList<Installation>();
> -
> +
> try
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> -
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> +
> List<Map<String, String>> installationsList =
> client.getAvailableInstallations();
> -
> +
> for ( Map context : installationsList )
> {
> Installation installation = new Installation();
> @@ -589,6 +612,10 @@ public class DefaultDistributedBuildMana
> installations.add( installation );
> }
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> +
> return installations;
> }
> catch ( Exception e )
> @@ -601,26 +628,26 @@ public class DefaultDistributedBuildMana
> throws ContinuumException
> {
> BuildResult buildResult =
> buildResultDao.getLatestBuildResultForProject( projectId );
> -
> +
> if ( buildResult != null )
> {
> String buildAgentUrl = buildResult.getBuildUrl();
> -
> +
> if ( buildAgentUrl == null )
> {
> return "";
> }
> -
> +
> try
> {
> if ( directory == null )
> {
> directory = "";
> }
> -
> +
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> return client.generateWorkingCopyContent( projectId,
> directory, baseUrl, imageBaseUrl );
> }
> }
> @@ -633,6 +660,10 @@ public class DefaultDistributedBuildMana
> log.error( "Error while generating working copy content
> from build agent " + buildAgentUrl, e );
> }
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> +
> return "";
> }
>
> @@ -640,21 +671,21 @@ public class DefaultDistributedBuildMana
> throws ContinuumException
> {
> BuildResult buildResult =
> buildResultDao.getLatestBuildResultForProject( projectId );
> -
> +
> if ( buildResult != null )
> {
> String buildAgentUrl = buildResult.getBuildUrl();
> -
> +
> if ( buildAgentUrl == null )
> {
> return "";
> }
> -
> +
> try
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> return client.getProjectFileContent( projectId,
> directory, filename );
> }
> }
> @@ -667,6 +698,10 @@ public class DefaultDistributedBuildMana
> log.error( "Error while retrieving content of " + filename,
> e );
> }
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> +
> return "";
> }
>
> @@ -677,7 +712,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> client.removeFromPrepareBuildQueue( projectGroupId,
> scmRootId );
> }
> }
> @@ -695,6 +730,9 @@ public class DefaultDistributedBuildMana
> throw new ContinuumException( "Error occurred while removing
> projectGroupId=" + projectGroupId + " scmRootId=" +
> scmRootId + " from prepare build
> queue of agent " + buildAgentUrl, e );
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> }
>
> public void removeFromBuildQueue( String buildAgentUrl, int projectId,
> int buildDefinitionId )
> @@ -704,7 +742,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> client.removeFromBuildQueue( projectId, buildDefinitionId
> );
> }
> }
> @@ -722,6 +760,9 @@ public class DefaultDistributedBuildMana
> throw new ContinuumException( "Error occurred while removing
> project " + projectId +
> " from build queue of agent " +
> buildAgentUrl, e );
> }
> +
> + // call reload in case we disable the build agent
> + reload();
> }
>
> public void removeFromPrepareBuildQueue( List<String> hashCodes )
> @@ -735,7 +776,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> client.removeFromPrepareBuildQueue( hashCodes );
> }
> }
> @@ -749,6 +790,9 @@ public class DefaultDistributedBuildMana
> }
> }
> }
> +
> + // call reload in case we disable a build agent
> + reload();
> }
>
> public void removeFromBuildQueue( List<String> hashCodes )
> @@ -762,7 +806,7 @@ public class DefaultDistributedBuildMana
> {
> if ( isAgentAvailable( buildAgentUrl ) )
> {
> - SlaveBuildAgentTransportClient client = new
> SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> client.removeFromBuildQueue( hashCodes );
> }
> }
> @@ -776,11 +820,171 @@ public class DefaultDistributedBuildMana
> }
> }
> }
> +
> + // call reload in case we disable a build agent
> + reload();
> + }
> +
> + public boolean isProjectInAnyPrepareBuildQueue( int projectId, int
> buildDefinitionId )
> + throws ContinuumException
> + {
> + boolean found = false;
> +
> + synchronized( overallDistributedBuildQueues )
> + {
> + for ( String buildAgentUrl :
> overallDistributedBuildQueues.keySet() )
> + {
> + try
> + {
> + if ( isAgentAvailable( buildAgentUrl ) )
> + {
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> +
> + List<Map<String, Object>> projects =
> client.getProjectsAndBuildDefinitionsInPrepareBuildQueue();
> +
> + for ( Map<String, Object> context : projects )
> + {
> + int pid = ContinuumBuildConstant.getProjectId(
> context );
> + int buildId =
> ContinuumBuildConstant.getBuildDefinitionId( context );
> +
> + if ( pid == projectId && buildId ==
> buildDefinitionId )
> + {
> + found = true;
> + break;
>
I think you can just return true here and return false if the loop has
finished instead of the multiple if conditions and break statements?
+ }
> +
> + }
> + }
> +
> + if ( found )
> + {
> + break;
> + }
> + }
> + catch ( MalformedURLException e )
> + {
> + throw new ContinuumException( "Invalid build agent
> url: " + buildAgentUrl );
> + }
> + catch ( Exception e )
> + {
> + throw new ContinuumException( "Error while retrieving
> projects in prepare build queue", e );
> + }
> + }
> + }
> +
> + // call reload in case we disable a build agent
> + reload();
> +
> + if ( found )
> + {
> + return true;
> + }
> + else
> + {
> + return false;
> + }
> + }
> +
> + public boolean isProjectInAnyBuildQueue( int projectId, int
> buildDefinitionId )
> + throws ContinuumException
> + {
> + Map<String, List<BuildProjectTask>> map =
> getProjectsInBuildQueue();
> +
> + for ( String url : map.keySet() )
> + {
> + for ( BuildProjectTask task : map.get( url ) )
> + {
> + if ( task.getProjectId() == projectId &&
> task.getBuildDefinitionId() == buildDefinitionId )
> + {
> + return true;
> + }
> + }
> + }
> +
> + return false;
> + }
> +
> + public boolean isProjectCurrentlyPreparingBuild( int projectId, int
> buildDefinitionId )
> + throws ContinuumException
> + {
> + boolean found = false;
> +
> + synchronized( overallDistributedBuildQueues )
> + {
> + for ( String buildAgentUrl :
> overallDistributedBuildQueues.keySet() )
> + {
> + try
> + {
> + if ( isAgentAvailable( buildAgentUrl ) )
> + {
> + SlaveBuildAgentTransportService client =
> createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> + List<Map<String, Object>> projects =
> client.getProjectsAndBuildDefinitionsCurrentlyPreparingBuild();
> +
> + for ( Map<String, Object> context : projects )
> + {
> + int pid = ContinuumBuildConstant.getProjectId(
> context );
> + int buildId =
> ContinuumBuildConstant.getBuildDefinitionId( context );
> +
> + if ( pid == projectId && buildId ==
> buildDefinitionId )
> + {
> + found = true;
> + break;
>
Same comment as above :)
> + }
> + }
> + }
> +
> + if ( found )
> + {
> + break;
> + }
> + }
> + catch ( MalformedURLException e )
> + {
> + throw new ContinuumException( "Invalid build agent
> url: " + buildAgentUrl );
> + }
> + catch ( Exception e )
> + {
> + throw new ContinuumException( "Error retrieving
> projects currently preparing build in " + buildAgentUrl, e );
> + }
> + }
> + }
> +
> + // call reload in case we disable a build agent
> + reload();
> +
> + if ( found )
> + {
> + return true;
> + }
> + else
> + {
> + return false;
> + }
> + }
> +
> + public boolean isProjectCurrentlyBuilding( int projectId, int
> buildDefinitionId )
> + throws ContinuumException
> + {
> + Map<String, BuildProjectTask> map =
> getProjectsCurrentlyBuilding();
> +
> + for ( String url : map.keySet() )
> + {
> + BuildProjectTask task = map.get( url );
> +
> + if ( task.getProjectId() == projectId &&
> task.getBuildDefinitionId() == buildDefinitionId )
> + {
> + return true;
> + }
> + }
> +
> + return false;
> }
>
Thanks,
Deng
Re: svn commit: r933451 [1/2] - in /continuum/trunk:
continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/
continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/
continuum-buildagent/conti
Posted by Marica Tan <ma...@gmail.com>.
On Tue, Apr 13, 2010 at 1:48 PM, Deng Ching <oc...@apache.org> wrote:
> On Tue, Apr 13, 2010 at 8:26 AM, <ct...@apache.org> wrote:
>
> >
> > - OverallDistributedBuildQueue overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByGroup( projectGroupId );
> > -
> > - if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) &&
> > overallDistributedBuildQueue == null )
> > + OverallDistributedBuildQueue overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByGroup( projectGroupId, scmRoots,
> scmRootId
> > );
> > +
> > + if ( overallDistributedBuildQueue == null )
> > {
> > - if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap ) )
> > - {
> > - log.warn( "No build agent configured in build agent
> group.
> > Not building projects." );
> > + log.info( "no overall build queue by group" );
> >
> > - throw new NoBuildAgentInGroupException( "No build agent
> > configured in build agent group" );
> > + if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) )
> > + {
> > + if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap
> )
> > )
> > + {
> > + log.warn( "No build agent configured in build agent
> > group. Not building projects." );
> > +
> > + throw new NoBuildAgentInGroupException( "No build
> > agent configured in build agent group" );
> > + }
> > + else
> > + {
> > + // get overall distributed build queue from build
> > agent group
> > + overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap
> );
> > + log.info( "got overall build queue by agent group"
> );
> > + }
> > }
> > else
> > {
> > - // get overall distributed build queue from build agent
> > group
> > - overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap
> );
> > + // project does not have build agent group
> > + overallDistributedBuildQueue =
> > getOverallDistributedBuildQueue();
> > + log.info( "get overall build queue in all agents" );
> >
>
> Can we improve the log.info logs above? It looks like these these got left
> out for tracing/debugging purposes :)
>
>
> > }
> > }
> > - else if ( overallDistributedBuildQueue == null )
> > - {
> > - // project does not have build agent group
> > - overallDistributedBuildQueue =
> > getOverallDistributedBuildQueue();
> > - }
> >
> > if ( overallDistributedBuildQueue != null )
> > {
> > @@ -329,8 +336,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> >
> > List<Map<String, Object>> projects =
> > client.getProjectsInPrepareBuildQueue();
> >
> > @@ -353,6 +359,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> >
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -369,8 +378,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > Map<String, Object> project =
> > client.getProjectCurrentlyPreparingBuild();
> >
> > if ( !project.isEmpty() )
> > @@ -389,6 +397,10 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -405,8 +417,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > Map<String, Object> project =
> > client.getProjectCurrentlyBuilding();
> >
> > if ( !project.isEmpty() )
> > @@ -426,6 +437,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> >
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -444,8 +458,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > List<Map<String, Object>> projects =
> > client.getProjectsInBuildQueue();
> >
> > for ( Map<String, Object> context : projects )
> > @@ -466,6 +479,10 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -494,10 +511,13 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> >
> > client.cancelBuild();
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> > catch ( MalformedURLException e )
> > {
> > @@ -515,40 +535,40 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > Map<String, Object> map = new HashMap<String, Object>();
> > -
> > +
> > String buildAgentUrl = getBuildAgent( projectId );
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return null;
> > }
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > -
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > Map<String, Object> result = client.getBuildResult(
> > projectId );
> > -
> > +
> > if ( result != null )
> > {
> > int buildDefinitionId =
> > ContinuumBuildConstant.getBuildDefinitionId( result );
> > -
> > +
> > Project project =
> projectDao.getProjectWithAllDetails(
> > projectId );
> > BuildDefinition buildDefinition =
> > buildDefinitionDao.getBuildDefinition( buildDefinitionId );
> > -
> > +
> > BuildResult oldBuildResult =
> >
> > buildResultDao.getLatestBuildResultForBuildDefinition( projectId,
> > buildDefinitionId );
> > -
> > +
> > BuildResult buildResult =
> > distributedBuildUtil.convertMapToBuildResult( result );
> > buildResult.setBuildDefinition( buildDefinition );
> > buildResult.setBuildNumber( project.getBuildNumber()
> +
> > 1 );
> > buildResult.setModifiedDependencies(
> > distributedBuildUtil.getModifiedDependencies( oldBuildResult, result ) );
> > buildResult.setScmResult(
> > distributedBuildUtil.getScmResult( result ) );
> > -
> > +
> > String buildOutput =
> > ContinuumBuildConstant.getBuildOutput( result );
> > -
> > +
> > map.put( ContinuumBuildConstant.KEY_BUILD_RESULT,
> > buildResult );
> > map.put( ContinuumBuildConstant.KEY_BUILD_OUTPUT,
> > buildOutput );
> > }
> > @@ -562,7 +582,10 @@ public class DefaultDistributedBuildMana
> > {
> > throw new ContinuumException( "Error while retrieving build
> > result for project" + projectId, e );
> > }
> > -
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -570,15 +593,15 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > List<Installation> installations = new ArrayList<Installation>();
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > -
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > List<Map<String, String>> installationsList =
> > client.getAvailableInstallations();
> > -
> > +
> > for ( Map context : installationsList )
> > {
> > Installation installation = new Installation();
> > @@ -589,6 +612,10 @@ public class DefaultDistributedBuildMana
> > installations.add( installation );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return installations;
> > }
> > catch ( Exception e )
> > @@ -601,26 +628,26 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > BuildResult buildResult =
> > buildResultDao.getLatestBuildResultForProject( projectId );
> > -
> > +
> > if ( buildResult != null )
> > {
> > String buildAgentUrl = buildResult.getBuildUrl();
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return "";
> > }
> > -
> > +
> > try
> > {
> > if ( directory == null )
> > {
> > directory = "";
> > }
> > -
> > +
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > return client.generateWorkingCopyContent( projectId,
> > directory, baseUrl, imageBaseUrl );
> > }
> > }
> > @@ -633,6 +660,10 @@ public class DefaultDistributedBuildMana
> > log.error( "Error while generating working copy content
> > from build agent " + buildAgentUrl, e );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return "";
> > }
> >
> > @@ -640,21 +671,21 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > BuildResult buildResult =
> > buildResultDao.getLatestBuildResultForProject( projectId );
> > -
> > +
> > if ( buildResult != null )
> > {
> > String buildAgentUrl = buildResult.getBuildUrl();
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return "";
> > }
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > return client.getProjectFileContent( projectId,
> > directory, filename );
> > }
> > }
> > @@ -667,6 +698,10 @@ public class DefaultDistributedBuildMana
> > log.error( "Error while retrieving content of " +
> filename,
> > e );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return "";
> > }
> >
> > @@ -677,7 +712,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromPrepareBuildQueue( projectGroupId,
> > scmRootId );
> > }
> > }
> > @@ -695,6 +730,9 @@ public class DefaultDistributedBuildMana
> > throw new ContinuumException( "Error occurred while removing
> > projectGroupId=" + projectGroupId + " scmRootId=" +
> > scmRootId + " from prepare
> build
> > queue of agent " + buildAgentUrl, e );
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> >
> > public void removeFromBuildQueue( String buildAgentUrl, int
> projectId,
> > int buildDefinitionId )
> > @@ -704,7 +742,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromBuildQueue( projectId, buildDefinitionId
> > );
> > }
> > }
> > @@ -722,6 +760,9 @@ public class DefaultDistributedBuildMana
> > throw new ContinuumException( "Error occurred while removing
> > project " + projectId +
> > " from build queue of agent " +
> > buildAgentUrl, e );
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> >
> > public void removeFromPrepareBuildQueue( List<String> hashCodes )
> > @@ -735,7 +776,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromPrepareBuildQueue( hashCodes );
> > }
> > }
> > @@ -749,6 +790,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > }
> >
> > public void removeFromBuildQueue( List<String> hashCodes )
> > @@ -762,7 +806,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromBuildQueue( hashCodes );
> > }
> > }
> > @@ -776,11 +820,171 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > + }
> > +
> > + public boolean isProjectInAnyPrepareBuildQueue( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + boolean found = false;
> > +
> > + synchronized( overallDistributedBuildQueues )
> > + {
> > + for ( String buildAgentUrl :
> > overallDistributedBuildQueues.keySet() )
> > + {
> > + try
> > + {
> > + if ( isAgentAvailable( buildAgentUrl ) )
> > + {
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > + List<Map<String, Object>> projects =
> > client.getProjectsAndBuildDefinitionsInPrepareBuildQueue();
> > +
> > + for ( Map<String, Object> context : projects )
> > + {
> > + int pid =
> ContinuumBuildConstant.getProjectId(
> > context );
> > + int buildId =
> > ContinuumBuildConstant.getBuildDefinitionId( context );
> > +
> > + if ( pid == projectId && buildId ==
> > buildDefinitionId )
> > + {
> > + found = true;
> > + break;
> >
>
> I think you can just return true here and return false if the loop has
> finished instead of the multiple if conditions and break statements?
>
>
I need to call the reload() function at the end because a build agent
might have been disabled while in the loop.
Initially, the removal of the distributed build queue when a build agent is
disabled is inside the disableBuildAgent method. But this causes a
concurrent modification exception so I had to
move it out there, thus calling the reload function at the end.
+ }
> > +
> > + }
> > + }
> > +
> > + if ( found )
> > + {
> > + break;
> > + }
> > + }
> > + catch ( MalformedURLException e )
> > + {
> > + throw new ContinuumException( "Invalid build agent
> > url: " + buildAgentUrl );
> > + }
> > + catch ( Exception e )
> > + {
> > + throw new ContinuumException( "Error while
> retrieving
> > projects in prepare build queue", e );
> > + }
> > + }
> > + }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > + if ( found )
> > + {
> > + return true;
> > + }
> > + else
> > + {
> > + return false;
> > + }
> > + }
> > +
> > + public boolean isProjectInAnyBuildQueue( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + Map<String, List<BuildProjectTask>> map =
> > getProjectsInBuildQueue();
> > +
> > + for ( String url : map.keySet() )
> > + {
> > + for ( BuildProjectTask task : map.get( url ) )
> > + {
> > + if ( task.getProjectId() == projectId &&
> > task.getBuildDefinitionId() == buildDefinitionId )
> > + {
> > + return true;
> > + }
> > + }
> > + }
> > +
> > + return false;
> > + }
> > +
> > + public boolean isProjectCurrentlyPreparingBuild( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + boolean found = false;
> > +
> > + synchronized( overallDistributedBuildQueues )
> > + {
> > + for ( String buildAgentUrl :
> > overallDistributedBuildQueues.keySet() )
> > + {
> > + try
> > + {
> > + if ( isAgentAvailable( buildAgentUrl ) )
> > + {
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > + List<Map<String, Object>> projects =
> > client.getProjectsAndBuildDefinitionsCurrentlyPreparingBuild();
> > +
> > + for ( Map<String, Object> context : projects )
> > + {
> > + int pid =
> ContinuumBuildConstant.getProjectId(
> > context );
> > + int buildId =
> > ContinuumBuildConstant.getBuildDefinitionId( context );
> > +
> > + if ( pid == projectId && buildId ==
> > buildDefinitionId )
> > + {
> > + found = true;
> > + break;
> >
>
> Same comment as above :)
>
>
> > + }
> > + }
> > + }
> > +
> > + if ( found )
> > + {
> > + break;
> > + }
> > + }
> > + catch ( MalformedURLException e )
> > + {
> > + throw new ContinuumException( "Invalid build agent
> > url: " + buildAgentUrl );
> > + }
> > + catch ( Exception e )
> > + {
> > + throw new ContinuumException( "Error retrieving
> > projects currently preparing build in " + buildAgentUrl, e );
> > + }
> > + }
> > + }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > + if ( found )
> > + {
> > + return true;
> > + }
> > + else
> > + {
> > + return false;
> > + }
> > + }
> > +
> > + public boolean isProjectCurrentlyBuilding( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + Map<String, BuildProjectTask> map =
> > getProjectsCurrentlyBuilding();
> > +
> > + for ( String url : map.keySet() )
> > + {
> > + BuildProjectTask task = map.get( url );
> > +
> > + if ( task.getProjectId() == projectId &&
> > task.getBuildDefinitionId() == buildDefinitionId )
> > + {
> > + return true;
> > + }
> > + }
> > +
> > + return false;
> > }
> >
>
>
> Thanks,
> Deng
>
Re: svn commit: r933451 [1/2] - in /continuum/trunk:
continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/
continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/
continuum-buildagent/conti
Posted by Marica Tan <ma...@gmail.com>.
Ok Brett :) Noted.
Thanks,
--
Marica
On Wed, Apr 14, 2010 at 10:32 AM, Brett Porter <br...@apache.org> wrote:
> It'd be helpful when replying to snip the code down to the relevant amount,
> as it was hard to see the actual comments in this thread :)
>
>
> On 13/04/2010, at 4:54 PM, Marica Tan wrote:
>
> > On Tue, Apr 13, 2010 at 1:48 PM, Deng Ching <oc...@apache.org> wrote:
> >
> >> On Tue, Apr 13, 2010 at 8:26 AM, <ct...@apache.org> wrote:
> >>
> >>>
> >>> - OverallDistributedBuildQueue overallDistributedBuildQueue =
> >>> getOverallDistributedBuildQueueByGroup( projectGroupId );
> >>> -
> >>> - if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) &&
> >>> overallDistributedBuildQueue == null )
> >>> + OverallDistributedBuildQueue overallDistributedBuildQueue =
>
Re: svn commit: r933451 [1/2] - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/ continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/ continuum-buildagent/conti
Posted by Brett Porter <br...@apache.org>.
It'd be helpful when replying to snip the code down to the relevant amount, as it was hard to see the actual comments in this thread :)
On 13/04/2010, at 4:54 PM, Marica Tan wrote:
> On Tue, Apr 13, 2010 at 1:48 PM, Deng Ching <oc...@apache.org> wrote:
>
>> On Tue, Apr 13, 2010 at 8:26 AM, <ct...@apache.org> wrote:
>>
>>>
>>> - OverallDistributedBuildQueue overallDistributedBuildQueue =
>>> getOverallDistributedBuildQueueByGroup( projectGroupId );
>>> -
>>> - if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) &&
>>> overallDistributedBuildQueue == null )
>>> + OverallDistributedBuildQueue overallDistributedBuildQueue =
Re: svn commit: r933451 [1/2] - in /continuum/trunk:
continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/
continuum-buildagent/continuum-buildagent-api/src/main/java/org/apache/continuum/buildagent/
continuum-buildagent/conti
Posted by Marica Tan <ma...@gmail.com>.
On Tue, Apr 13, 2010 at 1:48 PM, Deng Ching <oc...@apache.org> wrote:
> On Tue, Apr 13, 2010 at 8:26 AM, <ct...@apache.org> wrote:
>
> >
> > - OverallDistributedBuildQueue overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByGroup( projectGroupId );
> > -
> > - if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) &&
> > overallDistributedBuildQueue == null )
> > + OverallDistributedBuildQueue overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByGroup( projectGroupId, scmRoots,
> scmRootId
> > );
> > +
> > + if ( overallDistributedBuildQueue == null )
> > {
> > - if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap ) )
> > - {
> > - log.warn( "No build agent configured in build agent
> group.
> > Not building projects." );
> > + log.info( "no overall build queue by group" );
> >
> > - throw new NoBuildAgentInGroupException( "No build agent
> > configured in build agent group" );
> > + if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) )
> > + {
> > + if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap
> )
> > )
> > + {
> > + log.warn( "No build agent configured in build agent
> > group. Not building projects." );
> > +
> > + throw new NoBuildAgentInGroupException( "No build
> > agent configured in build agent group" );
> > + }
> > + else
> > + {
> > + // get overall distributed build queue from build
> > agent group
> > + overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap
> );
> > + log.info( "got overall build queue by agent group"
> );
> > + }
> > }
> > else
> > {
> > - // get overall distributed build queue from build agent
> > group
> > - overallDistributedBuildQueue =
> > getOverallDistributedBuildQueueByAgentGroup( projectsBuildDefinitionsMap
> );
> > + // project does not have build agent group
> > + overallDistributedBuildQueue =
> > getOverallDistributedBuildQueue();
> > + log.info( "get overall build queue in all agents" );
> >
>
> Can we improve the log.info logs above? It looks like these these got left
> out for tracing/debugging purposes :)
>
Yes, thanks for pointing that out :)
>
>
> > }
> > }
> > - else if ( overallDistributedBuildQueue == null )
> > - {
> > - // project does not have build agent group
> > - overallDistributedBuildQueue =
> > getOverallDistributedBuildQueue();
> > - }
> >
> > if ( overallDistributedBuildQueue != null )
> > {
> > @@ -329,8 +336,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> >
> > List<Map<String, Object>> projects =
> > client.getProjectsInPrepareBuildQueue();
> >
> > @@ -353,6 +359,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> >
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -369,8 +378,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > Map<String, Object> project =
> > client.getProjectCurrentlyPreparingBuild();
> >
> > if ( !project.isEmpty() )
> > @@ -389,6 +397,10 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -405,8 +417,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > Map<String, Object> project =
> > client.getProjectCurrentlyBuilding();
> >
> > if ( !project.isEmpty() )
> > @@ -426,6 +437,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> >
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -444,8 +458,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client =
> > - new SlaveBuildAgentTransportClient( new URL(
> > buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > List<Map<String, Object>> projects =
> > client.getProjectsInBuildQueue();
> >
> > for ( Map<String, Object> context : projects )
> > @@ -466,6 +479,10 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -494,10 +511,13 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> >
> > client.cancelBuild();
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> > catch ( MalformedURLException e )
> > {
> > @@ -515,40 +535,40 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > Map<String, Object> map = new HashMap<String, Object>();
> > -
> > +
> > String buildAgentUrl = getBuildAgent( projectId );
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return null;
> > }
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > -
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > Map<String, Object> result = client.getBuildResult(
> > projectId );
> > -
> > +
> > if ( result != null )
> > {
> > int buildDefinitionId =
> > ContinuumBuildConstant.getBuildDefinitionId( result );
> > -
> > +
> > Project project =
> projectDao.getProjectWithAllDetails(
> > projectId );
> > BuildDefinition buildDefinition =
> > buildDefinitionDao.getBuildDefinition( buildDefinitionId );
> > -
> > +
> > BuildResult oldBuildResult =
> >
> > buildResultDao.getLatestBuildResultForBuildDefinition( projectId,
> > buildDefinitionId );
> > -
> > +
> > BuildResult buildResult =
> > distributedBuildUtil.convertMapToBuildResult( result );
> > buildResult.setBuildDefinition( buildDefinition );
> > buildResult.setBuildNumber( project.getBuildNumber()
> +
> > 1 );
> > buildResult.setModifiedDependencies(
> > distributedBuildUtil.getModifiedDependencies( oldBuildResult, result ) );
> > buildResult.setScmResult(
> > distributedBuildUtil.getScmResult( result ) );
> > -
> > +
> > String buildOutput =
> > ContinuumBuildConstant.getBuildOutput( result );
> > -
> > +
> > map.put( ContinuumBuildConstant.KEY_BUILD_RESULT,
> > buildResult );
> > map.put( ContinuumBuildConstant.KEY_BUILD_OUTPUT,
> > buildOutput );
> > }
> > @@ -562,7 +582,10 @@ public class DefaultDistributedBuildMana
> > {
> > throw new ContinuumException( "Error while retrieving build
> > result for project" + projectId, e );
> > }
> > -
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return map;
> > }
> >
> > @@ -570,15 +593,15 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > List<Installation> installations = new ArrayList<Installation>();
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > -
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > List<Map<String, String>> installationsList =
> > client.getAvailableInstallations();
> > -
> > +
> > for ( Map context : installationsList )
> > {
> > Installation installation = new Installation();
> > @@ -589,6 +612,10 @@ public class DefaultDistributedBuildMana
> > installations.add( installation );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return installations;
> > }
> > catch ( Exception e )
> > @@ -601,26 +628,26 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > BuildResult buildResult =
> > buildResultDao.getLatestBuildResultForProject( projectId );
> > -
> > +
> > if ( buildResult != null )
> > {
> > String buildAgentUrl = buildResult.getBuildUrl();
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return "";
> > }
> > -
> > +
> > try
> > {
> > if ( directory == null )
> > {
> > directory = "";
> > }
> > -
> > +
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > return client.generateWorkingCopyContent( projectId,
> > directory, baseUrl, imageBaseUrl );
> > }
> > }
> > @@ -633,6 +660,10 @@ public class DefaultDistributedBuildMana
> > log.error( "Error while generating working copy content
> > from build agent " + buildAgentUrl, e );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return "";
> > }
> >
> > @@ -640,21 +671,21 @@ public class DefaultDistributedBuildMana
> > throws ContinuumException
> > {
> > BuildResult buildResult =
> > buildResultDao.getLatestBuildResultForProject( projectId );
> > -
> > +
> > if ( buildResult != null )
> > {
> > String buildAgentUrl = buildResult.getBuildUrl();
> > -
> > +
> > if ( buildAgentUrl == null )
> > {
> > return "";
> > }
> > -
> > +
> > try
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > return client.getProjectFileContent( projectId,
> > directory, filename );
> > }
> > }
> > @@ -667,6 +698,10 @@ public class DefaultDistributedBuildMana
> > log.error( "Error while retrieving content of " +
> filename,
> > e );
> > }
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > +
> > return "";
> > }
> >
> > @@ -677,7 +712,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromPrepareBuildQueue( projectGroupId,
> > scmRootId );
> > }
> > }
> > @@ -695,6 +730,9 @@ public class DefaultDistributedBuildMana
> > throw new ContinuumException( "Error occurred while removing
> > projectGroupId=" + projectGroupId + " scmRootId=" +
> > scmRootId + " from prepare
> build
> > queue of agent " + buildAgentUrl, e );
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> >
> > public void removeFromBuildQueue( String buildAgentUrl, int
> projectId,
> > int buildDefinitionId )
> > @@ -704,7 +742,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromBuildQueue( projectId, buildDefinitionId
> > );
> > }
> > }
> > @@ -722,6 +760,9 @@ public class DefaultDistributedBuildMana
> > throw new ContinuumException( "Error occurred while removing
> > project " + projectId +
> > " from build queue of agent " +
> > buildAgentUrl, e );
> > }
> > +
> > + // call reload in case we disable the build agent
> > + reload();
> > }
> >
> > public void removeFromPrepareBuildQueue( List<String> hashCodes )
> > @@ -735,7 +776,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromPrepareBuildQueue( hashCodes );
> > }
> > }
> > @@ -749,6 +790,9 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > }
> >
> > public void removeFromBuildQueue( List<String> hashCodes )
> > @@ -762,7 +806,7 @@ public class DefaultDistributedBuildMana
> > {
> > if ( isAgentAvailable( buildAgentUrl ) )
> > {
> > - SlaveBuildAgentTransportClient client = new
> > SlaveBuildAgentTransportClient( new URL( buildAgentUrl ) );
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > client.removeFromBuildQueue( hashCodes );
> > }
> > }
> > @@ -776,11 +820,171 @@ public class DefaultDistributedBuildMana
> > }
> > }
> > }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > + }
> > +
> > + public boolean isProjectInAnyPrepareBuildQueue( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + boolean found = false;
> > +
> > + synchronized( overallDistributedBuildQueues )
> > + {
> > + for ( String buildAgentUrl :
> > overallDistributedBuildQueues.keySet() )
> > + {
> > + try
> > + {
> > + if ( isAgentAvailable( buildAgentUrl ) )
> > + {
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > +
> > + List<Map<String, Object>> projects =
> > client.getProjectsAndBuildDefinitionsInPrepareBuildQueue();
> > +
> > + for ( Map<String, Object> context : projects )
> > + {
> > + int pid =
> ContinuumBuildConstant.getProjectId(
> > context );
> > + int buildId =
> > ContinuumBuildConstant.getBuildDefinitionId( context );
> > +
> > + if ( pid == projectId && buildId ==
> > buildDefinitionId )
> > + {
> > + found = true;
> > + break;
> >
>
> I think you can just return true here and return false if the loop has
> finished instead of the multiple if conditions and break statements?
>
> + }
> > +
> > + }
> > + }
> > +
> > + if ( found )
> > + {
> > + break;
> > + }
> > + }
> > + catch ( MalformedURLException e )
> > + {
> > + throw new ContinuumException( "Invalid build agent
> > url: " + buildAgentUrl );
> > + }
> > + catch ( Exception e )
> > + {
> > + throw new ContinuumException( "Error while
> retrieving
> > projects in prepare build queue", e );
> > + }
> > + }
> > + }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > + if ( found )
> > + {
> > + return true;
> > + }
> > + else
> > + {
> > + return false;
> > + }
> > + }
> > +
> > + public boolean isProjectInAnyBuildQueue( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + Map<String, List<BuildProjectTask>> map =
> > getProjectsInBuildQueue();
> > +
> > + for ( String url : map.keySet() )
> > + {
> > + for ( BuildProjectTask task : map.get( url ) )
> > + {
> > + if ( task.getProjectId() == projectId &&
> > task.getBuildDefinitionId() == buildDefinitionId )
> > + {
> > + return true;
> > + }
> > + }
> > + }
> > +
> > + return false;
> > + }
> > +
> > + public boolean isProjectCurrentlyPreparingBuild( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + boolean found = false;
> > +
> > + synchronized( overallDistributedBuildQueues )
> > + {
> > + for ( String buildAgentUrl :
> > overallDistributedBuildQueues.keySet() )
> > + {
> > + try
> > + {
> > + if ( isAgentAvailable( buildAgentUrl ) )
> > + {
> > + SlaveBuildAgentTransportService client =
> > createSlaveBuildAgentTransportClientConnection( buildAgentUrl );
> > + List<Map<String, Object>> projects =
> > client.getProjectsAndBuildDefinitionsCurrentlyPreparingBuild();
> > +
> > + for ( Map<String, Object> context : projects )
> > + {
> > + int pid =
> ContinuumBuildConstant.getProjectId(
> > context );
> > + int buildId =
> > ContinuumBuildConstant.getBuildDefinitionId( context );
> > +
> > + if ( pid == projectId && buildId ==
> > buildDefinitionId )
> > + {
> > + found = true;
> > + break;
> >
>
> Same comment as above :)
>
>
> > + }
> > + }
> > + }
> > +
> > + if ( found )
> > + {
> > + break;
> > + }
> > + }
> > + catch ( MalformedURLException e )
> > + {
> > + throw new ContinuumException( "Invalid build agent
> > url: " + buildAgentUrl );
> > + }
> > + catch ( Exception e )
> > + {
> > + throw new ContinuumException( "Error retrieving
> > projects currently preparing build in " + buildAgentUrl, e );
> > + }
> > + }
> > + }
> > +
> > + // call reload in case we disable a build agent
> > + reload();
> > +
> > + if ( found )
> > + {
> > + return true;
> > + }
> > + else
> > + {
> > + return false;
> > + }
> > + }
> > +
> > + public boolean isProjectCurrentlyBuilding( int projectId, int
> > buildDefinitionId )
> > + throws ContinuumException
> > + {
> > + Map<String, BuildProjectTask> map =
> > getProjectsCurrentlyBuilding();
> > +
> > + for ( String url : map.keySet() )
> > + {
> > + BuildProjectTask task = map.get( url );
> > +
> > + if ( task.getProjectId() == projectId &&
> > task.getBuildDefinitionId() == buildDefinitionId )
> > + {
> > + return true;
> > + }
> > + }
> > +
> > + return false;
> > }
> >
>
>
> Thanks,
> Deng
>