Search in sources :

Example 1 with Status

use of org.apache.oozie.client.WorkflowAction.Status in project oozie by apache.

the class SshActionExecutor method getActionStatus.

/**
 * Get action status.
 *
 * @param context
 * @param action action object.
 * @return status of the action(RUNNING/OK/ERROR).
 * @throws ActionExecutorException thrown if there is any error in getting status.
 */
protected Status getActionStatus(Context context, WorkflowAction action) throws ActionExecutorException {
    String command = SSH_COMMAND_BASE + action.getTrackerUri() + " ps -p " + action.getExternalId();
    Status aStatus;
    int returnValue = getReturnValue(command);
    if (returnValue == 0) {
        aStatus = Status.RUNNING;
    } else {
        String outFile = getRemoteFileName(context, action, "error", false, true);
        String checkErrorCmd = SSH_COMMAND_BASE + action.getTrackerUri() + " ls " + outFile;
        int retVal = getReturnValue(checkErrorCmd);
        if (retVal == 0) {
            aStatus = Status.ERROR;
        } else {
            aStatus = Status.OK;
        }
    }
    return aStatus;
}
Also used : Status(org.apache.oozie.client.WorkflowAction.Status)

Example 2 with Status

use of org.apache.oozie.client.WorkflowAction.Status in project oozie by apache.

the class SshActionExecutor method check.

/**
 * Check ssh action status.
 *
 * @param context action execution context.
 * @param action action object.
 * @throws org.apache.oozie.action.ActionExecutorException
 */
@Override
public void check(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.trace("check() start for action={0}", action.getId());
    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);
    }
    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 {
                final Process process = Runtime.getRuntime().exec(dataCommand.split("\\s"));
                final StringBuffer outBuffer = new StringBuffer();
                final StringBuffer errBuffer = new StringBuffer();
                boolean overflow = false;
                drainBuffers(process, outBuffer, errBuffer, maxLen);
                LOG.trace("outBuffer={0}", outBuffer);
                LOG.trace("errBuffer={0}", errBuffer);
                if (outBuffer.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(outBuffer.toString()));
                LOG.trace("Execution data set. status={0}, properties={1}", status, PropertiesUtils.stringToProperties(outBuffer.toString()));
            } catch (Exception ex) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_UNKNOWN_ERROR", "unknown error", ex);
            }
        } else {
            LOG.trace("Execution data set to null. status={0}", status);
            context.setExecutionData(status.toString(), null);
        }
    } else {
        if (status == Status.ERROR) {
            LOG.warn("Execution data set to null in ERROR");
            context.setExecutionData(status.toString(), null);
        } else {
            LOG.warn("Execution data not set");
            context.setExternalStatus(status.toString());
        }
    }
    LOG.trace("check() end for action={0}", action);
}
Also used : Status(org.apache.oozie.client.WorkflowAction.Status) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Aggregations

Status (org.apache.oozie.client.WorkflowAction.Status)2 IOException (java.io.IOException)1 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 Namespace (org.jdom.Namespace)1