Search in sources :

Example 16 with SLACalcStatus

use of org.apache.oozie.sla.SLACalcStatus 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();
        }
    }
}
Also used : TestSLAService(org.apache.oozie.sla.TestSLAService) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) EventQueue(org.apache.oozie.event.EventQueue) Date(java.util.Date) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 17 with SLACalcStatus

use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.

the class TestJMSSLAEventListener method testSLAJobSelectorsNegative.

@Test
public void testSLAJobSelectorsNegative() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus startMiss = _createSLACalcStatus(id);
    SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
    startMiss.setId(id);
    startMissBean.setAppName("Test-SLA-Start-Miss");
    startMissBean.setAppType(AppType.COORDINATOR_ACTION);
    startMissBean.setUser("dummyuser");
    startMiss.setEventStatus(EventStatus.START_MISS);
    startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
    startMiss.setMsgType(MessageType.SLA);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    // Pass a selector which does not match and assert for null message
    String selector = JMSHeaderConstants.EVENT_STATUS + "='SLA_END_MISS'";
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMiss), selector);
    slaListener.onStartMiss(startMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    assertNull(message);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 18 with SLACalcStatus

use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.

the class TestJMSSLAEventListener method testOnSLADurationMetEvent.

public void testOnSLADurationMetEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus durationMet = _createSLACalcStatus(id);
    SLARegistrationBean durationMetBean = durationMet.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-01T14:00Z");
    long expectedDuration = (expectedEndDate.getTime() - actualStartDate.getTime()) / (1000 * 60);
    durationMet.setId(id);
    durationMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    durationMetBean.setAppName("Test-SLA-Duration-Met");
    durationMet.setEventStatus(EventStatus.DURATION_MET);
    durationMet.setSLAStatus(SLAStatus.MET);
    durationMetBean.setAppType(AppType.COORDINATOR_ACTION);
    durationMetBean.setUser("dummyuser");
    durationMetBean.setNotificationMsg("notification of duration met");
    durationMetBean.setExpectedStart(expectedStartDate);
    durationMet.setActualStart(actualStartDate);
    durationMetBean.setExpectedEnd(expectedEndDate);
    durationMet.setActualEnd(actualEndDate);
    durationMetBean.setExpectedDuration(expectedDuration);
    long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
    durationMet.setActualDuration(actualDuration);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(durationMet));
    slaListener.onDurationMet(durationMet);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage durationMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.DURATION_MET, durationMissMsg.getEventStatus());
    assertEquals(SLAStatus.MET, durationMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, durationMissMsg.getAppType());
    assertEquals(MessageType.SLA, durationMissMsg.getMessageType());
    assertEquals("Test-SLA-Duration-Met", durationMissMsg.getAppName());
    assertEquals("dummyuser", durationMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", durationMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", durationMissMsg.getParentId());
    assertEquals(expectedStartDate, durationMissMsg.getExpectedStartTime());
    assertEquals(actualStartDate, durationMissMsg.getActualStartTime());
    assertEquals(expectedEndDate, durationMissMsg.getExpectedEndTime());
    assertEquals(actualEndDate, durationMissMsg.getActualEndTime());
    assertEquals(expectedDuration, durationMissMsg.getExpectedDuration());
    assertEquals(actualDuration, durationMissMsg.getActualDuration());
    assertEquals("notification of duration met", durationMissMsg.getNotificationMessage());
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) Date(java.util.Date) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 19 with SLACalcStatus

use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.

the class TestJMSSLAEventListener method testOnSLADurationMissEvent.

public void testOnSLADurationMissEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus durationMiss = _createSLACalcStatus(id);
    SLARegistrationBean durationMissBean = durationMiss.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-01T14:00Z");
    long expectedDuration = (expectedEndDate.getTime() - actualStartDate.getTime()) / (1000 * 60);
    durationMiss.setId(id);
    durationMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    durationMissBean.setAppName("Test-SLA-Duration-Miss");
    durationMiss.setEventStatus(EventStatus.DURATION_MISS);
    durationMiss.setSLAStatus(SLAStatus.IN_PROCESS);
    durationMissBean.setAppType(AppType.COORDINATOR_ACTION);
    durationMissBean.setUser("dummyuser");
    durationMissBean.setNotificationMsg("notification of duration miss");
    durationMissBean.setExpectedStart(expectedStartDate);
    durationMiss.setActualStart(actualStartDate);
    durationMissBean.setExpectedEnd(expectedEndDate);
    durationMiss.setActualEnd(actualEndDate);
    durationMissBean.setExpectedDuration(expectedDuration);
    long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
    durationMiss.setActualDuration(actualDuration);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(durationMiss));
    slaListener.onDurationMiss(durationMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage durationMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.DURATION_MISS, durationMissMsg.getEventStatus());
    assertEquals(SLAStatus.IN_PROCESS, durationMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, durationMissMsg.getAppType());
    assertEquals(MessageType.SLA, durationMissMsg.getMessageType());
    assertEquals("Test-SLA-Duration-Miss", durationMissMsg.getAppName());
    assertEquals("dummyuser", durationMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", durationMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", durationMissMsg.getParentId());
    assertEquals(expectedStartDate, durationMissMsg.getExpectedStartTime());
    assertEquals(actualStartDate, durationMissMsg.getActualStartTime());
    assertEquals(expectedEndDate, durationMissMsg.getExpectedEndTime());
    assertEquals(actualEndDate, durationMissMsg.getActualEndTime());
    assertEquals(expectedDuration, durationMissMsg.getExpectedDuration());
    assertEquals(actualDuration, durationMissMsg.getActualDuration());
    assertEquals("notification of duration miss", durationMissMsg.getNotificationMessage());
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) Date(java.util.Date) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 20 with SLACalcStatus

use of org.apache.oozie.sla.SLACalcStatus in project oozie by apache.

the class TestSLAEmailEventListener method testNoDestAddress.

public void testNoDestAddress() 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 empty address as alert contact
    eventBean.setAlertContact("");
    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);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

Aggregations

SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)24 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)18 Date (java.util.Date)17 MessageConsumer (javax.jms.MessageConsumer)8 Session (javax.jms.Session)8 TextMessage (javax.jms.TextMessage)8 MimeMessage (javax.mail.internet.MimeMessage)8 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)7 SLAService (org.apache.oozie.sla.service.SLAService)4 Test (org.junit.Test)4 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Configuration (org.apache.hadoop.conf.Configuration)2 SLACalculator (org.apache.oozie.sla.SLACalculator)2 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)2 TestSLAService (org.apache.oozie.sla.TestSLAService)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 ArrayList (java.util.ArrayList)1