Search in sources :

Example 76 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 77 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 78 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 79 with XConfiguration

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

Example 80 with XConfiguration

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

the class TestSLAEventGeneration method testSLASchema1BackwardCompatibilitySubmitStart.

@Test
public void testSLASchema1BackwardCompatibilitySubmitStart() throws Exception {
    assertNotNull(ehs);
    SLAService slas = services.get(SLAService.class);
    assertNotNull(slas);
    Path appPath = getFsTestCaseDir();
    writeToFile(SLA_XML_1, appPath, "workflow.xml");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, appPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    Date nominal = cal.getTime();
    String nominalTime = DateUtils.formatDateOozieTZ(nominal);
    conf.set("nominal_time", nominalTime);
    _testWorkflowJobSubmitStart(conf, slas, false);
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) SLAService(org.apache.oozie.sla.service.SLAService) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Date(java.util.Date) Test(org.junit.Test)

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