public interface Session
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(""); JobTemplate jt = session.createJobTemplate(); jt.setRemoteCommand("sleeper.sh"); jt.setArgs(Collections.singletonList("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™ Language Binding HowToModifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 the 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
available 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
available 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 instance 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 range of parametric jobs,
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.
|
static final int SUSPEND
static final int RESUME
static final int HOLD
static final int RELEASE
static final int TERMINATE
static final java.lang.String JOB_IDS_SESSION_ALL
static final java.lang.String JOB_IDS_SESSION_ANY
static final long TIMEOUT_WAIT_FOREVER
static final long TIMEOUT_NO_WAIT
static final int UNDETERMINED
static final int QUEUED_ACTIVE
static final int SYSTEM_ON_HOLD
static final int USER_ON_HOLD
static final int USER_SYSTEM_ON_HOLD
static final int RUNNING
static final int SYSTEM_SUSPENDED
static final int USER_SUSPENDED
static final int USER_SYSTEM_SUSPENDED
static final int DONE
static final int FAILED
void init(java.lang.String contact) throws DrmaaException
If contact is null
or "", the default DRM system
is used, provided there is only one DRMAA implementation available.
If there is more than one DRMAA implementation available, 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.DrmaaException
- May be be one of the following:
void exit() throws DrmaaException
DrmaaException
- May be one of the following:
JobTemplate createJobTemplate() throws DrmaaException
DrmaaException
- May be one of the following:
JobTemplate
void deleteJobTemplate(JobTemplate jt) throws DrmaaException
jt
- the JobTemplate to deleteDrmaaException
- May be one of the following:
java.lang.String runJob(JobTemplate jt) throws DrmaaException
jt
- the job template to be used to create the jobDrmaaException
- May be one of the following:
java.util.List runBulkJobs(JobTemplate jt, int start, int end, int incr) throws DrmaaException
The JobTemplate class defines a PARAMETRIC_INDEX
placeholder for use in specifying paths in the job template. 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 jobDrmaaException
- May be one of the following:
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 conditions
in multithreaded applications, the DRMAA implementation user should
explicitly synchronize this call with any other job submission 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 it 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 sessions or jobs submitted via native utilities.
If jobId is JOB_IDS_SESSION_ALL
and the control
action fails for one or more jobs, and InternalException will be thrown,
and the state of the jobs in the session will be undefined.
jobId
- The id of the job to controlaction
- the control action to be takenDrmaaException
- May be one of the following:
void synchronize(java.util.List jobIds, long timeout, boolean dispose) throws DrmaaException
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
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 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 jobs' internal data records, which includes a record of the jobs'
consumption of system resources during their execution and other
statistical information. If this parameter is set to true
,
the DRM will dispose of the jobs' data records at the end of
the synchroniize() call. If set to false
, the data records
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 informationDrmaaException
- May be one of the following:
wait(java.lang.String, long)
JobInfo wait(java.lang.String jobId, long timeout) throws DrmaaException
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(), synchronize(), control(), or getJobProgramStatus() 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 were 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 in the
JobInfo object. The values contain the amount of resources consumed by
the job and are implementation defined. If no resource usage
information is available for the finished job, the resourceUsage
property of the returned JobInfo instance will be null
.
In the 0.5 version of this method, a NoResourceUsageException would be thrown if the target job finished with no resource usage information. In the current implementation, no exception is thrown in that case. Instead, the JobInfo.getResourceUsage() method will return null.
jobId
- the id of the job for which to waittimeout
- the maximum number of seconds to waitDrmaaException
- May be one of the following:
JobInfo
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 suspendedUSER_SYSTEM_SUSPENDED
: job is user and system
suspendedDONE
: job finished normallyFAILED
: job finished, but failed.The DRMAA implementation must always get the status of jobId from DRM
system unless the status has already been determined to be
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 retrievedDrmaaException
- May be one of the following:
java.lang.String getContact()
DrmaaException
- May be one of the following:
Version getVersion()
DrmaaException
- May be one of the following:
Version
java.lang.String getDrmSystem()
DrmaaException
- May be one of the following:
java.lang.String getDrmaaImplementation()
DrmaaException
- May be one of the following:
The contents of this file are licensed under the Sun Industry Standards Source License version 1.2.
Copyright 2008, Sun Microsystems, Inc.