continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1673628 - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/dao/ continuum-core/src/main/java/org/apache/continuum/builder/ continuum-core/src/main/resources/META-INF/ continuum-core/src/test/java/org/apache/continuum/b...
Date Wed, 15 Apr 2015 03:24:08 GMT
Author: batkinson
Date: Wed Apr 15 03:24:08 2015
New Revision: 1673628

URL: http://svn.apache.org/r1673628
Log:
[CONTINUUM-1704] Old builds show in progress when they are not actually running

Added:
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/OrphanBuildStatusUpdater.java
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/OrphanBuildStatusUpdaterTest.java
Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/BuildResultDao.java
    continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
    continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/BuildResultDaoImpl.java
    continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/BuildResultDao.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/BuildResultDao.java?rev=1673628&r1=1673627&r2=1673628&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/BuildResultDao.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/BuildResultDao.java
Wed Apr 15 03:24:08 2015
@@ -56,6 +56,9 @@ public interface BuildResultDao
     BuildResult getPreviousBuildResultInSuccess( int projectId, int buildResultId )
         throws ContinuumStoreException;
 
+    int resolveOrphanedInProgressResults()
+        throws ContinuumStoreException;
+
     long getNbBuildResultsForProject( int projectId );
 
     /**

Added: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/OrphanBuildStatusUpdater.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/OrphanBuildStatusUpdater.java?rev=1673628&view=auto
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/OrphanBuildStatusUpdater.java
(added)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/OrphanBuildStatusUpdater.java
Wed Apr 15 03:24:08 2015
@@ -0,0 +1,52 @@
+package org.apache.continuum.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.continuum.builder.distributed.work.BuildStatusUpdater;
+import org.apache.continuum.dao.BuildResultDao;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component( role = BuildStatusUpdater.class, hint = "orphans" )
+public class OrphanBuildStatusUpdater
+    implements BuildStatusUpdater
+{
+    private static final Logger log = LoggerFactory.getLogger( OrphanBuildStatusUpdater.class
);
+
+    @Requirement
+    private BuildResultDao buildResultDao;
+
+    public void performScan()
+    {
+        try
+        {
+            log.info( "scanning for orphaned in-progress build results" );
+            int updated = buildResultDao.resolveOrphanedInProgressResults();
+            log.info( "finished: fixed {} results", updated );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            log.warn( "failed to resolve orphaned build results: ", e.getMessage() );
+        }
+    }
+}

Modified: continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml?rev=1673628&r1=1673627&r2=1673628&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml (original)
+++ continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml Wed Apr
15 03:24:08 2015
@@ -76,4 +76,10 @@
     <property name="concurrent" value="false"/>
   </bean>
 
+  <bean name="orphanedBuildJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
+    <property name="targetObject" ref="buildStatusUpdater#orphans"/>
+    <property name="targetMethod" value="performScan"/>
+    <property name="concurrent" value="false"/>
+  </bean>
+
 </beans>

Added: continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/OrphanBuildStatusUpdaterTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/OrphanBuildStatusUpdaterTest.java?rev=1673628&view=auto
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/OrphanBuildStatusUpdaterTest.java
(added)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/continuum/builder/OrphanBuildStatusUpdaterTest.java
Wed Apr 15 03:24:08 2015
@@ -0,0 +1,153 @@
+package org.apache.continuum.builder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.continuum.builder.distributed.work.BuildStatusUpdater;
+import org.apache.continuum.dao.BuildDefinitionDao;
+import org.apache.continuum.dao.BuildResultDao;
+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.store.ContinuumStoreException;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.maven.continuum.project.ContinuumProjectState.*;
+import static org.junit.Assert.assertEquals;
+
+public class OrphanBuildStatusUpdaterTest
+    extends AbstractContinuumTest
+{
+
+    private BuildResultDao resultDao;
+
+    private BuildDefinitionDao buildDefDao;
+
+    private List<BuildResult> canceled = new ArrayList<BuildResult>();
+
+    private List<BuildResult> ok = new ArrayList<BuildResult>();
+
+    private List<BuildResult> building = new ArrayList<BuildResult>();
+
+    private BuildDefinition defOne;
+
+    private BuildDefinition defTwo;
+
+    @Before
+    public void populateTestData()
+        throws Exception
+    {
+        resultDao = lookup( BuildResultDao.class );
+        buildDefDao = lookup( BuildDefinitionDao.class );
+
+        defOne = addBuildDef();
+        defTwo = addBuildDef();
+
+        // NOTE: Build results added in build order - last added is most recent build
+
+        Project noCleanup = addProject( "One In-Progress (No Cleanup)" );
+        addResult( noCleanup, defOne, BUILDING, building );
+
+        Project oneCleanup = addProject( "Two In-Progress With Success (One Cleanup)" );
+        addResult( oneCleanup, defTwo, BUILDING, canceled );
+        addResult( oneCleanup, defTwo, OK, ok );
+        addResult( oneCleanup, defTwo, BUILDING, building );
+
+        Project twoCleanup = addProject( "Three In-Progress With Success (Two Cleanup)" );
+        addResult( twoCleanup, defTwo, BUILDING, canceled );
+        addResult( twoCleanup, defTwo, OK, ok );
+        addResult( twoCleanup, defTwo, BUILDING, canceled );
+        addResult( twoCleanup, defTwo, BUILDING, building );
+
+        Project bdNoCleanup = addProject( "Two In-Progress (No Cleanup)" );
+        addResult( bdNoCleanup, defOne, BUILDING, building );
+        addResult( bdNoCleanup, defTwo, BUILDING, building );
+    }
+
+    @Test
+    public void testOrphansResolvedSafely()
+        throws ContinuumStoreException
+    {
+        lookup( BuildStatusUpdater.class, "orphans" ).performScan();
+        verifyResults();
+    }
+
+    private BuildDefinition addBuildDef()
+        throws ContinuumStoreException
+    {
+        BuildDefinition def = new BuildDefinition();
+        def.setAlwaysBuild( false );
+        def.setBuildFresh( false );
+        def.setDefaultForProject( false );
+        def.setTemplate( false );
+        def = buildDefDao.addBuildDefinition( def );
+        return def;
+    }
+
+    private void addResult( Project project, BuildDefinition buildDef, int state, List<BuildResult>
expected )
+        throws ContinuumStoreException
+    {
+        BuildResult br = new BuildResult();
+
+        // nullability constraints
+        br.setBuildNumber( 0 );
+        br.setEndTime( 0 );
+        br.setExitCode( 0 );
+        br.setStartTime( 0 );
+        br.setTrigger( 0 );
+
+        // associate relationship
+        br.setBuildDefinition( buildDef );
+
+        // set the build result
+        br.setState( state );
+
+        // persist the result
+        resultDao.addBuildResult( project, br );
+        br = resultDao.getBuildResult( br.getId() );
+        expected.add( br );
+    }
+
+    private void verifyResults()
+        throws ContinuumStoreException
+    {
+        for ( BuildResult br : ok )
+        {
+            assertEquals( "Successful results should be untouched", OK,
+                          resultDao.getBuildResult( br.getId() ).getState() );
+        }
+
+        for ( BuildResult br : building )
+        {
+            assertEquals( "Latest building result for build def should be untouched", BUILDING,
+                          resultDao.getBuildResult( br.getId() ).getState() );
+        }
+
+        for ( BuildResult br : canceled )
+        {
+            assertEquals( "Prior building results for build def should be canceled", CANCELLED,
+                          resultDao.getBuildResult( br.getId() ).getState() );
+        }
+    }
+}

Modified: continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/BuildResultDaoImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/BuildResultDaoImpl.java?rev=1673628&r1=1673627&r2=1673628&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/BuildResultDaoImpl.java
(original)
+++ continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/BuildResultDaoImpl.java
Wed Apr 15 03:24:08 2015
@@ -34,8 +34,13 @@ import javax.jdo.Transaction;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
+import static org.apache.maven.continuum.project.ContinuumProjectState.BUILDING;
+import static org.apache.maven.continuum.project.ContinuumProjectState.CANCELLED;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -718,6 +723,42 @@ public class BuildResultDaoImpl
         }
         finally
         {
+            rollback( tx );
+        }
+    }
+
+    public int resolveOrphanedInProgressResults()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+        Transaction tx = pm.currentTransaction();
+        try
+        {
+            tx.begin();
+            Query query = pm.newQuery( BuildResult.class );
+            query.declareVariables( "BuildResult r1" );
+            String filter = String.format( "this.project.id == r1.project.id"
+                                               + " && this.buildDefinition.id ==
r1.buildDefinition.id"
+                                               + " && this.state == %s"
+                                               + " && this.id < r1.id", BUILDING
);
+            query.setFilter( filter );
+            int updateCount = 0;
+            List<BuildResult> orphans = (List<BuildResult>) pm.detachCopyAll(
(List) query.execute() );
+            Set<Integer> updatedIds = new HashSet<Integer>();
+            for ( BuildResult orphan : orphans )
+            {
+                if ( updatedIds.contains( orphan.getId() ) )
+                    continue;
+                orphan.setState( CANCELLED );
+                orphan.setError( "Build appears to have been orphaned, final status is unknown."
);
+                updateObject( orphan );
+                updatedIds.add( orphan.getId() );
+            }
+            tx.commit();
+            return updatedIds.size();
+        }
+        finally
+        {
             rollback( tx );
         }
     }

Modified: continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml?rev=1673628&r1=1673627&r2=1673628&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml Wed Apr
15 03:24:08 2015
@@ -126,12 +126,18 @@
     <property name="jobDetail" ref="distributedBuildStatusUpdateJob"/>
     <property name="cronExpression" value="0 * * * * ?"/>
   </bean>
+  <bean id="orphanedBuildTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
+    <property name="jobDetail" ref="orphanedBuildJob"/>
+    <property name="cronExpression" value="0 */5 * * * ?"/>
+  </bean>
+
 
   <!-- maintenance scheduler -->
   <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
     <property name="triggers">
       <list>
         <ref bean="distributedBuildStatusTrigger"/>
+        <ref bean="orphanedBuildTrigger"/>
       </list>
     </property>
     <property name="schedulerName" value="maintenance"/>



Mime
View raw message