You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2015/06/03 03:48:22 UTC

svn commit: r1683208 - in /manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler: interfaces/ jobs/ notifications/ system/

Author: kwright
Date: Wed Jun  3 01:48:22 2015
New Revision: 1683208

URL: http://svn.apache.org/r1683208
Log:
Add stop reasons to INotificationConnector interface.  Part of CONNECTORS-1208.

Modified:
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/IJobManager.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobResetThread.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobStartThread.java

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/IJobManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/IJobManager.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/IJobManager.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/IJobManager.java Wed Jun  3 01:48:22 2015
@@ -19,7 +19,7 @@
 package org.apache.manifoldcf.crawler.interfaces;
 
 import org.apache.manifoldcf.core.interfaces.*;
-import java.util.ArrayList;
+import java.util.List;
 
 /** This manager deals with jobs.  Each job is associated with a repository connection, and has a number
 * of scheduling options: starting every n hours/days/weeks/months, on specific dates, or "continuous" (which basically
@@ -819,7 +819,7 @@ public interface IJobManager
   *@param currentTime is the current time in milliseconds since epoch.
   *@param unwaitList is filled in with the set of job id's that were resumed (Long's).
   */
-  public void startJobs(long currentTime, ArrayList unwaitList)
+  public void startJobs(long currentTime, List<Long> unwaitList)
     throws ManifoldCFException;
 
 
@@ -827,7 +827,7 @@ public interface IJobManager
   *@param currentTime is the current time in milliseconds since epoch.
   *@param waitList is filled in with the set of job id's that were put into a wait state (Long's).
   */
-  public void waitJobs(long currentTime, ArrayList waitList)
+  public void waitJobs(long currentTime, List<Long> waitList)
     throws ManifoldCFException;
 
   /** Get the list of jobs that are ready for seeding.
@@ -1102,8 +1102,9 @@ public interface IJobManager
   * and will record the jobs that have been so modified.
   *@param timestamp is the current time in milliseconds since epoch.
   *@param modifiedJobs is filled in with the set of IJobDescription objects that were stopped.
+  *@param stopNotificationTypes is filled in with the type of stop notification.
   */
-  public void finishJobStops(long timestamp, ArrayList modifiedJobs)
+  public void finishJobStops(long timestamp, List<IJobDescription> modifiedJobs, List<Integer> stopNotificationTypes)
     throws ManifoldCFException;
 
   /** Complete the sequence that resumes jobs, either from a pause or from a scheduling window
@@ -1112,7 +1113,7 @@ public interface IJobManager
   *@param timestamp is the current time in milliseconds since epoch.
   *@param modifiedJobs is filled in with the set of IJobDescription objects that were resumed.
   */
-  public void finishJobResumes(long timestamp, ArrayList modifiedJobs)
+  public void finishJobResumes(long timestamp, List<IJobDescription> modifiedJobs)
     throws ManifoldCFException;
     
   /** Put all eligible jobs in the "shutting down" state.
@@ -1129,7 +1130,7 @@ public interface IJobManager
   *@param currentTime is the current time in milliseconds since epoch.
   *@param resetJobs is filled in with the set of IJobDescription objects that were reset.
   */
-  public void resetJobs(long currentTime, ArrayList resetJobs)
+  public void resetJobs(long currentTime, List<IJobDescription> resetJobs)
     throws ManifoldCFException;
 
 

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java Wed Jun  3 01:48:22 2015
@@ -48,6 +48,13 @@ public interface INotificationConnector
 {
   public static final String _rcsid = "@(#)$Id$";
 
+  // Job stop reasons
+  public final int STOP_ERRORABORT = 0;
+  public final int STOP_MANUALABORT = 1;
+  public final int STOP_MANUALPAUSE = 2;
+  public final int STOP_SCHEDULEPAUSE = 3;
+  public final int STOP_RESTART = 4;
+  
   /** Request arbitrary connector information.
   * This method is called directly from the API in order to allow API users to perform any one of several
   * connector-specific queries.  These are usually used to create external UI's.  The connector will be
@@ -61,8 +68,9 @@ public interface INotificationConnector
 
   /** Notify of job stop
   *@param spec is the notification specification.
+  *@param stopReason is the reason for the stop.
   */
-  public void notifyOfJobStop(Specification spec)
+  public void notifyOfJobStop(Specification spec, int stopReason)
     throws ManifoldCFException, ServiceInterruption;
 
   /** Notify of job end

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java Wed Jun  3 01:48:22 2015
@@ -5859,7 +5859,7 @@ public class JobManager implements IJobM
   *@param unwaitList is filled in with the set of job ID objects that were resumed.
   */
   @Override
-  public void startJobs(long currentTime, ArrayList unwaitList)
+  public void startJobs(long currentTime, List<Long> unwaitList)
     throws ManifoldCFException
   {
     // This method should compare the lasttime field against the current time, for all
@@ -6097,7 +6097,7 @@ public class JobManager implements IJobM
   *@param waitList is filled in with the set of job ID's that were put into a wait state.
   */
   @Override
-  public void waitJobs(long currentTime, ArrayList waitList)
+  public void waitJobs(long currentTime, List<Long> waitList)
     throws ManifoldCFException
   {
     // This method assesses jobs that are ACTIVE or PAUSED to see if they should be
@@ -8148,7 +8148,7 @@ public class JobManager implements IJobM
   *@param modifiedJobs is filled in with the set of IJobDescription objects that were resumed.
   */
   @Override
-  public void finishJobResumes(long timestamp, ArrayList modifiedJobs)
+  public void finishJobResumes(long timestamp, List<IJobDescription> modifiedJobs)
     throws ManifoldCFException
   {
     // Alternative to using a write lock here: Put this in a transaction, with a "FOR UPDATE" on the first query.
@@ -8196,9 +8196,10 @@ public class JobManager implements IJobM
   * and will record the jobs that have been so modified.
   *@param timestamp is the current time in milliseconds since epoch.
   *@param modifiedJobs is filled in with the set of IJobDescription objects that were stopped.
+  *@param stopNotificationTypes is filled in with the type of stop notification.
   */
   @Override
-  public void finishJobStops(long timestamp, ArrayList modifiedJobs)
+  public void finishJobStops(long timestamp, List<IJobDescription> modifiedJobs, List<Integer> stopNotificationTypes)
     throws ManifoldCFException
   {
     // Alternative to using a write lock here: Put this in a transaction, with a "FOR UPDATE" on the first query.
@@ -8215,7 +8216,7 @@ public class JobManager implements IJobM
       StringBuilder sb = new StringBuilder("SELECT ");
       ArrayList list = new ArrayList();
           
-      sb.append(jobs.idField)
+      sb.append(jobs.idField).append(",").append(jobs.statusField).append(",").append(jobs.errorField)
         .append(" FROM ").append(jobs.getTableName()).append(" WHERE ")
         .append(database.buildConjunctionClause(list,new ClauseDescription[]{
           new MultiClause(jobs.statusField,new Object[]{
@@ -8238,7 +8239,9 @@ public class JobManager implements IJobM
       {
         IResultRow row = set.getRow(i++);
         Long jobID = (Long)row.getValue(jobs.idField);
-
+        int jobStatus = jobs.stringToStatus((String)row.getValue(jobs.statusField));
+        String errorText = (String)row.getValue(jobs.errorField);
+        
         sb = new StringBuilder("SELECT ");
         list.clear();
 
@@ -8266,7 +8269,8 @@ public class JobManager implements IJobM
             
         IJobDescription jobDesc = jobs.load(jobID,true);
         modifiedJobs.add(jobDesc);
-
+        stopNotificationTypes.add(mapToNotificationType(jobStatus,(errorText==null || errorText.length() == 0)));
+        
         jobs.finishStopJob(jobID,timestamp);
             
         Logging.jobs.info("Stopped job "+jobID);
@@ -8278,6 +8282,29 @@ public class JobManager implements IJobM
     }
   }
 
+  protected static Integer mapToNotificationType(int jobStatus, boolean noErrorText)
+  {
+    switch (jobStatus)
+    {
+    case Jobs.STATUS_ABORTING:
+    case Jobs.STATUS_ABORTINGSHUTTINGDOWN:
+      return noErrorText?INotificationConnector.STOP_MANUALABORT:INotificationConnector.STOP_ERRORABORT;
+    case Jobs.STATUS_ABORTINGFORRESTART:
+    case Jobs.STATUS_ABORTINGFORRESTARTMINIMAL:
+      return INotificationConnector.STOP_RESTART;
+    case Jobs.STATUS_PAUSING:
+    case Jobs.STATUS_PAUSINGSEEDING:
+    case Jobs.STATUS_PAUSINGWAITING:
+    case Jobs.STATUS_PAUSINGWAITINGSEEDING:
+      return INotificationConnector.STOP_MANUALPAUSE;
+    case Jobs.STATUS_ACTIVEWAITING:
+    case Jobs.STATUS_ACTIVEWAITINGSEEDING:
+      return INotificationConnector.STOP_SCHEDULEPAUSE;
+    default:
+      throw new RuntimeException("Unexpected job status: "+jobStatus);
+    }
+  }
+
   protected void noDocPriorities(Long jobID)
     throws ManifoldCFException
   {
@@ -8333,7 +8360,7 @@ public class JobManager implements IJobM
   *@param resetJobs is filled in with the set of IJobDescription objects that were reset.
   */
   @Override
-  public void resetJobs(long currentTime, ArrayList resetJobs)
+  public void resetJobs(long currentTime, List<IJobDescription> resetJobs)
     throws ManifoldCFException
   {
     // Alternative to using a write lock here: Put this in a transaction, with a "FOR UPDATE" on the first query.

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java Wed Jun  3 01:48:22 2015
@@ -64,10 +64,19 @@ public abstract class BaseNotificationCo
     return false;
   }
 
+  /** Notify of job stop
+  *@param spec is the notification specification.
+  *@param stopReason is the reason for the stop.
+  */
+  public void notifyOfJobStop(Specification spec, int stopReason)
+    throws ManifoldCFException, ServiceInterruption
+  {
+    notifyOfJobStop(spec);
+  }
+
   /** Notify of job stop.
   *@param spec is the notification specification.
   */
-  @Override
   public void notifyOfJobStop(Specification spec)
     throws ManifoldCFException, ServiceInterruption
   {

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobResetThread.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobResetThread.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobResetThread.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobResetThread.java Wed Jun  3 01:48:22 2015
@@ -68,11 +68,12 @@ public class JobResetThread extends Thre
           // See if there are any completed jobs
           long currentTime = System.currentTimeMillis();
           
-          ArrayList jobStops = new ArrayList();
-          jobManager.finishJobStops(currentTime,jobStops);
-          ArrayList jobResumes = new ArrayList();
+          List<IJobDescription> jobStops = new ArrayList<IJobDescription>();
+          List<Integer> jobStopNotifications = new ArrayList<Integer>();
+          jobManager.finishJobStops(currentTime,jobStops,jobStopNotifications);
+          List<IJobDescription> jobResumes = new ArrayList<IJobDescription>();
           jobManager.finishJobResumes(currentTime,jobResumes);
-          ArrayList jobCompletions = new ArrayList();
+          List<IJobDescription> jobCompletions = new ArrayList<IJobDescription>();
           jobManager.resetJobs(currentTime,jobCompletions);
           
           // If there were any job aborts, we must reprioritize all active documents, since we've done something
@@ -92,18 +93,20 @@ public class JobResetThread extends Thre
           int k = 0;
           while (k < jobStops.size())
           {
-            IJobDescription desc = (IJobDescription)jobStops.get(k++);
+            IJobDescription desc = jobStops.get(k);
+            Integer notificationType = jobStopNotifications.get(k);
             connectionManager.recordHistory(desc.getConnectionName(),
               null,connectionManager.ACTIVITY_JOBSTOP,null,
               desc.getID().toString()+"("+desc.getDescription()+")",null,null,null);
             // As a courtesy, call all the notification connections (if any)
-            doStopNotifications(desc,notificationManager,notificationPool);
+            doStopNotifications(desc,notificationType,notificationManager,notificationPool);
+            k++;
           }
 
           k = 0;
           while (k < jobResumes.size())
           {
-            IJobDescription desc = (IJobDescription)jobResumes.get(k++);
+            IJobDescription desc = jobResumes.get(k++);
             connectionManager.recordHistory(desc.getConnectionName(),
               null,connectionManager.ACTIVITY_JOBCONTINUE,null,
               desc.getID().toString()+"("+desc.getDescription()+")",null,null,null);
@@ -112,7 +115,7 @@ public class JobResetThread extends Thre
           k = 0;
           while (k < jobCompletions.size())
           {
-            IJobDescription desc = (IJobDescription)jobCompletions.get(k++);
+            IJobDescription desc = jobCompletions.get(k++);
             connectionManager.recordHistory(desc.getConnectionName(),
               null,connectionManager.ACTIVITY_JOBEND,null,
               desc.getID().toString()+"("+desc.getDescription()+")",null,null,null);
@@ -179,7 +182,7 @@ public class JobResetThread extends Thre
     }
   }
 
-  protected static void doStopNotifications(IJobDescription jobDescription, INotificationConnectionManager notificationManager,
+  protected static void doStopNotifications(IJobDescription jobDescription, int notificationType, INotificationConnectionManager notificationManager,
     INotificationConnectorPool notificationPool)
     throws ManifoldCFException
   {
@@ -196,7 +199,7 @@ public class JobResetThread extends Thre
           {
             try
             {
-              connector.notifyOfJobStop(jobDescription.getNotificationSpecification(j));
+              connector.notifyOfJobStop(jobDescription.getNotificationSpecification(j),notificationType);
             }
             finally
             {

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobStartThread.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobStartThread.java?rev=1683208&r1=1683207&r2=1683208&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobStartThread.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/JobStartThread.java Wed Jun  3 01:48:22 2015
@@ -68,25 +68,25 @@ public class JobStartThread extends Thre
           if (Logging.threads.isDebugEnabled())
             Logging.threads.debug("Job start thread - checking for jobs to start at "+new Long(currentTime).toString());
           // Start any waiting jobs
-          ArrayList unwaitJobs = new ArrayList();
+          List<Long> unwaitJobs = new ArrayList<Long>();
           jobManager.startJobs(currentTime,unwaitJobs);
           // Log these events in the event log
           int k = 0;
           while (k < unwaitJobs.size())
           {
-            Long jobID = (Long)unwaitJobs.get(k++);
+            Long jobID = unwaitJobs.get(k++);
             IJobDescription desc = jobManager.load(jobID);
             connectionManager.recordHistory(desc.getConnectionName(),
               null,connectionManager.ACTIVITY_JOBUNWAIT,null,
               desc.getID().toString()+"("+desc.getDescription()+")",null,null,null);
           }
           // Cause jobs out of window to stop.
-          ArrayList waitJobs = new ArrayList();
+          List<Long> waitJobs = new ArrayList<Long>();
           jobManager.waitJobs(currentTime,waitJobs);
           k = 0;
           while (k < waitJobs.size())
           {
-            Long jobID = (Long)waitJobs.get(k++);
+            Long jobID = waitJobs.get(k++);
             IJobDescription desc = jobManager.load(jobID);
             connectionManager.recordHistory(desc.getConnectionName(),
               null,connectionManager.ACTIVITY_JOBWAIT,null,