From: Brett Porter Date: Tue, 5 Sep 2006 04:08:15 +0000 (+0000) Subject: [MRM-161] add the reporter scheduled task X-Git-Tag: archiva-0.9-alpha-1~613 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c0e84cdce77eeae82e6d3c8cb5bf692703c7a37d;p=archiva.git [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 --- diff --git a/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-configuration/src/main/mdo/configuration.mdo index 87572e448..17d9ddfc2 100644 --- a/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-configuration/src/main/mdo/configuration.mdo @@ -73,11 +73,11 @@ 0 0 * * * ? - converterCronExpression + reporterCronExpression 1.0.0 String - When to run the converter mechanism. Default is every 4 hours, on the half hour. - 0 30 0/4 * * ? + When to run the indexing mechanism. Default is every hour on the half hour. + 0 30 * * * ? globalBlackListPatterns diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java index 70e753b6b..f300e5bcd 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java @@ -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 class DefaultRepositoryTaskScheduler 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 @@ public class DefaultRepositoryTaskScheduler { 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 class DefaultRepositoryTaskScheduler try { scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP ); + scheduler.unscheduleJob( REPORTER_JOB, DISCOVERER_GROUP ); } catch ( SchedulerException e ) { @@ -167,4 +189,10 @@ public class DefaultRepositoryTaskScheduler { indexerTask.execute(); } + + public void runReporter() + throws TaskExecutionException + { + reporterTask.execute(); + } } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java index 9b78aba5c..08b1ca5cc 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java @@ -30,4 +30,7 @@ public interface RepositoryTaskScheduler void runIndexer() throws TaskExecutionException; + + void runReporter() + throws TaskExecutionException; } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexRecordExistsArtifactFilter.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexRecordExistsArtifactFilter.java deleted file mode 100644 index b1fb288b9..000000000 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexRecordExistsArtifactFilter.java +++ /dev/null @@ -1,44 +0,0 @@ -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.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; - -import java.util.Collection; - -/** - * Filter that removes artifacts already in the index. - * TODO: we could do timestamp comparisons here - */ -public class IndexRecordExistsArtifactFilter - implements ArtifactFilter -{ - private final Collection keys; - - public IndexRecordExistsArtifactFilter( Collection keys ) - { - this.keys = keys; - } - - public boolean include( Artifact artifact ) - { - String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + - ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ); - return !keys.contains( artifactKey ); - } -} diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java index 269bc3bf7..534039461 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java @@ -27,6 +27,7 @@ import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter; 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.List; import java.util.Map; /** - * Task for discovering changes in the repository. + * Task for discovering changes in the repository and updating the index accordingly. * * @author Brett Porter * @plexus.component role="org.apache.maven.archiva.scheduler.task.RepositoryTask" role-hint="indexer" @@ -100,7 +101,7 @@ public class IndexerTask throws TaskExecutionException { long time = System.currentTimeMillis(); - getLogger().info( "Starting repository discovery process" ); + getLogger().info( "Starting repository indexing process" ); RepositoryArtifactIndex index = indexFactory.createStandardIndex( indexPath ); diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/ReporterTask.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/ReporterTask.java new file mode 100644 index 000000000..641e920bf --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/ReporterTask.java @@ -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 Brett Porter + * @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! + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/IndexRecordExistsArtifactFilter.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/IndexRecordExistsArtifactFilter.java new file mode 100644 index 000000000..a5bdf9522 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/IndexRecordExistsArtifactFilter.java @@ -0,0 +1,44 @@ +package org.apache.maven.archiva.indexer.record; + +/* + * 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.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; + +import java.util.Collection; + +/** + * Filter that removes artifacts already in the index. + * TODO: we could do timestamp comparisons here + */ +public class IndexRecordExistsArtifactFilter + implements ArtifactFilter +{ + private final Collection keys; + + public IndexRecordExistsArtifactFilter( Collection keys ) + { + this.keys = keys; + } + + public boolean include( Artifact artifact ) + { + String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + + ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ); + return !keys.contains( artifactKey ); + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunIndexerAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunIndexerAction.java deleted file mode 100644 index 5517ca61f..000000000 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunIndexerAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.archiva.web.action.admin; - -/* - * 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 com.opensymphony.xwork.ActionSupport; -import org.apache.maven.archiva.scheduler.RepositoryTaskScheduler; -import org.apache.maven.archiva.scheduler.TaskExecutionException; - -/** - * Configures the application. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="runIndexerAction" - */ -public class RunIndexerAction - extends ActionSupport -{ - /** - * @plexus.requirement - */ - private RepositoryTaskScheduler taskScheduler; - - public String execute() - throws TaskExecutionException - { - taskScheduler.runIndexer(); - - return SUCCESS; - } -} diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunRepositoryTaskAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunRepositoryTaskAction.java new file mode 100644 index 000000000..fcafe3307 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunRepositoryTaskAction.java @@ -0,0 +1,51 @@ +package org.apache.maven.archiva.web.action.admin; + +/* + * 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 com.opensymphony.xwork.ActionSupport; +import org.apache.maven.archiva.scheduler.RepositoryTaskScheduler; +import org.apache.maven.archiva.scheduler.TaskExecutionException; + +/** + * Configures the application. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="runRepositoryTaskAction" + */ +public class RunRepositoryTaskAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private RepositoryTaskScheduler taskScheduler; + + public String runIndexer() + throws TaskExecutionException + { + taskScheduler.runIndexer(); + + return SUCCESS; + } + + public String runReporter() + throws TaskExecutionException + { + taskScheduler.runReporter(); + + return SUCCESS; + } +} diff --git a/archiva-webapp/src/main/resources/xwork.xml b/archiva-webapp/src/main/resources/xwork.xml index 1901fdb3b..f228e57c3 100644 --- a/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-webapp/src/main/resources/xwork.xml @@ -208,7 +208,11 @@ - + + index + + + index diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp index a48926dd5..2271c6d4f 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp @@ -31,6 +31,7 @@ + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp index 0dc1405f6..94f8aa6d5 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp @@ -43,10 +43,16 @@ - <%-- 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) --%> ">Run Now + + Reporting Schedule + + + + ">Run Now + diff --git a/design/white-site/src/site/xdoc/admin/config.xml b/design/white-site/src/site/xdoc/admin/config.xml index ffe8a294a..c4a292ec3 100644 --- a/design/white-site/src/site/xdoc/admin/config.xml +++ b/design/white-site/src/site/xdoc/admin/config.xml @@ -16,6 +16,10 @@ Indexing Cron Expression:

+

+ Reporting Cron Expression: + +

diff --git a/design/white-site/src/site/xdoc/admin/index.xml b/design/white-site/src/site/xdoc/admin/index.xml index a634ee484..e903ceaa2 100644 --- a/design/white-site/src/site/xdoc/admin/index.xml +++ b/design/white-site/src/site/xdoc/admin/index.xml @@ -21,6 +21,13 @@ Run Now + + Reporting Schedule + ... + + Run Now + +