continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r775961 - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/dao/ continuum-api/src/main/java/org/apache/maven/continuum/ continuum-core/src/main/java/org/apache/maven/continuum/ continuum-model/src/main/java/ continuum-m...
Date Mon, 18 May 2009 14:07:54 GMT
Author: ctan
Date: Mon May 18 14:07:51 2009
New Revision: 775961

URL: http://svn.apache.org/viewvc?rev=775961&view=rev
Log:
[CONTINUUM-1712] added jpox project summary to improve performance of group summary page
merge -r 775955:775956 of 1.3.x branch

Added:
    continuum/trunk/continuum-model/src/main/java/
    continuum/trunk/continuum-model/src/main/java/org/
    continuum/trunk/continuum-model/src/main/java/org/apache/
    continuum/trunk/continuum-model/src/main/java/org/apache/continuum/
    continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/
    continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/
    continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
  (with props)
    continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
  (with props)
Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
    continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
    continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
    continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java (original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/dao/ProjectDao.java Mon
May 18 14:07:51 2009
@@ -19,12 +19,14 @@
  * under the License.
  */
 
+import org.apache.continuum.model.project.ProjectGroupSummary;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -79,4 +81,6 @@
 
     Project getProjectWithDependencies( int projectId )
         throws ContinuumStoreException;
+
+    Map<Integer, ProjectGroupSummary> getProjectsSummary();
 }

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
Mon May 18 14:07:51 2009
@@ -26,6 +26,7 @@
 
 import org.apache.continuum.builder.distributed.manager.DistributedBuildManager;
 import org.apache.continuum.buildmanager.BuildsManager;
+import org.apache.continuum.model.project.ProjectGroupSummary;
 import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.model.release.ContinuumReleaseResult;
 import org.apache.continuum.purge.ContinuumPurgeManager;
@@ -147,6 +148,8 @@
 
     Map<Integer, BuildResult> getBuildResultsInSuccess();
 
+    Map<Integer, ProjectGroupSummary> getProjectsSummaryByGroups();
+
     // ----------------------------------------------------------------------
     // Building
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Mon May 18 14:07:51 2009
@@ -48,6 +48,7 @@
 import org.apache.continuum.dao.ProjectGroupDao;
 import org.apache.continuum.dao.ProjectScmRootDao;
 import org.apache.continuum.dao.ScheduleDao;
+import org.apache.continuum.model.project.ProjectGroupSummary;
 import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.model.release.ContinuumReleaseResult;
 import org.apache.continuum.purge.ContinuumPurgeManager;
@@ -740,6 +741,11 @@
         return projectDao.getAllProjectsByName();
     }
 
+    public Map<Integer, ProjectGroupSummary> getProjectsSummaryByGroups()
+    {
+        return projectDao.getProjectsSummary();
+    }
+
     // ----------------------------------------------------------------------
     // Building
     // ----------------------------------------------------------------------

Added: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java?rev=775961&view=auto
==============================================================================
--- continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
(added)
+++ continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
Mon May 18 14:07:51 2009
@@ -0,0 +1,93 @@
+package org.apache.continuum.model.project;
+
+public class ProjectGroupSummary
+{
+    private int projectGroupId;
+
+    private int numberOfSuccesses;
+
+    private int numberOfFailures;
+
+    private int numberOfErrors;
+
+    private int numberOfProjects;
+
+    public ProjectGroupSummary()
+    {
+    }
+
+    public ProjectGroupSummary( int projectGroupId )
+    {
+        this.projectGroupId = projectGroupId;
+    }
+
+    public int getProjectGroupId()
+    {
+        return projectGroupId;
+    }
+    
+    public void setProjectGroupId( int projectGroupId )
+    {
+        this.projectGroupId = projectGroupId;
+    }
+
+    public void setNumberOfSuccesses( int numberOfSuccesses )
+    {
+        this.numberOfSuccesses = numberOfSuccesses;
+    }
+
+    public int getNumberOfSuccesses()
+    {
+        return numberOfSuccesses;
+    }
+
+    public void setNumberOfFailures( int numberOfFailures )
+    {
+        this.numberOfFailures = numberOfFailures;
+    }
+
+    public int getNumberOfFailures()
+    {
+        return numberOfFailures;
+    }
+
+    public void setNumberOfErrors( int numberOfErrors )
+    {
+        this.numberOfErrors = numberOfErrors;
+    }
+
+    public int getNumberOfErrors()
+    {
+        return numberOfErrors;
+    }
+
+    public void setNumberOfProjects( int numberOfProjects )
+    {
+        this.numberOfProjects = numberOfProjects;
+    }
+
+    public int getNumberOfProjects()
+    {
+        return numberOfProjects;
+    }
+
+    public void addProjects( int projects )
+    {
+        this.numberOfProjects += projects;
+    }
+
+    public void addNumberOfSuccesses( int numberOfSuccesses )
+    {
+        this.numberOfSuccesses += numberOfSuccesses;
+    }
+
+    public void addNumberOfErrors( int numberOfErrors )
+    {
+        this.numberOfErrors += numberOfErrors;
+    }
+
+    public void addNumberOfFailures( int numberOfFailures )
+    {
+        this.numberOfFailures += numberOfFailures;
+    }
+}

Propchange: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectGroupSummary.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java?rev=775961&view=auto
==============================================================================
--- continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
(added)
+++ continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
Mon May 18 14:07:51 2009
@@ -0,0 +1,49 @@
+package org.apache.continuum.model.project;
+
+public class ProjectSummaryResult
+{
+    private int projectGroupId;
+
+    private int projectState;
+
+    private long size;
+
+    public ProjectSummaryResult( int projectGroupId, int projectState, long size )
+    {
+        this.projectGroupId = projectGroupId;
+
+        this.projectState = projectState;
+
+        this.size = size;
+    }
+
+    public int getProjectGroupId()
+    {
+        return projectGroupId;
+    }
+
+    public void setProjectGroupId( int projectGroupId )
+    {
+        this.projectGroupId = projectGroupId;
+    }
+
+    public int getProjectState()
+    {
+        return projectState;
+    }
+
+    public void setProjectState( int projectState )
+    {
+        this.projectState = projectState;
+    }
+
+    public long getSize()
+    {
+        return size;
+    }
+
+    public void setSize( long size )
+    {
+        this.size = size;
+    }
+}

Propchange: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-model/src/main/java/org/apache/continuum/model/project/ProjectSummaryResult.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
(original)
+++ continuum/trunk/continuum-store/src/main/java/org/apache/continuum/dao/ProjectDaoImpl.java
Mon May 18 14:07:51 2009
@@ -19,6 +19,8 @@
  * under the License.
  */
 
+import org.apache.continuum.model.project.ProjectGroupSummary;
+import org.apache.continuum.model.project.ProjectSummaryResult;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
@@ -31,7 +33,10 @@
 import javax.jdo.Transaction;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -299,4 +304,78 @@
     {
         return (Project) getObjectById( Project.class, projectId, PROJECT_DEPENDENCIES_FETCH_GROUP
);
     }
+
+    public Map<Integer, ProjectGroupSummary> getProjectsSummary()
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( Project.class );
+
+            Query query = pm.newQuery( extent );
+
+            query.setResult( "projectGroup.id as projectGroupId, state as projectState, count(state)
as size" );
+
+            query.setResultClass( ProjectSummaryResult.class );
+
+            query.setGrouping( "projectGroup.id, state" );
+
+            List<ProjectSummaryResult> results = (List<ProjectSummaryResult>)
query.execute();
+
+            Map<Integer, ProjectGroupSummary> summaries = processProjectGroupSummary(
results );
+
+            tx.commit();
+
+            return summaries;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    private Map<Integer, ProjectGroupSummary> processProjectGroupSummary( List<ProjectSummaryResult>
results )
+    {
+        Map<Integer, ProjectGroupSummary> map = new HashMap<Integer, ProjectGroupSummary>();
+
+        for ( ProjectSummaryResult result : results )
+        {
+            ProjectGroupSummary summary;
+            int projectGroupId = result.getProjectGroupId();
+            int size = new Long( result.getSize() ).intValue();
+            int state = result.getProjectState();
+            
+            if ( map.containsKey( projectGroupId ) )
+            {
+                summary = map.get( projectGroupId );
+            }
+            else
+            {
+                summary = new ProjectGroupSummary( projectGroupId );
+            }
+
+            summary.addProjects( size );
+
+            if ( state == 2 )
+            {
+                summary.addNumberOfSuccesses( size );
+            }
+            else if ( state == 3 )
+            {
+                summary.addNumberOfFailures( size );
+            }
+            else if ( state == 4 )
+            {
+                summary.addNumberOfErrors( size );
+            }
+
+            map.put( projectGroupId, summary );
+        }
+        return map;
+    }
 }

Modified: continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
(original)
+++ continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
Mon May 18 14:07:51 2009
@@ -1204,9 +1204,9 @@
             .getVersion(), project.getWorkingDirectory() );
     }
 
-    private static Project createTestProject( String artifactId, int buildNumber, String
description, String groupId,
-                                              String name, String scmUrl, int state, String
url, String version,
-                                              String workingDirectory )
+    protected static Project createTestProject( String artifactId, int buildNumber, String
description, String groupId,
+                                                String name, String scmUrl, int state, String
url, String version,
+                                                String workingDirectory )
     {
         Project project = new Project();
         project.setArtifactId( artifactId );

Modified: continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
(original)
+++ continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
Mon May 18 14:07:51 2009
@@ -22,6 +22,7 @@
 import org.apache.continuum.dao.BuildDefinitionDao;
 import org.apache.continuum.dao.BuildDefinitionTemplateDao;
 import org.apache.continuum.dao.BuildResultDao;
+import org.apache.continuum.model.project.ProjectGroupSummary;
 import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.model.release.ContinuumReleaseResult;
 import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
@@ -48,6 +49,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
@@ -1354,6 +1356,52 @@
         releaseResults = releaseResultDao.getAllContinuumReleaseResults();
         assertEquals( "check size of continuum release results", 1, releaseResults.size()
);
     }
+
+	public void testGetProjectSummaryByProjectGroup()
+	    throws Exception
+	{
+	    List<Project> projects = projectDao.getProjectsInGroup( defaultProjectGroup.getId()
);
+	    assertEquals( 2, projects.size() );
+
+	    Project project = projects.get( 0 );
+	    project.setState( 2 );
+	    projectDao.updateProject( project );
+
+	    project = projects.get( 1 );
+	    project.setState( 2 );
+	    projectDao.updateProject( project );
+
+	    ProjectGroup newGroup = projectGroupDao.getProjectGroupWithProjects( testProjectGroup2.getId()
);
+	    Project project1 = createTestProject( testProject1 );
+	    project1.setState( 4 );
+	    newGroup.addProject( project1 );
+
+	    Project project2 = createTestProject( testProject2 );
+	    project2.setState( 1 );
+	    newGroup.addProject( project2 );
+	    projectGroupDao.updateProjectGroup( newGroup );
+
+	    Map<Integer, ProjectGroupSummary> summaries = projectDao.getProjectsSummary();
+
+	    assertNotNull( summaries );
+	    assertEquals( "check size of project summaries", 2, summaries.size() );
+
+	    ProjectGroupSummary summary = summaries.get( testProjectGroup2.getId() );
+	    assertEquals( "check id of project group", testProjectGroup2.getId(), summary.getProjectGroupId()
);
+	    assertEquals( "check number of errors", 1, summary.getNumberOfErrors() );
+	    assertEquals( "check number of successes", 0, summary.getNumberOfSuccesses() );
+	    assertEquals( "check number of failures", 0, summary.getNumberOfFailures() );
+	    assertEquals( "check number of projects", 2, summary.getNumberOfProjects() );
+
+	    summary = summaries.get( defaultProjectGroup.getId() );
+	    assertEquals( "check id of project group", defaultProjectGroup.getId(), summary.getProjectGroupId()
);
+        assertEquals( "check number of errors", 0, summary.getNumberOfErrors() );
+        assertEquals( "check number of successes", 2, summary.getNumberOfSuccesses() );
+        assertEquals( "check number of failures", 0, summary.getNumberOfFailures() );
+        assertEquals( "check number of projects", 2, summary.getNumberOfProjects() );
+
+	}
+
     // ----------------------------------------------------------------------
     //  HELPER METHODS
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
Mon May 18 14:07:51 2009
@@ -22,9 +22,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.continuum.model.project.ProjectGroupSummary;
 import org.apache.maven.continuum.ContinuumException;
-import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
 import org.apache.maven.continuum.web.model.GroupSummary;
@@ -50,7 +51,7 @@
     {
         groups = new ArrayList<GroupSummary>();
 
-        Collection<ProjectGroup> projectGroups = getContinuum().getAllProjectGroupsWithProjects();
+        Collection<ProjectGroup> projectGroups = getContinuum().getAllProjectGroups();
 
         for ( ProjectGroup projectGroup : projectGroups )
         {
@@ -65,39 +66,20 @@
                 groupModel.setName( projectGroup.getName() );
                 groupModel.setDescription( projectGroup.getDescription() );
 
-                //TODO: Create a summary jpox request so code will be more simple and performance
will be better
-                Collection<Project> projects = projectGroup.getProjects();
+                Map<Integer, ProjectGroupSummary> summaries = getContinuum().getProjectsSummaryByGroups();
+                ProjectGroupSummary summary = summaries.get( projectGroup.getId() );
 
-                groupModel.setNumProjects( projects.size() );
-
-                int numSuccesses = 0;
-                int numFailures = 0;
-                int numErrors = 0;
-
-                for ( Project project : projects )
+                if ( summary != null )
                 {
-
-                    if ( project.getState() == 2 )
-                    {
-                        numSuccesses++;
-                    }
-                    else if ( project.getState() == 3 )
-                    {
-                        numFailures++;
-                    }
-                    else if ( project.getState() == 4 )
-                    {
-                        numErrors++;
-                    }
+                    groupModel.setNumProjects( summary.getNumberOfProjects() );
+                    groupModel.setNumErrors( summary.getNumberOfErrors() );
+                    groupModel.setNumFailures( summary.getNumberOfFailures() );
+                    groupModel.setNumSuccesses( summary.getNumberOfSuccesses() );
                 }
 
                 //todo wire in the next scheduled build for the project group and a meaningful
status message
                 //groupModel.setNextScheduledBuild( "unknown" );
                 //groupModel.setStatusMessage( "none" );
-
-                groupModel.setNumSuccesses( numSuccesses );
-                groupModel.setNumFailures( numFailures );
-                groupModel.setNumErrors( numErrors );
                 logger.debug( "GroupSummaryAction: adding group to groups list " + groupModel.getName()
);
                 groups.add( groupModel );
             }

Modified: continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo?rev=775961&r1=775960&r2=775961&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo (original)
+++ continuum/trunk/continuum-webapp/src/main/mdo/view-models.mdo Mon May 18 14:07:51 2009
@@ -262,7 +262,7 @@
           <required>true</required>
           <description>number of successful builds in the project group</description>
           <type>int</type>
-          <defaultValue>-1</defaultValue>
+          <defaultValue>0</defaultValue>
         </field>
         <field>
           <name>numFailures</name>
@@ -270,7 +270,7 @@
           <required>true</required>
           <description>number of failed builds in the project group</description>
           <type>int</type>
-          <defaultValue>-1</defaultValue>
+          <defaultValue>0</defaultValue>
         </field>
         <field>
           <name>numErrors</name>
@@ -278,7 +278,7 @@
           <required>true</required>
           <description>number of errored builds in the project group</description>
           <type>int</type>
-          <defaultValue>-1</defaultValue>
+          <defaultValue>0</defaultValue>
         </field>
         <field>
           <name>repositoryId</name>



Mime
View raw message