Search in sources :

Example 6 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean 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());
}
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 7 with SLARegistrationBean

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

the class TestSLAAlertXCommand method registerSLABean.

private void registerSLABean(String jobId, AppType appType, String parentId, Date nominalTime) throws Exception {
    SLARegistrationBean slaRegBean = new SLARegistrationBean();
    slaRegBean.setNominalTime(nominalTime);
    slaRegBean.setId(jobId);
    slaRegBean.setAppType(appType);
    // 1 hour back
    startTime = new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000);
    slaRegBean.setExpectedStart(startTime);
    slaRegBean.setExpectedDuration(3600 * 1000);
    slaRegBean.setParentId(parentId);
    // 1 hour ahead
    slaRegBean.setExpectedEnd(endTime);
    Services.get().get(SLAService.class).addRegistrationEvent(slaRegBean);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLAService(org.apache.oozie.sla.service.SLAService) Date(java.util.Date)

Example 8 with SLARegistrationBean

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

the class SLARegistrationQueryExecutor method getIfExist.

@Override
public SLARegistrationBean getIfExist(SLARegQuery namedQuery, Object... parameters) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    Query query = getSelectQuery(namedQuery, em, parameters);
    Object ret = jpaService.executeGet(namedQuery.name(), query, em);
    if (ret == null && !namedQuery.equals(SLARegQuery.GET_SLA_REG_ALL)) {
        return null;
    }
    SLARegistrationBean bean = constructBean(namedQuery, ret, parameters);
    return bean;
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) JPAService(org.apache.oozie.service.JPAService)

Example 9 with SLARegistrationBean

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

the class SLARegistrationQueryExecutor method constructBean.

private SLARegistrationBean constructBean(SLARegQuery namedQuery, Object ret, Object... parameters) throws JPAExecutorException {
    SLARegistrationBean bean;
    Object[] arr;
    switch(namedQuery) {
        case GET_SLA_REG_ALL:
            bean = (SLARegistrationBean) ret;
            if (bean != null) {
                bean.setSlaConfig(bean.getSlaConfig());
            }
            break;
        case GET_SLA_REG_ON_RESTART:
            bean = new SLARegistrationBean();
            arr = (Object[]) ret;
            bean.setNotificationMsg((String) arr[0]);
            bean.setUpstreamApps((String) arr[1]);
            bean.setSlaConfig((String) arr[2]);
            bean.setJobData((String) arr[3]);
            break;
        case GET_SLA_CONFIGS:
            bean = new SLARegistrationBean();
            arr = (Object[]) ret;
            bean.setId((String) arr[0]);
            bean.setSlaConfig((String) arr[1]);
            break;
        case GET_SLA_EXPECTED_VALUE_CONFIG:
            bean = new SLARegistrationBean();
            arr = (Object[]) ret;
            bean.setId((String) arr[0]);
            bean.setSlaConfig((String) arr[1]);
            bean.setExpectedStart((Timestamp) arr[2]);
            bean.setExpectedEnd((Timestamp) arr[3]);
            bean.setExpectedDuration((Long) arr[4]);
            bean.setNominalTime((Timestamp) arr[5]);
            break;
        case GET_SLA_REG_FOR_PARENT_ID:
            bean = new SLARegistrationBean();
            arr = (Object[]) ret;
            bean.setId((String) arr[0]);
            bean.setSlaConfig((String) arr[1]);
            break;
        default:
            throw new JPAExecutorException(ErrorCode.E0603, "QueryExecutor cannot construct job bean for " + namedQuery.name());
    }
    return bean;
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean)

Example 10 with SLARegistrationBean

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

the class SLARegistrationQueryExecutor method getList.

@Override
public List<SLARegistrationBean> getList(SLARegQuery namedQuery, Object... parameters) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    Query query = getSelectQuery(namedQuery, em, parameters);
    List<?> retList = (List<?>) jpaService.executeGetList(namedQuery.name(), query, em);
    List<SLARegistrationBean> beanList = new ArrayList<SLARegistrationBean>();
    if (retList != null) {
        for (Object ret : retList) {
            beanList.add(constructBean(namedQuery, ret));
        }
    }
    return beanList;
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService)

Aggregations

SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)38 Date (java.util.Date)21 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)18 ArrayList (java.util.ArrayList)8 MessageConsumer (javax.jms.MessageConsumer)8 Session (javax.jms.Session)8 TextMessage (javax.jms.TextMessage)8 MimeMessage (javax.mail.internet.MimeMessage)8 JPAService (org.apache.oozie.service.JPAService)8 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)7 EntityManager (javax.persistence.EntityManager)6 Query (javax.persistence.Query)6 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)6 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 JsonBean (org.apache.oozie.client.rest.JsonBean)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Test (org.junit.Test)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3