use of org.apache.oozie.sla.service.SLAService 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.sla.service.SLAService in project oozie by apache.
the class TestSLAEventGeneration method testWorkflowJobSLANewSubmitStart.
/**
* Test for SLA Events generated through Workflow Job Commands
* Submit and Start
*
* @throws Exception
*/
@Test
public void testWorkflowJobSLANewSubmitStart() throws Exception {
assertNotNull(ehs);
SLAService slas = services.get(SLAService.class);
assertNotNull(slas);
String wfXml = IOUtils.getResourceAsString("wf-job-sla.xml", -1);
Path appPath = getFsTestCaseDir();
writeToFile(wfXml, appPath, "workflow.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, appPath.toString());
conf.set(OozieClient.USER_NAME, getTestUser());
_testWorkflowJobSubmitStart(conf, slas, true);
}
use of org.apache.oozie.sla.service.SLAService in project oozie by apache.
the class TestSLAEventGeneration method testWorkflowJobSLANewKill.
/**
* Test for SLA Events generated through Workflow Job Kill Command
*
* @throws Exception
*/
@Test
public void testWorkflowJobSLANewKill() throws Exception {
assertNotNull(ehs);
SLAService slas = services.get(SLAService.class);
assertNotNull(slas);
String wfXml = IOUtils.getResourceAsString("wf-job-sla.xml", -1);
Path appPath = getFsTestCaseDir();
writeToFile(wfXml, appPath, "workflow.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, appPath.toString());
conf.set(OozieClient.USER_NAME, getTestUser());
_testWorkflowJobKillCommand(conf, slas);
}
use of org.apache.oozie.sla.service.SLAService 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());
}
use of org.apache.oozie.sla.service.SLAService 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