continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r726727 [2/2] - in /continuum/branches/continuum-distributed-builds: continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/ continuum-builder/src/main/java/org/apache/continuum/builder/utils/ continuum-distribute...
Date Mon, 15 Dec 2008 16:23:54 GMT
Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java?rev=726727&r1=726726&r2=726727&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
Mon Dec 15 08:23:53 2008
@@ -1,13 +1,18 @@
 package org.apache.continuum.buildagent.taskqueue.execution;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
 import org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager;
+import org.apache.continuum.buildagent.utils.BuildContextToBuildDefinition;
+import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 import org.apache.continuum.taskqueue.BuildProjectTask;
 import org.apache.continuum.utils.ContinuumUtils;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.codehaus.plexus.action.ActionManager;
@@ -39,8 +44,6 @@
         BuildProjectTask buildProjectTask = (BuildProjectTask) task;
 
         int projectId = buildProjectTask.getProjectId();
-        int buildDefinitionId = buildProjectTask.getBuildDefinitionId();
-        int trigger = buildProjectTask.getTrigger();
 
         log.info( "Initializing build" );
         BuildContext context = buildContextManager.getBuildContext( projectId );
@@ -52,7 +55,7 @@
             return;
         }
         
-        log.info( "Starting build of " + context.getProjectId() );
+        log.info( "Starting build of " + context.getProjectName() );
         startBuild( context );
 
         try
@@ -61,36 +64,11 @@
 
             performAction( "execute-builder", context );
 
-            performAction( "deploy-artifact", context );
-
-            /*
-            context.setCancelled( (Boolean) actionContext.get( AbstractContinuumAction.KEY_CANCELLED
) );
-
-            String s = (String) actionContext.get( AbstractContinuumAction.KEY_BUILD_ID );
-
-            if ( s != null && !context.isCancelled() )
-            {
-                try
-                {
-                    context.setBuildResult( buildResultDao.getBuildResult( Integer.valueOf(
s ) ) );
-                }
-                catch ( NumberFormatException e )
-                {
-                    throw new TaskExecutionException( "Internal error: build id not an integer",
e );
-                }
-                catch ( ContinuumObjectNotFoundException e )
-                {
-                    throw new TaskExecutionException( "Internal error: Cannot find build
result", e );
-                }
-                catch ( ContinuumStoreException e )
-                {
-                    throw new TaskExecutionException( "Error loading build result", e );
-                }
-            }*/
+            updateBuildResult( context, null );
         }
         finally
         {
-            //endBuild( context );
+            endBuild( context );
         }
     }
 
@@ -112,6 +90,30 @@
     private void startBuild( BuildContext buildContext )
     {
         // inform master that project is building ( to set the state )
+        
+    }
+
+    private void endBuild( BuildContext buildContext )
+    {
+        // return build result to master
+        BuildResult buildResult = buildContext.getBuildResult();
+
+        Map<String, Object> result = new HashMap<String, Object>();
+        result.put( ContinuumBuildAgentUtil.KEY_PROJECT_ID, new Integer( buildContext.getProjectId()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION_ID, new Integer( buildContext.getBuildDefinitionId()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_TRIGGER, new Integer( buildContext.getTrigger()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_STATE, new Integer( buildResult.getState()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_START, new Long( buildResult.getStartTime()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_END, new Long( buildResult.getEndTime()
) );
+        result.put( ContinuumBuildAgentUtil.KEY_BUILD_EXIT_CODE, new Integer( buildResult.getExitCode()
) );
+        if ( buildResult.getError() != null )
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_BUILD_ERROR, buildResult.getError() );
+        }
+        else
+        {
+            result.put( ContinuumBuildAgentUtil.KEY_BUILD_ERROR, "" );
+        }
     }
 
     private void performAction( String actionName, BuildContext context )
@@ -148,25 +150,37 @@
             exception = new TaskExecutionException( "Error executing action '" + actionName
+ "'", e );
             error = ContinuumUtils.throwableToString( exception );
         }
-    
-        // TODO: clean this up. We catch the original exception from the action, and then
update the buildresult
-        // for it - we need to because of the specialized error message for SCM.
-        // If updating the buildresult fails, log the previous error and throw the new one.
-        // If updating the buildresult succeeds, throw the original exception. The build
result should NOT
-        // be updated again - a TaskExecutionException is final, no further action should
be taken upon it.
-    
-        /*
-        try
+
+        updateBuildResult( context, error );
+
+        throw exception;
+    }
+
+    private void updateBuildResult( BuildContext context, String error )
+    {
+        context.setBuildResult( ContinuumBuildAgentUtil.getBuildResult( context.getActionContext(),
null ) );
+        
+        if ( context.getBuildResult() == null )
         {
-            updateBuildResult( context, error );
+            BuildResult build = new BuildResult();
+
+            build.setState( ContinuumProjectState.ERROR );
+
+            build.setTrigger( context.getTrigger() );
+
+            build.setStartTime( context.getBuildStartTime() );
+
+            build.setEndTime( System.currentTimeMillis() );
+
+            build.setBuildDefinition( BuildContextToBuildDefinition.getBuildDefinition( context
) );
+
+            if ( error != null )
+            {
+                build.setError( error );
+            }
+
+            context.setBuildResult( build );
         }
-        catch ( TaskExecutionException e )
-        {
-            log.error( "Error updating build result after receiving the following exception:
", exception );
-            throw e;
-        }*/
-    
-        throw exception;
     }
 
     private String getValidationMessages( ScmRepositoryException ex )

Added: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java?rev=726727&view=auto
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
(added)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
Mon Dec 15 08:23:53 2008
@@ -0,0 +1,129 @@
+package org.apache.continuum.buildagent.taskqueue.manager;
+
+import java.util.List;
+
+import org.apache.continuum.taskqueue.BuildProjectTask;
+import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.TaskQueue;
+import org.codehaus.plexus.taskqueue.TaskQueueException;
+import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
+import org.codehaus.plexus.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultTaskQueueManager
+    implements TaskQueueManager, Contextualizable
+{
+    private Logger log = LoggerFactory.getLogger( this.getClass() );
+
+    /**
+     * @plexus.requirement role-hint="build-agent"
+     */
+    private TaskQueue buildQueue;
+
+    private PlexusContainer container;
+
+    public void cancelBuild()
+        throws TaskQueueManagerException
+    {
+        removeProjectsFromBuildQueue();
+        cancelCurrentBuild();
+    }
+
+    public TaskQueue getBuildQueue()
+    {
+        return buildQueue;
+    }
+
+    public int getCurrentProjectInBuilding()
+        throws TaskQueueManagerException
+    {
+        Task task = getBuildTaskQueueExecutor().getCurrentTask();
+        if ( task != null )
+        {
+            if ( task instanceof BuildProjectTask )
+            {
+                return ( (BuildProjectTask) task ).getProjectId();
+            }
+        }
+        return -1;
+    }
+    
+    private void removeProjectsFromBuildQueue()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            List<BuildProjectTask> queues = buildQueue.getQueueSnapshot();
+        
+            if ( queues != null )
+            {
+                for ( BuildProjectTask task : queues )
+                {
+                    log.info( "remove project '" + task.getProjectName() + "' from build
queue" );
+                    buildQueue.remove( task );
+                }
+            }
+            else
+            {
+                log.info( "no build task in queue" );
+            }
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new TaskQueueManagerException( "Error while getting build tasks from queue",
e );
+        }
+    }
+
+    private boolean cancelCurrentBuild()
+        throws TaskQueueManagerException
+    {
+        Task task = getBuildTaskQueueExecutor().getCurrentTask();
+        
+        if ( task != null )
+        {
+            if ( task instanceof BuildProjectTask )
+            {
+                log.info( "Cancelling current build task" );
+                return getBuildTaskQueueExecutor().cancelTask( task );
+            }
+            else
+            {
+                log.warn( "Current task not a BuildProjectTask - not cancelling" );
+            }
+        }
+        else
+        {
+            log.warn( "No task running - not cancelling" );
+        }
+        return false;
+    }
+
+    public TaskQueueExecutor getBuildTaskQueueExecutor()
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "build-agent"
);
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new TaskQueueManagerException( e.getMessage(), e );
+        }
+    }
+    
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+}

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultTaskQueueManager.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java?rev=726727&r1=726726&r2=726727&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/TaskQueueManager.java
Mon Dec 15 08:23:53 2008
@@ -5,10 +5,13 @@
 
 public interface TaskQueueManager
 {
-    TaskQueue getBuildQueue();
+    String ROLE = TaskQueueManager.class.getName();
 
-    TaskQueue getPrepareBuildQueue();
+    TaskQueue getBuildQueue();
 
     void cancelBuild()
         throws TaskQueueManagerException;
+
+    int getCurrentProjectInBuilding()
+        throws TaskQueueManagerException;
 }

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToProject.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToProject.java?rev=726727&r1=726726&r2=726727&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToProject.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/BuildContextToProject.java
Mon Dec 15 08:23:53 2008
@@ -14,6 +14,8 @@
 
         project.setId( buildContext.getProjectId() );
 
+        project.setName( buildContext.getProjectName() );
+
         project.setScmUrl( buildContext.getScmUrl() );
 
         project.setScmUsername( buildContext.getScmPassword());

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java?rev=726727&r1=726726&r2=726727&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
Mon Dec 15 08:23:53 2008
@@ -77,13 +77,18 @@
 
     public static final String KEY_BUILD_RESULT = "build-result";
 
-    public static final String KEY_CANCELLED = "cancelled";
+    public static final String KEY_PROJECT_NAME = "project-name";
 
     public static Integer getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
     }
 
+    public static String getProjectName( Map context )
+    {
+        return getString( context, KEY_PROJECT_NAME );
+    }
+
     public static Integer getBuildDefinitionId( Map context )
     {
         return getInteger( context, KEY_BUILD_DEFINITION_ID );
@@ -179,11 +184,6 @@
         return (BuildResult) getObject( context, KEY_BUILD_RESULT );
     }
 
-    public static boolean isCancelled( Map context )
-    {
-        return (Boolean) getObject( context, KEY_CANCELLED );
-    }
-
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

Modified: continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/resources/META-INF/plexus/components.xml?rev=726727&r1=726726&r2=726727&view=diff
==============================================================================
--- continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/resources/META-INF/plexus/components.xml
(original)
+++ continuum/branches/continuum-distributed-builds/continuum-distributed-build/continuum-buildagent/continuum-buildagent-core/src/main/resources/META-INF/plexus/components.xml
Mon Dec 15 08:23:53 2008
@@ -21,28 +21,28 @@
   <components>
     <component>
       <role>org.codehaus.plexus.taskqueue.TaskQueue</role>
-      <role-hint>prepare-build-agent</role-hint>
+      <role-hint>build-agent</role-hint>
       <implementation>org.codehaus.plexus.taskqueue.DefaultTaskQueue</implementation>
       <lifecycle-handler>plexus-configurable</lifecycle-handler>
     </component>
 
     <component>
       <role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
-      <role-hint>prepare-build-agent</role-hint>
+      <role-hint>build-agent</role-hint>
       <implementation>org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor</implementation>
       <instantiation-strategy>singleton</instantiation-strategy>
       <requirements>
         <requirement>
           <role>org.codehaus.plexus.taskqueue.execution.TaskExecutor</role>
-          <role-hint>prepare-build-agent</role-hint>
+          <role-hint>build-agent</role-hint>
         </requirement>
         <requirement>
           <role>org.codehaus.plexus.taskqueue.TaskQueue</role>
-          <role-hint>prepare-build-agent</role-hint>
+          <role-hint>build-agent</role-hint>
         </requirement>
       </requirements>
       <configuration>
-        <name>prepare-build-agent</name>
+        <name>build-agent</name>
       </configuration>
     </component>
   </components>



Mime
View raw message