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());
}
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());
}
}
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"));
}
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");
}
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());
}
}
Aggregations