extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/service/JobCompletionHandler.java

Code
Comments
Other
Rev Date Author Line
4245 21 Nov 16 nicklas 1 package net.sf.basedb.opengrid.service;
4245 21 Nov 16 nicklas 2
4245 21 Nov 16 nicklas 3 import net.sf.basedb.core.Job;
4245 21 Nov 16 nicklas 4 import net.sf.basedb.core.SessionControl;
4245 21 Nov 16 nicklas 5 import net.sf.basedb.opengrid.JobStatus;
4245 21 Nov 16 nicklas 6 import net.sf.basedb.opengrid.OpenGridSession;
4245 21 Nov 16 nicklas 7 import net.sf.basedb.util.extensions.Action;
4301 13 Jan 17 nicklas 8 import net.sf.basedb.util.extensions.ActionFactory;
4301 13 Jan 17 nicklas 9 import net.sf.basedb.util.extensions.InvokationContext;
4245 21 Nov 16 nicklas 10
4245 21 Nov 16 nicklas 11 /**
4245 21 Nov 16 nicklas 12   Callback interface when a job has been completed on an Open Grid cluster.
4245 21 Nov 16 nicklas 13   The extension point is "net.sf.basedb.opengrid.job-complete". A typical
4301 13 Jan 17 nicklas 14   implementation need to implement this interface and also an 
4301 13 Jan 17 nicklas 15   {@link ActionFactory}.
4245 21 Nov 16 nicklas 16   
4301 13 Jan 17 nicklas 17   The {@link ActionFactory#prepareContext(InvokationContext)}  method is called with only a 
4245 21 Nov 16 nicklas 18   session control available (the ROOT user is logged in). The context may be used
4301 13 Jan 17 nicklas 19   for completing multiple jobs. The {@link ActionFactory#getActions(InvokationContext)}
4245 21 Nov 16 nicklas 20   may be called multiple times. The job is set as the current item, and the 
4245 21 Nov 16 nicklas 21   {@link JobStatus} is available as the "job-status" attribute. It is recommended 
4301 13 Jan 17 nicklas 22   that the {@code getAction()} method make some checks and only return
4284 21 Dec 16 nicklas 23   actions if the extension is actually going to handle the job. Note that
4245 21 Nov 16 nicklas 24   the extension point is called both for successful and failed jobs! Check
4245 21 Nov 16 nicklas 25   the {@link JobStatus} before deciding what to do.
4245 21 Nov 16 nicklas 26   
4245 21 Nov 16 nicklas 27   If the action factory create actions a new impersonated session control
4245 21 Nov 16 nicklas 28   is created. The logged in user is set to the owner of the job and
4245 21 Nov 16 nicklas 29   if the job has an active project it is activated. If the action need to
4245 21 Nov 16 nicklas 30   make changes to the database it must create a DbControl itself. The actions
4245 21 Nov 16 nicklas 31   SHOULD NOT change the job item since that will be handled by the service.
4245 21 Nov 16 nicklas 32   
4245 21 Nov 16 nicklas 33   @author nicklas
4245 21 Nov 16 nicklas 34   @since 1.0
4245 21 Nov 16 nicklas 35 */
4245 21 Nov 16 nicklas 36 public interface JobCompletionHandler 
4245 21 Nov 16 nicklas 37   extends Action
4245 21 Nov 16 nicklas 38 {
4245 21 Nov 16 nicklas 39
4245 21 Nov 16 nicklas 40   /**
4245 21 Nov 16 nicklas 41     Called when the job has been completed (successful or failed). The handler
4245 21 Nov 16 nicklas 42     should return a message with some useful information about the job. The
4245 21 Nov 16 nicklas 43     handler may throw an exception in case there is a problem. If it do, 
4245 21 Nov 16 nicklas 44     the job status will be changed to ERROR and no more handlers are called.
4245 21 Nov 16 nicklas 45     
4245 21 Nov 16 nicklas 46     @param sc A session control with the owner of the job logged in and the same project active (if any)
4245 21 Nov 16 nicklas 47     @param session An open session to the cluster that executed the job
4245 21 Nov 16 nicklas 48     @param job The job as it is represented in BASE (do not change!)
4245 21 Nov 16 nicklas 49     @param status Status information about the job from the cluster 
4245 21 Nov 16 nicklas 50     
4245 21 Nov 16 nicklas 51     @return A status message the will be saved to {@link Job#getStatusMessage()} 
4245 21 Nov 16 nicklas 52   */
4245 21 Nov 16 nicklas 53   public String jobCompleted(SessionControl sc, OpenGridSession session, Job job, JobStatus status);
4245 21 Nov 16 nicklas 54   
4245 21 Nov 16 nicklas 55 }