Class OpenGridSession

All Implemented Interfaces:
Closeable, AutoCloseable

public class OpenGridSession
extends AbstractSession<OpenGridCluster>
implements Closeable
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
  • Field Details

  • Constructor Details

  • Method Details

    • executeOnNode

      public CmdResult<String> executeOnNode​(String cmd, String node, int timeout)
      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:
      AbstractSession.executeCmd(String, int)
    • executeNow

      public CmdResult<String> executeNow​(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. 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 to executeOnNode(String, String, int)
      Since:
      1.5
    • getClusterDate

      public CmdResult<Date> getClusterDate()
      Get the current date and time of the cluster node.
    • getHostInfo

      public CmdResult<String> getHostInfo()
      Utility method for getting information about the cluster hardware and operating system by executing the ClusterConfig.getHostInfoCommand().
    • getOpenGridInfo

      public CmdResult<String> getOpenGridInfo()
      Utility method for getting information about the Open Grid Scheduler software version by executing the ClusterConfig.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

      public CmdResult<List<JobStatus>> qsub​(DbControl dc, List<JobDefinition> jobs)
      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 otherwise
      jobs - 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

      public CmdResult<String> qdel​(JobIdentifier jobId)
      Abort the job with the specified job id.
    • qstat

      public CmdResult<JobStatus> qstat​(JobIdentifier jobId, boolean useLocalTimeAdjustment)
      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 job
      useLocalTimeAdjustment - TRUE if the times from the cluster should be adjusted to match local time on this server
    • qacct

      public CmdResult<JobStatus> qacct​(JobIdentifier jobId, boolean useLocalTimeAdjustment)
      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 job
      useLocalTimeAdjustment - TRUE if the times from the cluster should be adjusted to match local time on this server
    • readProgress

      public CmdResult<JobStatus> readProgress​(JobStatus jobStatus)
      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

      public CmdResult<JobStatus> readStderr​(JobStatus jobStatus)
      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

      public String getJobFileAsString​(String jobName, String filename, String encoding)
      Utility method for downloading a result file from a job as a text file.
      Parameters:
      jobName - The name of the job
      filename - The name of the file
      encoding - Encoding to use (UTF-8 is recommended, but it depends on the program the created it)
      Returns:
      The file data as a string