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.commons.lang.StringUtils;
24 import org.apache.archiva.security.ArchivaRoleConstants;
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.
43 * plexus.component role="com.opensymphony.xwork2.Action" role-hint="systemStatus" instantiation-strategy="per-lookup"
45 @Controller( "systemStatus" )
47 public class SystemStatusAction
48 extends AbstractActionSupport
49 implements SecureAction
52 * plexus.requirement role="org.codehaus.plexus.taskqueue.TaskQueue"
54 private Map<String, TaskQueue> queues;
57 * plexus.requirement role="org.codehaus.plexus.cache.Cache"
59 private Map<String, Cache> caches;
65 private RepositoryScanner scanner;
67 private String memoryStatus;
69 private String cacheKey;
72 public void initialize()
75 queues = getBeansOfType( TaskQueue.class );
76 caches = getBeansOfType( Cache.class );
79 public SecureActionBundle getSecureActionBundle()
80 throws SecureActionException
82 SecureActionBundle bundle = new SecureActionBundle();
84 bundle.setRequiresAuthentication( true );
85 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
90 public String execute()
92 Runtime runtime = Runtime.getRuntime();
94 long total = runtime.totalMemory();
95 long used = total - runtime.freeMemory();
96 long max = runtime.maxMemory();
97 memoryStatus = formatMemory( used ) + "/" + formatMemory( total ) + " (Max: " + formatMemory( max ) + ")";
102 public String flush()
104 if( !StringUtils.isEmpty( cacheKey ) )
106 Cache cache = caches.get( cacheKey );
113 private static String formatMemory( long l )
115 return l / ( 1024 * 1024 ) + "M";
118 public String getMemoryStatus()
123 public RepositoryScanner getScanner()
128 public Map<String, Cache> getCaches()
133 public Map<String, TaskQueue> getQueues()
138 public String getCacheKey()
143 public void setCacheKey( String cacheKey )
145 this.cacheKey = cacheKey;