Search in sources :

Example 61 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class JavaActionExecutor method createLauncherConf.

@SuppressWarnings("unchecked")
Configuration createLauncherConf(FileSystem actionFs, Context context, WorkflowAction action, Element actionXml, Configuration actionConf) throws ActionExecutorException {
    try {
        // app path could be a file
        Path appPathRoot = new Path(context.getWorkflow().getAppPath());
        if (actionFs.isFile(appPathRoot)) {
            appPathRoot = appPathRoot.getParent();
        }
        // launcher job configuration
        Configuration launcherJobConf = createBaseHadoopConf(context, actionXml);
        // cancel delegation token on a launcher job which stays alive till child job(s) finishes
        // otherwise (in mapred action), doesn't cancel not to disturb running child job
        launcherJobConf.setBoolean("mapreduce.job.complete.cancel.delegation.tokens", true);
        setupLauncherConf(launcherJobConf, actionXml, appPathRoot, context);
        // Properties for when a launcher job's AM gets restarted
        if (ConfigurationService.getBoolean(HADOOP_YARN_KILL_CHILD_JOBS_ON_AMRESTART)) {
            // launcher time filter is required to prune the search of launcher tag.
            // Setting coordinator action nominal time as launcher time as it child job cannot launch before nominal
            // time. Workflow created time is good enough when workflow is running independently or workflow is
            // rerunning from failed node.
            long launcherTime = System.currentTimeMillis();
            String coordActionNominalTime = context.getProtoActionConf().get(CoordActionStartXCommand.OOZIE_COORD_ACTION_NOMINAL_TIME);
            if (coordActionNominalTime != null) {
                launcherTime = Long.parseLong(coordActionNominalTime);
            } else if (context.getWorkflow().getCreatedTime() != null) {
                launcherTime = context.getWorkflow().getCreatedTime().getTime();
            }
            String actionYarnTag = getActionYarnTag(getWorkflowConf(context), context.getWorkflow(), action);
            LauncherHelper.setupYarnRestartHandling(launcherJobConf, actionConf, actionYarnTag, launcherTime);
        } else {
            LOG.info(MessageFormat.format("{0} is set to false, not setting YARN restart properties", HADOOP_YARN_KILL_CHILD_JOBS_ON_AMRESTART));
        }
        String actionShareLibProperty = actionConf.get(ACTION_SHARELIB_FOR + getType());
        if (actionShareLibProperty != null) {
            launcherJobConf.set(ACTION_SHARELIB_FOR + getType(), actionShareLibProperty);
        }
        setLibFilesArchives(context, actionXml, appPathRoot, launcherJobConf);
        // Inject Oozie job information if enabled.
        injectJobInfo(launcherJobConf, actionConf, context, action);
        injectLauncherCallback(context, launcherJobConf);
        String jobId = context.getWorkflow().getId();
        String actionId = action.getId();
        Path actionDir = context.getActionDir();
        String recoveryId = context.getRecoveryId();
        // Getting the prepare XML from the action XML
        Namespace ns = actionXml.getNamespace();
        Element prepareElement = actionXml.getChild("prepare", ns);
        String prepareXML = "";
        if (prepareElement != null) {
            if (prepareElement.getChildren().size() > 0) {
                prepareXML = XmlUtils.prettyPrint(prepareElement).toString().trim();
            }
        }
        LauncherHelper.setupLauncherInfo(launcherJobConf, jobId, actionId, actionDir, recoveryId, actionConf, prepareXML);
        // Set the launcher Main Class
        LauncherHelper.setupMainClass(launcherJobConf, getLauncherMain(launcherJobConf, actionXml));
        LauncherHelper.setupLauncherURIHandlerConf(launcherJobConf);
        LauncherHelper.setupMaxOutputData(launcherJobConf, getMaxOutputData(actionConf));
        LauncherHelper.setupMaxExternalStatsSize(launcherJobConf, maxExternalStatsSize);
        LauncherHelper.setupMaxFSGlob(launcherJobConf, maxFSGlobMax);
        List<Element> list = actionXml.getChildren("arg", ns);
        String[] args = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            args[i] = list.get(i).getTextTrim();
        }
        LauncherHelper.setupMainArguments(launcherJobConf, args);
        // backward compatibility flag - see OOZIE-2872
        boolean nullArgsAllowed = ConfigurationService.getBoolean(LauncherAMUtils.CONF_OOZIE_NULL_ARGS_ALLOWED);
        launcherJobConf.setBoolean(LauncherAMUtils.CONF_OOZIE_NULL_ARGS_ALLOWED, nullArgsAllowed);
        // Make mapred.child.java.opts and mapreduce.map.java.opts equal, but give values from the latter priority; also append
        // <java-opt> and <java-opts> and give those highest priority
        StringBuilder opts = new StringBuilder(launcherJobConf.get(HADOOP_CHILD_JAVA_OPTS, ""));
        if (launcherJobConf.get(HADOOP_MAP_JAVA_OPTS) != null) {
            opts.append(" ").append(launcherJobConf.get(HADOOP_MAP_JAVA_OPTS));
        }
        List<Element> javaopts = actionXml.getChildren("java-opt", ns);
        // Either one or more <java-opt> element or one <java-opts> can be present since oozie-workflow-0.4
        if (!javaopts.isEmpty()) {
            for (Element opt : javaopts) {
                opts.append(" ").append(opt.getTextTrim());
            }
        } else {
            Element opt = actionXml.getChild("java-opts", ns);
            if (opt != null) {
                opts.append(" ").append(opt.getTextTrim());
            }
        }
        launcherJobConf.set(HADOOP_CHILD_JAVA_OPTS, opts.toString().trim());
        launcherJobConf.set(HADOOP_MAP_JAVA_OPTS, opts.toString().trim());
        injectLauncherTimelineServiceEnabled(launcherJobConf, actionConf);
        // properties from action that are needed by the launcher (e.g. QUEUE NAME, ACLs)
        // maybe we should add queue to the WF schema, below job-tracker
        actionConfToLauncherConf(actionConf, launcherJobConf);
        return launcherJobConf;
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Element(org.jdom.Element) Namespace(org.jdom.Namespace) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ConnectException(java.net.ConnectException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException)

Example 62 with Namespace

use of org.jdom.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.jdom.Element) Namespace(org.jdom.Namespace)

Example 63 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class PigActionExecutor method setupActionConf.

@Override
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
    super.setupActionConf(actionConf, context, actionXml, appPath);
    Namespace ns = actionXml.getNamespace();
    String script = actionXml.getChild("script", ns).getTextTrim();
    String pigName = new Path(script).getName();
    @SuppressWarnings("unchecked") List<Element> params = actionXml.getChildren("param", ns);
    String[] strParams = new String[params.size()];
    for (int i = 0; i < params.size(); i++) {
        strParams[i] = params.get(i).getTextTrim();
    }
    String[] strArgs = null;
    @SuppressWarnings("unchecked") 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();
        }
    }
    setPigScript(actionConf, pigName, strParams, strArgs);
    return actionConf;
}
Also used : Path(org.apache.hadoop.fs.Path) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 64 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class DecisionActionExecutor method start.

@SuppressWarnings("unchecked")
public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    try {
        String confStr = action.getConf();
        context.setStartData("-", "-", "-");
        Element conf = XmlUtils.parseXml(confStr);
        Namespace ns = conf.getNamespace();
        String externalState = null;
        for (Element eval : (List<Element>) conf.getChildren("case", ns)) {
            if (TRUE.equals(eval.getTextTrim())) {
                externalState = eval.getAttributeValue("to");
                break;
            }
        }
        if (externalState == null) {
            Element def = conf.getChild("default", ns);
            if (def != null) {
                externalState = def.getAttributeValue("to");
            }
        }
        if (externalState == null) {
            throw new IllegalStateException("Transition cannot be NULL");
        }
        // for decision we are piggybacking on external status to transfer the transition,
        // the {@link ActionEndCommand} does the special handling of setting it as signal value.
        context.setExecutionData(externalState, null);
    } catch (JDOMException ex) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, XML_ERROR, ex.getMessage(), ex);
    }
}
Also used : Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 65 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class ShellActionExecutor method setupActionConf.

@Override
Configuration setupActionConf(Configuration actionConf, Context context, Element actionXml, Path appPath) throws ActionExecutorException {
    super.setupActionConf(actionConf, context, actionXml, appPath);
    Namespace ns = actionXml.getNamespace();
    String exec = actionXml.getChild("exec", ns).getTextTrim();
    String execName = new Path(exec).getName();
    actionConf.set(ShellMain.CONF_OOZIE_SHELL_EXEC, execName);
    // Setting Shell command's arguments
    setListInConf("argument", actionXml, actionConf, ShellMain.CONF_OOZIE_SHELL_ARGS, false);
    // Setting Shell command's environment variable key=value
    setListInConf("env-var", actionXml, actionConf, ShellMain.CONF_OOZIE_SHELL_ENVS, true);
    // Setting capture output flag
    actionConf.setBoolean(ShellMain.CONF_OOZIE_SHELL_CAPTURE_OUTPUT, actionXml.getChild("capture-output", ns) != null);
    // Setting if ShellMain should setup HADOOP_CONF_DIR
    boolean setupHadoopConfDir = actionConf.getBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR, ConfigurationService.getBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR));
    actionConf.setBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR, setupHadoopConfDir);
    // Setting to control if ShellMain should write log4j.properties
    boolean writeL4J = actionConf.getBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_WRITE_LOG4J_PROPERTIES, ConfigurationService.getBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_WRITE_LOG4J_PROPERTIES));
    actionConf.setBoolean(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_WRITE_LOG4J_PROPERTIES, writeL4J);
    // Setting of content of log4j.properties, if to be written
    if (writeL4J) {
        String l4jContent = actionConf.get(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_LOG4J_CONTENT, ConfigurationService.get(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_LOG4J_CONTENT));
        actionConf.set(ShellMain.CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR_LOG4J_CONTENT, l4jContent);
    }
    return actionConf;
}
Also used : Path(org.apache.hadoop.fs.Path) Namespace(org.jdom.Namespace)

Aggregations

Namespace (org.jdom.Namespace)102 Element (org.jdom.Element)85 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)15 Configuration (org.apache.hadoop.conf.Configuration)15 JDOMException (org.jdom.JDOMException)15 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)13 ArrayList (java.util.ArrayList)12 Path (org.apache.hadoop.fs.Path)11 Document (org.jdom.Document)11 List (java.util.List)9 File (java.io.File)7 HashMap (java.util.HashMap)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 SAXBuilder (org.jdom.input.SAXBuilder)6 XMLOutputter (org.jdom.output.XMLOutputter)6 Writer (java.io.Writer)5 Attribute (org.jdom.Attribute)5 Format (org.jdom.output.Format)5