Search in sources :

Example 1 with SLASummaryBean

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;
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 2 with SLASummaryBean

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;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) JPAService(org.apache.oozie.service.JPAService) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 3 with SLASummaryBean

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;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 4 with SLASummaryBean

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);
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Query(javax.persistence.Query) Timestamp(java.sql.Timestamp) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 5 with SLASummaryBean

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

SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)22 Date (java.util.Date)8 Query (javax.persistence.Query)8 EntityManager (javax.persistence.EntityManager)6 JPAService (org.apache.oozie.service.JPAService)6 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)6 ArrayList (java.util.ArrayList)5 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JsonBean (org.apache.oozie.client.rest.JsonBean)4 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3 SLASummaryQuery (org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery)3 Timestamp (java.sql.Timestamp)2 List (java.util.List)2 Map (java.util.Map)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CommandException (org.apache.oozie.command.CommandException)2 SLAService (org.apache.oozie.sla.service.SLAService)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1