Search in sources :

Example 11 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class SLAJobEventXCommand method writeToDB.

/**
 * WriteSLA object to DB.
 *
 * @throws JPAExecutorException the JPA executor exception
 */
private void writeToDB() throws JPAExecutorException {
    byte eventProc = slaCalc.getEventProcessed();
    // no more processing, no transfer to history set
    if (slaCalc.getEventProcessed() >= 8) {
        slaCalc.setEventProcessed(8);
    }
    SLASummaryBean slaSummaryBean = new SLASummaryBean();
    slaSummaryBean.setId(slaCalc.getId());
    slaSummaryBean.setEventProcessed(eventProc);
    slaSummaryBean.setSLAStatus(slaCalc.getSLAStatus());
    slaSummaryBean.setEventStatus(slaCalc.getEventStatus());
    slaSummaryBean.setActualEnd(slaCalc.getActualEnd());
    slaSummaryBean.setActualStart(slaCalc.getActualStart());
    slaSummaryBean.setActualDuration(slaCalc.getActualDuration());
    slaSummaryBean.setJobStatus(slaCalc.getJobStatus());
    slaSummaryBean.setLastModifiedTime(new Date());
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES, slaSummaryBean);
    LOG.debug(" Stored SLA SummaryBean Job [{0}] eventProc = [{1}], status = [{2}]", slaCalc.getId(), slaCalc.getEventProcessed(), slaCalc.getJobStatus());
}
Also used : SLASummaryBean(org.apache.oozie.sla.SLASummaryBean) Date(java.util.Date)

Example 12 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class BatchQueryExecutor method executeBatchInsertUpdateDelete.

@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
    List<QueryEntry> queryList = new ArrayList<QueryEntry>();
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    if (updateList != null) {
        for (UpdateEntry entry : updateList) {
            Query query = null;
            JsonBean bean = entry.getBean();
            if (bean instanceof WorkflowJobBean) {
                query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
            } else if (bean instanceof WorkflowActionBean) {
                query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorJobBean) {
                query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
            } else if (bean instanceof CoordinatorActionBean) {
                query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
            } else if (bean instanceof BundleJobBean) {
                query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
            } else if (bean instanceof BundleActionBean) {
                query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
            } else if (bean instanceof SLARegistrationBean) {
                query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
            } else if (bean instanceof SLASummaryBean) {
                query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
            } else {
                throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
            }
            queryList.add(new QueryEntry(entry.getQueryName(), query));
        }
    }
    jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Query(javax.persistence.Query) WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) BundleActionQuery(org.apache.oozie.executor.jpa.BundleActionQueryExecutor.BundleActionQuery) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) QueryEntry(org.apache.oozie.service.JPAService.QueryEntry) EntityManager(javax.persistence.EntityManager) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) BundleActionBean(org.apache.oozie.BundleActionBean) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 13 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean 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)

Example 14 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class SLASummaryQueryExecutor method getIfExist.

@Override
public SLASummaryBean getIfExist(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)) {
        return null;
    }
    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 15 with SLASummaryBean

use of org.apache.oozie.sla.SLASummaryBean in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangePauseTime.

/**
 * test pause time change : pending should mark false if job is running with
 * pending true. two actions should be removed for pause time changes.
 *
 * @throws Exception
 */
public void testCoordChangePauseTime() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T04:59Z");
    // 2 hrs
    Date pauseTime = new Date(startTime.getTime() + (3 * HOURS_IN_MS));
    String pauseTimeChangeStr = "pausetime=" + DateUtils.formatDateOozieTZ(pauseTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
    CoordinatorActionBean ca1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean ca2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
    CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
    SLARegistrationBean slaRegBean1 = new SLARegistrationBean();
    slaRegBean1.setId(ca1.getId());
    SLARegistrationBean slaRegBean2 = new SLARegistrationBean();
    slaRegBean2.setId(ca2.getId());
    SLARegistrationBean slaRegBean3 = new SLARegistrationBean();
    slaRegBean3.setId(ca3.getId());
    SLARegistrationBean slaRegBean4 = new SLARegistrationBean();
    slaRegBean4.setId(ca4.getId());
    SLASummaryBean slaSummaryBean1 = new SLASummaryBean();
    slaSummaryBean1.setId(ca1.getId());
    SLASummaryBean slaSummaryBean3 = new SLASummaryBean();
    slaSummaryBean3.setId(ca3.getId());
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(slaRegBean1);
    insertList.add(slaRegBean2);
    insertList.add(slaRegBean3);
    insertList.add(slaRegBean4);
    insertList.add(slaSummaryBean1);
    insertList.add(slaSummaryBean3);
    JPAService jpaService = Services.get().get(JPAService.class);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    new CoordChangeXCommand(job.getId(), pauseTimeChangeStr).call();
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getPauseTime()), DateUtils.formatDateOozieTZ(pauseTime));
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    assertEquals(2, coordJob.getLastActionNumber());
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
        fail("Expected to fail as action 3 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 4));
        fail("Expected to fail as action 4 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    slaRegBean1 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean1.getId());
    assertNotNull(slaRegBean1);
    slaRegBean2 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean2.getId());
    assertNotNull(slaRegBean2);
    slaRegBean3 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean3.getId());
    assertNull(slaRegBean3);
    slaRegBean4 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean4.getId());
    assertNull(slaRegBean4);
    slaSummaryBean3 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean3.getId());
    assertNull(slaSummaryBean3);
    slaSummaryBean1 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean1.getId());
    assertNotNull(slaSummaryBean1);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordJobGetActionByActionNumberJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionByActionNumberJPAExecutor) JPAService(org.apache.oozie.service.JPAService) 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