mirror of
https://github.com/apache/archiva.git
synced 2025-03-09 11:14:17 +00:00
[MRM-161] add the reporter scheduled task
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440244 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d875b6a478
commit
c0e84cdce7
@ -73,11 +73,11 @@
|
||||
<defaultValue>0 0 * * * ?</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
<name>converterCronExpression</name>
|
||||
<name>reporterCronExpression</name>
|
||||
<version>1.0.0</version>
|
||||
<type>String</type>
|
||||
<description>When to run the converter mechanism. Default is every 4 hours, on the half hour.</description>
|
||||
<defaultValue>0 30 0/4 * * ?</defaultValue>
|
||||
<description>When to run the indexing mechanism. Default is every hour on the half hour.</description>
|
||||
<defaultValue>0 30 * * * ?</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
<name>globalBlackListPatterns</name>
|
||||
|
@ -61,11 +61,18 @@ public class DefaultRepositoryTaskScheduler
|
||||
|
||||
private static final String INDEXER_JOB = "indexerTask";
|
||||
|
||||
private static final String REPORTER_JOB = "reporterTask";
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="indexer"
|
||||
*/
|
||||
private RepositoryTask indexerTask;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="reporter"
|
||||
*/
|
||||
private RepositoryTask reporterTask;
|
||||
|
||||
public void start()
|
||||
throws StartingException
|
||||
{
|
||||
@ -97,13 +104,10 @@ public void start()
|
||||
private void scheduleJobs( Configuration configuration )
|
||||
throws ParseException, SchedulerException
|
||||
{
|
||||
// TODO! would be nice to queue jobs that are triggered so we could avoid two running at the same time (so have a queue for discovery based jobs so they didn't thrash the repo)
|
||||
if ( configuration.getIndexPath() != null )
|
||||
{
|
||||
JobDetail jobDetail = new JobDetail( INDEXER_JOB, DISCOVERER_GROUP, RepositoryTaskJob.class );
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put( AbstractJob.LOGGER, getLogger() );
|
||||
dataMap.put( RepositoryTaskJob.TASK_KEY, indexerTask );
|
||||
jobDetail.setJobDataMap( dataMap );
|
||||
JobDetail jobDetail = createJobDetail( INDEXER_JOB, indexerTask );
|
||||
|
||||
getLogger().info( "Scheduling indexer: " + configuration.getIndexerCronExpression() );
|
||||
CronTrigger trigger =
|
||||
@ -124,6 +128,23 @@ private void scheduleJobs( Configuration configuration )
|
||||
{
|
||||
getLogger().info( "Not scheduling indexer - index path is not configured" );
|
||||
}
|
||||
|
||||
JobDetail jobDetail = createJobDetail( REPORTER_JOB, reporterTask );
|
||||
|
||||
getLogger().info( "Scheduling reporter: " + configuration.getReporterCronExpression() );
|
||||
CronTrigger trigger =
|
||||
new CronTrigger( REPORTER_JOB + "Trigger", DISCOVERER_GROUP, configuration.getReporterCronExpression() );
|
||||
scheduler.scheduleJob( jobDetail, trigger );
|
||||
}
|
||||
|
||||
private JobDetail createJobDetail( String jobName, RepositoryTask task )
|
||||
{
|
||||
JobDetail jobDetail = new JobDetail( jobName, DISCOVERER_GROUP, RepositoryTaskJob.class );
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put( AbstractJob.LOGGER, getLogger() );
|
||||
dataMap.put( RepositoryTaskJob.TASK_KEY, task );
|
||||
jobDetail.setJobDataMap( dataMap );
|
||||
return jobDetail;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
@ -132,6 +153,7 @@ public void stop()
|
||||
try
|
||||
{
|
||||
scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP );
|
||||
scheduler.unscheduleJob( REPORTER_JOB, DISCOVERER_GROUP );
|
||||
}
|
||||
catch ( SchedulerException e )
|
||||
{
|
||||
@ -167,4 +189,10 @@ public void runIndexer()
|
||||
{
|
||||
indexerTask.execute();
|
||||
}
|
||||
|
||||
public void runReporter()
|
||||
throws TaskExecutionException
|
||||
{
|
||||
reporterTask.execute();
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,7 @@ public interface RepositoryTaskScheduler
|
||||
|
||||
void runIndexer()
|
||||
throws TaskExecutionException;
|
||||
|
||||
void runReporter()
|
||||
throws TaskExecutionException;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
|
||||
import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
|
||||
import org.apache.maven.archiva.indexer.RepositoryIndexException;
|
||||
import org.apache.maven.archiva.indexer.record.IndexRecordExistsArtifactFilter;
|
||||
import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
|
||||
import org.apache.maven.archiva.scheduler.TaskExecutionException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
@ -42,7 +43,7 @@
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Task for discovering changes in the repository.
|
||||
* Task for discovering changes in the repository and updating the index accordingly.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @plexus.component role="org.apache.maven.archiva.scheduler.task.RepositoryTask" role-hint="indexer"
|
||||
@ -100,7 +101,7 @@ private void execute( Configuration configuration, File indexPath )
|
||||
throws TaskExecutionException
|
||||
{
|
||||
long time = System.currentTimeMillis();
|
||||
getLogger().info( "Starting repository discovery process" );
|
||||
getLogger().info( "Starting repository indexing process" );
|
||||
|
||||
RepositoryArtifactIndex index = indexFactory.createStandardIndex( indexPath );
|
||||
|
||||
|
@ -0,0 +1,98 @@
|
||||
package org.apache.maven.archiva.scheduler.task;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationStore;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationStoreException;
|
||||
import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
|
||||
import org.apache.maven.archiva.scheduler.TaskExecutionException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Task for discovering problems in the repository.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @plexus.component role="org.apache.maven.archiva.scheduler.task.RepositoryTask" role-hint="reporter"
|
||||
*/
|
||||
public class ReporterTask
|
||||
extends AbstractLogEnabled
|
||||
implements RepositoryTask
|
||||
{
|
||||
/**
|
||||
* Configuration store.
|
||||
*
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ConfigurationStore configurationStore;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ConfiguredRepositoryFactory repoFactory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer"
|
||||
*/
|
||||
private Map artifactDiscoverers;
|
||||
|
||||
public void execute()
|
||||
throws TaskExecutionException
|
||||
{
|
||||
Configuration configuration;
|
||||
try
|
||||
{
|
||||
configuration = configurationStore.getConfigurationFromStore();
|
||||
}
|
||||
catch ( ConfigurationStoreException e )
|
||||
{
|
||||
throw new TaskExecutionException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
execute( configuration );
|
||||
}
|
||||
|
||||
private void execute( Configuration configuration )
|
||||
throws TaskExecutionException
|
||||
{
|
||||
long time = System.currentTimeMillis();
|
||||
getLogger().info( "Starting repository reporting process" );
|
||||
|
||||
// TODO!
|
||||
|
||||
time = System.currentTimeMillis() - time;
|
||||
getLogger().info( "Finished repository reporting process in " + time + "ms" );
|
||||
}
|
||||
|
||||
public void executeNowIfNeeded()
|
||||
throws TaskExecutionException
|
||||
{
|
||||
Configuration configuration;
|
||||
try
|
||||
{
|
||||
configuration = configurationStore.getConfigurationFromStore();
|
||||
}
|
||||
catch ( ConfigurationStoreException e )
|
||||
{
|
||||
throw new TaskExecutionException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
// TODO!
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.apache.maven.archiva.scheduler.task;
|
||||
package org.apache.maven.archiva.indexer.record;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Apache Software Foundation.
|
@ -23,9 +23,9 @@
|
||||
/**
|
||||
* Configures the application.
|
||||
*
|
||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="runIndexerAction"
|
||||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="runRepositoryTaskAction"
|
||||
*/
|
||||
public class RunIndexerAction
|
||||
public class RunRepositoryTaskAction
|
||||
extends ActionSupport
|
||||
{
|
||||
/**
|
||||
@ -33,11 +33,19 @@ public class RunIndexerAction
|
||||
*/
|
||||
private RepositoryTaskScheduler taskScheduler;
|
||||
|
||||
public String execute()
|
||||
public String runIndexer()
|
||||
throws TaskExecutionException
|
||||
{
|
||||
taskScheduler.runIndexer();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String runReporter()
|
||||
throws TaskExecutionException
|
||||
{
|
||||
taskScheduler.runReporter();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
@ -208,7 +208,11 @@
|
||||
<interceptor-ref name="defaultStack"/>
|
||||
</action>
|
||||
|
||||
<action name="runIndexer" class="runIndexerAction">
|
||||
<action name="runIndexer" class="runRepositoryTaskAction" method="runIndexer">
|
||||
<result type="redirect-action">index</result>
|
||||
</action>
|
||||
|
||||
<action name="runReporter" class="runRepositoryTaskAction" method="runReporter">
|
||||
<result type="redirect-action">index</result>
|
||||
</action>
|
||||
</package>
|
||||
|
@ -31,6 +31,7 @@
|
||||
<ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true">
|
||||
<ww:textfield name="indexPath" label="Index Directory" size="100"/>
|
||||
<ww:textfield name="indexerCronExpression" label="Indexing Schedule"/>
|
||||
<ww:textfield name="reporterCronExpression" label="Reporting Schedule"/>
|
||||
<ww:hidden name="proxy.protocol" value="http"/>
|
||||
<ww:textfield name="proxy.host" label="HTTP Proxy Host"/>
|
||||
<ww:textfield name="proxy.port" label="HTTP Proxy Port"/>
|
||||
|
@ -43,10 +43,16 @@
|
||||
<td>
|
||||
<ww:property value="indexerCronExpression"/>
|
||||
</td>
|
||||
<%-- TODO: a "run now without timestamp checking" operation should be here too, to pick up any stragglers (in the event of a bug) --%>
|
||||
<%-- TODO: a "delete index and run now" operation should be here too (really clean, remove deletions that didn't get picked up) --%>
|
||||
<td><a href="<ww:url action="runIndexer" />">Run Now</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Reporting Schedule</th>
|
||||
<td>
|
||||
<ww:property value="reporterCronExpression"/>
|
||||
</td>
|
||||
<td><a href="<ww:url action="runReporter" />">Run Now</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<ww:set name="proxy" value="proxy"/>
|
||||
|
@ -16,6 +16,10 @@
|
||||
Indexing Cron Expression:
|
||||
<input type="text"/>
|
||||
</p>
|
||||
<p>
|
||||
Reporting Cron Expression:
|
||||
<input type="text"/>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Save Configuration"/>
|
||||
</p>
|
||||
|
@ -21,6 +21,13 @@
|
||||
<a href="#">Run Now</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Reporting Schedule</th>
|
||||
<td>...</td>
|
||||
<td>
|
||||
<a href="#">Run Now</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user