continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r723613 - in /continuum/branches/continuum-distributed-builds: continuum-api/src/main/java/org/apache/continuum/distributed/ continuum-api/src/main/java/org/apache/maven/continuum/configuration/ continuum-commons/src/main/java/org/apache/ma...
Date Fri, 05 Dec 2008 06:44:26 GMT
Author: ctan
Date: Thu Dec  4 22:44:25 2008
New Revision: 723613

URL: http://svn.apache.org/viewvc?rev=723613&view=rev
Log:
- updated build agent, distributed build manager
- added test for update scm and build result

Added:
    continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/
    continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/
    continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManagerTest.java
Modified:
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/BuildAgent.java
    continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
    continuum/branches/continuum-distributed-builds/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
    continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
    continuum/branches/continuum-distributed-builds/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java

Modified: continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/BuildAgent.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/BuildAgent.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/BuildAgent.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/continuum/distributed/BuildAgent.java
Thu Dec  4 22:44:25 2008
@@ -10,6 +10,8 @@
 
     boolean busy;
 
+    boolean enabled;
+
     List<Project> projects;
 
     public String getUrl()
@@ -32,6 +34,16 @@
         this.busy = busy;
     }
 
+    public boolean isEnabled()
+    {
+        return enabled;
+    }
+
+    public void setEnabled( boolean enabled )
+    {
+        this.enabled = enabled;
+    }
+
     public List<Project> getProjects()
     {
         return projects;

Modified: continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-api/src/main/java/org/apache/maven/continuum/configuration/ConfigurationService.java
Thu Dec  4 22:44:25 2008
@@ -93,6 +93,8 @@
 
     void removeBuildAgent( BuildAgentConfiguration buildAgent );
 
+    void updateBuildAgent( BuildAgentConfiguration buildAgent );
+
     boolean isDistributedBuildEnabled();
 
     void setDistributedBuildEnabled( boolean distributedBuildEnabled );

Modified: continuum/branches/continuum-distributed-builds/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
Thu Dec  4 22:44:25 2008
@@ -321,6 +321,24 @@
         }
     }
 
+    public void updateBuildAgent( BuildAgentConfiguration buildAgent )
+    {
+        List<BuildAgentConfiguration> buildAgents = getBuildAgents();
+        if ( buildAgents != null )
+        {
+            for ( BuildAgentConfiguration agent : buildAgents )
+            {
+                if ( agent.getUrl().equals( buildAgent.getUrl() ) )
+                {
+                    agent.setDescription( buildAgent.getDescription() );
+                    agent.setEnabled( buildAgent.isEnabled() );
+                    
+                    return;
+                }
+            }
+        }
+    }
+
     public boolean isDistributedBuildEnabled()
     {
         return systemConf.isDistributedBuildEnabled();

Modified: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/AbstractDistributedBuildManager.java
Thu Dec  4 22:44:25 2008
@@ -58,8 +58,6 @@
 
     public static final String KEY_BUILD_STATE = "build-state";
 
-    public static final String KEY_SCM_STATE = "scm-state";
-
     public static final String KEY_SCM_COMMAND_OUTPUT = "scm-command-output";
 
     public static final String KEY_SCM_COMMAND_LINE = "scm-command-line";
@@ -141,7 +139,16 @@
 
     protected static String getString( Map context, String key )
     {
-        return (String) getObject( context, key );
+        Object obj = getObject( context, key, null );
+
+        if ( obj == null )
+        {
+            return null;
+        }
+        else
+        {
+            return (String) obj;
+        }
     }
 
     protected static String getString( Map context, String key, String defaultValue )
@@ -151,7 +158,16 @@
 
     protected static boolean getBoolean( Map context, String key )
     {
-        return ( (Boolean) getObject( context, key ) ).booleanValue();
+        Object obj = getObject( context, key, null );
+        
+        if ( obj == null )
+        {
+            return false;
+        }
+        else
+        {
+            return ( (Boolean) obj ).booleanValue();
+        }
     }
     
     protected static boolean getBoolean( Map context, String key, boolean defaultValue )

Modified: continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/main/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManager.java
Thu Dec  4 22:44:25 2008
@@ -80,7 +80,7 @@
      */
     private BuildResultDao buildResultDao;
 
-    private List<PrepareBuildProjectsTask> projectsBuildQueue;
+    private List<PrepareBuildProjectsTask> projectsBuildInQueue;
     
     private List<BuildAgent> buildAgents;
 
@@ -97,28 +97,26 @@
         {
             for ( BuildAgentConfiguration agent : agents )
             {
-                if ( agent.isEnabled() )
-                { 
-                    boolean found = false;
-    
-                    for ( BuildAgent buildAgent : buildAgents )
-                    {
-                        if ( buildAgent.getUrl().equals( agent.getUrl() ) )
-                        {
-                            found = true;
-                            break;
-                        }
-                    }
-    
-                    if ( !found )
+                boolean found = false;
+
+                for ( BuildAgent buildAgent : buildAgents )
+                {
+                    if ( buildAgent.getUrl().equals( agent.getUrl() ) )
                     {
-                        // ping it 
-                        BuildAgent buildAgent = new BuildAgent();
-                        buildAgent.setUrl( agent.getUrl() );
-                        buildAgent.setBusy( false );
-                        buildAgents.add( buildAgent );
+                        found = true;
+                        buildAgent.setEnabled( agent.isEnabled() );
+                        break;
                     }
                 }
+
+                if ( !found )
+                {
+                    BuildAgent buildAgent = new BuildAgent();
+                    buildAgent.setUrl( agent.getUrl() );
+                    buildAgent.setBusy( false );
+                    buildAgent.setEnabled( agent.isEnabled() );
+                    buildAgents.add( buildAgent );
+                }
             }
         }
     }
@@ -182,7 +180,7 @@
     public void buildProjectsInQueue()
         throws ContinuumException
     {
-        for ( PrepareBuildProjectsTask task : projectsBuildQueue )
+        for ( PrepareBuildProjectsTask task : projectsBuildInQueue )
         {
             Map projectsAndBuildDefinitions = task.getProjectsBuildDefinitionsMap();
             int trigger = task.getTrigger();
@@ -198,7 +196,7 @@
         
         for ( BuildAgent buildAgent : buildAgents )
         {
-            if ( !buildAgent.isBusy() )
+            if ( !buildAgent.isBusy() && buildAgent.isEnabled() )
             {
                 List buildContext = initializeBuildContext( projectsAndBuildDefinitionsMap,
trigger, buildAgent );
 
@@ -208,7 +206,7 @@
                 //{
                     //client.buildProjects( buildContext );
                 //}
-                //catch ( InterruptedException e )
+                //catch ( XmlRpcException e )
                 //{
                     //do something about the server Url
                     //client.getServerUrl();
@@ -222,13 +220,13 @@
         if ( !found && !inBuildQueue )
         {
             // all build agents are busy, put into projectBuildQueue for now
-            if ( projectsBuildQueue == null )
+            if ( projectsBuildInQueue == null )
             {
-                projectsBuildQueue = new ArrayList<PrepareBuildProjectsTask>();
+                projectsBuildInQueue = new ArrayList<PrepareBuildProjectsTask>();
             }
 
             PrepareBuildProjectsTask prepareBuildTask = new PrepareBuildProjectsTask( projectsAndBuildDefinitionsMap,
trigger );
-            projectsBuildQueue.add( prepareBuildTask );
+            projectsBuildInQueue.add( prepareBuildTask );
         }
     }
 
@@ -282,6 +280,11 @@
                     }
                 }
             }
+
+            if ( error != null )
+            {
+                updateBuildAgent( project.getId(), true );
+            }
         }
         catch ( ContinuumStoreException e )
         {
@@ -297,13 +300,22 @@
             int projectId = getProjectId( context );
             int buildDefinitionId = getBuildDefinitionId( context );
 
-            Project project = projectDao.getProjectWithBuildDetails( projectId );
+            Project project = projectDao.getProjectWithAllDetails( projectId );
             BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( buildDefinitionId
);
 
             BuildResult oldBuildResult =
                 buildResultDao.getLatestBuildResultForBuildDefinition( projectId, buildDefinitionId
);
 
-            int buildNumber = project.getBuildNumber() + 1;
+            int buildNumber;
+
+            if ( getBuildState( context ) == ContinuumProjectState.OK )
+            {
+                buildNumber = project.getBuildNumber() + 1;
+            }
+            else
+            {
+                buildNumber = project.getBuildNumber();
+            }
 
             // ----------------------------------------------------------------------
             // Make the buildResult
@@ -318,7 +330,6 @@
             buildResult.setError( getBuildError( context ) );
             buildResult.setExitCode( getBuildExitCode( context ) );
             buildResult.setModifiedDependencies( getModifiedDependencies( oldBuildResult,
context ) );
-            buildResult.setProject( project );
             buildResult.setState( getBuildState( context ) );
             buildResult.setTrigger( getTrigger( context ) );
             
@@ -331,7 +342,7 @@
 
             projectDao.updateProject( project );
 
-            updateBuildAgent( context );
+            updateBuildAgent( project.getId(), false );
         }
         catch ( ContinuumStoreException e )
         {
@@ -529,23 +540,33 @@
         return error;
     }
 
-    private void updateBuildAgent( Map context )
+    private void updateBuildAgent( int projectId, boolean removeAll )
         throws ContinuumException
     {
         for ( BuildAgent buildAgent : buildAgents )
         {
             for ( Project project : buildAgent.getProjects() )
             {
-                if ( project.getId() == getProjectId( context ) )
+                if ( project.getId() == projectId )
                 {
-                    buildAgent.getProjects().remove( project );
-                    
-                    if ( buildAgent.isBusy() && ( buildAgent.getProjects() == null
|| buildAgent.getProjects().size() == 0 ) )
+                    if ( removeAll )
                     {
+                        buildAgent.setProjects( null );
                         buildAgent.setBusy( false );
+
+                        buildProjectsInQueue();
                     }
+                    else
+                    {
+                        buildAgent.getProjects().remove( project );
 
-                    buildProjectsInQueue();
+                        if ( buildAgent.getProjects() == null || buildAgent.getProjects().size()
== 0 )
+                        {
+                            buildAgent.setBusy( false );
+
+                            buildProjectsInQueue();
+                        }
+                    }
                     return;
                 }
             }

Added: continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManagerTest.java?rev=723613&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManagerTest.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-core/src/test/java/org/apache/continuum/distributed/manager/DefaultDistributedBuildManagerTest.java
Thu Dec  4 22:44:25 2008
@@ -0,0 +1,132 @@
+package org.apache.continuum.distributed.manager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.continuum.dao.BuildResultDao;
+import org.apache.continuum.dao.ProjectScmRootDao;
+import org.apache.continuum.model.project.ProjectScmRoot;
+import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.project.ContinuumProjectState;
+
+public class DefaultDistributedBuildManagerTest
+    extends AbstractContinuumTest
+{
+    DistributedBuildManager distributedBuildManager;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        distributedBuildManager = (DistributedBuildManager) lookup( "distributedBuildManager"
);
+    }
+
+    public void testUpdateScmResult()
+        throws Exception
+    {
+        ProjectScmRootDao projectScmRootDao = (ProjectScmRootDao) lookup( ProjectScmRootDao.class.getName()
);
+        
+        Project project = addProject( "project1" );
+        project.setScmUrl( "http://sample/scmurl" );
+        getProjectDao().updateProject( project );
+
+        ProjectScmRoot scmRoot = new ProjectScmRoot();
+        scmRoot.setScmRootAddress( "http://sample/scmurl" );
+        scmRoot.setProjectGroup( project.getProjectGroup() );
+        projectScmRootDao.addProjectScmRoot( scmRoot );
+
+        ScmResult expectedScmResult = new ScmResult();
+        expectedScmResult.setSuccess( true );
+
+        Map context = new HashMap();
+        context.put( "project-id", project.getId() );
+        context.put( "scm-command-line", null );
+        context.put( "scm-command-output", null );
+        context.put( "scm-exception", null );
+        context.put( "scm-provider-message", null );
+        context.put( "prepare-build-finished", true );
+
+        distributedBuildManager.updateProjectScmRoot( context );
+
+        project = getProjectDao().getProjectWithScmDetails( project.getId() );
+
+        assertNotNull( project.getScmResult() );
+        assertScmResultEquals( expectedScmResult, project.getScmResult() );
+    }
+
+    public void testUpdateBuildResult()
+        throws Exception
+    {
+        Project project = addProject( "project1" );
+        project = getProjectDao().getProjectWithAllDetails( project.getId() );
+        
+        BuildDefinition buildDef = new BuildDefinition();
+        buildDef.setBuildFile( "pom.xml" );
+        buildDef.setGoals( "mvn clean" );
+        buildDef.setType( "maven2" );
+        buildDef.setTemplate( false );
+        
+        BuildDefinitionDao buildDefinitionDao = (BuildDefinitionDao) lookup( BuildDefinitionDao.class.getName()
);
+        buildDef = buildDefinitionDao.addBuildDefinition( buildDef );
+        
+        BuildResult expectedBuildResult = new BuildResult();
+        expectedBuildResult.setBuildNumber( project.getBuildNumber() + 1 );
+        expectedBuildResult.setBuildDefinition( buildDef );
+        expectedBuildResult.setError( null );
+        expectedBuildResult.setExitCode( 0 );
+        expectedBuildResult.setTrigger( ContinuumProjectState.TRIGGER_FORCED );
+        expectedBuildResult.setEndTime( new Long( "3456789012345" ) );
+        expectedBuildResult.setStartTime( new Long( "1234567890123" ) );
+        expectedBuildResult.setState( ContinuumProjectState.OK );
+
+        Map context = new HashMap();
+        context.put( "project-id", project.getId() );
+        context.put( "builddefinition-id", buildDef.getId() );
+        context.put( "build-start", expectedBuildResult.getStartTime() );
+        context.put( "build-end", expectedBuildResult.getEndTime() );
+        context.put( "build-error", expectedBuildResult.getError() );
+        context.put( "build-exit-code", expectedBuildResult.getExitCode() );
+        context.put( "build-state", expectedBuildResult.getState() );
+        context.put( "trigger", expectedBuildResult.getTrigger() );
+        
+        distributedBuildManager.updateBuildResult( context );
+
+        project = getProjectDao().getProjectWithBuildDetails( project.getId() );
+
+        BuildResultDao buildResultDao = (BuildResultDao) lookup( BuildResultDao.class.getName()
);
+        BuildResult buildResult = buildResultDao.getBuildResult( project.getLatestBuildId()
);
+
+        assertNotNull( buildResult );
+        assertBuildResultEquals( expectedBuildResult, buildResult );
+    }
+    
+    private void assertBuildResultEquals( BuildResult expected, BuildResult actual )
+        throws Exception
+    {
+        assertEquals( expected.getEndTime(), actual.getEndTime() );
+        assertEquals( expected.getStartTime(), actual.getStartTime() );
+        assertEquals( expected.getState(), actual.getState() );
+        assertEquals( expected.getBuildNumber(), actual.getBuildNumber() );
+        assertEquals( expected.getError(), actual.getError() );
+        assertEquals( expected.getExitCode(), actual.getExitCode() );
+        assertEquals( expected.getTrigger(), actual.getTrigger() );
+        assertEquals( expected.getBuildDefinition().getId(), actual.getBuildDefinition().getId()
);
+    }
+
+    private void assertScmResultEquals( ScmResult expected, ScmResult actual )
+        throws Exception
+    {
+        assertEquals( expected.getChanges(), actual.getChanges() );
+        assertEquals( expected.getCommandLine(), actual.getCommandLine() );
+        assertEquals( expected.getCommandOutput(), actual.getCommandOutput() );
+        assertEquals( expected.getException(), actual.getException() );
+        assertEquals( expected.getProviderMessage(), actual.getProviderMessage() );
+    }
+}

Modified: continuum/branches/continuum-distributed-builds/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java?rev=723613&r1=723612&r2=723613&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
Thu Dec  4 22:44:25 2008
@@ -123,14 +123,18 @@
             {
                 if ( buildAgent.getUrl().equals( agent.getUrl() ) )
                 {
-                    addActionError( getText( "buildAgent.error.exist" ) );
-                    return ERROR;
+                    agent.setDescription( buildAgent.getDescription() );
+                    agent.setEnabled( buildAgent.isEnabled() );
+
+                    configuration.updateBuildAgent( agent );
+                }
+                else
+                {
+                    configuration.addBuildAgent( buildAgent );
                 }
             }
         }
 
-        configuration.addBuildAgent( buildAgent );
-
         distributedBuildManager.reload();
 
         return SUCCESS;



Mime
View raw message