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