Search in sources :

Example 51 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 52 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 53 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 54 with WorkflowActionBean

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

Example 55 with WorkflowActionBean

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

the class TestSshActionExecutor method testNoArgsNorArg.

public void testNoArgsNorArg() throws Exception {
    String baseDir = getTestCaseDir();
    Path appPath = new Path(getNameNodeUri(), baseDir);
    Path script = new Path(baseDir, "script.sh");
    FileSystem fs = FileSystem.getLocal(createJobConf());
    Writer w = new OutputStreamWriter(fs.create(script));
    w.write("echo \"prop1=something\"");
    w.close();
    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>" + script.toString() + "</command>" + "<capture-output/>" + "</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() {

        @Override
        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) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException) XConfiguration(org.apache.oozie.util.XConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)249 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)164 XConfiguration (org.apache.oozie.util.XConfiguration)84 JPAService (org.apache.oozie.service.JPAService)79 Configuration (org.apache.hadoop.conf.Configuration)56 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 Path (org.apache.hadoop.fs.Path)48 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)42 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)32 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)32 ArrayList (java.util.ArrayList)30 Date (java.util.Date)29 Element (org.jdom.Element)29 FileSystem (org.apache.hadoop.fs.FileSystem)25 Writer (java.io.Writer)22 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 IOException (java.io.IOException)20 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)18