use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestDagEngine method testSubmit.
public void testSubmit() throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
OutputStream os = new FileOutputStream(new File(getTestCaseDir(), "config-default.xml"));
XConfiguration defaultConf = new XConfiguration();
defaultConf.set("a", "AA");
defaultConf.set("b", "BB");
defaultConf.set("e", "${d}${d}");
defaultConf.writeXml(os);
os.close();
final DagEngine engine = new DagEngine(getTestUser());
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set(OozieClient.ACTION_NOTIFICATION_URL, container.getServletURL("/callback") + "?jobId=$jobId&status=$status&nodeName=$nodeName");
conf.set("signal-value", "OK");
conf.set("external-status", "ok");
conf.set("error", "end.error");
conf.set("b", "B");
conf.set("c", "C");
conf.set("d", "${c}${c}");
conf.set("f", "${e}${e}");
final String jobId1 = engine.submitJob(conf, true);
WorkflowJob wf = engine.getJob(jobId1);
XConfiguration wfConf = new XConfiguration(new StringReader(wf.getConf()));
assertEquals("AA", wfConf.get("a"));
assertEquals("B", wfConf.get("b"));
assertEquals("C", conf.get("c"));
assertEquals("CC", conf.get("d"));
assertEquals("CCCC", conf.get("e"));
assertEquals("CCCCCCCC", conf.get("f"));
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJobBean bean = Services.get().get(WorkflowStoreService.class).create().getWorkflow(jobId1, false);
return bean.getWorkflowInstance().getStatus().isEndState();
}
});
assertEquals(WorkflowJob.Status.KILLED, engine.getJob(jobId1).getStatus());
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
return CallbackServlet.JOB_ID != null;
}
});
assertEquals(wf.getId(), CallbackServlet.JOB_ID);
assertTrue("kill".equals(CallbackServlet.NODE_NAME) || "a".equals(CallbackServlet.NODE_NAME));
assertTrue("T:null".equals(CallbackServlet.STATUS) || "T:kill".equals(CallbackServlet.STATUS));
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestBundleEngineSimple method testGetJob3.
public void testGetJob3() {
BundleEngine be = new BundleEngine();
try {
WorkflowJob wj = be.getJob("foo", 0, 1);
fail("Expected BundleEngineException was not thrown.");
} catch (BundleEngineException bee) {
assertEquals(ErrorCode.E0301, bee.getErrorCode());
}
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestBundleEngineSimple method testGetJob1.
public void testGetJob1() {
BundleEngine be = new BundleEngine();
try {
WorkflowJob wj = be.getJob("foo");
fail("Expected BundleEngineException was not thrown.");
} catch (BundleEngineException bee) {
assertEquals(ErrorCode.E0301, bee.getErrorCode());
}
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestWorkflow method testWorkflowWithStartAndEndCompletesSuccessfully.
public void testWorkflowWithStartAndEndCompletesSuccessfully() throws Exception {
final String wfApp = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='test-wf'>" + " <start to='end'/>" + " <end name='end'/>" + "</workflow-app>";
final FileSystem fs = getFileSystem();
final Path appPath = new Path(getFsTestCaseDir(), "app");
fs.mkdirs(appPath);
fs.mkdirs(new Path(appPath, "lib"));
final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
writer.write(wfApp);
writer.close();
final OozieClient wc = LocalOozie.getClient();
final Properties conf = wc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
conf.setProperty(OozieClient.USER_NAME, getTestUser());
final String jobId = wc.submit(conf);
assertNotNull(jobId);
WorkflowJob wf = wc.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
wc.start(jobId);
waitFor(1000, new Predicate() {
public boolean evaluate() throws Exception {
final WorkflowJob wf = wc.getJobInfo(jobId);
return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
wf = wc.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestWorkflow method runWorkflowFromFile.
private void runWorkflowFromFile(final String workflowFileName, final Properties additionalWorkflowProperties) throws IOException, OozieClientException {
final FileSystem fs = getFileSystem();
final Path appPath = new Path(getFsTestCaseDir(), "app");
fs.mkdirs(appPath);
fs.mkdirs(new Path(appPath, "lib"));
final Reader reader = getResourceAsReader(workflowFileName, -1);
final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
copyCharStream(reader, writer);
writer.close();
reader.close();
final Path path = getFsTestCaseDir();
final OozieClient oozieClient = LocalOozie.getClient();
final Properties conf = oozieClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("nameNodeBasePath", path.toString());
conf.setProperty("base", path.toUri().getPath());
conf.setProperty("nameNode", getNameNodeUri());
conf.setProperty("jobTracker", getJobTrackerUri());
for (final String additionalKey : additionalWorkflowProperties.stringPropertyNames()) {
conf.setProperty(additionalKey, additionalWorkflowProperties.getProperty(additionalKey));
}
final String jobId = oozieClient.submit(conf);
assertNotNull(jobId);
WorkflowJob wf = oozieClient.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
oozieClient.start(jobId);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
final WorkflowJob wf = oozieClient.getJobInfo(jobId);
return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
wf = oozieClient.getJobInfo(jobId);
assertNotNull(wf);
assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
Aggregations