use of org.apache.oozie.client.OozieClient in project oozie by apache.
the class TestSubWorkflowActionExecutor method testParentGlobalConfWithConfigDefault.
public void testParentGlobalConfWithConfigDefault() throws Exception {
try {
Path subWorkflowAppPath = createSubWorkflowXml();
createConfigDefaultXml();
createSubWorkflowConfigDefaultXml();
String workflowUri = createTestWorkflowXml(subWorkflowAppPath);
LocalOozie.start();
final OozieClient wfClient = LocalOozie.getClient();
Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, workflowUri);
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("appName", "var-app-name");
conf.setProperty("foo", "other");
final String jobId = wfClient.submit(conf);
wfClient.start(jobId);
// configuration should have overridden value
assertEquals("other", new XConfiguration(new StringReader(wfClient.getJobInfo(jobId).getConf())).get("foo"));
waitFor(JOB_TIMEOUT, new Predicate() {
public boolean evaluate() throws Exception {
return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.OK);
}
});
WorkflowJob subWorkflow = wfClient.getJobInfo(wfClient.getJobInfo(jobId).getActions().get(1).getExternalId());
Configuration subWorkflowConf = getWorkflowConfig(subWorkflow);
Element eConf = XmlUtils.parseXml(subWorkflow.getActions().get(1).getConf());
Element element = eConf.getChild("configuration", eConf.getNamespace());
Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(element).toString()));
// configuration in subWorkflow should have overridden value
assertEquals("other", subWorkflowConf.get("foo"));
assertEquals("foo1", actionConf.get("foo1"));
assertEquals("subconf", actionConf.get("foo2"));
assertEquals("foo3", actionConf.get("foo3"));
// Checking the action conf configuration.
assertEquals("actionconf", subWorkflowConf.get("foo3"));
assertEquals("subactionconf", actionConf.get("foo4"));
// config defaults are present
assertEquals("default", subWorkflowConf.get("parentConfigDefault"));
assertEquals("default", actionConf.get("subwfConfigDefault"));
} finally {
LocalOozie.stop();
}
}
use of org.apache.oozie.client.OozieClient in project oozie by apache.
the class TestLastModified method testWorkflowRun.
public void testWorkflowRun() throws Exception {
String wfApp = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='test-wf'>" + " <start to='end'/>" + " <end name='end'/>" + "</workflow-app>";
FileSystem fs = getFileSystem();
Path appPath = new Path(getFsTestCaseDir(), "app");
fs.mkdirs(appPath);
fs.mkdirs(new Path(appPath, "lib"));
fs.mkdirs(new Path("input-data"));
Writer inputWriter = new OutputStreamWriter(fs.create(new Path("input-data/data1.txt")));
inputWriter.write("Hello. This is my input data set.");
inputWriter.close();
Path workflowPath = new Path(appPath, "workflow.xml");
Writer writer = new OutputStreamWriter(fs.create(workflowPath));
writer.write(wfApp);
writer.close();
try {
LocalOozie.start();
final OozieClient wc = LocalOozie.getClient();
Properties conf = wc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, workflowPath.toString());
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
final String jobId = wc.submit(conf);
assertNotNull(jobId);
WorkflowJob wf = wc.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
boolean dateTest = wf.getLastModifiedTime().compareTo(wf.getCreatedTime()) >= 0 ? true : false;
assertEquals(true, dateTest);
wc.start(jobId);
wf = wc.getJobInfo(jobId);
Date lastModTime = wf.getLastModifiedTime();
wc.suspend(jobId);
wf = wc.getJobInfo(jobId);
dateTest = wf.getLastModifiedTime().compareTo(lastModTime) >= 0 ? true : false;
assertEquals(true, dateTest);
lastModTime = wf.getLastModifiedTime();
sleep(1000);
wc.resume(jobId);
wf = wc.getJobInfo(jobId);
dateTest = wf.getLastModifiedTime().compareTo(lastModTime) >= 0 ? true : false;
assertEquals(true, dateTest);
waitFor(600000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJob wf = wc.getJobInfo(jobId);
return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
wf = wc.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
dateTest = wf.getLastModifiedTime().compareTo(wf.getEndTime()) >= 0 ? true : false;
assertEquals(true, dateTest);
} finally {
LocalOozie.stop();
}
}
use of org.apache.oozie.client.OozieClient in project oozie by apache.
the class TestReRunXCommand method testRerunWithExistingConf.
// rerun should use existing wf conf
public void testRerunWithExistingConf() throws IOException, OozieClientException {
Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
Path path = getFsTestCaseDir();
getFileSystem().create(new Path(path, "p2"));
final OozieClient wfClient = LocalOozie.getClient();
final Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("nnbase", path.toString());
conf.setProperty("base", path.toUri().getPath());
Properties newConf = wfClient.createConfiguration();
newConf.setProperty("base", path.toUri().getPath());
final String jobId = wfClient.submit(conf);
wfClient.start(jobId);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED;
}
});
assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId).getStatus());
try {
wfClient.reRun(jobId, newConf);
} catch (OozieClientException e) {
assertTrue(e.getCause().getMessage().contains(ErrorCode.E0401.toString()));
}
newConf = wfClient.createConfiguration();
// Skip a non-executed node
getFileSystem().delete(new Path(path, "p2"), true);
newConf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
wfClient.reRun(jobId, newConf);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId).getStatus());
}
use of org.apache.oozie.client.OozieClient in project oozie by apache.
the class TestReRunXCommand method testRerun.
public void testRerun() throws IOException, OozieClientException {
Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
Path path = getFsTestCaseDir();
getFileSystem().create(new Path(path, "p2"));
final OozieClient wfClient = LocalOozie.getClient();
Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("nnbase", path.toString());
conf.setProperty("base", path.toUri().getPath());
final String jobId1 = wfClient.submit(conf);
wfClient.start(jobId1);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.KILLED;
}
});
assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
// Skip a non-executed node
conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1,fs2,dec3");
boolean failed = false;
try {
wfClient.reRun(jobId1, conf);
} catch (OozieClientException e) {
failed = true;
assertTrue(e.getCause().getMessage().contains(ErrorCode.E0807.toString()));
}
assertEquals(true, failed);
// Skip executed nodes
getFileSystem().delete(new Path(path, "p2"), true);
conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
wfClient.reRun(jobId1, conf);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
}
use of org.apache.oozie.client.OozieClient in project oozie by apache.
the class TestReRunXCommand method testRerunFromFailNodes.
public void testRerunFromFailNodes() throws IOException, OozieClientException {
Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
Path path = getFsTestCaseDir();
getFileSystem().create(new Path(path, "p2"));
final OozieClient wfClient = LocalOozie.getClient();
Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("nnbase", path.toString());
conf.setProperty("base", path.toUri().getPath());
final String jobId1 = wfClient.submit(conf);
wfClient.start(jobId1);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.KILLED;
}
});
assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
// Skip succeeded nodes
getFileSystem().delete(new Path(path, "p2"), true);
conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
wfClient.reRun(jobId1, conf);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
}
Aggregations