]> source.dussan.org Git - archiva.git/commitdiff
[MRM-161] add the reporter scheduled task
authorBrett Porter <brett@apache.org>
Tue, 5 Sep 2006 04:08:15 +0000 (04:08 +0000)
committerBrett Porter <brett@apache.org>
Tue, 5 Sep 2006 04:08:15 +0000 (04:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440244 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
archiva-configuration/src/main/mdo/configuration.mdo
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/RepositoryTaskScheduler.java
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexRecordExistsArtifactFilter.java [deleted file]
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/ReporterTask.java [new file with mode: 0644]
archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/IndexRecordExistsArtifactFilter.java [new file with mode: 0644]
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunIndexerAction.java [deleted file]
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/RunRepositoryTaskAction.java [new file with mode: 0644]
archiva-webapp/src/main/resources/xwork.xml
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp
design/white-site/src/site/xdoc/admin/config.xml
design/white-site/src/site/xdoc/admin/index.xml

index 87572e4480d48f029cc07d8c0a731e150a211c3a..17d9ddfc2f8ce5293f3aa238913df9a65a2b8934 100644 (file)
           <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>
index 70e753b6bd094363abe08d700754979b8b528bbc..f300e5bcd7b55960281c8ef9d646a0ec1901ea8a 100644 (file)
@@ -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();
+    }
 }
index 9b78aba5c8e62d21ec36c3195f96ebab7b501c9b..08b1ca5cc0638bd463b9a5aaabf5ba0deb6926a0 100644 (file)
@@ -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 (file)
index b1fb288..0000000
+++ /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 );
-    }
-}
index 269bc3bf773b0017d34443cce342303a44cb11ef..534039461a2c7410df21c4bd4d0ade87dde3919a 100644 (file)
@@ -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 <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 @@ 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 (file)
index 0000000..641e920
--- /dev/null
@@ -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!
+    }
+}
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 (file)
index 0000000..a5bdf95
--- /dev/null
@@ -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 (file)
index 5517ca6..0000000
+++ /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 (file)
index 0000000..fcafe33
--- /dev/null
@@ -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;
+    }
+}
index 1901fdb3b13ba413934cea755ce325968b352736..f228e57c3c9bc4270222b7ec9cadd4e6ef24dae1 100644 (file)
       <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>
index a48926dd56163bbc62528a72dca8fb05184e72f6..2271c6d4ff69a6a0116d5b7f9b71c5577290d57c 100644 (file)
@@ -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"/>
index 0dc1405f6f87987f2071022afb06fe0e85a3f59b..94f8aa6d5e798a9e41abb866efbc41345dcb7174 100644 (file)
     <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"/>
index ffe8a294a0b973ce3f82f90bc77832f4092d7ed9..c4a292ec3f3c80cbcff32184616ed88f63b266dd 100644 (file)
             Indexing Cron Expression:
             <input type="text"/>
           </p>
+          <p>
+            Reporting Cron Expression:
+            <input type="text"/>
+          </p>
           <p>
             <input type="submit" value="Save Configuration"/>
           </p>
index a634ee484cb82496cf58c1785ec86c34f8ba79ed..e903ceaa2a9a896ee86dfd52df764c0a804e0d97 100644 (file)
             <a href="#">Run Now</a>
           </td>
         </tr>
+        <tr>
+          <th>Reporting Schedule</th>
+          <td>...</td>
+          <td>
+            <a href="#">Run Now</a>
+          </td>
+        </tr>
       </table>
 
       <p>