use of org.apache.oozie.event.WorkflowActionEvent in project oozie by apache.
the class TestEventHandlerService method testEventListener.
@Test
public void testEventListener() throws Exception {
EventHandlerService ehs = _testEventHandlerService();
/*
* Workflow Job events
*/
WorkflowJobEvent event = new WorkflowJobEvent("jobid", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp", null, null);
ehs.queueEvent(event);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Job event STARTED"));
output.setLength(0);
event.setStatus(WorkflowJob.Status.SUSPENDED);
ehs.queueEvent(event);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Job event SUSPEND"));
output.setLength(0);
event.setStatus(WorkflowJob.Status.SUCCEEDED);
ehs.queueEvent(event);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Job event SUCCESS"));
output.setLength(0);
event.setStatus(WorkflowJob.Status.KILLED);
ehs.queueEvent(event);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Job event FAILURE"));
output.setLength(0);
/*
* Coordinator Action events
*/
CoordinatorActionEvent event2 = new CoordinatorActionEvent("parentid@1", "parentid", CoordinatorAction.Status.WAITING, getTestUser(), "myapp", null, null, null);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event WAITING"));
output.setLength(0);
event2.setStatus(CoordinatorAction.Status.RUNNING);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event STARTED"));
output.setLength(0);
event2.setStatus(CoordinatorAction.Status.SUSPENDED);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event SUSPEND"));
output.setLength(0);
event2.setStatus(CoordinatorAction.Status.SUCCEEDED);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event SUCCESS"));
output.setLength(0);
event2.setStatus(CoordinatorAction.Status.TIMEDOUT);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event FAILURE"));
output.setLength(0);
event2.setStatus(CoordinatorAction.Status.KILLED);
ehs.queueEvent(event2);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Coord Action event FAILURE"));
output.setLength(0);
/*
* Workflow Action events
*/
WorkflowActionEvent event3 = new WorkflowActionEvent("parentid@wfaction", "parentid", WorkflowAction.Status.RUNNING, getTestUser(), "myapp", null, null);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event STARTED"));
output.setLength(0);
event3.setStatus(WorkflowAction.Status.START_MANUAL);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event SUSPEND"));
output.setLength(0);
event3.setStatus(WorkflowAction.Status.OK);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event SUCCESS"));
output.setLength(0);
event3.setStatus(WorkflowAction.Status.ERROR);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event FAILURE"));
output.setLength(0);
event3.setStatus(WorkflowAction.Status.KILLED);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event FAILURE"));
output.setLength(0);
event3.setStatus(WorkflowAction.Status.FAILED);
ehs.queueEvent(event3);
ehs.new EventWorker().run();
assertTrue(output.toString().contains("Workflow Action event FAILURE"));
output.setLength(0);
}
use of org.apache.oozie.event.WorkflowActionEvent in project oozie by apache.
the class WorkflowXCommand method generateEvent.
protected void generateEvent(WorkflowActionBean wfAction, String wfUser) {
if (eventService.isSupportedApptype(AppType.WORKFLOW_ACTION.name())) {
WorkflowActionEvent event = new WorkflowActionEvent(wfAction.getId(), wfAction.getJobId(), wfAction.getStatus(), wfUser, wfAction.getName(), wfAction.getStartTime(), wfAction.getEndTime());
event.setErrorCode(wfAction.getErrorCode());
event.setErrorMessage(wfAction.getErrorMessage());
eventService.queueEvent(event);
}
}
use of org.apache.oozie.event.WorkflowActionEvent in project oozie by apache.
the class TestSLAJobEventListener method testOnJobEvent.
@Test
public void testOnJobEvent() throws Exception {
SLAService slas = services.get(SLAService.class);
SLAJobEventListener listener = new SLAJobEventListener();
listener.init(services.getConf());
// add dummy registration events to the SLAService map
SLARegistrationBean job = _createSLARegBean("wf1-W", AppType.WORKFLOW_JOB);
job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-23T00:00Z"));
slas.addRegistrationEvent(job);
assertEquals(1, slas.getSLACalculator().size());
Date actualStart = DateUtils.parseDateUTC("2012-07-22T01:00Z");
createWorkflow("wf1-W", actualStart);
WorkflowJobEvent wfe = new WorkflowJobEvent("wf1-W", "caId1", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", actualStart, null);
listener.onWorkflowJobEvent(wfe);
SLACalcStatus serviceObj = slas.getSLACalculator().get("wf1-W");
// job will be checked against DB.. since it's old job. all event will get evaluted and job will move to history set.
// check that start sla has been calculated
assertEquals(EventStatus.END_MISS, serviceObj.getEventStatus());
// Job switching to running is only partially
assertEquals(7, serviceObj.getEventProcessed());
assertEquals(0, slas.getSLACalculator().size());
createWorkflowAction("wfId1-W@wa1", "wf1-W");
job = _createSLARegBean("wfId1-W@wa1", AppType.WORKFLOW_ACTION);
job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
slas.addRegistrationEvent(job);
assertEquals(1, slas.getSLACalculator().size());
job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
WorkflowActionEvent wae = new WorkflowActionEvent("wfId1-W@wa1", "wf1-W", WorkflowAction.Status.RUNNING, "user1", "wf-app-name1", actualStart, null);
listener.onWorkflowActionEvent(wae);
serviceObj = slas.getSLACalculator().get("wfId1-W@wa1");
// check that start sla has been calculated
assertEquals(EventStatus.END_MISS, serviceObj.getEventStatus());
createCoord("cj1-C");
CoordinatorActionBean coordAction = createCoordAction("cj1-C@ca1", "cj1-C");
job = _createSLARegBean("cj1-C@ca1", AppType.COORDINATOR_ACTION);
job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
Date actualEnd = DateUtils.parseDateUTC("2012-07-22T02:00Z");
slas.addRegistrationEvent(job);
assertEquals(1, slas.getSLACalculator().size());
CoordinatorActionEvent cae = new CoordinatorActionEvent("cj1-C@ca1", "cj1-C", CoordinatorAction.Status.RUNNING, "user1", "coord-app-name1", null, actualEnd, null);
listener.onCoordinatorActionEvent(cae);
coordAction.setStatus(CoordinatorAction.Status.KILLED);
coordAction.setLastModifiedTime(new Date());
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction);
cae = new CoordinatorActionEvent("cj1-C@ca1", "cj1-C", CoordinatorAction.Status.KILLED, "user1", "coord-app-name1", null, actualEnd, null);
listener.onCoordinatorActionEvent(cae);
SLASummaryBean summary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1-C@ca1");
// check that all events are processed
assertEquals(8, summary.getEventProcessed());
assertEquals(EventStatus.END_MISS, summary.getEventStatus());
// all jobs are processed
assertEquals(0, slas.getSLACalculator().size());
job = _createSLARegBean("wf2-W", AppType.WORKFLOW_JOB);
// 2 hour before
job.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
// 1 hours after
job.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
slas.addRegistrationEvent(job);
assertEquals(1, slas.getSLACalculator().size());
createWorkflow("wf2-W", new Date());
wfe = new WorkflowJobEvent("wf2-W", "caId2", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", null, null);
listener.onWorkflowJobEvent(wfe);
serviceObj = slas.getSLACalculator().get("wf2-W");
assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
// Only duration and start are processed. Duration = -1
assertEquals(3, serviceObj.getEventProcessed());
assertEquals(1, slas.getSLACalculator().size());
}
Aggregations