1 package org.apache.maven.archiva.web.action.admin;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.repository.scanner.RepositoryScanner;
23 import org.apache.archiva.security.common.ArchivaRoleConstants;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.web.action.AbstractActionSupport;
26 import org.codehaus.plexus.cache.Cache;
27 import org.codehaus.plexus.redback.rbac.Resource;
28 import org.codehaus.plexus.taskqueue.TaskQueue;
29 import org.codehaus.redback.integration.interceptor.SecureAction;
30 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
31 import org.codehaus.redback.integration.interceptor.SecureActionException;
32 import org.springframework.context.annotation.Scope;
33 import org.springframework.stereotype.Controller;
35 import javax.annotation.PostConstruct;
36 import javax.inject.Inject;
40 * Shows system status information for the administrator.
44 @Controller( "systemStatus" )
46 public class SystemStatusAction
47 extends AbstractActionSupport
48 implements SecureAction
51 * plexus.requirement role="org.codehaus.plexus.taskqueue.TaskQueue"
53 private Map<String, TaskQueue> queues;
56 * plexus.requirement role="org.codehaus.plexus.cache.Cache"
58 private Map<String, Cache> caches;
64 private RepositoryScanner scanner;
66 private String memoryStatus;
68 private String cacheKey;
71 public void initialize()
74 queues = getBeansOfType( TaskQueue.class );
75 caches = getBeansOfType( Cache.class );
78 public SecureActionBundle getSecureActionBundle()
79 throws SecureActionException
81 SecureActionBundle bundle = new SecureActionBundle();
83 bundle.setRequiresAuthentication( true );
84 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
89 public String execute()
91 Runtime runtime = Runtime.getRuntime();
93 long total = runtime.totalMemory();
94 long used = total - runtime.freeMemory();
95 long max = runtime.maxMemory();
96 memoryStatus = formatMemory( used ) + "/" + formatMemory( total ) + " (Max: " + formatMemory( max ) + ")";
101 public String flush()
103 if( !StringUtils.isEmpty( cacheKey ) )
105 Cache cache = caches.get( cacheKey );
112 private static String formatMemory( long l )
114 return l / ( 1024 * 1024 ) + "M";
117 public String getMemoryStatus()
122 public RepositoryScanner getScanner()
127 public Map<String, Cache> getCaches()
132 public Map<String, TaskQueue> getQueues()
137 public String getCacheKey()
142 public void setCacheKey( String cacheKey )
144 this.cacheKey = cacheKey;