// Coord Action of jobs 5-6 already started and currently running (to test history set)
createDBEntryForStarted(id5, expectedStartTS, expectedEndTS2);
createDBEntryForStarted(id6, expectedStartTS, expectedEndTS2);
SLAService slas = Services.get().get(SLAService.class);
SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
slaCalcMem.init(Services.get().getConf());
List<String> slaMapKeys = new ArrayList<String>();
Iterator<String> itr = slaCalcMem.iterator();
while (itr.hasNext()) {
slaMapKeys.add(itr.next());
}
assertEquals(6, slaMapKeys.size());
DummyZKOozie dummyOozie_1 = null;
try {
// start another dummy oozie instance (dummy sla and event handler services)
dummyOozie_1 = new DummyZKOozie("a", "http://blah");
DummySLACalculatorMemory dummySlaCalcMem = new DummySLACalculatorMemory();
EventHandlerService dummyEhs = new EventHandlerService();
dummySlaCalcMem.setEventHandlerService(dummyEhs);
dummyEhs.init(Services.get());
dummySlaCalcMem.init(Services.get().getConf());
slaMapKeys = new ArrayList<String>();
itr = dummySlaCalcMem.iterator();
while (itr.hasNext()) {
slaMapKeys.add(itr.next());
}
assertEquals(6, slaMapKeys.size());
// Coord Action 1,3 run and update status on *non-dummy* server
updateCoordAction(id1, "RUNNING");
slaCalcMem
.addJobStatus(id1, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), null);
updateCoordAction(id3, "FAILED");
slaCalcMem.addJobStatus(id3, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, null, new Date());
// Coord Action 2,4 run and update status on *dummy* server
updateCoordAction(id2, "RUNNING");
dummySlaCalcMem.addJobStatus(id2, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(),
null);
updateCoordAction(id4, "FAILED");
dummySlaCalcMem.addJobStatus(id4, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, null,
new Date());
// Both servers iterate SlaMap (updateAllSlaStatus)
slaCalcMem.updateAllSlaStatus();
dummySlaCalcMem.updateAllSlaStatus();
// SlaMap on both Servers synced
SLACalcStatus sla1_nodummy = slaCalcMem.get(id1);
SLACalcStatus sla1_dummy = dummySlaCalcMem.get(id1);
SLACalcStatus sla2_nodummy = slaCalcMem.get(id2);
SLACalcStatus sla2_dummy = dummySlaCalcMem.get(id2);
assertEquals(1, sla1_nodummy.getEventProcessed());
assertEquals(1, sla1_dummy.getEventProcessed());
assertEquals(1, sla2_dummy.getEventProcessed());
assertEquals(1, sla2_nodummy.getEventProcessed());
assertFalse(slaCalcMem.isJobIdInSLAMap(id3));
assertFalse(dummySlaCalcMem.isJobIdInSLAMap(id3));
assertFalse(slaCalcMem.isJobIdInSLAMap(id4));
assertFalse(dummySlaCalcMem.isJobIdInSLAMap(id4));
Byte eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id3);
assertEquals(8, eventProc.byteValue());
eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id4);
assertEquals(8, eventProc.byteValue());
// Action 5 was processed as END_MISS in updateAllSlaStatus, put into history set
assertTrue(slaCalcMem.isJobIdInHistorySet(id5));
assertTrue(dummySlaCalcMem.isJobIdInHistorySet(id6));
// Action 6 was processed as END_MISS in updateAllSlaStatus, put into history set
assertTrue(slaCalcMem.isJobIdInHistorySet(id5));
assertTrue(dummySlaCalcMem.isJobIdInHistorySet(id6));
eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id5);
assertEquals(7, eventProc.byteValue());
eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id6);
assertEquals(7, eventProc.byteValue());
// Action 1 Succeeded on non-dummy server
updateCoordAction(id1, "SUCCEEDED");
slaCalcMem.addJobStatus(id1, CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(
System.currentTimeMillis() - 1800 * 1000), new Date());
// Action 2 Succeeded on dummy server
updateCoordAction(id2, "SUCCEEDED");
dummySlaCalcMem.addJobStatus(id2, CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(
System.currentTimeMillis() - 1800 * 1000), new Date());
// Both servers iterate SlaMap (updateAllSlaStatus)
slaCalcMem.updateAllSlaStatus();
dummySlaCalcMem.updateAllSlaStatus();
// Action 1, 2 are removed from both servers
assertNull(slaCalcMem.get(id1));
assertNull(dummySlaCalcMem.get(id1));
assertNull(slaCalcMem.get(id2));
assertNull(dummySlaCalcMem.get(id2));
eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id1);
assertEquals(8, eventProc.byteValue());
eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(
SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id2);
assertEquals(8, eventProc.byteValue());
// Test HistoryPurgeWorker purges Action 5,6 from history set
updateCoordAction(id5, "SUCCEEDED");
slaCalcMem.new HistoryPurgeWorker().run();
assertFalse(slaCalcMem.isJobIdInHistorySet(id5));
updateCoordAction(id6, "SUCCEEDED");
dummySlaCalcMem.new HistoryPurgeWorker().run();
assertFalse(dummySlaCalcMem.isJobIdInHistorySet(id6));
}