use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestSubWorkflowActionExecutor method testSubworkflowLib.
public void testSubworkflowLib() throws Exception {
XConfiguration protoConf = getBaseProtoConf();
WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
FileSystem fs = getFileSystem();
Path parentLibJar = new Path(getFsTestCaseDir(), "lib/parentLibrary.jar");
fs.create(parentLibJar);
assertTrue(fs.exists(parentLibJar));
String defaultConf = workflow.getConf();
XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
newConf.set(OozieClient.LIBPATH, parentLibJar.getParent().toString());
workflow.setConf(newConf.toXmlString());
Path subWorkflowAppPath = new Path(getFsTestCaseDir().toString(), "subwf");
Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
Writer writer = new OutputStreamWriter(fs.create(workflowPath));
writer.write(APP1);
writer.close();
Path subwfLibJar = new Path(subWorkflowAppPath, "lib/subwfLibrary.jar");
fs.create(subwfLibJar);
assertTrue(fs.exists(subwfLibJar));
final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + " <app-path>" + workflowPath.toString() + "</app-path>" + "</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());
WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
Configuration childConf = getWorkflowConfig(wf);
childConf = wps.createProtoActionConf(childConf, true);
assertEquals(childConf.get(WorkflowAppService.APP_LIB_PATH_LIST), subwfLibJar.toString());
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestSubWorkflowActionExecutor method testGetGroupFromParent.
public void testGetGroupFromParent() throws Exception {
Path subWorkflowAppPath = getFsTestCaseDir();
FileSystem fs = getFileSystem();
Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
Writer writer = new OutputStreamWriter(fs.create(workflowPath));
writer.write(APP1);
writer.close();
XConfiguration protoConf = getBaseProtoConf();
final WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
String defaultConf = workflow.getConf();
XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
String actionConf = "<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + " <app-path>" + workflowPath.toString() + "</app-path>" + " <configuration>" + " <property>" + " <name>a</name>" + " <value>A</value>" + " </property>" + " </configuration>" + "</sub-workflow>";
final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
action.setConf(actionConf);
// negative test
final SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
workflow.setConf(newConf.toXmlString());
subWorkflow.start(new Context(workflow, action), action);
OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
waitFor(5000, new Predicate() {
@Override
public boolean evaluate() throws Exception {
subWorkflow.check(new Context(workflow, action), action);
return action.getStatus() == WorkflowActionBean.Status.DONE;
}
});
subWorkflow.check(new Context(workflow, action), action);
subWorkflow.end(new Context(workflow, action), action);
assertEquals(WorkflowAction.Status.OK, action.getStatus());
WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
Configuration childConf = getWorkflowConfig(wf);
assertFalse(getTestGroup() == childConf.get(OozieClient.GROUP_NAME));
// positive test
newConf.set(OozieClient.GROUP_NAME, getTestGroup());
workflow.setConf(newConf.toXmlString());
final WorkflowActionBean action1 = new WorkflowActionBean();
action1.setConf(actionConf);
action1.setId("W1");
subWorkflow.start(new Context(workflow, action1), action1);
oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action1), SubWorkflowActionExecutor.LOCAL);
waitFor(5000, new Predicate() {
@Override
public boolean evaluate() throws Exception {
subWorkflow.check(new Context(workflow, action1), action1);
return action1.getStatus() == WorkflowActionBean.Status.DONE;
}
});
subWorkflow.check(new Context(workflow, action1), action1);
subWorkflow.end(new Context(workflow, action1), action1);
wf = oozieClient.getJobInfo(action1.getExternalId());
childConf = new XConfiguration(new StringReader(wf.getConf()));
assertEquals(getTestGroup(), childConf.get(OozieClient.GROUP_NAME));
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestSubWorkflowActionExecutor method testSubWorkflowRerun.
public void testSubWorkflowRerun() throws Exception {
try {
Path subWorkflowAppPath = getFsTestCaseDir();
FileSystem fs = getFileSystem();
Path subWorkflowPath = new Path(subWorkflowAppPath, "workflow.xml");
Writer writer = new OutputStreamWriter(fs.create(subWorkflowPath));
writer.write(getLazyWorkflow());
writer.close();
String workflowUri = getTestCaseFileUri("workflow.xml");
String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.4\" name=\"workflow\">" + "<start to=\"subwf\"/>" + "<action name=\"subwf\">" + " <sub-workflow xmlns='uri:oozie:workflow:0.4'>" + " <app-path>" + subWorkflowAppPath.toString() + "</app-path>" + " </sub-workflow>" + " <ok to=\"end\"/>" + " <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + " <message>Sub workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
writeToFile(appXml, workflowUri);
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");
final String jobId = wfClient.submit(conf);
wfClient.start(jobId);
waitFor(JOB_TIMEOUT, new Predicate() {
public boolean evaluate() throws Exception {
return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.RUNNING);
}
});
String subWorkflowExternalId = wfClient.getJobInfo(jobId).getActions().get(1).getExternalId();
wfClient.kill(wfClient.getJobInfo(jobId).getActions().get(1).getExternalId());
waitFor(JOB_TIMEOUT, new Predicate() {
public boolean evaluate() throws Exception {
return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.ERROR);
}
});
conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
wfClient.reRun(jobId, conf);
waitFor(JOB_TIMEOUT, new Predicate() {
public boolean evaluate() throws Exception {
return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) && (wfClient.getJobInfo(jobId).getActions().get(2).getStatus() == WorkflowAction.Status.OK);
}
});
WorkflowJob job = wfClient.getJobInfo(wfClient.getJobInfo(jobId).getActions().get(2).getExternalId());
assertEquals(WorkflowJob.Status.SUCCEEDED, job.getStatus());
assertEquals(job.getId(), subWorkflowExternalId);
} finally {
LocalOozie.stop();
}
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class TestSignalXCommand method _testSuspendPoints.
public void _testSuspendPoints() throws Exception {
services.destroy();
LocalOozie.start();
FileSystem fs = getFileSystem();
Path appPath = new Path(getFsTestCaseDir(), "app");
fs.mkdirs(appPath);
Reader reader = IOUtils.getResourceAsReader("wf-suspendpoints.xml", -1);
Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
IOUtils.copyCharStream(reader, writer);
writer.close();
reader.close();
final OozieClient oc = LocalOozie.getClient();
Properties conf = oc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty("oozie.suspend.on.nodes", "action1,nonexistant_action_name,decision1, action3,join1 ,fork1,action4b");
final String jobId = oc.submit(conf);
assertNotNull(jobId);
WorkflowJob wf = oc.getJobInfo(jobId);
assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
long beforeStart = System.currentTimeMillis();
oc.start(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action1" }, new String[] { ":start:" });
// Check for creation time
long afterStart = System.currentTimeMillis();
WorkflowJob wf1 = oc.getJobInfo(jobId);
for (WorkflowAction action : wf1.getActions()) {
WorkflowActionBean bean = (WorkflowActionBean) action;
assertNotNull(bean.getCreatedTime());
assertTrue((bean.getCreatedTime().getTime() > beforeStart) && (bean.getCreatedTime().getTime() < afterStart));
}
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "decision1" }, new String[] { ":start:", "action1", "action2" });
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action3" }, new String[] { ":start:", "action1", "action2", "decision1" });
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "fork1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3" });
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action4a", "action4b", "action4c" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1" });
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "join1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c" });
oc.resume(jobId);
checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUCCEEDED, new String[] {}, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c", "join1", "end" });
LocalOozie.stop();
}
use of org.apache.oozie.client.WorkflowJob in project oozie by apache.
the class AppInfoCollector method storeWorkflowJobDetails.
private void storeWorkflowJobDetails(final File outputDir, final String jobId, int maxChildActions) {
if (jobId == null || !isWorkflow(jobId)) {
return;
}
try {
System.out.print("Getting Details for " + jobId + "...");
final File workflowOutputDir = new File(outputDir, jobId);
if (!createOutputDirectory(workflowOutputDir)) {
return;
}
final File resolvedActionsDir = new File(workflowOutputDir, "resolved-actions");
if (!createOutputDirectory(resolvedActionsDir)) {
System.out.println("Workflow details already stored.");
return;
}
final WorkflowJob job = client.getJobInfo(jobId);
try (DiagBundleEntryWriter diagBundleEntryWriter = new DiagBundleEntryWriter(workflowOutputDir, "info.txt")) {
persistWorkflowJobInfo(maxChildActions, resolvedActionsDir, job, diagBundleEntryWriter);
}
storeCommonDetails(workflowOutputDir, jobId, "workflow", job.getConf());
System.out.println("Done");
} catch (IOException | OozieClientException e) {
System.err.printf("Exception occurred during the retrieval of workflow information: %s%n", e.getMessage());
}
}
Aggregations