1 package org.apache.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.redback.rbac.Resource;
23 import org.apache.archiva.repository.scanner.RepositoryScanner;
24 import org.apache.archiva.security.common.ArchivaRoleConstants;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.archiva.web.action.AbstractActionSupport;
27 import org.apache.archiva.redback.components.cache.Cache;
28 import org.apache.archiva.redback.components.taskqueue.TaskQueue;
29 import org.apache.archiva.redback.integration.interceptor.SecureAction;
30 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
31 import org.apache.archiva.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 private Map<String, TaskQueue> queues;
53 private Map<String, Cache> caches;
56 private RepositoryScanner scanner;
58 private String memoryStatus;
60 private String cacheKey;
63 public void initialize()
66 queues = getBeansOfType( TaskQueue.class );
67 caches = getBeansOfType( Cache.class );
70 public SecureActionBundle getSecureActionBundle()
71 throws SecureActionException
73 SecureActionBundle bundle = new SecureActionBundle();
75 bundle.setRequiresAuthentication( true );
76 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
81 public String execute()
83 Runtime runtime = Runtime.getRuntime();
85 long total = runtime.totalMemory();
86 long used = total - runtime.freeMemory();
87 long max = runtime.maxMemory();
88 memoryStatus = formatMemory( used ) + "/" + formatMemory( total ) + " (Max: " + formatMemory( max ) + ")";
95 if( !StringUtils.isEmpty( cacheKey ) )
97 Cache cache = caches.get( cacheKey );
104 private static String formatMemory( long l )
106 return l / ( 1024 * 1024 ) + "M";
109 public String getMemoryStatus()
114 public RepositoryScanner getScanner()
119 public Map<String, Cache> getCaches()
124 public Map<String, TaskQueue> getQueues()
129 public String getCacheKey()
134 public void setCacheKey( String cacheKey )
136 this.cacheKey = cacheKey;