use of org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor.SLASummaryFilter 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