Search in sources :

Example 1 with SLASummaryFilter

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);
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandException(org.apache.oozie.command.CommandException) SLASummaryFilter(org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor.SLASummaryFilter) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) JPAService(org.apache.oozie.service.JPAService) SLASummaryGetForFilterJPAExecutor(org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor) HashMap(java.util.HashMap) Map(java.util.Map) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 XException (org.apache.oozie.XException)1 CommandException (org.apache.oozie.command.CommandException)1 SLASummaryGetForFilterJPAExecutor (org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor)1 SLASummaryFilter (org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor.SLASummaryFilter)1 JPAService (org.apache.oozie.service.JPAService)1 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)1 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)1