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 |
Callback interface when a job has been completed on an Open Grid cluster. |
4245 |
21 Nov 16 |
nicklas |
The extension point is "net.sf.basedb.opengrid.job-complete". A typical |
4301 |
13 Jan 17 |
nicklas |
implementation need to implement this interface and also an |
4301 |
13 Jan 17 |
nicklas |
{@link ActionFactory}. |
4245 |
21 Nov 16 |
nicklas |
16 |
|
4301 |
13 Jan 17 |
nicklas |
The {@link ActionFactory#prepareContext(InvokationContext)} method is called with only a |
4245 |
21 Nov 16 |
nicklas |
session control available (the ROOT user is logged in). The context may be used |
4301 |
13 Jan 17 |
nicklas |
for completing multiple jobs. The {@link ActionFactory#getActions(InvokationContext)} |
4245 |
21 Nov 16 |
nicklas |
may be called multiple times. The job is set as the current item, and the |
4245 |
21 Nov 16 |
nicklas |
{@link JobStatus} is available as the "job-status" attribute. It is recommended |
4301 |
13 Jan 17 |
nicklas |
that the {@code getAction()} method make some checks and only return |
4284 |
21 Dec 16 |
nicklas |
actions if the extension is actually going to handle the job. Note that |
4245 |
21 Nov 16 |
nicklas |
the extension point is called both for successful and failed jobs! Check |
4245 |
21 Nov 16 |
nicklas |
the {@link JobStatus} before deciding what to do. |
4245 |
21 Nov 16 |
nicklas |
26 |
|
4245 |
21 Nov 16 |
nicklas |
If the action factory create actions a new impersonated session control |
4245 |
21 Nov 16 |
nicklas |
is created. The logged in user is set to the owner of the job and |
4245 |
21 Nov 16 |
nicklas |
if the job has an active project it is activated. If the action need to |
4245 |
21 Nov 16 |
nicklas |
make changes to the database it must create a DbControl itself. The actions |
4245 |
21 Nov 16 |
nicklas |
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 |
@author nicklas |
4245 |
21 Nov 16 |
nicklas |
@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 |
Called when the job has been completed (successful or failed). The handler |
4245 |
21 Nov 16 |
nicklas |
should return a message with some useful information about the job. The |
4245 |
21 Nov 16 |
nicklas |
handler may throw an exception in case there is a problem. If it do, |
4245 |
21 Nov 16 |
nicklas |
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 |
@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 |
@param session An open session to the cluster that executed the job |
4245 |
21 Nov 16 |
nicklas |
@param job The job as it is represented in BASE (do not change!) |
4245 |
21 Nov 16 |
nicklas |
@param status Status information about the job from the cluster |
4245 |
21 Nov 16 |
nicklas |
50 |
|
4245 |
21 Nov 16 |
nicklas |
@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 |
} |