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.security.ArchivaRoleConstants;
30 import org.apache.maven.archiva.web.action.PlexusActionSupport;
31 import org.codehaus.plexus.redback.rbac.Resource;
32 import org.codehaus.plexus.taskqueue.TaskQueueException;
33 import org.codehaus.redback.integration.interceptor.SecureAction;
34 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
35 import org.codehaus.redback.integration.interceptor.SecureActionException;
38 * Configures the application.
40 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="schedulerAction" instantiation-strategy="per-lookup"
42 public class SchedulerAction
43 extends PlexusActionSupport
44 implements SecureAction
46 private static final String REPO_SUCCESS = "repoSucces";
48 private static final String DB_SUCCESS = "dbSuccess";
53 private ArchivaTaskScheduler taskScheduler;
55 private String repoid;
57 public String scanRepository()
59 if ( StringUtils.isBlank( repoid ) )
61 addActionError( "Cannot run indexer on blank repository id." );
65 RepositoryTask task = new RepositoryTask();
66 task.setRepositoryId( repoid );
67 task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repoid );
68 task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
70 boolean scheduleTask = false;
74 if ( taskScheduler.isProcessingAnyRepositoryTask() )
76 if ( taskScheduler.isProcessingRepositoryTask( repoid ) )
78 addActionError( "Repository [" + repoid + "] task was already queued." );
90 catch ( ArchivaException e )
93 addActionError( e.getMessage() );
100 taskScheduler.queueRepositoryTask( task );
101 addActionMessage( "Your request to have repository [" + repoid + "] be indexed has been queued." );
103 catch ( TaskQueueException e )
105 addActionError( "Unable to queue your request to have repository [" + repoid + "] be indexed: "
110 // Return to the repositories screen.
114 public String updateDatabase()
116 DatabaseTask task = new DatabaseTask();
117 task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested" );
118 task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
120 boolean scheduleTask = false;
124 if ( taskScheduler.isProcessingDatabaseTask() )
126 addActionError( "Database task was already queued." );
133 catch ( ArchivaException e )
135 scheduleTask = false;
136 addActionError( e.getMessage() );
143 taskScheduler.queueDatabaseTask( task );
144 addActionMessage( "Your request to update the database has been queued." );
146 catch ( TaskQueueException e )
148 addActionError( "Unable to queue your request to update the database: " + e.getMessage() );
152 // Return to the database screen.
157 public void addActionMessage( String aMessage )
159 super.addActionMessage( aMessage );
160 log.info( "[ActionMessage] " + aMessage );
164 public void addActionError( String anErrorMessage )
166 super.addActionError( anErrorMessage );
167 log.warn( "[ActionError] " + anErrorMessage );
170 public SecureActionBundle getSecureActionBundle()
171 throws SecureActionException
173 SecureActionBundle bundle = new SecureActionBundle();
175 bundle.setRequiresAuthentication( true );
176 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_RUN_INDEXER, Resource.GLOBAL );
181 public String getRepoid()
186 public void setRepoid( String repoid )
188 this.repoid = repoid;