public class JobQueueScheduler extends Scheduler
Modifier and Type | Class and Description |
---|---|
private class |
JobQueueScheduler.DaemonThreadFactory
Simple thread factory which returns daemon threads instead of normal threads
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
adaptorName |
private InteractiveProcessFactory |
factory |
private FileSystem |
filesystem |
private java.util.concurrent.atomic.AtomicLong |
jobID |
private static org.slf4j.Logger |
LOGGER |
static int |
MAX_POLLING_DELAY
The maximum allowed value for the polling delay
|
static int |
MIN_POLLING_DELAY
The minimal allowed value for the polling delay
|
private static java.lang.String |
MULTI_QUEUE_NAME |
private java.util.concurrent.ExecutorService |
multiExecutor |
private java.util.List<JobExecutor> |
multiQ |
private long |
pollingDelay |
private java.util.ArrayList<java.util.List<JobExecutor>> |
queues |
private static java.lang.String |
SINGLE_QUEUE_NAME |
private java.util.concurrent.ExecutorService |
singleExecutor |
private java.util.List<JobExecutor> |
singleQ |
private long |
startupTimeout |
private static java.lang.String |
UNLIMITED_QUEUE_NAME |
private java.util.concurrent.ExecutorService |
unlimitedExecutor |
private java.util.List<JobExecutor> |
unlimitedQ |
private Path |
workingDirectory |
properties
Constructor and Description |
---|
JobQueueScheduler(java.lang.String uniqueID,
java.lang.String adaptorName,
java.lang.String location,
Credential credential,
InteractiveProcessFactory factory,
FileSystem filesystem,
Path workingDirectory,
int multiQThreads,
long pollingDelay,
long startupTimeout,
XenonProperties properties) |
Modifier and Type | Method and Description |
---|---|
JobStatus |
cancelJob(java.lang.String jobIdentifier)
Cancel a job.
|
private boolean |
cleanupJob(java.util.List<JobExecutor> queue,
java.lang.String jobIdentifier) |
private void |
cleanupJob(java.lang.String jobIdentifier) |
void |
close()
Close this Scheduler.
|
void |
end() |
private JobExecutor |
findJob(java.util.List<JobExecutor> queue,
java.lang.String jobIdentifier) |
private JobExecutor |
findJob(java.lang.String jobIdentifier) |
long |
getCurrentJobID() |
java.lang.String |
getDefaultQueueName()
Get the name of the default queue.
|
FileSystem |
getFileSystem()
Retrieve the
FileSystem used internally by this Scheduler . |
private void |
getJobs(java.util.List<JobExecutor> list,
java.util.List<java.lang.String> out) |
java.lang.String[] |
getJobs(java.lang.String... queueNames)
Get all job identifier of jobs currently in (one ore more) queues.
|
JobStatus |
getJobStatus(java.lang.String jobIdentifier)
Get the status of a Job.
|
java.lang.String[] |
getQueueNames()
Get the queue names supported by this Scheduler.
|
QueueStatus |
getQueueStatus(java.lang.String queueName)
Get the status of the
queue . |
QueueStatus[] |
getQueueStatuses(java.lang.String... queueNames)
Get the status of all
queues . |
boolean |
isOpen()
Test if the connection of this Scheduler is open.
|
private JobExecutor |
submit(JobDescription description,
boolean interactive) |
java.lang.String |
submitBatchJob(JobDescription description)
Submit a batch job.
|
Streams |
submitInteractiveJob(JobDescription description)
Submit an interactive job (optional operation).
|
private void |
verifyJobDescription(JobDescription description,
boolean interactive) |
JobStatus |
waitUntilDone(java.lang.String jobIdentifier,
long timeout)
Wait until a job is done or until a timeout expires.
|
JobStatus |
waitUntilRunning(java.lang.String jobIdentifier,
long timeout)
Wait until a job starts running, or until a timeout expires.
|
assertNonNullOrEmpty, assertPositive, create, create, create, create, equals, getAdaptorDescription, getAdaptorDescriptions, getAdaptorName, getAdaptorNames, getCredential, getJobStatuses, getLocation, getProperties, hashCode
private static final org.slf4j.Logger LOGGER
private static final java.lang.String SINGLE_QUEUE_NAME
private static final java.lang.String MULTI_QUEUE_NAME
private static final java.lang.String UNLIMITED_QUEUE_NAME
public static final int MIN_POLLING_DELAY
public static final int MAX_POLLING_DELAY
private final java.lang.String adaptorName
private final FileSystem filesystem
private final Path workingDirectory
private final java.util.List<JobExecutor> singleQ
private final java.util.List<JobExecutor> multiQ
private final java.util.List<JobExecutor> unlimitedQ
private final java.util.concurrent.ExecutorService singleExecutor
private final java.util.concurrent.ExecutorService multiExecutor
private final java.util.concurrent.ExecutorService unlimitedExecutor
private final long pollingDelay
private final long startupTimeout
private final InteractiveProcessFactory factory
private final java.util.concurrent.atomic.AtomicLong jobID
private final java.util.ArrayList<java.util.List<JobExecutor>> queues
public JobQueueScheduler(java.lang.String uniqueID, java.lang.String adaptorName, java.lang.String location, Credential credential, InteractiveProcessFactory factory, FileSystem filesystem, Path workingDirectory, int multiQThreads, long pollingDelay, long startupTimeout, XenonProperties properties) throws BadParameterException
BadParameterException
public long getCurrentJobID()
private void getJobs(java.util.List<JobExecutor> list, java.util.List<java.lang.String> out)
public java.lang.String getDefaultQueueName() throws XenonException
Scheduler
getDefaultQueueName
in class Scheduler
null
if no default queue is available.NotConnectedException
- If scheduler is closed.XenonException
- If an I/O error occurred.public java.lang.String[] getJobs(java.lang.String... queueNames) throws NoSuchQueueException
Scheduler
getJobs
in class Scheduler
queueNames
- the names of the queues.NoSuchQueueException
- If the queue does not exist in the scheduler.private JobExecutor findJob(java.util.List<JobExecutor> queue, java.lang.String jobIdentifier) throws XenonException
XenonException
private JobExecutor findJob(java.lang.String jobIdentifier) throws XenonException
XenonException
private boolean cleanupJob(java.util.List<JobExecutor> queue, java.lang.String jobIdentifier)
private void cleanupJob(java.lang.String jobIdentifier)
public JobStatus getJobStatus(java.lang.String jobIdentifier) throws XenonException
Scheduler
getJobStatus
in class Scheduler
jobIdentifier
- the job identifier of the job to get the status for.NoSuchJobException
- If the job is not known.XenonException
- If the status of the job could not be retrieved.public JobStatus waitUntilDone(java.lang.String jobIdentifier, long timeout) throws XenonException
Scheduler
This method will wait until a job is done (either gracefully or by being killed or producing an error), or until the timeout expires, whichever comes first. If the timeout expires, the job will continue to run.
The timeout is in milliseconds and must be >= 0. When timeout is 0, it will be ignored and this method will wait until the jobs is done.
A JobStatus is returned that can be used to determine why the call returned.
waitUntilDone
in class Scheduler
jobIdentifier
- the identifier of the to wait for.timeout
- the maximum time to wait for the job in milliseconds.NoSuchJobException
- If the job is not known.XenonException
- If the status of the job could not be retrieved.public JobStatus waitUntilRunning(java.lang.String jobIdentifier, long timeout) throws XenonException
Scheduler
This method will return as soon as the job is no longer waiting in the queue, or when the timeout expires, whichever comes first. If the job is no longer waiting in the queue, it may be running, but it may also be killed, finished or have produced an error. If the timeout expires, the job will continue to be queued normally.
The timeout is in milliseconds and must be >= 0. When timeout is 0, it will be ignored and this method will wait until the job is no longer queued.
A JobStatus is returned that can be used to determine why the call returned.
waitUntilRunning
in class Scheduler
jobIdentifier
- the identifier of the to wait for.timeout
- the maximum time to wait in milliseconds.NoSuchJobException
- If the job is not known.XenonException
- If the status of the job could not be retrieved.private void verifyJobDescription(JobDescription description, boolean interactive) throws XenonException
XenonException
private JobExecutor submit(JobDescription description, boolean interactive) throws XenonException
XenonException
public java.lang.String submitBatchJob(JobDescription description) throws XenonException
Scheduler
submitBatchJob
in class Scheduler
description
- the description of the batch job to submit.IncompleteJobDescriptionException
- If the description did not contain the required information.InvalidJobDescriptionException
- If the description contains illegal or conflicting values.UnsupportedJobDescriptionException
- If the description is not legal for this scheduler.XenonException
- If the Scheduler failed to get submit the job.public Streams submitInteractiveJob(JobDescription description) throws XenonException
Scheduler
submitInteractiveJob
in class Scheduler
description
- the description of the interactive job to submit.Streams
object containing the job identifier and the standard streams of a job.IncompleteJobDescriptionException
- If the description did not contain the required information.InvalidJobDescriptionException
- If the description contains illegal or conflicting values.UnsupportedJobDescriptionException
- If the description is not legal for this scheduler.XenonException
- If the Scheduler failed to get submit the job.public JobStatus cancelJob(java.lang.String jobIdentifier) throws XenonException
Scheduler
A status is returned that indicates the state of the job after the cancel. If the job was already done it cannot be cancelled.
A JobStatus
is returned that can be used to determine the state of the job after cancelJob returns. Note that it may take some time before the
job has actually terminated. The waitUntilDone
method can be used to wait until the job is terminated.
cancelJob
in class Scheduler
jobIdentifier
- the identifier of job to kill.NoSuchJobException
- If the job is not known.XenonException
- If the status of the job could not be retrieved.public QueueStatus getQueueStatus(java.lang.String queueName) throws XenonException
Scheduler
queue
.getQueueStatus
in class Scheduler
queueName
- the name of the queue.NoSuchQueueException
- If the queue does not exist in the scheduler.XenonException
- If the Scheduler failed to get its status.public java.lang.String[] getQueueNames()
Scheduler
getQueueNames
in class Scheduler
public QueueStatus[] getQueueStatuses(java.lang.String... queueNames) throws XenonException
Scheduler
queues
.
Note that this method will only throw an exception when this exception will influence all status requests. For example, if the scheduler is no longer
connected.
Exceptions that only refer to a single queue are returned in the QueueStatus returned for that queue.getQueueStatuses
in class Scheduler
queueNames
- the names of the queues.XenonException
- If the Scheduler failed to get the statuses.public void end()
public FileSystem getFileSystem() throws XenonException
Scheduler
FileSystem
used internally by this Scheduler
.
Often, a Scheduler
needs to access files or directories on the machine it will schedule jobs. For example, to ensure a working directory
exists, or to redirect the stdin, stdout or stderr streams used by a job.
This method returns this FileSystem
so it can also be used by the application to prepare input files for the jobs, or retrieve the output
files produced by the jobs.
getFileSystem
in class Scheduler
FileSystem
used by this Scheduler.XenonException
- if this Scheduler does not use a FileSystem
internally.public void close() throws XenonException
Scheduler
close
in interface java.lang.AutoCloseable
close
in class Scheduler
XenonException
- If the Scheduler failed to close.public boolean isOpen() throws XenonException
Scheduler
isOpen
in class Scheduler
true
if the connection of this Scheduler is still open, false
otherwise.XenonException
- If an I/O error occurred.