use of org.apache.oozie.event.CoordinatorActionEvent 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.CoordinatorActionEvent in project oozie by apache.
the class TestEventHandlerService method testEventLogging.
@Test
public void testEventLogging() throws Exception {
EventHandlerService ehs = _testEventHandlerService();
// job event
WorkflowJobEvent event = new WorkflowJobEvent("jobid", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp", null, null);
TestLogAppender appender = null;
Logger logger = null;
try {
appender = getTestLogAppender();
logger = Logger.getLogger(EventHandlerService.class);
logger.addAppender(appender);
logger.setLevel(Level.DEBUG);
ehs.queueEvent(event);
List<LoggingEvent> log = appender.getLog();
LoggingEvent logEntry = log.get(0);
assertEquals(Level.DEBUG, logEntry.getLevel());
assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid] ACTION[-] Queueing event : ID: jobid"));
assertEquals("org.apache.oozie.service.EventHandlerService", logEntry.getLoggerName());
ehs.new EventWorker().run();
log = appender.getLog();
logEntry = log.get(1);
assertEquals(Level.DEBUG, logEntry.getLevel());
assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid] ACTION[-] Processing event : ID: jobid"));
// action event
CoordinatorActionEvent event2 = new CoordinatorActionEvent("jobid2@1", "parentid", CoordinatorAction.Status.WAITING, getTestUser(), "myapp", null, null, null);
ehs.queueEvent(event2);
log = appender.getLog();
logEntry = log.get(2);
assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid2] ACTION[jobid2@1] Queueing event : ID: jobid2@1"));
WorkflowJobEvent event3 = new WorkflowJobEvent("jobid-other", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp-other", null, null);
ehs.queueEvent(event3);
log = appender.getLog();
logEntry = log.get(3);
assertTrue(logEntry.getMessage().toString().contains("APP[myapp-other] JOB[jobid-other] ACTION[-] Queueing event : ID: jobid-other"));
} finally {
logger.removeAppender(appender);
}
}
use of org.apache.oozie.event.CoordinatorActionEvent in project oozie by apache.
the class CoordinatorXCommand method generateEvent.
public static void generateEvent(CoordinatorActionBean coordAction, String user, String appName, Date startTime) {
if (eventService.isSupportedApptype(AppType.COORDINATOR_ACTION.name())) {
String missDep = coordAction.getMissingDependencies();
if (missDep != null && missDep.length() > 0) {
missDep = missDep.split(CoordELFunctions.INSTANCE_SEPARATOR)[0];
}
String pushMissDep = coordAction.getPushMissingDependencies();
if (pushMissDep != null && pushMissDep.length() > 0) {
pushMissDep = pushMissDep.split(CoordELFunctions.INSTANCE_SEPARATOR)[0];
}
String deps = missDep == null ? (pushMissDep == null ? null : pushMissDep) : (pushMissDep == null ? missDep : missDep + CoordELFunctions.INSTANCE_SEPARATOR + pushMissDep);
CoordinatorActionEvent event = new CoordinatorActionEvent(coordAction.getId(), coordAction.getJobId(), coordAction.getStatus(), user, appName, coordAction.getNominalTime(), startTime, deps);
event.setErrorCode(coordAction.getErrorCode());
event.setErrorMessage(coordAction.getErrorMessage());
eventService.queueEvent(event);
}
}
use of org.apache.oozie.event.CoordinatorActionEvent in project oozie by apache.
the class TestSLAEventGeneration method testFailureAndMissEventsOnKill.
/**
* Test Coord action KILLED from WAITING generates corresponding events Job
* - FAILURE and SLA - END_MISS
*
* @throws Exception
*/
public void testFailureAndMissEventsOnKill() throws Exception {
assertEquals(0, ehs.getEventQueue().size());
// CASE 1: Coord Job status - RUNNING (similar to RunningWithError,Paused and PausedWithError for
// this test's purpose)
CoordinatorJobBean job = this.addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-sla1.xml", 0);
// reset dummy externalId set by above test method
action.setExternalId(null);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
services.get(SLAService.class).addRegistrationEvent(TestSLAService._createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION));
new CoordKillXCommand(job.getId()).call();
assertEquals(1, ehs.getEventQueue().size());
CoordinatorActionEvent jobEvent = (CoordinatorActionEvent) ehs.getEventQueue().peek();
assertEquals(AppType.COORDINATOR_ACTION, jobEvent.getAppType());
assertEquals(JobEvent.EventStatus.FAILURE, jobEvent.getEventStatus());
assertEquals(action.getId(), jobEvent.getId());
ehs.new EventWorker().run();
SLACalcStatus slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
assertEquals(CoordinatorAction.Status.KILLED.name(), slaEvent.getJobStatus());
assertEquals(action.getId(), slaEvent.getId());
assertNotNull(slaEvent.getActualEnd());
// CASE 2: Coord Job status - PAUSED - Should not create event via CoordKill
// but via CoordActionUpdate
assertEquals(0, ehs.getEventQueue().size());
job = this.addRecordToCoordJobTable(CoordinatorJob.Status.PAUSED, false, false);
action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-sla1.xml", 0);
services.get(SLAService.class).addRegistrationEvent(TestSLAService._createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION));
new CoordKillXCommand(job.getId()).call();
assertEquals(0, ehs.getEventQueue().size());
WorkflowJobBean wf = new WorkflowJobBean();
wf.setId(action.getExternalId());
wf.setStatus(WorkflowJob.Status.KILLED);
wf.setParentId(action.getId());
wf.setEndTime(new Date());
jpa.execute(new WorkflowJobInsertJPAExecutor(wf));
new CoordActionUpdateXCommand(wf).call();
assertEquals(1, ehs.getEventQueue().size());
jobEvent = (CoordinatorActionEvent) ehs.getEventQueue().peek();
assertEquals(AppType.COORDINATOR_ACTION, jobEvent.getAppType());
assertEquals(JobEvent.EventStatus.FAILURE, jobEvent.getEventStatus());
assertEquals(action.getId(), jobEvent.getId());
ehs.new EventWorker().run();
slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
assertEquals(CoordinatorAction.Status.KILLED.name(), slaEvent.getJobStatus());
assertEquals(action.getId(), slaEvent.getId());
assertNotNull(slaEvent.getActualEnd());
}
use of org.apache.oozie.event.CoordinatorActionEvent 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