Search in sources :

Example 1 with SLAStatus

use of org.apache.oozie.client.event.SLAEvent.SLAStatus in project oozie by apache.

the class SLASummaryGetForFilterJPAExecutor method execute.

@SuppressWarnings("unchecked")
@Override
public List<SLASummaryBean> execute(EntityManager em) throws JPAExecutorException {
    List<SLASummaryBean> ssBean = null;
    StringBuilder sb = new StringBuilder(selectStr);
    Map<String, Object> queryParams = new LinkedHashMap<String, Object>();
    boolean firstCondition = true;
    boolean jobExists = true;
    if (filter.getJobId() != null) {
        firstCondition = false;
        if (filter.getParentId() != null) {
            sb.append("(s.jobId = :jobId OR s.parentId = :parentId)");
            queryParams.put("jobId", filter.getJobId());
            queryParams.put("parentId", filter.getParentId());
        } else {
            sb.append("s.jobId = :jobId");
            queryParams.put("jobId", filter.getJobId());
        }
    }
    if (filter.getParentId() != null && filter.getJobId() == null) {
        firstCondition = false;
        sb.append("s.parentId = :parentId");
        queryParams.put("parentId", filter.getParentId());
    }
    if (filter.getBundleId() != null || filter.getBundleName() != null) {
        firstCondition = false;
        Query bq;
        List<Object> returnList;
        try {
            if (filter.getBundleId() != null) {
                bq = em.createQuery(bundleIdQuery);
                bq.setParameter("bundleId", filter.getBundleId());
            } else {
                bq = em.createQuery(bundleNameQuery);
                bq.setParameter("appName", filter.getBundleName());
            }
            bq.setMaxResults(numMaxResults);
            returnList = (List<Object>) bq.getResultList();
        } catch (Exception e) {
            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
        }
        StringBuilder sub = null;
        int ind = 0;
        if (returnList.size() == 0) {
            jobExists = false;
        }
        for (Object obj : returnList) {
            String coordId = (String) obj;
            if (sub == null) {
                sub = new StringBuilder();
                sub.append("s.parentId in (:parentId").append(ind);
            } else {
                sub.append(",:parentId").append(ind);
            }
            queryParams.put("parentId" + ind, coordId);
            ind++;
        }
        if (sub != null) {
            sub.append(")");
            sb.append(sub.toString());
        }
    }
    if (filter.getAppName() != null) {
        if (firstCondition) {
            firstCondition = false;
        } else {
            sb.append(" AND ");
        }
        sb.append("s.appName = :appName");
        queryParams.put("appName", filter.getAppName());
    }
    if (filter.getNominalStart() != null) {
        if (firstCondition) {
            firstCondition = false;
        } else {
            sb.append(" AND ");
        }
        sb.append("s.nominalTimeTS >= :nominalTimeStart");
        queryParams.put("nominalTimeStart", new Timestamp(filter.getNominalStart().getTime()));
    }
    if (filter.getNominalEnd() != null) {
        if (firstCondition) {
            firstCondition = false;
        } else {
            sb.append(" AND ");
        }
        sb.append("s.nominalTimeTS <= :nominalTimeEnd");
        queryParams.put("nominalTimeEnd", new Timestamp(filter.getNominalEnd().getTime()));
    }
    if (filter.getEventStatus() != null) {
        processEventStatusFilter(filter, queryParams, sb, firstCondition);
    }
    if (filter.getSLAStatus() != null) {
        StringBuilder sub = null;
        int ind = 0;
        if (firstCondition) {
            firstCondition = false;
        } else {
            sb.append(" AND ");
        }
        for (SLAStatus status : filter.getSLAStatus()) {
            if (sub == null) {
                sub = new StringBuilder();
                sub.append("s.slaStatus in (:slaStatus").append(ind);
            } else {
                sub.append(",:slaStatus").append(ind);
            }
            queryParams.put("slaStatus" + ind, status.toString());
            ind++;
        }
        if (sub != null) {
            sub.append(")");
            sb.append(sub.toString());
        }
    }
    if (jobExists) {
        sb.append(" ORDER BY s.nominalTimeTS");
        LOG.debug("Query String: " + sb.toString());
        try {
            Query q = em.createQuery(sb.toString());
            for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
                q.setParameter(entry.getKey(), entry.getValue());
            }
            q.setMaxResults(numMaxResults);
            ssBean = (List<SLASummaryBean>) q.getResultList();
        } catch (Exception e) {
            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
        }
    }
    return ssBean;
}
Also used : Query(javax.persistence.Query) SLAStatus(org.apache.oozie.client.event.SLAEvent.SLAStatus) Timestamp(java.sql.Timestamp) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) LinkedHashMap(java.util.LinkedHashMap) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Aggregations

Timestamp (java.sql.Timestamp)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Query (javax.persistence.Query)1 SLAStatus (org.apache.oozie.client.event.SLAEvent.SLAStatus)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)1