Class CmdResult<R>

java.lang.Object
net.sf.basedb.opengrid.CmdResult<R>
Direct Known Subclasses:
CmdResult.DateResult, CmdResult.StdioResult, DirectEngine.StatusCmd, OpenGridEngine.QacctCmd, OpenGridEngine.QstatCmd, OpenGridEngine.QstatXmlCmd, SlurmEngine.SacctCmd, SlurmEngine.SqueueCmd, SlurmEngine.StatusCmd

public class CmdResult<R>
extends Object
Holds the result from executing a single command on a cluster.
Since:
1.0
Author:
nicklas
  • Field Details

    • cmd

      private final String cmd
    • exitStatus

      private int exitStatus
    • stdout

      private String stdout
    • stderr

      private String stderr
    • result

      private R result
    • exception

      private RuntimeException exception
  • Constructor Details

    • CmdResult

      public CmdResult​(String cmd)
      Creates a new result instance.
    • CmdResult

      public CmdResult​(CmdResult<?> other)
      Clone a cmd result instance except for the result field.
  • Method Details

    • getCmd

      public String getCmd()
      Get the command that was executed.
    • getHardTimeout

      public int getHardTimeout​(int timeout)
      Calculate a hard timeout for the command that depends on the given soft timeout. The soft timeout is the timeout that is given to AbstractSession.execute(CmdResult, int). If the command has not finished after the soft timeout it is allowed to continue as long as it is providing data on either the stdout or stderr stream until the hard timeout is reached. If this happens the command is aborted. The default implementation allows a hard timeout that is 10 times longer than the soft timeout. Subclasses may override this implementation if the need a different timeout.
      Parameters:
      timeout - The soft timeout in seconds
      Returns:
      The hard timeout in seconds
      Since:
      1.4
    • setExitStatus

      protected void setExitStatus​(int exitStatus)
    • getExitStatus

      public int getExitStatus()
      Get the exit status of the command. A value of 0 should indicate success, all other values some kind of error.
    • setResult

      protected void setResult​(R result)
    • getResult

      public R getResult()
      Get the result that was parsed from the command output. Normally, the result is only available if the exit status is 0. However the AbstractSession.executeCmd(String, int) will return stderr as the result if the command failed.
    • setStdout

      protected void setStdout​(String stdout)
    • getStdout

      public String getStdout()
      Get the text written to the standard output stream from the command.
    • setStderr

      protected void setStderr​(String stderr)
    • getStderr

      public String getStderr()
      Get the text written to standard error stream from the command.
    • setException

      protected void setException​(Exception ex)
    • getException

      public RuntimeException getException()
      Get the exception that may have caused a failure. Exception are typically indications that something was wrong on the local server and not the remote server.
    • throwExceptionIfNonZeroExitStatus

      public void throwExceptionIfNonZeroExitStatus()
      Throws an exception if the exist status is not 0. If an exception has been set by setException(Exception) that exception is re-thrown, otherwise a new RuntimeException is created with stderr (or stdout in case stderr is empty) as the message text.
    • parseResult

      protected void parseResult()
      This method is called after the command has been executed and the exit code, stdout and stderr has been updated. Subclasses can override this method to take actions. The default implementation does nothing.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • asJSONObject

      public org.json.simple.JSONObject asJSONObject​(JSONOptions options)
      Get the information in this result as a JSON object. The following properties are set by default: cmd exitStatus stdout stderr