Search in sources :

Example 11 with WorkflowAction

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

the class TestSharelibConfigs method getJavaActionConfiguration.

private XConfiguration getJavaActionConfiguration(WorkflowJob workflow) throws Exception {
    final WorkflowAction workflowAction = helper.getJavaAction(workflow);
    final Element element = XmlUtils.parseXml(workflowAction.getConf());
    final String configuration = XmlUtils.prettyPrint(element.getChild("configuration", element.getNamespace())).toString();
    return new XConfiguration(new StringReader(configuration));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowAction(org.apache.oozie.client.WorkflowAction) Element(org.jdom.Element) StringReader(java.io.StringReader)

Example 12 with WorkflowAction

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

the class TestShellActionExecutor method testShellScriptHadoopConfDir.

/**
 * Test if a shell script could run successfully with {@link ShellMain#CONF_OOZIE_SHELL_SETUP_HADOOP_CONF_DIR} enabled.
 *
 * @throws Exception
 */
public void testShellScriptHadoopConfDir() throws Exception {
    FileSystem fs = getFileSystem();
    // Create the script file with canned shell command
    Path script = new Path(getAppPath(), SHELL_SCRIPTNAME);
    Writer w = new OutputStreamWriter(fs.create(script));
    w.write(SHELL_SCRIPT_HADOOP_CONF_DIR_CONTENT);
    w.write(SHELL_SCRIPT_YARN_CONF_DIR_CONTENT);
    w.write(SHELL_SCRIPT_LOG4J_EXISTENCE_CHECKER);
    w.write(SHELL_SCRIPT_LOG4J_CONTENT_COUNTER);
    w.close();
    // Create sample Shell action xml
    String actionXml = "<shell>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<configuration>" + "<property><name>oozie.action.shell.setup.hadoop.conf.dir</name><value>true</value></property>" + "</configuration>" + "<exec>" + SHELL_EXEC + "</exec>" + "<argument>" + SHELL_PARAM + "</argument>" + "<argument>" + SHELL_SCRIPTNAME + "</argument>" + "<file>" + script.toString() + "#" + script.getName() + "</file>" + "<capture-output/>" + "</shell>";
    // Submit and verify the job's status
    WorkflowAction action = _testSubmit(actionXml, true, "");
    String oozieActionConfXml = PropertiesUtils.stringToProperties(action.getData()).getProperty("OOZIE_ACTION_CONF_XML");
    String hadoopConfDir = PropertiesUtils.stringToProperties(action.getData()).getProperty("HADOOP_CONF_DIR");
    String yarnConfDir = PropertiesUtils.stringToProperties(action.getData()).getProperty("YARN_CONF_DIR");
    String log4jExists = PropertiesUtils.stringToProperties(action.getData()).getProperty("L4J_EXISTS");
    String log4jFileLineCount = PropertiesUtils.stringToProperties(action.getData()).getProperty("L4J_LC");
    String log4BadAppenderCount = PropertiesUtils.stringToProperties(action.getData()).getProperty("L4J_APPENDER");
    assertNotNull(oozieActionConfXml);
    assertNotNull(hadoopConfDir);
    String s = new File(oozieActionConfXml).getParent() + File.separator + "oozie-hadoop-conf-";
    Assert.assertTrue("Expected HADOOP_CONF_DIR to start with " + s + " but was " + hadoopConfDir, hadoopConfDir.startsWith(s));
    Assert.assertTrue("Expected YARN_CONF_DIR to start with " + s + " but was " + yarnConfDir, yarnConfDir.startsWith(s));
    Assert.assertEquals("Expected log4j.properties file to exist", "yes", log4jExists);
    Assert.assertTrue("Expected log4j.properties to have non-zero line count, but has: " + log4jFileLineCount, Integer.parseInt(log4jFileLineCount) > 0);
    Assert.assertEquals("Expected log4j.properties to have no container appender references (CLA/CLRA)", 0, Integer.parseInt(log4BadAppenderCount));
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 13 with WorkflowAction

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

the class TestShellActionExecutor method submitAction.

/**
 * Submit the Shell action using Shell ActionExecutor
 *
 * @param context
 * @return The RunningJob of the Launcher Mapper
 * @throws Exception
 */
private String submitAction(Context context) throws Exception {
    ShellActionExecutor ae = new ShellActionExecutor();
    WorkflowAction action = context.getAction();
    ae.prepareActionDir(getFileSystem(), context);
    // Submit the action
    ae.submitLauncher(getFileSystem(), context, action);
    String jobId = action.getExternalId();
    String jobTracker = action.getTrackerUri();
    String consoleUrl = action.getConsoleUrl();
    assertNotNull(jobId);
    assertNotNull(jobTracker);
    assertNotNull(consoleUrl);
    return jobId;
}
Also used : WorkflowAction(org.apache.oozie.client.WorkflowAction)

Example 14 with WorkflowAction

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

the class TestShellActionExecutor method testEnvVar.

/**
 * Test that env variable can contain '=' symbol within value
 *
 * @throws Exception
 */
public void testEnvVar() throws Exception {
    Services.get().destroy();
    Services services = new Services();
    services.getConf().setInt(LauncherAMUtils.CONF_OOZIE_ACTION_MAX_OUTPUT_DATA, 8 * 1042);
    services.init();
    FileSystem fs = getFileSystem();
    // Create the script file with canned shell command
    Path script = new Path(getAppPath(), SHELL_SCRIPTNAME);
    Writer w = new OutputStreamWriter(fs.create(script));
    w.write(SHELL_SCRIPT_CONTENT_ENVVAR);
    w.close();
    String envValueHavingEqualSign = "a=b;c=d";
    // Create sample shell action xml
    String actionXml = "<shell>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<exec>" + SHELL_EXEC + "</exec>" + "<argument>" + SHELL_PARAM + "</argument>" + "<argument>" + SHELL_SCRIPTNAME + "</argument>" + "<argument>A</argument>" + "<argument>B</argument>" + "<env-var>var1=val1</env-var>" + "<env-var>var2=" + envValueHavingEqualSign + "</env-var>" + "<file>" + script.toString() + "#" + script.getName() + "</file>" + "<capture-output />" + "</shell>";
    Context context = createContext(actionXml);
    // Submit the action
    final String launcherId = submitAction(context);
    waitUntilYarnAppDoneAndAssertSuccess(launcherId);
    ShellActionExecutor ae = new ShellActionExecutor();
    WorkflowAction action = context.getAction();
    ae.check(context, action);
    ae.end(context, action);
    // Checking action data from shell script output
    assertEquals(envValueHavingEqualSign, PropertiesUtils.stringToProperties(action.getData()).getProperty("var2"));
}
Also used : Path(org.apache.hadoop.fs.Path) Services(org.apache.oozie.service.Services) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 15 with WorkflowAction

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

the class WorkflowGraphHandler method fillWorkflowActions.

private Map<String, WorkflowAction> fillWorkflowActions() {
    final Map<String, WorkflowAction> workflowActions = new LinkedHashMap<>();
    boolean found = false;
    for (final WorkflowAction wfAction : job.getActions()) {
        workflowActions.put(wfAction.getName(), wfAction);
        if (!found) {
            switch(wfAction.getStatus()) {
                case KILLED:
                case ERROR:
                case FAILED:
                    // Assuming on error the workflow eventually ends with kill node
                    showKill = true;
                    found = true;
                    break;
                default:
                    // Look further
                    break;
            }
        }
    }
    return workflowActions;
}
Also used : WorkflowAction(org.apache.oozie.client.WorkflowAction) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

WorkflowAction (org.apache.oozie.client.WorkflowAction)41 FileSystem (org.apache.hadoop.fs.FileSystem)9 Path (org.apache.hadoop.fs.Path)8 IOException (java.io.IOException)6 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)6 WorkflowJob (org.apache.oozie.client.WorkflowJob)6 Writer (java.io.Writer)5 Properties (java.util.Properties)5 OozieClient (org.apache.oozie.client.OozieClient)5 XConfiguration (org.apache.oozie.util.XConfiguration)5 OutputStreamWriter (java.io.OutputStreamWriter)4 Configuration (org.apache.hadoop.conf.Configuration)3 Element (org.jdom.Element)3 File (java.io.File)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 URISyntaxException (java.net.URISyntaxException)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)2