use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testUserAlertEventSetting.
public void testUserAlertEventSetting() throws Exception {
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
// user choose only END MISS, thus, START_MISS email should not be sent
eventBean.setAlertEvents(EventStatus.END_MISS.name());
Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
Date actualstartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
event.setEventStatus(EventStatus.START_MISS);
event.setId(id);
eventBean.setAppName("Test-SLA-Start-Miss");
eventBean.setUser("dummyuser");
eventBean.setNominalTime(startDate);
eventBean.setExpectedStart(startDate);
eventBean.setAlertContact("alert-receiver@oozie.com");
event.setActualStart(actualstartDate);
eventBean.setAppType(AppType.COORDINATOR_ACTION);
slaEmailListener.onStartMiss(event);
// START_MISS should not be sent
MimeMessage[] msgs = greenMail.getReceivedMessages();
assertEquals(msgs.length, 0);
// DURATION_MISS should not be sent
event.setEventStatus(EventStatus.DURATION_MISS);
slaEmailListener.onDurationMiss(event);
msgs = greenMail.getReceivedMessages();
assertEquals(msgs.length, 0);
// END_MISS should be sent
event.setEventStatus(EventStatus.END_MISS);
slaEmailListener.onEndMiss(event);
msgs = greenMail.getReceivedMessages();
assertNotNull(msgs[0]);
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testOnStartMiss.
public void testOnStartMiss() throws Exception {
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
Date actualstartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
event.setEventStatus(EventStatus.START_MISS);
event.setJobStatus(JobEvent.EventStatus.STARTED.toString());
event.setId(id);
eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
eventBean.setAppName("Test-SLA-Start-Miss");
eventBean.setUser("dummyuser");
eventBean.setNominalTime(startDate);
eventBean.setExpectedStart(startDate);
eventBean.setNotificationMsg("Notification of Missing Expected Start Time");
eventBean.setAlertContact("alert-receiver@oozie.com");
event.setActualStart(actualstartDate);
eventBean.setAppType(AppType.COORDINATOR_ACTION);
slaEmailListener.onStartMiss(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@oozie.com");
assertEquals(msg.getSubject(), "OOZIE - SLA " + EventStatus.START_MISS + " (AppName=Test-SLA-Start-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.START_MISS.toString()) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.JOB_STATUS.toString() + sep + JobEvent.EventStatus.STARTED.toString()) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.NOTIFICATION_MESSAGE.toString() + sep + "Notification of Missing Expected Start Time") > -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-Start-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 + startDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_START_TIME.toString() + sep + startDate) > -1);
assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_START_TIME.toString() + sep + actualstartDate) > -1);
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testInvalidDestAddress.
public void testInvalidDestAddress() throws Exception {
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
// set invalid address as alert contact
eventBean.setAlertContact("invalidAddress");
event.setEventStatus(EventStatus.START_MISS);
event.setId(id);
eventBean.setAppType(AppType.COORDINATOR_ACTION);
eventBean.setAppName("Test-SLA-Start-Miss");
eventBean.setUser("dummyuser");
eventBean.setExpectedStart(startDate);
eventBean.setNotificationMsg("notification of start miss");
eventBean.setAppType(AppType.COORDINATOR_ACTION);
event.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
slaEmailListener.onStartMiss(event);
MimeMessage[] msgs = greenMail.getReceivedMessages();
assertEquals(msgs.length, 0);
}
use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.
the class TestSLAEmailEventListener method testMultipleDestAddress.
public void testMultipleDestAddress() throws Exception {
String id = "0000000-000000000000001-oozie-wrkf-C@1";
SLACalcStatus event = _createSLACalcStatus(id);
SLARegistrationBean eventBean = event.getSLARegistrationBean();
Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
// set multiple addresses as alert contact
eventBean.setAlertContact("alert-receiver1@oozie.com, alert-receiver2@oozie.com");
event.setEventStatus(EventStatus.START_MISS);
event.setId(id);
eventBean.setAppType(AppType.COORDINATOR_ACTION);
eventBean.setAppName("Test-SLA-Start-Miss");
eventBean.setUser("dummyuser");
eventBean.setExpectedStart(startDate);
eventBean.setNotificationMsg("notification of start miss");
eventBean.setAppType(AppType.COORDINATOR_ACTION);
event.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
slaEmailListener.onStartMiss(event);
MimeMessage[] msgs = greenMail.getReceivedMessages();
MimeMessage msg = msgs[0];
assertEquals(msg.getFrom()[0].toString(), "oozie@localhost");
assertEquals(msg.getRecipients(RecipientType.TO)[0].toString(), "alert-receiver1@oozie.com");
assertEquals(msg.getRecipients(RecipientType.TO)[1].toString(), "alert-receiver2@oozie.com");
}
Aggregations