Package net.sf.basedb.opengrid
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.PendingJobsCmd
,SlurmEngine.SacctCmd
,SlurmEngine.SqueueCmd
,SlurmEngine.StatusCmd
Holds the result from executing a single command on a cluster.
- Since:
- 1.0
- Author:
- nicklas
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An implementation that parses the 'stdout' to a date if the exit code is 0.static class
An implementation that set the result to 'stdout' if the exit code is 0, and to 'stderr' if not. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.json.simple.JSONObject
asJSONObject
(JSONOptions options) Get the information in this result as a JSON object.getCmd()
Get the command that was executed.Get the exception that may have caused a failure.int
Get the exit status of the command.int
getHardTimeout
(int timeout) Calculate a hard timeout for the command that depends on the given soft timeout.Get the result that was parsed from the command output.Get the text written to standard error stream from the command.Get the text written to the standard output stream from the command.protected void
This method is called after the command has been executed and the exit code, stdout and stderr has been updated.protected void
protected void
setExitStatus
(int exitStatus) protected void
protected void
protected void
void
Throws an exception if the exist status is not 0.toString()
-
Field Details
-
cmd
-
exitStatus
private int exitStatus -
stdout
-
stderr
-
result
-
exception
-
-
Constructor Details
-
CmdResult
Creates a new result instance. -
CmdResult
Clone a cmd result instance except for the result field.
-
-
Method Details
-
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 toAbstractSession.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
-
getResult
Get the result that was parsed from the command output. Normally, the result is only available if the exit status is 0. However theAbstractSession.executeCmd(String, int)
will return stderr as the result if the command failed. -
setStdout
-
getStdout
Get the text written to the standard output stream from the command. -
setStderr
-
getStderr
Get the text written to standard error stream from the command. -
setException
-
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 bysetException(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
-
asJSONObject
Get the information in this result as a JSON object. The following properties are set by default: cmd exitStatus stdout stderr
-