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());
}
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);
}
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;
}
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;
}
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;
}
Aggregations