Search in sources :

Example 56 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean 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 57 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean 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)

Example 58 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestSshActionExecutor method testJobStart.

public void testJobStart() throws ActionExecutorException {
    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));
    final WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>localhost</host>" + "<command>echo</command>" + "<capture-output/>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    ssh.start(context, action);
    waitFor(30 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            ssh.check(context, action);
            return Status.DONE == action.getStatus();
        }
    });
    ssh.end(context, action);
    assertEquals(Status.OK, action.getStatus());
    assertEquals("something", PropertiesUtils.stringToProperties(action.getData()).getProperty("prop1"));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 59 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestSshActionExecutor method testJobStartAndKill.

/**
 * test {@code SshActionExecutor.start()/kill()}
 * sequence call
 */
public void testJobStartAndKill() 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() + "'>" + "<host>localhost</host>" + "<command>top</command>" + "<capture-output/>" + "</ssh>");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    ssh.start(context, action);
    Context contextMock = mock(Context.class);
    ssh.kill(contextMock, action);
    verify(contextMock).setEndData(WorkflowAction.Status.KILLED, "ERROR");
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 60 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestSshActionExecutor method testConnectionErrors.

// TODO Move this test case over to a new class. Conflict between this one
// and testConnectionErrors. The property to replace the ssh user cannot be
// reset in a good way during runtime.
// 
// public void testOozieUserMismatch() throws ActionExecutorException {
// String baseDir = getTestCaseDir();
// Path appPath = new Path(getNameNodeUri(), baseDir);
// 
// Services.get().getConf().setBoolean(SshActionExecutor.CONF_SSH_ALLOW_USER_AT_HOST, false);
// XConfiguration protoConf = new XConfiguration();
// protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
// protoConf.setStrings(WorkflowAppService.HADOOP_UGI, getTestUser() + "," + getTestGroup());
// 
// 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("wfId");
// 
// final WorkflowActionBean action = new WorkflowActionBean();
// action.setId("actionId_" + System.currentTimeMillis());
// action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" +
// "<host>invalid@localhost</host>" +
// "<command>echo</command>" +
// "<capture-output/>" +
// "<args>\"prop1=something\"</args>" +
// "</ssh>");
// action.setName("ssh");
// 
// final SshActionExecutor ssh = new SshActionExecutor();
// 
// final Context context = new Context(workflow, action);
// try {
// ssh.start(context, action);
// assertTrue(false);
// } catch (ActionExecutorException ex) {
// System.err.println("Caught exception, Error Code: " + ex.getErrorCode());
// assertEquals(SshActionExecutor.ERR_USER_MISMATCH, ex.getErrorCode());
// }
// }
public void testConnectionErrors() throws ActionExecutorException {
    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));
    final WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>blabla</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    action.setName("ssh");
    final SshActionExecutor ssh = new SshActionExecutor();
    final Context context = new Context(workflow, action);
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing COULD_NOT_RESOLVE_HOST");
        assertEquals("COULD_NOT_RESOLVE_HOST", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.TRANSIENT, ex.getErrorType());
    }
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>11.11.11.11</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing COULD_NOT_CONNECT");
        assertEquals("COULD_NOT_CONNECT", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.TRANSIENT, ex.getErrorType());
    }
    action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" + "<host>y@localhost</host>" + "<command>echo</command>" + "<args>\"prop1=something\"</args>" + "</ssh>");
    try {
        ssh.start(context, action);
    } catch (ActionExecutorException ex) {
        System.out.println("Testing AUTH_FAILED");
        assertEquals("AUTH_FAILED", ex.getErrorCode());
        assertEquals(ActionExecutorException.ErrorType.NON_TRANSIENT, ex.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

WorkflowJobBean (org.apache.oozie.WorkflowJobBean)304 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)164 JPAService (org.apache.oozie.service.JPAService)95 XConfiguration (org.apache.oozie.util.XConfiguration)94 Configuration (org.apache.hadoop.conf.Configuration)66 Date (java.util.Date)60 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)58 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)57 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)53 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)53 Path (org.apache.hadoop.fs.Path)50 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)32 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)30 Element (org.jdom.Element)28 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)26 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)25 HashMap (java.util.HashMap)23 BundleJobBean (org.apache.oozie.BundleJobBean)21