* @param context action execution context.
* @param action action object.
*/
@Override
public void check(Context context, WorkflowAction action) throws ActionExecutorException {
Status status = getActionStatus(context, action);
boolean captureOutput = false;
try {
Element eConf = XmlUtils.parseXml(action.getConf());
Namespace ns = eConf.getNamespace();
captureOutput = eConf.getChild("capture-output", ns) != null;
}
catch (JDOMException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_XML_PARSE_FAILED",
"unknown error", ex);
}
XLog log = XLog.getLog(getClass());
log.debug("Capture Output: {0}", captureOutput);
if (status == Status.OK) {
if (captureOutput) {
String outFile = getRemoteFileName(context, action, "stdout", false, true);
String dataCommand = SSH_COMMAND_BASE + action.getTrackerUri() + " cat " + outFile;
log.debug("Ssh command [{0}]", dataCommand);
try {
Process process = Runtime.getRuntime().exec(dataCommand.split("\\s"));
StringBuffer buffer = new StringBuffer();
boolean overflow = false;
drainBuffers(process, buffer, null, maxLen);
if (buffer.length() > maxLen) {
overflow = true;
}
if (overflow) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR,
"ERR_OUTPUT_EXCEED_MAX_LEN", "unknown error");
}
context.setExecutionData(status.toString(), PropertiesUtils.stringToProperties(buffer.toString()));
}
catch (Exception ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_UNKNOWN_ERROR",
"unknown error", ex);
}
}
else {
context.setExecutionData(status.toString(), null);
}
}
else {
if (status == Status.ERROR) {
context.setExecutionData(status.toString(), null);
}
else {
context.setExternalStatus(status.toString());
}
}
}