Package net.sf.basedb.opengrid
Class OpenGridSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
An open session to an Open Grid cluster. It provides a lot
of extra functionality for submitting jobs, check job status,
abort jobs, etc. Do not forget to
AbstractSession.close()
the session after use.
A session is not thread-safe and need external synchronization if
used with multiple threads.- Since:
- 1.0
- Author:
- nicklas
-
Nested Class Summary
Nested classes/interfaces inherited from class net.sf.basedb.opengrid.AbstractSession
AbstractSession.CloseResourceOutputStream, AbstractSession.UploadSourceWrapper
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ClusterEngine
private Integer
private static final ExtensionsLogger
-
Constructor Summary
ConstructorDescriptionOpenGridSession
(OpenGridCluster cluster, net.schmizz.sshj.SSHClient ssh) Session are typically created fromOpenGridCluster.connect(int)
. -
Method Summary
Modifier and TypeMethodDescriptionexecuteNow
(JobDefinition job, String node, int timeout) Execute a command on a node in the cluster with support for uploading files before the command is executed.executeOnNode
(String cmd, String node, int timeout) Execute a command on a node in the cluster.Get the current date and time of the cluster node.Utility method for getting information about the cluster hardware and operating system by executing theClusterConfig.getHostInfoCommand()
.getJobFileAsString
(String jobName, String filename, String encoding) Utility method for downloading a result file from a job as a text file.Utility method for getting information about the Open Grid Scheduler software version by executing theClusterConfig.getOpenGridInfoCommand()
.int
Get the time different in seconds between the BASE server and the remote host.qacct
(JobIdentifier jobId, boolean useLocalTimeAdjustment) Issue a command to find out information about a job that has ended.qdel
(JobIdentifier jobId) Abort the job with the specified job id.qstat
(JobIdentifier jobId, boolean useLocalTimeAdjustment) Issue a command, parse the result and return the information as a JobStatus object.qsub
(DbControl dc, List<JobDefinition> jobs) Submit jobs to the cluster.readProgress
(JobStatus jobStatus) Read the 'progress' information for the job and update job status instance.readStderr
(JobStatus jobStatus) Read the 'stderr' file and update the message in the job status instance.Methods inherited from class net.sf.basedb.opengrid.AbstractSession
close, downloadFile, execute, executeCmd, getHost, getMetadata, isClosed, mkdirs, readFile, uploadFile, writeFile
-
Field Details
-
logger
-
engine
-
localTimeAdjustment
-
-
Constructor Details
-
OpenGridSession
OpenGridSession(OpenGridCluster cluster, net.schmizz.sshj.SSHClient ssh) Session are typically created fromOpenGridCluster.connect(int)
.
-
-
Method Details
-
executeOnNode
Execute a command on a node in the cluster.- Parameters:
node
- The name of the node, or null to execute on the master- See Also:
-
executeNow
Execute a command on a node in the cluster with support for uploading files before the command is executed. The job definition is used for the file upload only. The files are removed again after the command has been executed, unless the debug flag is set. If there are no files, this method is equivalent toexecuteOnNode(String, String, int)
- Since:
- 1.5
-
getClusterDate
Get the current date and time of the cluster node. -
getHostInfo
Utility method for getting information about the cluster hardware and operating system by executing theClusterConfig.getHostInfoCommand()
. -
getOpenGridInfo
Utility method for getting information about the Open Grid Scheduler software version by executing theClusterConfig.getOpenGridInfoCommand()
. -
getTimeAdjustment
public int getTimeAdjustment()Get the time different in seconds between the BASE server and the remote host. A positive value means the remote host is ahead of BASE, a negative value that the remote host is behind. NOTE! The value returned by this method is cached for the length of the session -
qsub
Submit jobs to the cluster. If any of the jobs are connected to BASE jobs a DbControl is required. The BASE jobs will be updated with information about the jobs on the cluster. If the transaction is not committed the jobs on the cluster will automatically be aborted.- Parameters:
dc
- An open DbControl connection. This is needed if any of the job definitions are connected to a BASE job but can be null otherwisejobs
- A list with job definitions that should be submitted to the cluster- Returns:
- A list with job status information. The order is the same as the order of the job definitions
-
qdel
Abort the job with the specified job id. -
qstat
Issue a command, parse the result and return the information as a JobStatus object. If the command returns exit code 1 it means that the job was not found, other non-zero exit code probably means that there is some kind of error. A JobStatus instance is only returned if the exit status is 0. Note! The cluster is only queried the first time this method is called which will retrieve and cache information about all queued/running jobs. Calling this method more than once will use the cached information.- Parameters:
jobId
- Identifier for the jobuseLocalTimeAdjustment
- TRUE if the times from the cluster should be adjusted to match local time on this server
-
qacct
Issue a command to find out information about a job that has ended. The result is parsed and returned as a JobStatus object. If the command returns exit code 1 it means that the job was not found, other non-zero exit code probably means that there is some kind of error. A JobStatus instance is only returned if the exit status is 0.- Parameters:
jobId
- Identifier for the jobuseLocalTimeAdjustment
- TRUE if the times from the cluster should be adjusted to match local time on this server
-
readProgress
Read the 'progress' information for the job and update job status instance.- Parameters:
jobStatus
- The job status instance to update with the progress information- Returns:
- A CmdResult with the same JobStatus instance in the result
-
readStderr
Read the 'stderr' file and update the message in the job status instance.- Parameters:
jobStatus
- The job status instance to update with the progress information- Returns:
- A CmdResult with the same JobStatus instance in the result
-
getJobFileAsString
Utility method for downloading a result file from a job as a text file.- Parameters:
jobName
- The name of the jobfilename
- The name of the fileencoding
- Encoding to use (UTF-8 is recommended, but it depends on the program the created it)- Returns:
- The file data as a string
-