From 56ed8dbfef4607cd48a8087c271dbca313aaea65 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 12 Mar 2012 22:26:12 +0000 Subject: [PATCH] [MRM-1580] system status page current scanner stats. fix average value. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299907 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/api/model/ConsumerScanningStatistics.java | 12 ++++++++++++ .../rest/services/DefaultSystemStatusService.java | 8 ++++++++ .../services/ManagedRepositoriesServiceTest.java | 3 ++- .../src/main/webapp/js/archiva/general-admin.js | 9 +++------ .../webapp/js/archiva/templates/general-admin.html | 6 +++--- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ConsumerScanningStatistics.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ConsumerScanningStatistics.java index 1df24589b..73e94135d 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ConsumerScanningStatistics.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ConsumerScanningStatistics.java @@ -34,6 +34,8 @@ public class ConsumerScanningStatistics private long time; + private String average; + public ConsumerScanningStatistics() { // no op @@ -68,4 +70,14 @@ public class ConsumerScanningStatistics { this.time = time; } + + public String getAverage() + { + return average; + } + + public void setAverage( String average ) + { + this.average = average; + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java index a8cca6993..404f3434c 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java @@ -26,6 +26,7 @@ import org.apache.archiva.rest.api.model.QueueEntry; import org.apache.archiva.rest.api.model.RepositoryScannerStatistics; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.SystemStatusService; +import org.apache.archiva.rest.services.utils.ConsumerScanningStatisticsComparator; import org.codehaus.plexus.cache.Cache; import org.codehaus.plexus.cache.CacheStatistics; import org.codehaus.plexus.taskqueue.TaskQueue; @@ -184,6 +185,7 @@ public class DefaultSystemStatusService private List mapConsumerScanningStatistics( RepositoryScannerInstance instance ) { + DecimalFormat decimalFormat = new DecimalFormat( "###.##" ); // FIXME take care of NPE here !!! List ret = new ArrayList( instance.getConsumerCounts().size() ); @@ -193,8 +195,14 @@ public class DefaultSystemStatusService consumerScanningStatistics.setConsumerKey( entry.getKey() ); consumerScanningStatistics.setCount( entry.getValue() ); consumerScanningStatistics.setTime( instance.getConsumerTimings().get( entry.getKey() ) ); + if ( consumerScanningStatistics.getCount() > 0 ) + { + consumerScanningStatistics.setAverage( decimalFormat.format( + consumerScanningStatistics.getTime() / consumerScanningStatistics.getCount() ) ); + } ret.add( consumerScanningStatistics ); } + Collections.sort( ret, ConsumerScanningStatisticsComparator.INSTANCE ); return ret; } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java index b4530af8a..684b8529b 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java @@ -140,7 +140,8 @@ public class ManagedRepositoriesServiceTest ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader ); - ArchivaRepositoryStatistics archivaRepositoryStatistics = service.getManagedRepositoryStatistics( testRepoId ); + ArchivaRepositoryStatistics archivaRepositoryStatistics = + service.getManagedRepositoryStatistics( testRepoId, "en" ); assertNotNull( archivaRepositoryStatistics ); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js index 9eea30622..96818a33b 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js @@ -691,15 +691,12 @@ $(function() { } }); - var dataStr='[{"managedRepository":{"id":"snapshots","name":"Archiva Managed Snapshot Repository","layout":"default","indexDirectory":null,"location":"/Users/olamy/dev/tests/archiva-appserver-base-test/data/repositories/snapshots","snapshots":true,"releases":false,"blockRedeployments":false,"cronExpression":"0 0,30 * * * ?","stagingRepository":null,"scanned":true,"daysOlder":30,"retentionCount":2,"deleteReleasedSnapshots":false,"stageRepoNeeded":false,"resetStats":false},"consumerScanningStatistics":[{"consumerKey":"create-missing-checksums","count":83,"time":137},{"consumerKey":"metadata-updater","count":83,"time":192},{"consumerKey":"duplicate-artifacts","count":10,"time":2788},{"consumerKey":"index-content","count":134,"time":10},{"consumerKey":"create-archiva-metadata","count":82,"time":9399}],"totalFileCount":403,"newFileCount":403},{"managedRepository":{"id":"internal","name":"the Archiva Managed Internal Repository","layout":"default","indexDirectory":null,"location":"/Users/olamy/dev/tests/archiva-appserver-base-test/data/repositories/internal","snapshots":false,"releases":true,"blockRedeployments":true,"cronExpression":"0 */5 * * * ?","stagingRepository":null,"scanned":true,"daysOlder":30,"retentionCount":2,"deleteReleasedSnapshots":false,"stageRepoNeeded":false,"resetStats":false},"consumerScanningStatistics":[{"consumerKey":"create-missing-checksums","count":12,"time":2206},{"consumerKey":"metadata-updater","count":12,"time":1261},{"consumerKey":"duplicate-artifacts","count":12,"time":3461},{"consumerKey":"index-content","count":19,"time":0},{"consumerKey":"create-archiva-metadata","count":11,"time":3615}],"totalFileCount":58,"newFileCount":58}]'; - var data= mapRepositoryScannerStatisticsList( $.parseJSON(dataStr)); - $.log("size:"+data.length); - mainContent.find("#status_scanning" ).html($("#status_scanning_tmpl").tmpl({repositoryScannerStatisticsList:data})); - $.ajax("restServices/archivaServices/systemStatusService/repositoryScannerStatistics", { type: "GET", success: function(data){ - //mainContent.find("#status_scanning" ).html("#status_scanning_tmpl" ).tmpl(data); + var stats= mapRepositoryScannerStatisticsList(data); + $.log("size:"+data.length); + mainContent.find("#status_scanning" ).html($("#status_scanning_tmpl").tmpl({repositoryScannerStatisticsList:stats})); } }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html index 833b157d8..6ce314f4b 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html @@ -418,7 +418,7 @@