use of org.apache.oozie.command.wf.ActionStartXCommand in project oozie by apache.
the class TestEventGeneration method testInvalidXMLCoordinatorFailsForNoDuplicates.
@Test
public void testInvalidXMLCoordinatorFailsForNoDuplicates() throws Exception {
Date startTime = DateUtils.parseDateOozieTZ("2009-02-01T23:59Z");
Date endTime = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
// test coordinator action events (failure from ActionStartX)
ehs.getAppTypes().add("workflow_action");
CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
CoordinatorActionBean action = addRecordToCoordActionTable(coord.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-sla1.xml", 0);
WorkflowJobBean wf = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, action.getId());
action.setExternalId(wf.getId());
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
String waId = _createWorkflowAction(wf.getId(), "wf-action");
new ActionStartXCommand(waId, action.getType()).call();
final CoordJobGetJPAExecutor readCmd2 = new CoordJobGetJPAExecutor(coord.getId());
waitFor(1 * 100, new Predicate() {
@Override
public boolean evaluate() throws Exception {
return jpaService.execute(readCmd2).getStatus() == CoordinatorJob.Status.KILLED;
}
});
assertEquals(3, queue.size());
HashMap<AppType, JobEvent> eventsMap = new HashMap<AppType, JobEvent>();
while (queue.size() > 0) {
JobEvent event = (JobEvent) queue.poll();
eventsMap.put(event.getAppType(), event);
}
assertEquals(3, eventsMap.size());
// Check the WF action
{
JobEvent wfActionEvent = eventsMap.get(AppType.WORKFLOW_ACTION);
assertNotNull("There should be a WF action", wfActionEvent);
assertEquals(EventStatus.FAILURE, wfActionEvent.getEventStatus());
assertEquals(waId, wfActionEvent.getId());
assertEquals(AppType.WORKFLOW_ACTION, wfActionEvent.getAppType());
}
// Check the WF job
{
JobEvent wfJobEvent = eventsMap.get(AppType.WORKFLOW_JOB);
assertNotNull("There should be a WF job", wfJobEvent);
assertEquals(EventStatus.FAILURE, wfJobEvent.getEventStatus());
assertEquals(wf.getId(), wfJobEvent.getId());
assertEquals(AppType.WORKFLOW_JOB, wfJobEvent.getAppType());
}
// Check the Coordinator action
{
JobEvent coordActionEvent = eventsMap.get(AppType.COORDINATOR_ACTION);
assertNotNull("There should be a Coordinator action", coordActionEvent);
assertEquals(EventStatus.FAILURE, coordActionEvent.getEventStatus());
assertEquals(action.getId(), coordActionEvent.getId());
assertEquals(AppType.COORDINATOR_ACTION, coordActionEvent.getAppType());
}
queue.clear();
}
use of org.apache.oozie.command.wf.ActionStartXCommand 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.command.wf.ActionStartXCommand in project oozie by apache.
the class TestEventGeneration method testWorkflowActionEvent.
@Test
public void testWorkflowActionEvent() throws Exception {
assertEquals(queue.size(), 0);
// avoid noise from other apptype events by setting it to only
// workflow action
ehs.setAppTypes(new HashSet<String>(Arrays.asList("workflow_action")));
WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP, true);
// adding record sets externalChildID to dummy workflow-id so resetting it
action.setExternalChildIDs(null);
WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_START, action);
// Starting job
new ActionStartXCommand(action.getId(), "map-reduce").call();
WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
action = jpaService.execute(wfActionGetCmd);
assertEquals(WorkflowAction.Status.RUNNING, action.getStatus());
assertEquals(1, queue.size());
WorkflowActionEvent event = (WorkflowActionEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.STARTED, event.getEventStatus());
assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(action.getName(), event.getAppName());
assertEquals(action.getStartTime(), event.getStartTime());
assertEquals(0, queue.size());
// Suspending job
ActionExecutor.Context context = new ActionXCommand.ActionExecutorContext(job, action, false, false);
ActionExecutor executor = Services.get().get(ActionService.class).getExecutor(action.getType());
ActionCheckXCommandForTest dac = new ActionCheckXCommandForTest(context, executor, action.getId());
dac.execute();
action = dac.getAction();
assertEquals(WorkflowAction.Status.START_MANUAL, action.getStatus());
assertEquals(1, queue.size());
event = (WorkflowActionEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.SUSPEND, event.getEventStatus());
assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(action.getName(), event.getAppName());
assertEquals(0, queue.size());
// Killing job
action.setStatus(WorkflowAction.Status.KILLED);
action.setPendingOnly();
// its already set by XTestCase add action record method above
action.setEndTime(null);
WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQuery.UPDATE_ACTION_END, action);
new ActionKillXCommand(action.getId()).call();
action = jpaService.execute(wfActionGetCmd);
assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
assertEquals(1, queue.size());
event = (WorkflowActionEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.FAILURE, event.getEventStatus());
assertEquals(AppType.WORKFLOW_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(action.getName(), event.getAppName());
assertEquals(action.getStartTime(), event.getStartTime());
assertNotNull(action.getEndTime());
assertNotNull(event.getEndTime());
assertEquals(action.getEndTime(), event.getEndTime());
assertEquals(0, queue.size());
}
Aggregations