use of org.apache.oozie.store.WorkflowStore in project oozie by apache.
the class TestActionFailover method testFsFailover.
public void testFsFailover() throws Exception {
Path wf = new Path(getFsTestCaseDir(), "workflow.xml");
Reader reader = IOUtils.getResourceAsReader("failover-fs-wf.xml", -1);
Writer writer = new OutputStreamWriter(getFileSystem().create(wf));
IOUtils.copyCharStream(reader, writer);
final OozieClient wfClient = LocalOozie.getClient();
Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, wf.toString());
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
final Path source = new Path(getFsTestCaseDir(), "fsfailover-source");
getFileSystem().mkdirs(source);
final Path target = new Path(getFsTestCaseDir().toString(), "fsfailover-target");
conf.setProperty("source", source.toString());
conf.setProperty("target", target.toUri().getPath());
final String jobId1 = wfClient.submit(conf);
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
try {
wfClient.start(jobId1);
fail("Should have skipped commit for failover testing");
} catch (OozieClientException oce) {
assertTrue(oce.getMessage().contains("Skipping Commit for Failover Testing"));
}
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return getFileSystem().exists(target);
}
});
assertFalse(getFileSystem().exists(target));
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection");
}
});
assertFalse(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection"));
assertEquals(WorkflowJob.Status.RUNNING, wfClient.getJobInfo(jobId1).getStatus());
WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId1, false);
assertEquals(1, actions.size());
WorkflowActionBean action = actions.get(0);
assertEquals(WorkflowAction.Status.PREP, action.getStatus());
assertEquals(StartActionExecutor.TYPE, action.getType());
setSystemProperty(FaultInjection.FAULT_INJECTION, "false");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "false");
ActionStartXCommand actionStartCommand = new ActionStartXCommand(action.getId(), action.getType());
actionStartCommand.call();
sleep(500);
store = Services.get().get(WorkflowStoreService.class).create();
actions = store.getActionsForWorkflow(jobId1, false);
action = actions.get(0);
assertEquals(WorkflowAction.Status.OK, action.getStatus());
waitFor(5 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
final String jobId2 = wfClient.submit(conf);
wfClient.start(jobId2);
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId2).getStatus() == WorkflowJob.Status.KILLED;
}
});
assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
}
use of org.apache.oozie.store.WorkflowStore in project oozie by apache.
the class TestActionErrors method _testDataNotSet.
/**
* Provides functionality to test for set*Data calls not being made by the Action Handler.
*
* @param avoidParam set*Data function call to avoid.
* @param expActionErrorCode the expected action error code.
* @throws Exception
*/
private void _testDataNotSet(String avoidParam, String expActionErrorCode) 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);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("external-status", "ok");
conf.set("signal-value", "based_on_action_status");
conf.set(avoidParam, "true");
final String jobId = engine.submitJob(conf, true);
final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
store.beginTrx();
Thread.sleep(2000);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJobBean bean = store.getWorkflow(jobId, false);
return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.FAILED);
}
});
store.commitTrx();
store.closeTrx();
final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
store2.beginTrx();
assertEquals(WorkflowInstance.Status.FAILED, store2.getWorkflow(jobId, false).getWorkflowInstance().getStatus());
assertEquals(WorkflowJob.Status.FAILED, engine.getJob(jobId).getStatus());
List<WorkflowActionBean> actions = store2.getActionsForWorkflow(jobId, false);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
assertEquals(expActionErrorCode, action.getErrorCode());
store2.commitTrx();
store2.closeTrx();
}
use of org.apache.oozie.store.WorkflowStore in project oozie by apache.
the class TestSubmitXCommand method testSubmitAppName.
public void testSubmitAppName() throws Exception {
Configuration conf = new XConfiguration();
String workflowUri = getTestCaseFileUri("workflow.xml");
String appXml = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='${appName}-foo'> " + "<start to='end' /> " + "<end name='end' /> " + "</workflow-app>";
writeToFile(appXml, workflowUri);
conf.set(OozieClient.APP_PATH, workflowUri);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("appName", "var-app-name");
SubmitXCommand sc = new SubmitXCommand(conf);
String jobId = sc.call();
WorkflowStoreService wss = Services.get().get(WorkflowStoreService.class);
WorkflowStore ws = wss.create();
WorkflowJobBean wfb = ws.getWorkflow(jobId, false);
assertEquals("var-app-name-foo", wfb.getAppName());
}
Aggregations