You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/03/12 15:29:18 UTC

svn commit: r1299683 - in /archiva/trunk/archiva-modules/archiva-web: archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/ archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ archiva-rest/archiva-...

Author: olamy
Date: Mon Mar 12 14:29:17 2012
New Revision: 1299683

URL: http://svn.apache.org/viewvc?rev=1299683&view=rev
Log:
[MRM-1580] system status page display caches.

Added:
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java   (with props)
Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html

Added: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java?rev=1299683&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java (added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java Mon Mar 12 14:29:17 2012
@@ -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();
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/CacheEntry.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java?rev=1299683&r1=1299682&r2=1299683&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SystemStatusService.java Mon Mar 12 14:29:17 2012
@@ -18,6 +18,7 @@ package org.apache.archiva.rest.api.serv
  * 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<QueueEntry> getQueueEntries()
         throws ArchivaRestServiceException;
 
+    @Path( "cacheEntries" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    List<CacheEntry> getCacheEntries()
+        throws ArchivaRestServiceException;
+
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java?rev=1299683&r1=1299682&r2=1299683&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSystemStatusService.java Mon Mar 12 14:29:17 2012
@@ -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.Se
 
 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<String, TaskQueue> queues = null;
+    private Map<String, TaskQueue> queues = null;
+
+    Map<String, Cache> 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<CacheEntry> getCacheEntries()
+        throws ArchivaRestServiceException
+    {
+        List<CacheEntry> cacheEntries = new ArrayList<CacheEntry>( caches.size() );
+        DecimalFormat decimalFormat = new DecimalFormat( "#%" );
+
+        for ( Map.Entry<String, Cache> 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;
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties?rev=1299683&r1=1299682&r2=1299683&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties Mon Mar 12 14:29:17 2012
@@ -297,6 +297,7 @@ system-status.header.scanning=Repository
 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
 
 
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js?rev=1299683&r1=1299682&r2=1299683&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js Mon Mar 12 14:29:17 2012
@@ -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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html?rev=1299683&r1=1299682&r2=1299683&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html Mon Mar 12 14:29:17 2012
@@ -310,6 +310,10 @@
 </script>
 
 <script id="system-status-main" type="text/html">
+
+  <div class="page-header">
+    <h3>${$.i18n.prop('system-status.header.main')}</h3>
+  </div>
   <div class="page-header">
     <h4>${$.i18n.prop('system-status.header.queues')}</h4>
   </div>
@@ -354,12 +358,38 @@
 
 </script>
 
+<script id="status_caches_tmpl" type="text/html">
+  <table class="table table-condensed">
+    <thead>
+      <tr>
+        <th>${$.i18n.prop('system-status.caches.grid.header.key')}</th>
+        <th>${$.i18n.prop('system-status.caches.grid.header.size')}</th>
+        <th>${$.i18n.prop('system-status.caches.grid.header.cacheHits')}</th>
+        <th>${$.i18n.prop('system-status.caches.grid.header.cacheMiss')}</th>
+        <th>${$.i18n.prop('system-status.caches.grid.header.cacheHitRate')}</th>
+      </tr>
+    </thead>
+    <tbody>
+    {{each(i,cacheEntry) cacheEntries}}
+      <tr>
+        <td>${cacheEntry.key}</td>
+        <td>${cacheEntry.size}</td>
+        <td>${cacheEntry.cacheHits}</td>
+        <td>${cacheEntry.cacheMiss}</td>
+        <td>${cacheEntry.cacheHitRate}</td>
+      </tr>
+    {{/each}}
+    </tbody>
+  </table>
+</script>
+
+
 <script id="status_queues_tmpl" type="text/html">
   <table class="table table-condensed">
     <thead>
       <tr>
         <th>${$.i18n.prop('system-status.queues.grid.header.key')}</th>
-        <th>${$.i18n.prop('system-status.queues.grid.header.number')}</th>
+        <th>${$.i18n.prop('system-status.queues.grid.header.size')}</th>
       </tr>
     </thead>
     <tbody>
@@ -375,4 +405,3 @@
 
 
 
-