diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-10-01 10:27:16 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-10-01 10:27:16 +0000 |
commit | 5cdf0b8fa4251ef40c94e9416ccb4843214bf2e2 (patch) | |
tree | 8c9e2c03db5c903456e1c7d02dfbad5724f88e50 /archiva-modules/archiva-scheduled | |
parent | 3a14379327bd67fd63ac28c0157701b02a4610ce (diff) | |
download | archiva-5cdf0b8fa4251ef40c94e9416ccb4843214bf2e2.tar.gz archiva-5cdf0b8fa4251ef40c94e9416ccb4843214bf2e2.zip |
[MRM-84]
-added statistics report in reports UI
-added statistics report generator with tests
-added new fields (totalProjectCount, totalGroupCount, totalArtifactCount and totalSize) to RepositoryContentStatistics table
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@700729 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-scheduled')
-rw-r--r-- | archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java index 527ee34fc..65393a164 100644 --- a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java @@ -20,10 +20,14 @@ package org.apache.maven.archiva.scheduled.executors; */ import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.ObjectNotFoundException; +import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics; import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.repository.RepositoryException; @@ -38,6 +42,7 @@ import org.codehaus.plexus.taskqueue.execution.TaskExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.util.List; /** @@ -112,19 +117,95 @@ public class ArchivaRepositoryScanningTaskExecutor log.info( "Finished repository task: " + stats.toDump( arepo ) ); - // I hate jpox and modello - RepositoryContentStatistics dbstats = new RepositoryContentStatistics(); - dbstats.setDuration( stats.getDuration() ); - dbstats.setNewFileCount( stats.getNewFileCount() ); - dbstats.setRepositoryId( stats.getRepositoryId() ); - dbstats.setTotalFileCount( stats.getTotalFileCount() ); - dbstats.setWhenGathered( stats.getWhenGathered() ); + RepositoryContentStatistics dbstats = constructRepositoryStatistics( arepo, sinceWhen, results, stats ); - dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( dbstats ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( dbstats ); } catch ( RepositoryException e ) - { + { throw new TaskExecutionException( "Repository error when executing repository job.", e ); - } + } } + + private RepositoryContentStatistics constructRepositoryStatistics( ManagedRepositoryConfiguration arepo, + long sinceWhen, + List<RepositoryContentStatistics> results, + RepositoryScanStatistics stats ) + { + // I hate jpox and modello <-- and so do I + RepositoryContentStatistics dbstats = new RepositoryContentStatistics(); + dbstats.setDuration( stats.getDuration() ); + dbstats.setNewFileCount( stats.getNewFileCount() ); + dbstats.setRepositoryId( stats.getRepositoryId() ); + dbstats.setTotalFileCount( stats.getTotalFileCount() ); + dbstats.setWhenGathered( stats.getWhenGathered() ); + + // MRM-84 + /* + List<RepositoryContentStatistics> secondResults = dao.query( new MostRecentRepositoryScanStatistics( arepo.getId() ) ); + if ( CollectionUtils.isNotEmpty( results ) ) + { + RepositoryContentStatistics lastStats = secondResults.get( 0 ); + sinceWhen = lastStats.getWhenGathered().getTime() + lastStats.getDuration(); + } + */ + + // total artifact count + try + { + List artifacts = dao.getArtifactDAO().queryArtifacts( + new ArtifactsByRepositoryConstraint( arepo.getId(), stats.getWhenGathered(), "groupId", true ) ); + dbstats.setTotalArtifactCount( artifacts.size() ); + } + catch ( ObjectNotFoundException oe ) + { + log.error( "Object not found in the database : " + oe.getMessage() ); + } + catch ( ArchivaDatabaseException ae ) + { + log.error( "Error occurred while querying artifacts for artifact count : " + ae.getMessage() ); + } + + + // total repo size + long size = FileUtils.sizeOfDirectory( new File( arepo.getLocation() ) ); + dbstats.setTotalSize( size ); + + /* + TODO: + + // total unique groups + List<String> repos = new ArrayList<String>(); + repos.add( arepo.getId() ); + try + { + List<String> groupIds = dao.getArtifactDAO().queryArtifacts( new UniqueGroupIdConstraint( repos ) ); + dbstats.setTotalGroupCount( groupIds.size() ); + } + catch ( ObjectNotFoundException oe ) + { + + } + catch ( ArchivaDatabaseException ae ) + { + + } + + // total unique projects + try + { + List<Object[]> artifactIds = dao.getArtifactDAO().queryArtifacts( new UniqueArtifactIdConstraint( arepo.getId(), true ) ); + dbstats.setTotalProjectCount( artifactIds.size() ); + } + catch ( ObjectNotFoundException oe ) + { + + } + catch ( ArchivaDatabaseException ae ) + { + + }*/ + + return dbstats; + } } |