Search in sources :

Example 86 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace 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 in case if action cannot be executed
 */
@SuppressFBWarnings(value = { "COMMAND_INJECTION", "PATH_TRAVERSAL_OUT" }, justification = "Tracker URI is specified in the WF action, and action dir path is from context")
@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;
    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 StringBuffer outBuffer = getActionOutputMessage(dataCommand);
                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);
            String actionErrorMsg = getActionErrorMessage(context, action);
            LOG.warn("{0}: Script failed on remote host with [{1}]", ErrorCode.E1111, actionErrorMsg);
            context.setErrorInfo(ErrorCode.E1111.toString(), actionErrorMsg);
        } 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.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom2.JDOMException) Namespace(org.jdom2.Namespace) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 87 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class SshActionExecutor method start.

/**
 * Start the ssh action execution.
 *
 * @param context action execution context.
 * @param action action object.
 * @throws org.apache.oozie.action.ActionExecutorException in case if action cannot be executed
 */
@SuppressWarnings("unchecked")
@Override
public void start(final Context context, final WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    String confStr = action.getConf();
    Element conf;
    try {
        conf = XmlUtils.parseXml(confStr);
    } catch (Exception ex) {
        throw convertException(ex);
    }
    Namespace nameSpace = conf.getNamespace();
    Element hostElement = conf.getChild("host", nameSpace);
    String hostString = hostElement.getValue().trim();
    hostString = prepareUserHost(hostString, context);
    final String host = hostString;
    final String dirLocation = execute(new Callable<String>() {

        public String call() throws Exception {
            return setupRemote(host, context, action);
        }
    });
    String runningPid = execute(new Callable<String>() {

        public String call() throws Exception {
            return checkIfRunning(host, context, action);
        }
    });
    String pid = "";
    LOG.trace("runningPid={0}", runningPid);
    if (runningPid == null) {
        final Element commandElement = conf.getChild("command", nameSpace);
        final boolean ignoreOutput = conf.getChild("capture-output", nameSpace) == null;
        boolean preserve = false;
        if (commandElement != null) {
            String[] args = null;
            // Will either have <args>, <arg>, or neither (but not both)
            List<Element> argsList = conf.getChildren("args", nameSpace);
            // Arguments in an <args> are "flattened" (spaces are delimiters)
            if (argsList != null && argsList.size() > 0) {
                StringBuilder argsString = new StringBuilder("");
                for (Element argsElement : argsList) {
                    argsString = argsString.append(argsElement.getValue()).append(" ");
                }
                args = new String[] { argsString.toString() };
            } else {
                // Arguments in an <arg> are preserved, even with spaces
                argsList = conf.getChildren("arg", nameSpace);
                if (argsList != null && argsList.size() > 0) {
                    preserve = true;
                    args = new String[argsList.size()];
                    for (int i = 0; i < argsList.size(); i++) {
                        Element argsElement = argsList.get(i);
                        args[i] = argsElement.getValue();
                        // them or escape their space (because the scripts will split them up otherwise)
                        if (args[i].contains(" ") && !(args[i].startsWith("\"") && args[i].endsWith("\"") || args[i].startsWith("'") && args[i].endsWith("'"))) {
                            args[i] = StringUtils.escapeString(args[i], '\\', ' ');
                        }
                    }
                }
            }
            final String[] argsF = args;
            final String recoveryId = context.getRecoveryId();
            final boolean preserveF = preserve;
            pid = execute(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return doExecute(host, dirLocation, commandElement.getValue(), argsF, ignoreOutput, action, recoveryId, preserveF);
                }
            });
        }
        context.setStartData(pid, host, host);
    } else {
        pid = runningPid;
        context.setStartData(pid, host, host);
        check(context, action);
    }
}
Also used : Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException) Namespace(org.jdom2.Namespace) Callable(java.util.concurrent.Callable)

Example 88 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class Hive2ActionExecutor method setupActionConf.

@Override
@SuppressWarnings("unchecked")
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
    Configuration conf = super.setupActionConf(actionConf, context, actionXml, appPath);
    Namespace ns = actionXml.getNamespace();
    String jdbcUrl = actionXml.getChild("jdbc-url", ns).getTextTrim();
    conf.set(HIVE2_JDBC_URL, jdbcUrl);
    String password = null;
    Element passwordElement = actionXml.getChild("password", ns);
    if (passwordElement != null) {
        password = actionXml.getChild("password", ns).getTextTrim();
        conf.set(HIVE2_PASSWORD, password);
    }
    Element queryElement = actionXml.getChild("query", ns);
    Element scriptElement = actionXml.getChild("script", ns);
    if (scriptElement != null) {
        String script = scriptElement.getTextTrim();
        String scriptName = new Path(script).getName();
        this.addScriptToCache = true;
        conf.set(HIVE2_SCRIPT, scriptName);
    } else if (queryElement != null) {
        // Unable to use getTextTrim due to https://issues.apache.org/jira/browse/HIVE-8182
        String query = queryElement.getText();
        conf.set(HIVE2_QUERY, query);
    } else {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "INVALID_ARGUMENTS", "Hive 2 action requires one of <script> or <query> to be set. Neither were found.");
    }
    List<Element> params = (List<Element>) actionXml.getChildren("param", ns);
    String[] strParams = new String[params.size()];
    for (int i = 0; i < params.size(); i++) {
        strParams[i] = params.get(i).getTextTrim();
    }
    ActionUtils.setStrings(conf, HIVE2_PARAMS, strParams);
    String[] strArgs = null;
    List<Element> eArgs = actionXml.getChildren("argument", ns);
    if (eArgs != null && eArgs.size() > 0) {
        strArgs = new String[eArgs.size()];
        for (int i = 0; i < eArgs.size(); i++) {
            strArgs[i] = eArgs.get(i).getTextTrim();
        }
    }
    ActionUtils.setStrings(conf, HIVE2_ARGS, strArgs);
    return conf;
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) ArrayList(java.util.ArrayList) Namespace(org.jdom2.Namespace)

Example 89 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class HiveActionExecutor method setupActionConf.

@Override
@SuppressWarnings("unchecked")
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
    Configuration conf = super.setupActionConf(actionConf, context, actionXml, appPath);
    Namespace ns = actionXml.getNamespace();
    Element scriptElement = actionXml.getChild("script", ns);
    Element queryElement = actionXml.getChild("query", ns);
    if (scriptElement != null) {
        String script = scriptElement.getTextTrim();
        String scriptName = new Path(script).getName();
        this.addScriptToCache = true;
        conf.set(HIVE_SCRIPT, scriptName);
    } else if (queryElement != null) {
        // Unable to use getTextTrim due to https://issues.apache.org/jira/browse/HIVE-8182
        String query = queryElement.getText();
        conf.set(HIVE_QUERY, query);
    } else {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "INVALID_ARGUMENTS", "Hive action requires one of <script> or <query> to be set. Neither were found.");
    }
    List<Element> params = (List<Element>) actionXml.getChildren("param", ns);
    String[] strParams = new String[params.size()];
    for (int i = 0; i < params.size(); i++) {
        strParams[i] = params.get(i).getTextTrim();
    }
    ActionUtils.setStrings(conf, HIVE_PARAMS, strParams);
    String[] strArgs = null;
    List<Element> eArgs = actionXml.getChildren("argument", ns);
    if (eArgs != null && eArgs.size() > 0) {
        strArgs = new String[eArgs.size()];
        for (int i = 0; i < eArgs.size(); i++) {
            strArgs[i] = eArgs.get(i).getTextTrim();
        }
    }
    ActionUtils.setStrings(conf, HIVE_ARGS, strArgs);
    return conf;
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) ArrayList(java.util.ArrayList) Namespace(org.jdom2.Namespace)

Example 90 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class JavaActionExecutor method handleJavaOpts.

private boolean handleJavaOpts(Element actionXml, StringBuilder javaOpts) {
    Namespace ns = actionXml.getNamespace();
    boolean oldJavaOpts = false;
    @SuppressWarnings("unchecked") List<Element> javaopts = actionXml.getChildren("java-opt", ns);
    for (Element opt : javaopts) {
        javaOpts.append(" ").append(opt.getTextTrim());
        oldJavaOpts = true;
    }
    Element opt = actionXml.getChild("java-opts", ns);
    if (opt != null) {
        javaOpts.append(" ").append(opt.getTextTrim());
        oldJavaOpts = true;
    }
    if (oldJavaOpts) {
        LOG.warn("Note: <java-opts> inside the action is used in the workflow. Please move <java-opts> tag under" + " the <launcher> element. See the documentation for details");
    }
    return oldJavaOpts;
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Namespace (org.jdom2.Namespace)105 Element (org.jdom2.Element)87 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 ArrayList (java.util.ArrayList)16 Configuration (org.apache.hadoop.conf.Configuration)15 HashMap (java.util.HashMap)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 StringReader (java.io.StringReader)13 List (java.util.List)13 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)10 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)9 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)9 Attribute (org.jdom2.Attribute)9 Writer (java.io.Writer)8 RegistrationServiceClient (com.google.cloud.servicedirectory.v1.RegistrationServiceClient)7 Map (java.util.Map)7 Document (org.jdom2.Document)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6