Search in sources :

Example 71 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestSubWorkflowActionExecutor method testSubWorkflowRecovery.

public void testSubWorkflowRecovery() throws Exception {
    Path subWorkflowAppPath = getFsTestCaseDir();
    FileSystem fs = getFileSystem();
    Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
    Writer writer = new OutputStreamWriter(fs.create(workflowPath));
    writer.write(APP1);
    writer.close();
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    subWorkflow.start(new Context(workflow, action), action);
    final OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    waitFor(JOB_TIMEOUT, new Predicate() {

        public boolean evaluate() throws Exception {
            return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    String extId = action.getExternalId();
    assertEquals(workflow.getId(), oozieClient.getJobInfo(extId).getParentId());
    assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(extId).getStatus());
    WorkflowActionBean action1 = new WorkflowActionBean();
    action1.setId(action.getId());
    action1.setName(action.getName());
    action1.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>wrongAppPath</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    subWorkflow.start(new Context(workflow, action1), action1);
    assertEquals(extId, action1.getExternalId());
    assertEquals(workflow.getId(), oozieClient.getJobInfo(extId).getParentId());
    subWorkflow.check(new Context(workflow, action1), action1);
    assertEquals(WorkflowAction.Status.DONE, action1.getStatus());
    subWorkflow.end(new Context(workflow, action1), action1);
    assertEquals(WorkflowAction.Status.OK, action1.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 72 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestSubWorkflowActionExecutor method testSubWorkflowConfCreation.

public void testSubWorkflowConfCreation() throws Exception {
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>hdfs://foo:9000/user/bar/workflow.xml</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    assertNotNull(oozieClient);
    oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), "http://localhost:8080/oozie");
    assertNotNull(oozieClient);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 73 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestSubWorkflowActionExecutor method testSubWorkflowStart.

public void testSubWorkflowStart() throws Exception {
    Path subWorkflowAppPath = getFsTestCaseDir();
    FileSystem fs = getFileSystem();
    Writer writer = new OutputStreamWriter(fs.create(new Path(subWorkflowAppPath, "workflow.xml")));
    writer.write(APP1);
    writer.close();
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>" + subWorkflowAppPath + "</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    subWorkflow.start(new Context(workflow, action), action);
    final OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    waitFor(JOB_TIMEOUT, new Predicate() {

        public boolean evaluate() throws Exception {
            return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(action.getExternalId()).getStatus());
    subWorkflow.check(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.DONE, action.getStatus());
    subWorkflow.end(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    assertEquals(workflow.getId(), oozieClient.getJobInfo(action.getExternalId()).getParentId());
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 74 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestSubWorkflowActionExecutor method testParentGlobalConfWithConfigDefault.

public void testParentGlobalConfWithConfigDefault() throws Exception {
    try {
        Path subWorkflowAppPath = createSubWorkflowXml();
        createConfigDefaultXml();
        createSubWorkflowConfigDefaultXml();
        String workflowUri = createTestWorkflowXml(subWorkflowAppPath);
        LocalOozie.start();
        final OozieClient wfClient = LocalOozie.getClient();
        Properties conf = wfClient.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, workflowUri);
        conf.setProperty(OozieClient.USER_NAME, getTestUser());
        conf.setProperty("appName", "var-app-name");
        conf.setProperty("foo", "other");
        final String jobId = wfClient.submit(conf);
        wfClient.start(jobId);
        // configuration should have overridden value
        assertEquals("other", new XConfiguration(new StringReader(wfClient.getJobInfo(jobId).getConf())).get("foo"));
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.OK);
            }
        });
        WorkflowJob subWorkflow = wfClient.getJobInfo(wfClient.getJobInfo(jobId).getActions().get(1).getExternalId());
        Configuration subWorkflowConf = getWorkflowConfig(subWorkflow);
        Element eConf = XmlUtils.parseXml(subWorkflow.getActions().get(1).getConf());
        Element element = eConf.getChild("configuration", eConf.getNamespace());
        Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(element).toString()));
        // configuration in subWorkflow should have overridden value
        assertEquals("other", subWorkflowConf.get("foo"));
        assertEquals("foo1", actionConf.get("foo1"));
        assertEquals("subconf", actionConf.get("foo2"));
        assertEquals("foo3", actionConf.get("foo3"));
        // Checking the action conf configuration.
        assertEquals("actionconf", subWorkflowConf.get("foo3"));
        assertEquals("subactionconf", actionConf.get("foo4"));
        // config defaults are present
        assertEquals("default", subWorkflowConf.get("parentConfigDefault"));
        assertEquals("default", actionConf.get("subwfConfigDefault"));
    } finally {
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 75 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestSshActionExecutor method testSshCheckWithInvalidXml.

/**
 * test {@code SshActionExecutor.check()} method with invalid
 * xml configuration
 */
public void testSshCheckWithInvalidXml() throws Exception {
    String baseDir = getTestCaseDir();
    Path appPath = new Path(getNameNodeUri(), baseDir);
    XConfiguration protoConf = new XConfiguration();
    protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.APP_PATH, appPath.toString());
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setConf(wfConf.toXmlString());
    workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
    workflow.setProtoActionConf(protoConf.toXmlString());
    workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'> invalid body ");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    try {
        ssh.check(context, action);
        fail("testSshCheckWithInvalidXml expected ex error");
    } catch (ActionExecutorException aex) {
        // ActionExecutorException should be thrown to pass the test
        assertEquals("ERR_XML_PARSE_FAILED", aex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.ERROR, aex.getErrorType());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

XConfiguration (org.apache.oozie.util.XConfiguration)373 Configuration (org.apache.hadoop.conf.Configuration)241 Path (org.apache.hadoop.fs.Path)106 StringReader (java.io.StringReader)97 File (java.io.File)92 IOException (java.io.IOException)78 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)75 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)70 CommandException (org.apache.oozie.command.CommandException)68 Element (org.jdom.Element)66 Writer (java.io.Writer)58 Date (java.util.Date)50 FileSystem (org.apache.hadoop.fs.FileSystem)48 FileWriter (java.io.FileWriter)45 Reader (java.io.Reader)43 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)37 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)28 OutputStream (java.io.OutputStream)27 FileOutputStream (java.io.FileOutputStream)25