use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class SLASummaryQueryExecutor method constructBean.
private SLASummaryBean constructBean(SLASummaryQuery namedQuery, Object ret, Object... parameters) throws JPAExecutorException {
SLASummaryBean bean;
switch(namedQuery) {
case GET_SLA_SUMMARY:
bean = (SLASummaryBean) ret;
break;
case GET_SLA_SUMMARY_EVENTPROCESSED:
bean = new SLASummaryBean();
bean.setEventProcessed(((Byte) ret).intValue());
break;
case GET_SLA_SUMMARY_EVENTPROCESSED_LAST_MODIFIED:
Object[] arr = (Object[]) ret;
bean = new SLASummaryBean();
bean.setEventProcessed((Byte) arr[0]);
bean.setLastModifiedTime((Timestamp) 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.SLASummaryBean in project oozie by apache.
the class SLASummaryQueryExecutor method get.
@Override
public SLASummaryBean get(SLASummaryQuery 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(SLASummaryQuery.GET_SLA_SUMMARY)) {
throw new JPAExecutorException(ErrorCode.E0604, query.toString());
}
SLASummaryBean bean = constructBean(namedQuery, ret, parameters);
return bean;
}
use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class SLASummaryQueryExecutor method getList.
@Override
public List<SLASummaryBean> getList(SLASummaryQuery namedQuery, Object... parameters) throws JPAExecutorException {
JPAService jpaService = Services.get().get(JPAService.class);
EntityManager em = jpaService.getEntityManager();
Query query = getSelectQuery(namedQuery, em, parameters);
@SuppressWarnings("unchecked") List<SLASummaryBean> beanList = (List<SLASummaryBean>) jpaService.executeGetList(namedQuery.name(), query, em);
return beanList;
}
use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class SLASummaryGetRecordsOnRestartJPAExecutor method execute.
@SuppressWarnings("unchecked")
@Override
public List<SLASummaryBean> execute(EntityManager em) throws JPAExecutorException {
List<SLASummaryBean> ssBean;
try {
Query q = em.createNamedQuery("GET_SLA_SUMMARY_RECORDS_RESTART");
Timestamp ts = new Timestamp(System.currentTimeMillis() - days * 24 * 60 * 60 * 1000);
q.setParameter("lastModifiedTime", ts);
ssBean = q.getResultList();
return ssBean;
} catch (Exception e) {
throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
}
}
use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.
the class V2SLAServlet method getSLASummaryList.
private JSONObject getSLASummaryList(HttpServletRequest request, HttpServletResponse response) throws ServletException, CommandException {
String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? null : request.getParameter(RestConstants.TIME_ZONE_PARAM);
String filterString = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
String maxResults = request.getParameter(RestConstants.LEN_PARAM);
// Default
int numMaxResults = 1000;
if (maxResults != null) {
numMaxResults = Integer.parseInt(maxResults);
}
if (filterString == null || filterString.equals("")) {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, RestConstants.JOBS_FILTER_PARAM);
}
try {
Map<String, List<String>> filterList = parseFilter(URLDecoder.decode(filterString, "UTF-8"), SLA_FILTER_NAMES);
SLASummaryFilter filter = new SLASummaryFilter();
if (!filterList.containsKey(OozieClient.FILTER_SLA_APPNAME) && !filterList.containsKey(OozieClient.FILTER_SLA_ID) && !filterList.containsKey(OozieClient.FILTER_SLA_PARENT_ID) && !filterList.containsKey(OozieClient.FILTER_BUNDLE) && !filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_START) && !filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_END)) {
StringBuffer st = new StringBuffer();
st.append("At least one of the filter parameters - ").append(OozieClient.FILTER_SLA_APPNAME).append(",").append(OozieClient.FILTER_SLA_ID).append(",").append(OozieClient.FILTER_SLA_PARENT_ID).append(",").append(OozieClient.FILTER_BUNDLE).append(",").append(OozieClient.FILTER_SLA_NOMINAL_START).append(" or ").append(OozieClient.FILTER_SLA_NOMINAL_END).append(" should be specified in the filter query parameter");
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, st.toString());
}
if (filterList.containsKey(OozieClient.FILTER_SLA_ID)) {
filter.setJobId(filterList.get(OozieClient.FILTER_SLA_ID).get(0));
}
if (filterList.containsKey(OozieClient.FILTER_SLA_PARENT_ID)) {
filter.setParentId(filterList.get(OozieClient.FILTER_SLA_PARENT_ID).get(0));
}
if (filterList.containsKey(OozieClient.FILTER_BUNDLE)) {
String bundle = filterList.get(OozieClient.FILTER_BUNDLE).get(0);
if (isBundleId(bundle)) {
filter.setBundleId(bundle);
} else {
filter.setBundleName(bundle);
}
}
if (filterList.containsKey(OozieClient.FILTER_SLA_EVENT_STATUS)) {
filter.setEventStatus(filterList.get(OozieClient.FILTER_SLA_EVENT_STATUS).get(0));
}
if (filterList.containsKey(OozieClient.FILTER_SLA_STATUS)) {
filter.setSLAStatus(filterList.get(OozieClient.FILTER_SLA_STATUS).get(0));
}
if (filterList.containsKey(OozieClient.FILTER_SLA_APPNAME)) {
filter.setAppName(filterList.get(OozieClient.FILTER_SLA_APPNAME).get(0));
}
if (filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_START)) {
filter.setNominalStart(DateUtils.parseDateUTC(filterList.get(OozieClient.FILTER_SLA_NOMINAL_START).get(0)));
}
if (filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_END)) {
filter.setNominalEnd(DateUtils.parseDateUTC(filterList.get(OozieClient.FILTER_SLA_NOMINAL_END).get(0)));
}
JPAService jpaService = Services.get().get(JPAService.class);
List<SLASummaryBean> slaSummaryList = null;
if (jpaService != null) {
slaSummaryList = jpaService.execute(new SLASummaryGetForFilterJPAExecutor(filter, numMaxResults));
} else {
XLog.getLog(getClass()).error(ErrorCode.E0610);
}
List<String> jobIds = new ArrayList<String>();
for (SLASummaryBean summaryBean : slaSummaryList) {
jobIds.add(summaryBean.getId());
}
List<SLARegistrationBean> SLARegistrationList = SLARegistrationQueryExecutor.getInstance().getList(SLARegQuery.GET_SLA_CONFIGS, jobIds);
Map<String, Map<String, String>> jobIdSLAConfigMap = new HashMap<String, Map<String, String>>();
for (SLARegistrationBean registrationBean : SLARegistrationList) {
jobIdSLAConfigMap.put(registrationBean.getId(), registrationBean.getSLAConfigMap());
}
return SLASummaryBean.toJSONObject(slaSummaryList, jobIdSLAConfigMap, timeZoneId);
} catch (XException ex) {
throw new CommandException(ex);
} catch (UnsupportedEncodingException e) {
throw new XServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ErrorCode.E0307, "Unsupported Encoding", e);
} catch (ParseException e) {
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, filterString, e);
}
}
Aggregations