use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class DummySLACalculatorMemory method testNoDuplicateEventsInHA.
public void testNoDuplicateEventsInHA() throws Exception {
String id1 = "0000001-130521183438837-oozie-test-C@1";
SLAService slas = Services.get().get(SLAService.class);
SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
// loads the job in sla map
slaCalcMem.init(Services.get().getConf());
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
EventQueue ehs_q = ehs.getEventQueue();
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();
dummySlaCalcMem.init(Services.get().getConf());
EventHandlerService dummyEhs = new EventHandlerService();
dummySlaCalcMem.setEventHandlerService(dummyEhs);
dummyEhs.init(Services.get());
EventQueue dummyEhs_q = dummyEhs.getEventQueue();
// get MISS
Date expectedStartTS = new Date(System.currentTimeMillis() + 2 * 3600 * 1000);
// get MISS
Date expectedEndTS = new Date(System.currentTimeMillis() + 1 * 3600 * 1000);
SLASummaryBean sla = createDBEntryForStarted(id1, expectedStartTS, expectedEndTS, 0);
sla.setExpectedDuration(-1);
sla.setLastModifiedTime(new Date());
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_EXPECTED_TIMES, sla);
// Action started on Server 1
updateCoordAction(id1, "RUNNING");
slaCalcMem.addJobStatus(id1, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), null);
assertEquals(1, ehs_q.size());
SLACalcStatus s1 = (SLACalcStatus) ehs_q.poll();
assertEquals(SLAStatus.IN_PROCESS, s1.getSLAStatus());
// Action ended on Server 2
updateCoordAction(id1, "FAILED");
dummySlaCalcMem.addJobStatus(id1, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, new Date(System.currentTimeMillis() - 1800 * 1000), new Date());
SLACalcStatus s2 = (SLACalcStatus) dummyEhs_q.poll();
assertEquals(SLAStatus.MISS, s2.getSLAStatus());
slaCalcMem.updateAllSlaStatus();
dummySlaCalcMem.updateAllSlaStatus();
// no dupe event should be created again by Server 1
assertEquals(0, ehs_q.size());
} finally {
if (dummyOozie_1 != null) {
dummyOozie_1.teardown();
}
}
}
use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class XDataTestCase method addRecordToSLASummaryTable.
/**
* Insert sla summary for test
* @param appName application name
* @param status sla status
* @return
* @throws Exception
*/
protected SLASummaryBean addRecordToSLASummaryTable(String appName, SLAStatus status) throws Exception {
SLASummaryBean sla = new SLASummaryBean();
Date today = new Date();
sla.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.COORDINATOR));
sla.setAppName(appName);
sla.setAppType(AppType.COORDINATOR_JOB);
sla.setCreatedTime(today);
sla.setNominalTime(today);
sla.setExpectedStart(today);
sla.setExpectedEnd(today);
sla.setExpectedDuration(100);
sla.setJobStatus("RUNNING");
sla.setSLAStatus(status);
sla.setEventStatus(EventStatus.START_MET);
sla.setLastModifiedTime(today);
sla.setUser("oozie");
sla.setParentId(Services.get().get(UUIDService.class).generateId(ApplicationType.BUNDLE));
sla.setEventProcessed(1);
sla.setActualStart(today);
sla.setActualEnd(today);
sla.setActualDuration(100);
try {
SLASummaryQueryExecutor.getInstance().insert(sla);
} catch (JPAExecutorException je) {
je.printStackTrace();
fail("Unable to insert the test sla event record to table");
throw je;
}
return sla;
}
Aggregations