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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.common.ArchivaException;
24 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
25 import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
26 import org.apache.maven.archiva.scheduled.tasks.ArchivaTask;
27 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
28 import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
29 import org.apache.maven.archiva.scheduled.tasks.TaskCreator;
30 import org.apache.maven.archiva.security.ArchivaRoleConstants;
31 import org.apache.maven.archiva.web.action.PlexusActionSupport;
32 import org.codehaus.plexus.redback.rbac.Resource;
33 import org.codehaus.plexus.taskqueue.TaskQueueException;
34 import org.codehaus.redback.integration.interceptor.SecureAction;
35 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
36 import org.codehaus.redback.integration.interceptor.SecureActionException;
39 * Configures the application.
41 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="schedulerAction" instantiation-strategy="per-lookup"
43 public class SchedulerAction
44 extends PlexusActionSupport
45 implements SecureAction
50 private ArchivaTaskScheduler taskScheduler;
52 private String repoid;
54 public String scanRepository()
56 if ( StringUtils.isBlank( repoid ) )
58 addActionError( "Cannot run indexer on blank repository id." );
62 RepositoryTask task = TaskCreator.createRepositoryTask( repoid, "" );
64 boolean scheduleTask = false;
68 if ( taskScheduler.isProcessingAnyRepositoryTask() )
70 if ( taskScheduler.isProcessingRepositoryTask( repoid ) )
72 addActionError( "Repository [" + repoid + "] task was already queued." );
84 catch ( ArchivaException e )
87 addActionError( e.getMessage() );
94 taskScheduler.queueRepositoryTask( task );
95 addActionMessage( "Your request to have repository [" + repoid + "] be indexed has been queued." );
97 catch ( TaskQueueException e )
99 addActionError( "Unable to queue your request to have repository [" + repoid + "] be indexed: "
104 // Return to the repositories screen.
108 public String updateDatabase()
110 DatabaseTask task = new DatabaseTask();
111 task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested" );
112 task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
114 boolean scheduleTask = false;
118 if ( taskScheduler.isProcessingDatabaseTask() )
120 addActionError( "Database task was already queued." );
127 catch ( ArchivaException e )
129 scheduleTask = false;
130 addActionError( e.getMessage() );
137 taskScheduler.queueDatabaseTask( task );
138 addActionMessage( "Your request to update the database has been queued." );
140 catch ( TaskQueueException e )
142 addActionError( "Unable to queue your request to update the database: " + e.getMessage() );
146 // Return to the database screen.
151 public void addActionMessage( String aMessage )
153 super.addActionMessage( aMessage );
154 log.info( "[ActionMessage] " + aMessage );
158 public void addActionError( String anErrorMessage )
160 super.addActionError( anErrorMessage );
161 log.warn( "[ActionError] " + anErrorMessage );
164 public SecureActionBundle getSecureActionBundle()
165 throws SecureActionException
167 SecureActionBundle bundle = new SecureActionBundle();
169 bundle.setRequiresAuthentication( true );
170 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_RUN_INDEXER, Resource.GLOBAL );
175 public String getRepoid()
180 public void setRepoid( String repoid )
182 this.repoid = repoid;