use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestJMSSLAEventListener method testOnSLAEndMetEvent.
public void testOnSLAEndMetEvent() throws Exception {
JMSSLAEventListener slaListener = new JMSSLAEventListener();
slaListener.init(conf);
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus endMet = _createSLACalcStatus(id);
SLARegistrationBean endMetBean = endMet.getSLARegistrationBean();
Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T12:00Z");
Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T11:00Z");
endMet.setId(id);
endMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
endMetBean.setAppName("Test-SLA-End-Met");
endMet.setEventStatus(EventStatus.END_MET);
endMet.setSLAStatus(SLAStatus.MET);
endMetBean.setAppType(AppType.COORDINATOR_ACTION);
endMetBean.setUser("dummyuser");
endMetBean.setNotificationMsg("notification of end met");
endMetBean.setExpectedEnd(expectedEndDate);
endMet.setActualEnd(actualEndDate);
ConnectionContext jmsContext = getConnectionContext();
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(endMet));
slaListener.onEndMet(endMet);
TextMessage message = (TextMessage) consumer.receive(5000);
SLAMessage slaEndMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
// check msg header
assertEquals(EventStatus.END_MET, slaEndMissMsg.getEventStatus());
assertEquals(SLAStatus.MET, slaEndMissMsg.getSLAStatus());
assertEquals(AppType.COORDINATOR_ACTION, slaEndMissMsg.getAppType());
assertEquals(MessageType.SLA, slaEndMissMsg.getMessageType());
assertEquals("Test-SLA-End-Met", slaEndMissMsg.getAppName());
assertEquals("dummyuser", slaEndMissMsg.getUser());
// check msg body
assertEquals("0000000-000000000000001-oozie-wrkf-C@1", slaEndMissMsg.getId());
assertEquals("0000000-000000000000001-oozie-wrkf-C", slaEndMissMsg.getParentId());
assertEquals(expectedEndDate, slaEndMissMsg.getExpectedEndTime());
assertEquals(actualEndDate, slaEndMissMsg.getActualEndTime());
assertEquals("notification of end met", slaEndMissMsg.getNotificationMessage());
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class DummySLACalculatorMemory method testSLAUpdateWithHA.
public void testSLAUpdateWithHA() throws Exception {
String id1 = "0000001-130521183438837-oozie-test-C@1";
String id2 = "0000002-130521183438837-oozie-test-C@1";
String id3 = "0000003-130521183438837-oozie-test-C@1";
String id4 = "0000004-130521183438837-oozie-test-C@1";
String id5 = "0000005-130521183438837-oozie-test-C@1";
String id6 = "0000006-130521183438837-oozie-test-C@1";
// 2 hrs passed
Date expectedStartTS = new Date(System.currentTimeMillis() - 2 * 3600 * 1000);
// 1 hour ahead
Date expectedEndTS1 = new Date(System.currentTimeMillis() + 1 * 3600 * 1000);
// 1 hour passed
Date expectedEndTS2 = new Date(System.currentTimeMillis() - 1 * 3600 * 1000);
// Coord Action of jobs 1-4 not started yet
createDBEntry(id1, expectedStartTS, expectedEndTS1);
createDBEntry(id2, expectedStartTS, expectedEndTS1);
createDBEntry(id3, expectedStartTS, expectedEndTS1);
createDBEntry(id4, expectedStartTS, expectedEndTS1);
// Coord Action of jobs 5-6 already started and currently running (to test history set)
createDBEntryForStarted(id5, expectedStartTS, expectedEndTS2, 1);
createDBEntryForStarted(id6, expectedStartTS, expectedEndTS2, 1);
SLAService slas = Services.get().get(SLAService.class);
SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
slaCalcMem.init(Services.get().getConf());
slaCalcMem.updateAllSlaStatus();
List<String> slaMapKeys = new ArrayList<String>();
Iterator<String> itr = slaCalcMem.iterator();
while (itr.hasNext()) {
slaMapKeys.add(itr.next());
}
// 4 jobs expected end is not yet reached
// 2 jobs has end miss, waiting for job to complete
assertEquals(4, slaMapKeys.size());
assertEquals(2, slaCalcMem.getHistorySet().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());
dummySlaCalcMem.updateAllSlaStatus();
slaMapKeys = new ArrayList<String>();
itr = dummySlaCalcMem.iterator();
while (itr.hasNext()) {
slaMapKeys.add(itr.next());
}
assertEquals(4, slaMapKeys.size());
assertEquals(2, dummySlaCalcMem.getHistorySet().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));
} finally {
if (dummyOozie_1 != null) {
dummyOozie_1.teardown();
}
}
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestCoordSubmitXCommand method testSubmitWithSLAAlertsDisable.
public void testSubmitWithSLAAlertsDisable() throws Exception {
Configuration conf = new XConfiguration();
File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
// CASE 1: Failure case i.e. multiple data-in instances
Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
Writer writer = new FileWriter(appPathFile);
IOUtils.copyCharStream(reader, writer);
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set("frequency", "coord:days(1)");
conf.set(OozieClient.USER_NAME, getTestUser());
reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
appPathFile = new File(getTestCaseDir(), "workflow.xml");
writer = new FileWriter(appPathFile);
IOUtils.copyCharStream(reader, writer);
conf.set("wfAppPath", appPathFile.getPath());
Date nominalTime = new Date();
conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
String coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
SLAService slaService = services.get(SLAService.class);
SLACalculator calc = slaService.getSLACalculator();
SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
Configuration conf1 = new Configuration(conf);
// CASE I: "ALL"
conf1.set(OozieClient.SLA_DISABLE_ALERT, "ALL");
coordId = new CoordSubmitXCommand(conf1).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaService = services.get(SLAService.class);
calc = slaService.getSLACalculator();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE II: Date Range
Configuration conf2 = new Configuration(conf);
Date startRangeDate = new Date(nominalTime.getTime() - 3600 * 1000);
conf2.set(OozieClient.SLA_DISABLE_ALERT, DateUtils.formatDateOozieTZ(startRangeDate) + "::" + DateUtils.formatDateOozieTZ(nominalTime));
coordId = new CoordSubmitXCommand(conf2).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE III: Coord name (negative test)
Configuration conf3 = new Configuration(conf);
conf3.set(OozieClient.SLA_DISABLE_ALERT_COORD, "test-coord-sla-x");
coordId = new CoordSubmitXCommand(conf3).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE IV: Older than n(hours)
Date otherNominalTime = new Date(nominalTime.getTime() - 73 * 3600 * 1000);
conf = new XConfiguration();
appPathFile = new File(getTestCaseDir(), "coordinator.xml");
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(otherNominalTime));
conf.setInt(OozieClient.SLA_DISABLE_ALERT_OLDER_THAN, 72);
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// catchup mode
conf = new XConfiguration();
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// normal mode
conf = new XConfiguration();
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testOnEndMiss.
public void testOnEndMiss() throws Exception {
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
Date expectedStartDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T12:00Z");
Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T13:00Z");
event.setId(id);
eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
event.setEventStatus(EventStatus.END_MISS);
event.setJobStatus(JobEvent.EventStatus.SUCCESS.toString());
eventBean.setAppName("Test-SLA-End-Miss");
eventBean.setUser("dummyuser");
eventBean.setNominalTime(expectedStartDate);
eventBean.setExpectedStart(expectedStartDate);
eventBean.setExpectedEnd(expectedEndDate);
eventBean.setNotificationMsg("notification of end miss");
eventBean.setAlertContact("alert-receiver-endmiss@oozie.com");
eventBean.setAppType(AppType.COORDINATOR_ACTION);
eventBean.setExpectedStart(expectedStartDate);
eventBean.setExpectedEnd(expectedEndDate);
event.setActualStart(actualStartDate);
event.setActualEnd(actualEndDate);
slaEmailListener.onEndMiss(event);
MimeMessage[] msgs = greenMail.getReceivedMessages();
MimeMessage msg = msgs[0];
// check message header
assertEquals(msg.getFrom()[0].toString(), "oozie@localhost");
assertEquals(msg.getRecipients(RecipientType.TO)[0].toString(), "alert-receiver-endmiss@oozie.com");
assertEquals(msg.getSubject(), "OOZIE - SLA " + EventStatus.END_MISS + " (AppName=Test-SLA-End-Miss, JobID=0000000-000000000000001-oozie-wrkf-C@1)");
// check message body
String msgBody = msg.getContent().toString();
String headerSep = SLAEmailEventListener.EMAIL_BODY_HEADER_SEPARATER;
String sep = SLAEmailEventListener.EMAIL_BODY_FIELD_SEPARATER;
String indent = SLAEmailEventListener.EMAIL_BODY_FIELD_INDENT;
assertTrue(msgBody.indexOf("Status" + headerSep) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.EVENT_STATUS.toString() + sep + EventStatus.END_MISS.toString()) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.JOB_STATUS.toString() + sep + JobEvent.EventStatus.SUCCESS.toString()) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.NOTIFICATION_MESSAGE.toString() + sep + "notification of end miss") > -1);
assertTrue(msgBody.indexOf("Job Details" + headerSep) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.APP_TYPE.toString() + sep + AppType.COORDINATOR_ACTION) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.APP_NAME.toString() + sep + "Test-SLA-End-Miss") > -1);
assertTrue(msgBody.indexOf(indent + EmailField.USER.toString() + sep + "dummyuser") > -1);
assertTrue(msgBody.indexOf(indent + EmailField.JOBID.toString() + sep + "0000000-000000000000001-oozie-wrkf-C@1") > -1);
assertTrue(msgBody.indexOf(indent + EmailField.PARENT_JOBID.toString() + sep + "0000000-000000000000001-oozie-wrkf-C") > -1);
assertTrue(msgBody.indexOf(indent + EmailField.JOB_URL.toString() + sep + conf.get(SLAEmailEventListener.OOZIE_BASE_URL) + "/?job=" + "0000000-000000000000001-oozie-wrkf-C@1") > -1);
assertTrue(msgBody.indexOf(indent + EmailField.PARENT_JOB_URL.toString() + sep + conf.get(SLAEmailEventListener.OOZIE_BASE_URL) + "/?job=" + "0000000-000000000000001-oozie-wrkf-C") > -1);
assertTrue(msgBody.indexOf("SLA Details" + headerSep) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.NOMINAL_TIME.toString() + sep + expectedStartDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_START_TIME.toString() + sep + expectedStartDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_START_TIME.toString() + sep + actualStartDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_END_TIME.toString() + sep + expectedEndDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_END_TIME.toString() + sep + actualEndDate) > -1);
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testBlackList.
public void testBlackList() throws Exception {
String blackListedEmail = "alert-receiver@oozie.com";
// add email to blacklist
slaEmailListener.addBlackList(blackListedEmail);
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
event.setEventStatus(EventStatus.START_MISS);
eventBean.setAlertContact(blackListedEmail);
eventBean.setAppType(AppType.COORDINATOR_ACTION);
eventBean.setAppName("Test-SLA-Start-Miss");
eventBean.setUser("dummyuser");
eventBean.setAlertContact("alert-receiver@oozie.com");
event.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
// blacklist blocks email from being sent out
slaEmailListener.onStartMiss(event);
MimeMessage[] msgs = greenMail.getReceivedMessages();
assertEquals(msgs.length, 0);
// wait 1.5 sec (cache timeout set to 1sec in test's setup)
Thread.sleep(1500);
// cache is evicted
slaEmailListener.onStartMiss(event);
msgs = greenMail.getReceivedMessages();
assertEquals(msgs.length, 1);
}
Aggregations