use of org.apache.oozie.service.EventHandlerService in project oozie by apache.
the class TestSLACalculatorMemory method testDisablingAlertsEvents.
@SuppressWarnings("serial")
public void testDisablingAlertsEvents() throws Exception {
SLAService slaService = Services.get().get(SLAService.class);
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
SLACalculator slaCalculator = slaService.getSLACalculator();
// create dummy sla records and coord action records
String id1 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 1);
String id2 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 2);
SLACalcStatus slaCalcObj1 = slaCalculator.get(id1);
assertFalse(slaCalcObj1.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
SLACalcStatus slaCalcObj2 = slaCalculator.get(id2);
assertFalse(slaCalcObj2.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().size() > 0);
// check that SLACalculator sends no event
ehs.getEventQueue().clear();
SLASummaryBean persistentSla = new SLASummaryBean(slaCalcObj1);
// reset eventProcessed for the sla calc objects
persistentSla.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
persistentSla = new SLASummaryBean(slaCalcObj2);
persistentSla.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
// CASE I : list of sla ids, no new params
slaService.enableChildJobAlert(Arrays.asList(id1, id2));
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().isEmpty());
// CASE II : ALL
_setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 3);
_setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 4);
slaCalculator.enableChildJobAlert(Arrays.asList("00020-1234567-wrkf-C"));
slaCalculator.updateAllSlaStatus();
assertFalse(ehs.getEventQueue().isEmpty());
// CASE III : resume w/ new params
final String id5 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 5);
Date now = new Date();
now.setTime(now.getTime() - 10 * 60 * 1000);
final String newParams = RestConstants.SLA_NOMINAL_TIME + "=" + DateUtils.formatDateOozieTZ(now) + ";" + RestConstants.SLA_SHOULD_END + "=5";
slaCalculator.changeDefinition(new ArrayList<Pair<String, Map<String, String>>>() {
{
add(new Pair<String, Map<String, String>>(id5, JobUtils.parseChangeValue(newParams)));
}
});
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().size() > 0);
}
use of org.apache.oozie.service.EventHandlerService in project oozie by apache.
the class TestSLACalculatorMemory method testDuplicateStartMiss.
@Test
public void testDuplicateStartMiss() throws Exception {
// test start-miss
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
// 1 hour back
Date startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000);
slaRegBean.setExpectedStart(startTime);
// to avoid duration miss
slaRegBean.setExpectedDuration(2 * 3600 * 1000);
// 1 hour ahead
slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000));
String jobId = slaRegBean.getId();
slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean);
slaCalcMemory.updateJobSla(jobId);
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
assertEquals(1, slaSummary.getEventProcessed());
assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
job1.setStatus(WorkflowJob.Status.RUNNING);
job1.setStartTime(startTime);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1);
slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.STARTED, new Date(System.currentTimeMillis()), null);
slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
assertEquals(1, slaSummary.getEventProcessed());
assertEquals(SLAStatus.IN_PROCESS, slaSummary.getSLAStatus());
assertEquals(WorkflowJob.Status.RUNNING.toString(), slaSummary.getJobStatus());
assertEquals(1, ehs.getEventQueue().size());
}
use of org.apache.oozie.service.EventHandlerService in project oozie by apache.
the class TestSLAService method testUpdateSLA.
@Test
public void testUpdateSLA() throws Exception {
SLAService slas = Services.get().get(SLAService.class);
assertNotNull(slas);
assertTrue(SLAService.isEnabled());
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
// test start-miss
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
SLARegistrationBean sla1 = _createSLARegistration(wfJob.getId(), AppType.WORKFLOW_JOB);
// 1 hour back
sla1.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
// 1 hour back
sla1.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
// 10 mins
sla1.setExpectedDuration(10 * 60 * 1000);
slas.addRegistrationEvent(sla1);
assertEquals(1, slas.getSLACalculator().size());
slas.runSLAWorker();
ehs.new EventWorker().run();
assertEventNoDuplicates(output.toString(), "Sla START - MISS!!!");
assertEventNoDuplicates(output.toString(), "Sla END - MISS!!!");
output.setLength(0);
// test different jobs and events start-met and end-miss
WorkflowJobBean wfJob2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
sla1 = _createSLARegistration(wfJob2.getId(), AppType.WORKFLOW_JOB);
// 1 hour ahead
sla1.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
// 2 hours ahead
sla1.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 3600 * 1000));
slas.addRegistrationEvent(sla1);
wfJob2.setStatusStr("RUNNING");
wfJob2.setLastModifiedTime(new Date());
wfJob2.setStartTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob2);
slas.addStatusEvent(sla1.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
CoordinatorActionBean action = addRecordToCoordActionTable("coord_id-C", 1, CoordinatorAction.Status.TIMEDOUT, "coord-action-get.xml", 0);
SLARegistrationBean sla2 = _createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION);
// 1 hour ahead only for testing
sla2.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
// 2 hours back
sla2.setExpectedEnd(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
// to process duration too
sla2.setExpectedDuration(10);
slas.addRegistrationEvent(sla2);
assertEquals(3, slas.getSLACalculator().size());
Date startTime = new Date();
WorkflowJobBean wfJob3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
wfJob3.setStatusStr("SUCCEEDED");
wfJob3.setLastModifiedTime(new Date());
wfJob3.setStartTime(startTime);
wfJob3.setEndTime(startTime);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob3);
action.setCreatedTime(startTime);
action.setStatus(CoordinatorAction.Status.SUCCEEDED);
action.setLastModifiedTime(new Date());
action.setExternalId(wfJob3.getId());
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_RERUN, action);
slas.addStatusEvent(sla1.getId(), CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
slas.addStatusEvent(sla2.getId(), CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, startTime, new Date());
slas.runSLAWorker();
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla1.getId() + " Sla START - MET!!!"));
assertTrue(output.toString().contains(sla2.getId() + " Sla END - MISS!!!"));
assertTrue(output.toString().contains(sla2.getId() + " Sla DURATION - MET!!!"));
output.setLength(0);
// test same job multiple events (start-miss, end-miss) through regular check
WorkflowJobBean job4 = addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
job4.setLastModifiedTime(new Date());
job4.setEndTime(new Date());
job4.setStartTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job4);
sla2 = _createSLARegistration(job4.getId(), AppType.WORKFLOW_JOB);
// 2 hours back
sla2.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
// 1 hour back
sla2.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 3600 * 1000));
slas.addRegistrationEvent(sla2);
// tests job slaProcessed == 7 removed from map
assertEquals(3, slas.getSLACalculator().size());
slas.runSLAWorker();
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla2.getId() + " Sla START - MISS!!!"));
assertTrue(output.toString().contains(sla2.getId() + " Sla END - MISS!!!"));
output.setLength(0);
// As expected duration is not set, duration shall be processed and job removed from map
assertEquals(2, slas.getSLACalculator().size());
// test same job multiple events (start-met, end-met) through job status event
sla1 = _createCoordActionSLARegistration(CoordinatorAction.Status.SUCCEEDED.name());
// 1 hour ahead
sla1.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
// 2 hours ahead
sla1.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 3600 * 1000));
slas.addRegistrationEvent(sla1);
assertEquals(3, slas.getSLACalculator().size());
slas.addStatusEvent(sla1.getId(), CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(), new Date());
slas.runSLAWorker();
assertEquals(2, ehs.getEventQueue().size());
ehs.new EventWorker().run();
assertTrue(output.toString().contains(sla1.getId() + " Sla START - MET!!!"));
assertTrue(output.toString().contains(sla1.getId() + " Sla END - MET!!!"));
}
Aggregations