From: Olivier Lamy Date: Mon, 12 Mar 2012 14:29:17 +0000 (+0000) Subject: [MRM-1580] system status page display caches. X-Git-Tag: archiva-1.4-M3~1052 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fac85e0b4ba271d3797bc7b5a858924274bdbd34;p=archiva.git [MRM-1580] system status page display caches. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299683 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java new file mode 100644 index 000000000..74e1e252a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java @@ -0,0 +1,119 @@ +package org.apache.archiva.rest.api.model; +/* + * 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 javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; + +/** + * @author Olivier Lamy + * @since 1.4-M3 + */ +@XmlRootElement( name = "cacheEntry" ) +public class CacheEntry + implements Serializable +{ + private String key; + + private long size; + + private long cacheHits; + + private long cacheMiss; + + private String cacheHitRate; + + public CacheEntry() + { + // no op + } + + public CacheEntry( String key, long size, long cacheHits, long cacheMiss, String cacheHitRate ) + { + this.key = key; + this.size = size; + this.cacheHits = cacheHits; + this.cacheMiss = cacheMiss; + this.cacheHitRate = cacheHitRate; + } + + public String getKey() + { + return key; + } + + public void setKey( String key ) + { + this.key = key; + } + + public long getSize() + { + return size; + } + + public void setSize( long size ) + { + this.size = size; + } + + public long getCacheHits() + { + return cacheHits; + } + + public void setCacheHits( long cacheHits ) + { + this.cacheHits = cacheHits; + } + + public long getCacheMiss() + { + return cacheMiss; + } + + public void setCacheMiss( long cacheMiss ) + { + this.cacheMiss = cacheMiss; + } + + public String getCacheHitRate() + { + return cacheHitRate; + } + + public void setCacheHitRate( String cacheHitRate ) + { + this.cacheHitRate = cacheHitRate; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "CacheEntry" ); + sb.append( "{key='" ).append( key ).append( '\'' ); + sb.append( ", size=" ).append( size ); + sb.append( ", cacheHits=" ).append( cacheHits ); + sb.append( ", cacheMiss=" ).append( cacheMiss ); + sb.append( ", cacheHitRate=" ).append( cacheHitRate ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java index 370e01e43..91773482f 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java @@ -18,6 +18,7 @@ package org.apache.archiva.rest.api.services; * under the License. */ +import org.apache.archiva.rest.api.model.CacheEntry; import org.apache.archiva.rest.api.model.QueueEntry; import org.apache.archiva.security.common.ArchivaRoleConstants; import org.codehaus.plexus.redback.authorization.RedbackAuthorization; @@ -57,4 +58,11 @@ public interface SystemStatusService List getQueueEntries() throws ArchivaRestServiceException; + @Path( "cacheEntries" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + List getCacheEntries() + throws ArchivaRestServiceException; + } 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 de0776519..9bda1ecf5 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 @@ -18,9 +18,12 @@ package org.apache.archiva.rest.services; * under the License. */ +import org.apache.archiva.rest.api.model.CacheEntry; import org.apache.archiva.rest.api.model.QueueEntry; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.SystemStatusService; +import org.codehaus.plexus.cache.Cache; +import org.codehaus.plexus.cache.CacheStatistics; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.springframework.context.ApplicationContext; @@ -28,6 +31,7 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.ws.rs.core.Response; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -47,13 +51,19 @@ public class DefaultSystemStatusService private ApplicationContext applicationContext; - Map queues = null; + private Map queues = null; + + Map caches = null; + @Inject public DefaultSystemStatusService( ApplicationContext applicationContext ) { this.applicationContext = applicationContext; + queues = getBeansOfType( applicationContext, TaskQueue.class ); + + caches = getBeansOfType( applicationContext, Cache.class ); } public String getMemoryStatus() @@ -99,4 +109,21 @@ public class DefaultSystemStatusService Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() ); } } + + public List getCacheEntries() + throws ArchivaRestServiceException + { + List cacheEntries = new ArrayList( caches.size() ); + DecimalFormat decimalFormat = new DecimalFormat( "#%" ); + + for ( Map.Entry entry : caches.entrySet() ) + { + CacheStatistics cacheStatistics = entry.getValue().getStatistics(); + cacheEntries.add( new CacheEntry( entry.getKey(), cacheStatistics.getSize(), cacheStatistics.getCacheHits(), + cacheStatistics.getCacheMiss(), + decimalFormat.format( cacheStatistics.getCacheHitRate() ).toString() ) ); + } + + return cacheEntries; + } } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index ff30c3214..dd5a6502e 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -297,6 +297,7 @@ system-status.header.scanning=Repository Scans Currently in Progress system-status.header.scanning.inprogress.none=No scans in progress. system-status.queues.grid.header.key=Queue system-status.queues.grid.header.number=Size +system-status.header.main=System Status 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 67b339156..5fe5d8fec 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 @@ -573,9 +573,35 @@ $(function() { return new QueueEntry(item.key,item.entriesNumber); }) } - return null; + return []; } + CacheEntry=function(key,size,cacheHits,cacheMiss,cacheHitRate){ + this.key=key; + this.size=size; + this.cacheHits=cacheHits; + this.cacheMiss=cacheMiss; + this.cacheHitRate=cacheHitRate; + } + + mapCacheEntries=function(data){ + if(data!=null){ + return $.map(data,function(item){ + return new CacheEntry(item.key,item.size,item.cacheHits,item.cacheMiss,item.cacheHitRate); + }) + } + return []; + } + + displayCacheEntries=function(){ + $.ajax("restServices/archivaServices/systemStatusService/cacheEntries", { + type: "GET", + success: function(data){ + var cacheEntries=mapCacheEntries(data); + $("#main-content #status_caches").html($("#status_caches_tmpl" ).tmpl({cacheEntries: cacheEntries})); + } + }); + } displaySystemStatus=function(){ screenChange(); @@ -613,6 +639,9 @@ $(function() { } }); + displayCacheEntries(); } + + }); \ No newline at end of file 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 48a713987..9b2dcc096 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 @@ -310,6 +310,10 @@ + + +