continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r349420 - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/ continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-core/src/main/java/org/apache/maven/continuum/ continuum-store/src/main/jav...
Date Mon, 28 Nov 2005 16:24:19 GMT
Author: evenisse
Date: Mon Nov 28 08:23:42 2005
New Revision: 349420

URL: http://svn.apache.org/viewcvs?rev=349420&view=rev
Log:
[CONTINUUM-448] Improve performance of "show projects" page
[CONTINUUM-477] Improve performance of enqueuing projects - First part
[CONTINUUM-478] Restore state of project when they're "In Progress" when continuum restart

Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
    maven/continuum/trunk/continuum-web/src/main/resources/templates/screens/Summary.vm

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?rev=349420&r1=349419&r2=349420&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
Mon Nov 28 08:23:42 2005
@@ -63,8 +63,11 @@
     Collection getProjects()
         throws ContinuumException;
 
-    BuildResult getLatestBuildResultForProject( int projectId )
-        throws ContinuumException;
+    BuildResult getLatestBuildResultForProject( int projectId );
+
+    Map getLatestBuildResults();
+
+    Map getBuildResultsInSuccess();
 
     // ----------------------------------------------------------------------
     // Queues

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=349420&r1=349419&r2=349420&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
Mon Nov 28 08:23:42 2005
@@ -32,6 +32,7 @@
 import java.io.File;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -51,6 +52,10 @@
     ProjectNotifier storeNotifier( ProjectNotifier notifier )
         throws ContinuumStoreException;
 
+    Map getDefaultBuildDefinitions();
+
+    BuildDefinition getDefaultBuildDefinition( int projectId );
+
     BuildDefinition getBuildDefinition( int buildDefinitionId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException;
 
@@ -140,8 +145,13 @@
     ProjectGroup getProjectGroupByGroupId( String groupId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException;
 
-    BuildResult getLatestBuildResultForProject( int projectId )
-        throws ContinuumStoreException;
+    BuildResult getLatestBuildResultForProject( int projectId );
+
+    Map getLatestBuildResults();
+
+    List getBuildResultByBuildNumber( int projectId, int buildNumber );
+
+    Map getBuildResultsInSuccess();
 
     void addBuildResult( Project project, BuildResult build )
         throws ContinuumStoreException, ContinuumObjectNotFoundException;

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=349420&r1=349419&r2=349420&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Mon Nov 28 08:23:42 2005
@@ -148,50 +148,34 @@
         return store.getAllProjectsByName();
     }
 
+    public Map getLatestBuildResults()
+    {
+        return store.getLatestBuildResults();
+    }
+
+    public Map getBuildResultsInSuccess()
+    {
+        return store.getBuildResultsInSuccess();
+    }
+
     public BuildResult getLatestBuildResultForProject( int projectId )
-        throws ContinuumException
     {
-        try
-        {
-            return store.getLatestBuildResultForProject( projectId );
-        }
-        catch ( ContinuumStoreException e )
-        {
-            throw logAndCreateException( "Error while getting the last build for project
'" + projectId + "'.", e );
-        }
+        return store.getLatestBuildResultForProject( projectId );
     }
 
     public BuildResult getBuildResultByBuildNumber( int projectId, int buildNumber )
         throws ContinuumException
     {
-        //TODO : Get build result with a store request
-
-        List buildResults;
+        List builds = store.getBuildResultByBuildNumber( projectId, buildNumber );
 
-        try
-        {
-            buildResults = new ArrayList( store.getProjectWithBuilds( projectId ).getBuildResults()
);
-        }
-        catch ( ContinuumStoreException e )
+        if ( builds.isEmpty() )
         {
-            throw logAndCreateException( "Exception while getting build results for project.",
e );
+            return null;
         }
-
-        Collections.reverse( buildResults );
-
-        Iterator buildResultsIterator = buildResults.iterator();
-
-        for ( Iterator i = buildResults.iterator(); i.hasNext(); )
+        else
         {
-            BuildResult br = (BuildResult) i.next();
-
-            if ( br.getBuildNumber() == buildNumber )
-            {
-                return br;
-            }
+            return (BuildResult) builds.get( 0 );
         }
-
-        return null;
     }
 
     // ----------------------------------------------------------------------
@@ -336,11 +320,20 @@
             projectsList = getProjects();
         }
 
+        Map buildDefinitionsIds = store.getDefaultBuildDefinitions();
+
         for ( Iterator i = projectsList.iterator(); i.hasNext(); )
         {
             Project project = (Project) i.next();
 
-            buildProject( project.getId(), trigger );
+            Integer buildDefId = (Integer) buildDefinitionsIds.get( new Integer( project.getId()
) );
+
+            if ( buildDefId == null )
+            {
+                throw new ContinuumException( "Project (id=" + project.getId() + " doens't
have a default build definition." );
+            }
+
+            buildProject( project.getId(), buildDefId.intValue(), trigger );
         }
     }
 
@@ -364,16 +357,19 @@
         {
             Project p = (Project) projectIterator.next();
 
-            Project project = getProjectWithAllDetails( p.getId() );
-
-            for ( Iterator bdIterator = project.getBuildDefinitions().iterator(); bdIterator.hasNext();
)
+            if ( !isInBuildingQueue( p.getId() ) && !isInCheckoutQueue( p.getId()
) )
             {
-                BuildDefinition buildDef = (BuildDefinition) bdIterator.next();
+                Project project = getProjectWithAllDetails( p.getId() );
 
-                if ( schedule.getId() == buildDef.getSchedule().getId() )
+                for ( Iterator bdIterator = project.getBuildDefinitions().iterator(); bdIterator.hasNext();
)
                 {
-                    //TODO: Fix trigger name
-                    buildProject( project.getId(), buildDef.getId(), ContinuumProjectState.TRIGGER_UNKNOWN
);
+                    BuildDefinition buildDef = (BuildDefinition) bdIterator.next();
+
+                    if ( schedule.getId() == buildDef.getSchedule().getId() )
+                    {
+                        //TODO: Fix trigger name
+                        buildProject( project.getId(), buildDef.getId(), ContinuumProjectState.TRIGGER_UNKNOWN,
false );
+                    }
                 }
             }
         }
@@ -382,19 +378,17 @@
     public void buildProject( int projectId )
         throws ContinuumException
     {
-        BuildDefinition buildDef = getDefaultBuildDefinition( projectId );
-
-        if ( buildDef == null )
-        {
-            throw new ContinuumException( "Project (id=" + projectId + " doens't have a default
build definition." );
-        }
-
-        buildProject( projectId, buildDef.getId(), ContinuumProjectState.TRIGGER_FORCED );
+        buildProject( projectId, ContinuumProjectState.TRIGGER_FORCED );
     }
 
     public void buildProject( int projectId, int trigger )
         throws ContinuumException
     {
+        if ( isInBuildingQueue( projectId ) || isInCheckoutQueue( projectId ) )
+        {
+            return;
+        }
+
         BuildDefinition buildDef = getDefaultBuildDefinition( projectId );
 
         if ( buildDef == null )
@@ -402,15 +396,24 @@
             throw new ContinuumException( "Project (id=" + projectId + " doens't have a default
build definition." );
         }
 
-        buildProject( projectId, buildDef.getId(), trigger );
+        buildProject( projectId, buildDef.getId(), trigger, false );
     }
 
-    public synchronized void buildProject( int projectId, int buildDefinitionId, int trigger
)
+    public void buildProject( int projectId, int buildDefinitionId, int trigger )
         throws ContinuumException
     {
-        if ( isInBuildingQueue( projectId ) || isInCheckoutQueue( projectId ) )
+        buildProject( projectId, buildDefinitionId, trigger, true );
+    }
+
+    private synchronized void buildProject( int projectId, int buildDefinitionId, int trigger,
boolean checkQueues )
+        throws ContinuumException
+    {
+        if ( checkQueues )
         {
-            return;
+            if ( isInBuildingQueue( projectId ) || isInCheckoutQueue( projectId ) )
+            {
+                return;
+            }
         }
 
         try
@@ -902,21 +905,7 @@
     public BuildDefinition getDefaultBuildDefinition( int projectId )
         throws ContinuumException
     {
-        List buildDefinitions = getBuildDefinitions( projectId );
-
-        BuildDefinition buildDefinition = null;
-
-        for ( Iterator i = buildDefinitions.iterator(); i.hasNext(); )
-        {
-            buildDefinition = (BuildDefinition) i.next();
-
-            if ( buildDefinition.isDefaultForProject() )
-            {
-                break;
-            }
-        }
-
-        return buildDefinition;
+        return store.getDefaultBuildDefinition( projectId );
     }
 
     public BuildDefinition getBuildDefinition( int projectId, int buildDefinitionId )
@@ -958,20 +947,13 @@
         {
             buildDefinition.setDefaultForProject( true );
             
-            List buildDefinitions = getBuildDefinitions( projectId );
+            BuildDefinition bd = getDefaultBuildDefinition( projectId );
 
-            for ( Iterator i = buildDefinitions.iterator(); i.hasNext(); )
+            if ( bd != null )
             {
-                BuildDefinition bd = (BuildDefinition) i.next();
-
-                if ( bd.isDefaultForProject() )
-                {
-                    bd.setDefaultForProject( false );
-
-                    storeBuildDefinition( bd );
+                bd.setDefaultForProject( false );
 
-                    break;
-                }
+                storeBuildDefinition( bd );
             }
         }
 
@@ -1008,20 +990,13 @@
         {
             buildDefinition.setDefaultForProject( true );
             
-            List buildDefinitions = getBuildDefinitions( projectId );
+            BuildDefinition bd = getDefaultBuildDefinition( projectId );
 
-            for ( Iterator i = buildDefinitions.iterator(); i.hasNext(); )
+            if ( bd != null )
             {
-                BuildDefinition bd = (BuildDefinition) i.next();
-
-                if ( bd.isDefaultForProject() )
-                {
-                    bd.setDefaultForProject( false );
+                bd.setDefaultForProject( false );
 
-                    storeBuildDefinition( bd );
-
-                    break;
-                }
+                storeBuildDefinition( bd );
             }
         }
 
@@ -1694,6 +1669,25 @@
         {
             Project project = (Project) it.next();
 
+            if ( project.getState() != ContinuumProjectState.NEW &&
+                 project.getState() != ContinuumProjectState.OK &&
+                 project.getState() != ContinuumProjectState.FAILED &&
+                 project.getState() != ContinuumProjectState.ERROR )
+            {
+                project.setState( project.getOldState() );
+
+                project.setOldState( 0 );
+
+                try
+                {
+                    store.updateProject( project );
+                }
+                catch( ContinuumStoreException e )
+                {
+                    throw new InitializationException( "Database is corrupted.", e );
+                }
+            }
+            
             getLogger().info( " " + project.getId() + ":" + project.getName() + ":" + project.getExecutorId()
);
         }
     }

Modified: maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=349420&r1=349419&r2=349420&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
Mon Nov 28 08:23:42 2005
@@ -33,6 +33,12 @@
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import javax.jdo.Extent;
 import javax.jdo.JDOException;
 import javax.jdo.JDOHelper;
@@ -42,9 +48,6 @@
 import javax.jdo.PersistenceManagerFactory;
 import javax.jdo.Query;
 import javax.jdo.Transaction;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -219,29 +222,73 @@
         {
             tx.begin();
 
-            Object id = pm.newObjectIdInstance( Project.class, new Integer( projectId ) );
+            Extent extent = pm.getExtent( BuildResult.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareParameters( "int projectId" );
+
+            query.setFilter( "this.project.id == projectId && this.project.latestBuildId
== this.id" );
 
-            Project project = (Project) pm.getObjectById( id );
+            List result = (List) query.execute( new Integer( projectId ) );
 
-            int buildId = project.getLatestBuildId();
+            result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
 
-            if ( buildId > 0 )
+            if ( result != null && !result.isEmpty() )
             {
-                id = pm.newObjectIdInstance( BuildResult.class, new Integer( buildId ) );
+                return (BuildResult) result.get( 0 );
+            }
+        }
+        finally
+        {
+            rollback( tx );
+        }
+        return null;
+    }
 
-                Object object = pm.getObjectById( id );
+    public Map getLatestBuildResults()
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
 
-                BuildResult build = (BuildResult) pm.detachCopy( object );
+        Transaction tx = pm.currentTransaction();
 
-                tx.commit();
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildResult.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.setFilter( "this.project.latestBuildId == this.id" );
 
-                return build;
+            List result = (List) query.execute();
+
+            result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
+
+            if ( result != null && !result.isEmpty() )
+            {
+                Map builds = new HashMap();
+
+                for ( Iterator i = result.iterator(); i.hasNext(); )
+                {
+                    BuildResult br = (BuildResult) i.next();
+
+                    builds.put( new Integer( br.getProject().getId() ), br );
+                }
+
+                return builds;
             }
         }
         finally
         {
             rollback( tx );
         }
+
         return null;
     }
 
@@ -259,6 +306,105 @@
         return notifier;
     }
 
+    public BuildDefinition getDefaultBuildDefinition( int projectId )
+    {
+        getLogger().info( "project :" + projectId );
+        long startDate = System.currentTimeMillis();
+
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( Project.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition"
);
+
+            query.declareParameters( "int projectId" );
+
+            query.declareVariables ("BuildDefinition buildDef");
+
+            query.setFilter( "this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject
== true && this.id == projectId" );
+
+            query.setResult( "buildDef" );
+
+            List result = (List) query.execute( new Integer( projectId ) );
+
+            result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
+
+            if ( result != null && !result.isEmpty() )
+            {
+                BuildDefinition bd = (BuildDefinition) result.get( 0 );
+                getLogger().info( "nb bd for project " + projectId + " : " + result.size()
+ " - bd id : " + bd.getId() );
+                return bd;
+            }
+        }
+        finally
+        {
+            rollback( tx );
+            getLogger().info( "getDefaultBuildDefinition : " + ( System.currentTimeMillis()
- startDate ) + "ms" );
+        }
+
+        return null;
+    }
+
+    public Map getDefaultBuildDefinitions()
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( Project.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition"
);
+
+            query.setFilter( "this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject
== true" );
+
+            query.declareVariables ("BuildDefinition buildDef");
+
+            query.setResult( "this.id, buildDef.id" );
+
+            List result = (List) query.execute();
+
+            //result = (List) pm.detachCopyAll( result );
+
+            Map builds = new HashMap();
+
+            if ( result != null && !result.isEmpty() )
+            {
+                for ( Iterator i = result.iterator(); i.hasNext(); )
+                {
+                    Object[] obj = (Object[]) i.next();
+
+                    builds.put( (Integer) obj[0], (Integer) obj[1] );
+                }
+
+                return builds;
+            }
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+
+        return null;
+    }
+
     public BuildDefinition getBuildDefinition( int buildDefinitionId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
@@ -682,6 +828,82 @@
         throws ContinuumObjectNotFoundException, ContinuumStoreException
     {
         return (BuildResult) getObjectById( BuildResult.class, buildId, BUILD_RESULT_WITH_DETAILS_FETCH_GROUP
);
+    }
+
+    public List getBuildResultByBuildNumber( int projectId, int buildNumber )
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildResult.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareParameters( "int projectId, int buildNumber" );
+
+            query.setFilter( "this.project.id == projectId && this.buildNumber ==
buildNumber" );
+
+            List result = (List) query.execute( new Integer( projectId ), new Integer( buildNumber
) );
+
+            result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
+
+            return result;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    public Map getBuildResultsInSuccess()
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildResult.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.setFilter( "this.project.buildNumber == this.buildNumber" );
+
+            List result = (List) query.execute();
+
+            result = (List) pm.detachCopyAll( result );
+
+            tx.commit();
+
+            if ( result != null && !result.isEmpty() )
+            {
+                Map builds = new HashMap();
+
+                for ( Iterator i = result.iterator(); i.hasNext(); )
+                {
+                    BuildResult br = (BuildResult) i.next();
+
+                    builds.put( new Integer( br.getProject().getId() ), br );
+                }
+
+                return builds;
+            }
+        }
+        finally
+        {
+            rollback( tx );
+        }
+
+        return null;
     }
 
     public void removeProject( Project project )

Modified: maven/continuum/trunk/continuum-web/src/main/resources/templates/screens/Summary.vm
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-web/src/main/resources/templates/screens/Summary.vm?rev=349420&r1=349419&r2=349420&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-web/src/main/resources/templates/screens/Summary.vm (original)
+++ maven/continuum/trunk/continuum-web/src/main/resources/templates/screens/Summary.vm Mon
Nov 28 08:23:42 2005
@@ -35,6 +35,8 @@
       </tr>
 
       #set ( $items = $continuum.projects )
+      #set ( $buildResults = $continuum.getLatestBuildResults() )
+      #set ( $buildResultsInSuccess = $continuum.getBuildResultsInSuccess() )
 
       #foreach ( $item in $items )
       #if ( $item.state == 2 )
@@ -48,7 +50,7 @@
       <tr class="$css.nextClass">
         <td>
           #if ( $item.state == 1 || $item.state == 2 || $item.state == 3 || $item.state ==
4 )
-            #set ( $latestBuild = $continuum.getLatestBuildResultForProject( $item.id ) )
+            #set ( $latestBuild = $buildResults.get( $item.id ) )
             #set ( $generatedState = $state.generate( $item ) )
             #if ( $latestBuild && $generatedState != "New" )
               <a href="$link.setPage('ProjectBuild.vm').addQueryData('view','ProjectBuild').addQueryData('buildId',$latestBuild.id).addQueryData('id',$item.id)">$generatedState</a></td>
@@ -66,7 +68,7 @@
             <b>In&nbsp;queue</b>
           #elseif ( $item.state == 1 || $item.state == 2 || $item.state == 3 || $item.state
== 4 )
             #if ( $item.buildNumber != 0 )
-              #set ( $build = $continuum.getBuildResultByBuildNumber( $item.id, $item.buildNumber
) )
+              #set ( $build = $buildResultsInSuccess.get( $item.id ) )
               <a href="$link.setPage('ProjectBuild.vm').addQueryData('view','ProjectBuild').addQueryData('buildId',$build.id).addQueryData('id',$item.id)">$item.buildNumber</a>
             #else
               $item.buildNumber



Mime
View raw message