|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface represents a the operations available for interacting with the DRM. In DRMAA, (almost) all DRM interaction occur within the context of a session. The spec also strongly recommends that a DRMAA implementation not allow concurrent sessions. Since DRMAA has no facility for user authentication or authorization, most DRMAA implementations will likely only support one session per implementation instance.
In order to use a Session, it must first be initialized. Once initialized it is the responsibility of the programmer to ensure that the session also be explicitly terminated. Otherwise, session artifacts may be left behind on the client and/or server. A handy way to make sure the Session is terminated is to set up a shutdown hook to call the exit() method on the active session.
To get a Session implementation appropriate for the DRM in use, one uses the SessionFactory.getSession() method.
Example:
public static void main (String[] args) throws Exception { SessionFactory factory = SessionFactory.getFactory (); Session session = factory.getSession (); try { session.init (null); JobTemplate jt = session.createJobTemplate (); jt.setRemoteCommand ("sleeper.sh"); jt.setArgs (new String[] {"5"}); String id = session.runJob (jt); session.deleteJobTemplate (jt); while (session.getJobProgramStatus (id) != Session.RUNNING) { Thread.sleep (1000); } System.out.println ("Job " + id + " is now running."); session.control (id, Session.SUSPEND); Thread.sleep (1000); session.control (id, Session.RELEASE); JobInfo info = session.wait (id, Session.TIMEOUT_WAIT_FOREVER); System.out.println ("Job " + info.getJobId () + " exited with status: " + info.getExitStatus ()); session.exit (); } catch (DrmaaException e) { System.out.println ("Error: " + e.getMessage ()); } }
Runtime.addShutdownHook(java.lang.Thread)
,
SessionFactory
,
Grid
Engine DRMAA Java[TM] Language Binding HowToField Summary | |
static int |
DONE
Job has finished normally |
static int |
FAILED
Job finished, but terminated abnormally |
static int |
HOLD
Put the job on hold |
static java.lang.String |
JOB_IDS_SESSION_ALL
All jobs submitted during this DRMAA session |
static java.lang.String |
JOB_IDS_SESSION_ANY
Any job from the session |
static int |
QUEUED_ACTIVE
Job is queued and active |
static int |
RELEASE
Release the hold on the job |
static int |
RESUME
Resume the job |
static int |
RUNNING
Job is running |
static int |
SUSPEND
Suspend the job |
static int |
SYSTEM_ON_HOLD
Job is queued and in system hold |
static int |
SYSTEM_SUSPENDED
Job is system suspended |
static int |
TERMINATE
Kill the job |
static long |
TIMEOUT_NO_WAIT
Return immediately if no result is available |
static long |
TIMEOUT_WAIT_FOREVER
Wait indefinitely for a result |
static int |
UNDETERMINED
Job status cannot be determined |
static int |
USER_ON_HOLD
Job is queued and in user hold |
static int |
USER_SUSPENDED
Job is user suspended |
static int |
USER_SYSTEM_ON_HOLD
Job is queued and in user and system hold |
static int |
USER_SYSTEM_SUSPENDED
Job is user suspended |
Method Summary | |
void |
control(java.lang.String jobId,
int action)
Hold, release, suspend, resume, or kill the job identified by jobId. |
JobTemplate |
createJobTemplate()
Get a new job template. |
void |
deleteJobTemplate(JobTemplate jt)
Deallocate a job template. |
void |
exit()
Disengage from DRM and allow the DRMAA implementation to perform any necessary internal cleanup. |
java.lang.String |
getContact()
If called before init(), this method returns a comma delimited String containing the contact Strings available from the default DRMAA implementation, one element per DRM system available. |
java.lang.String |
getDrmaaImplementation()
If called before init(), this method returns a comma delimited list of DRMAA implementations, one element for each DRMAA implementation provided. |
java.lang.String |
getDrmSystem()
If called before init(), this method returns a comma delimited list of DRM systems, one element per DRM system implementation provided. |
int |
getJobProgramStatus(java.lang.String jobId)
Get the program status of the job identified by jobId. |
Version |
getVersion()
Returns a Version object containing the major and minor version numbers of the DRMAA library. |
void |
init(java.lang.String contact)
Initialize the DRMAA implementation. |
java.util.List |
runBulkJobs(JobTemplate jt,
int start,
int end,
int incr)
Submit a set of parametric jobs, dependent on the implied loop index, each with attributes defined in the job template, jt. |
java.lang.String |
runJob(JobTemplate jt)
Submit a job with attributes defined in the job template, jt. |
void |
synchronize(java.util.List jobIds,
long timeout,
boolean dispose)
Wait until all jobs specified by jobIds have finished execution. |
JobInfo |
wait(java.lang.String jobId,
long timeout)
This method will wait for a job with jobId to finish execution or fail. |
Field Detail |
public static final int SUSPEND
public static final int RESUME
public static final int HOLD
public static final int RELEASE
public static final int TERMINATE
public static final java.lang.String JOB_IDS_SESSION_ALL
public static final java.lang.String JOB_IDS_SESSION_ANY
public static final long TIMEOUT_WAIT_FOREVER
public static final long TIMEOUT_NO_WAIT
public static final int UNDETERMINED
public static final int QUEUED_ACTIVE
public static final int SYSTEM_ON_HOLD
public static final int USER_ON_HOLD
public static final int USER_SYSTEM_ON_HOLD
public static final int RUNNING
public static final int SYSTEM_SUSPENDED
public static final int USER_SUSPENDED
public static final int USER_SYSTEM_SUSPENDED
public static final int DONE
public static final int FAILED
Method Detail |
public void init(java.lang.String contact) throws DrmaaException
Initialize the DRMAA implementation. contact is an implementation-dependent string that may be used to specify which DRM system to use. This routine must be called before any other DRMAA calls, except for getVersion(), getDRMSystem(), getDRMAAImplementation(), or getContact().
If contact isnull
, the default DRM system is used,
provided there is only one DRMAA implementation in the module.
If there is more than one DRMAA implementation in the module, init() throws a
NoDefaultContactStringSelectedException.
init() should be called only once, by only one of the threads. The main thread is
recommended. A call to init() by another thread or additional calls to init()
by the same thread with throw a SessionAlreadyActiveException.
contact
- implementation-dependent string that may be used to specify
which DRM system to use. If null, will select the default DRM if there
is only one DRMAA implementation available.
DrmaaException
- May be be one of the following:
public void exit() throws DrmaaException
DrmaaException
- May be one of the following:
public JobTemplate createJobTemplate() throws DrmaaException
DrmaaException
- May be one of the following:
JobTemplate
public void deleteJobTemplate(JobTemplate jt) throws DrmaaException
jt
- the JobTemplate to delete
DrmaaException
- May be one of the following:
public java.lang.String runJob(JobTemplate jt) throws DrmaaException
jt
- the job template to be used to create the job
DrmaaException
- May be one of the following:
public java.util.List runBulkJobs(JobTemplate jt, int start, int end, int incr) throws DrmaaException
Submit a set of parametric jobs, dependent on the implied loop index, each with attributes defined in the job template, jt. The returned job identifiers are Strings identical to those returned from the underlying DRM system.
The JobTemplate class defines a PARAMETRIC_INDEX
placeholder for use in
specifying paths. This placeholder is used to represent the individual
identifiers of the tasks submitted through this method.
start
- the starting value for the loop indexend
- the terminating value for the loop indexincr
- the value by which to increment the loop index each iterationjt
- the job template to be used to create the job
DrmaaException
- May be one of the following:
public void control(java.lang.String jobId, int action) throws DrmaaException
Hold, release, suspend, resume, or kill the job identified by jobId.
If jobId is JOB_IDS_SESSION_ALL
, then this routine acts on all jobs
submitted during this DRMAA session up to the moment control() is
called. To avoid thread races in multithreaded applications, the DRMAA
implementation user should explicitly synchronize this call with any other
job submission calls or control calls that may change the number of remote
jobs.
The legal values for action and their meanings are:
SUSPEND
: stop the job,RESUME
: (re)start the job,HOLD
: put the job on-hold,RELEASE
: release the hold on the job, andTERMINATE
: kill the job.This method returns once the action has been acknowledged by the DRM system, but does not necessarily wait until the action has been completed.
Some DRMAA implementations may allow this method to be used to control jobs submitted external to the DRMAA session, such as jobs submitted by other DRMAA session in other DRMAA implementations or jobs submitted via native utilities.
jobId
- The id of the job to controlaction
- the control action to be taken
DrmaaException
- May be one of the following:
public void synchronize(java.util.List jobIds, long timeout, boolean dispose) throws DrmaaException
Wait until all jobs specified by jobIds have finished execution.
If jobIds contains JOB_IDS_SESSION_ALL
, then this method waits for all
jobs submitted during this DRMAA session up to the moment
synchronize() is called. To avoid thread race conditions in multithreaded
applications, the DRMAA implementation user should explicitly synchronize
this call with any other job submission calls or control calls that may
change the number of remote jobs.
To prevent blocking indefinitely in this call, the caller may use a timeout
specifying after how many seconds to block in this call. The value
TIMEOUT_WAIT_FOREVER MAY
be specified to wait indefinitely for a result.
The value TIMEOUT_NO_WAIT MAY
be specified to return immediately if no
result is available. If the call exits before the timeout has elapsed, all the
jobs have been waited on or there was an interrupt.
If the invocation exits on timeout, an ExitTimeException is thrown.
The caller should check system time before and after this call in order to
be sure of how much time has passed.
The dispose parameter specifies how to treat the reaping of the remote job's
internal data record, which includes a record of the job's consumption of system
resources during its execution and other statistical information. If set to
true
, the DRM will dispose of the job's data record at the end of
the synchroniize() call. If set to false
, the data record will be
left for future access via the wait() method.
jobIds
- the ids of the jobs to synchronizetimeout
- the maximum number of seconds to waitdispose
- specifies how to treat reaping information
DrmaaException
- May be one of the following:
wait(java.lang.String, long)
public JobInfo wait(java.lang.String jobId, long timeout) throws DrmaaException
This method will wait for a job with jobId to finish execution or fail.
If the special string, JOB_IDS_SESSION_ANY
, is provided as the
jobId,
this routine will wait for any job from the session. This routine is
modeled on the wait3 POSIX routine.
The timeout value is used to specify the desired behavior when a result
is not immediately available. The value, TIMEOUT_WAIT_FOREVER
, may be
specified to wait indefinitely for a result. The value,
TIMEOUT_NO_WAIT
,
may be specified to return immediately if no result is available.
Alternatively, a number of seconds may be specified to indicate how
long to wait for a result to become available.
If the call exits before timeout, either the job has been waited on successfully or there was an interrupt. If the invocation exits on timeout, an ExitTimeoutException is thrown. The caller should check system time before and after this call in order to be sure how much time has passed.
The routine reaps job data records on a successful call, so any subsequent calls to wait() will fail, throwing an InvalidJobException, meaning that the job's data record has been already reaped. This exception is the same as if the job was unknown. (The only case where wait() can be successfully called on a single job more than once is when the previous call to wait() timed out before the job finished.)
When successful, the resource usage information for the job is provided as a Map of usage parameter names and their values. The values contain the amount of resources consumed by the job and are implementation defined.
jobId
- the id of the job for which to waittimeout
- the maximum number of seconds to wait
DrmaaException
- May be one of the following:
public int getJobProgramStatus(java.lang.String jobId) throws DrmaaException
UNDETERMINED
: process status cannot be determinedQUEUED_ACTIVE
: job is queued and activeSYSTEM_ON_HOLD
: job is queued and in system holdUSER_ON_HOLD
: job is queued and in user holdUSER_SYSTEM_ON_HOLD
: job is queued and in user and system holdRUNNING
: job is runningSYSTEM_SUSPENDED
: job is system suspendedUSER_SUSPENDED
: job is user suspendedDONE
: job finished normallyFAILED
: job finished, but failed.FAILED
or DONE
and the
status has been successfully cached. Terminated jobs return a FAILED
status.
jobId
- the id of the job whose status is to be retrieved
DrmaaException
- May be one of the following:
public java.lang.String getContact()
public Version getVersion()
Version
public java.lang.String getDrmSystem()
public java.lang.String getDrmaaImplementation()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |