Search in sources :

Example 66 with BundleJobBean

use of org.apache.oozie.BundleJobBean in project oozie by apache.

the class TestCoordJobsGetFromParentIdJPAExecutor method testGetBundleParentTooMany.

public void testGetBundleParentTooMany() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobBean bundleJob = addRecordToBundleJobTable(Job.Status.SUCCEEDED, false);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob1.setAppName("coordJob1");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob1);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob2.setAppName("coordJob2");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob2);
    CoordinatorJobBean coordJob3 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob3.setAppName("coordJob3");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob3);
    CoordinatorJobBean coordJob4 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob4.setAppName("coordJob4");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob4);
    CoordinatorJobBean coordJob5 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob5.setAppName("coordJob5");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob5);
    CoordinatorActionBean coordAction1 = addRecordToCoordActionTable(coordJob1.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordAction2 = addRecordToCoordActionTable(coordJob2.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordAction3 = addRecordToCoordActionTable(coordJob3.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordAction4 = addRecordToCoordActionTable(coordJob4.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordAction5 = addRecordToCoordActionTable(coordJob5.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    BundleActionBean bundleAction1 = addRecordToBundleActionTable(bundleJob.getId(), coordJob1.getId(), coordJob1.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction2 = addRecordToBundleActionTable(bundleJob.getId(), coordJob2.getId(), coordJob2.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction3 = addRecordToBundleActionTable(bundleJob.getId(), coordJob3.getId(), coordJob3.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction4 = addRecordToBundleActionTable(bundleJob.getId(), coordJob4.getId(), coordJob4.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction5 = addRecordToBundleActionTable(bundleJob.getId(), coordJob5.getId(), coordJob5.getAppName(), 0, Job.Status.SUCCEEDED);
    List<String> children = new ArrayList<String>();
    // Get the first 3
    children.addAll(jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleJob.getId(), 3)));
    assertEquals(3, children.size());
    // Get the next 3 (though there's only 2 more)
    children.addAll(jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleJob.getId(), 3, 3)));
    assertEquals(5, children.size());
    checkChildren(children, coordJob1.getId(), coordJob2.getId(), coordJob3.getId(), coordJob4.getId(), coordJob5.getId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 67 with BundleJobBean

use of org.apache.oozie.BundleJobBean in project oozie by apache.

the class BulkJPAExecutor method actionQuery.

/**
 * Compose the coord action level query comprising bundle id/appname filter and coord action
 * status filter (if specified) and start-time or nominal-time filter (if specified)
 * @param em
 * @param bundles
 * @param times
 * @param responseList
 * @return Query string
 * @throws ParseException
 */
@SuppressWarnings("unchecked")
private String actionQuery(final List<String> coords, final List<String> params, List<String> statuses, EntityManager em, List<BundleJobBean> bundles, Map<String, Timestamp> times, List<BulkResponseImpl> responseList) throws ParseException {
    Query q = em.createNamedQuery("BULK_MONITOR_ACTIONS_QUERY");
    StringBuilder getActions = new StringBuilder(q.toString());
    int offset = getActions.indexOf("ORDER");
    StringBuilder conditionClause = new StringBuilder();
    if (coords != null) {
        PARAM_TYPE type = getParamType(coords.get(0), 'C');
        if (type == PARAM_TYPE.NAME) {
            conditionClause.append(inClause(coords.size(), "appName", 'c', "param"));
            params.addAll(coords);
        } else if (type == PARAM_TYPE.ID) {
            conditionClause.append(inClause(coords.size(), "id", 'c', "param"));
            params.addAll(coords);
        }
    }
    // Query: Select <columns> from CoordinatorActionBean a, CoordinatorJobBean c WHERE a.jobId = c.id
    // AND c.bundleId = :bundleId AND c.appName/id IN (...) AND a.statusStr IN (...)
    conditionClause.append(statusClause(statuses));
    offset = getActions.indexOf("ORDER");
    getActions.insert(offset - 1, conditionClause);
    // Query: Select <columns> from CoordinatorActionBean a, CoordinatorJobBean c WHERE a.jobId = c.id
    // AND c.bundleId = :bundleId AND c.appName/id IN (...) AND a.statusStr IN (...)
    // AND a.createdTimestamp >= startCreated _or_ a.createdTimestamp <= endCreated
    // AND a.nominalTimestamp >= startNominal _or_ a.nominalTimestamp <= endNominal
    timesClause(getActions, offset, times);
    q = em.createQuery(getActions.toString());
    Iterator<Entry<String, Timestamp>> iter = times.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, Timestamp> time = iter.next();
        q.setParameter(time.getKey(), time.getValue());
    }
    // pagination
    q.setFirstResult(start - 1);
    q.setMaxResults(len);
    if (coords != null) {
        fillParameters(q, "param", coords);
    }
    if (statuses != null) {
        fillParameters(q, "status", statuses);
    }
    // repeatedly execute above query for each bundle
    for (BundleJobBean bundle : bundles) {
        q.setParameter("bundleId", bundle.getId());
        List<Object[]> response = q.getResultList();
        for (Object[] r : response) {
            BulkResponseImpl br = getResponseFromObject(bundle, r);
            responseList.add(br);
        }
    }
    return q.toString();
}
Also used : Query(javax.persistence.Query) Timestamp(java.sql.Timestamp) Entry(java.util.Map.Entry) BundleJobBean(org.apache.oozie.BundleJobBean) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl)

Example 68 with BundleJobBean

use of org.apache.oozie.BundleJobBean in project oozie by apache.

the class BulkJPAExecutor method countQuery.

/**
 * Get total number of records for use with offset and len in API
 * @param clause
 * @param em
 * @param bundles
 * @return total count of coord actions
 */
private long countQuery(List<String> statuses, List<String> params, String clause, EntityManager em, List<BundleJobBean> bundles, Map<String, Timestamp> times) {
    Query q = em.createNamedQuery("BULK_MONITOR_COUNT_QUERY");
    StringBuilder getTotal = new StringBuilder(q.toString() + " ");
    // Query: select COUNT(a) from CoordinatorActionBean a, CoordinatorJobBean c
    // get entire WHERE clause from above i.e. actionQuery() for all conditions on coordinator job
    // and action status and times
    getTotal.append(clause.substring(clause.indexOf("WHERE"), clause.indexOf("ORDER")));
    int offset = getTotal.indexOf("bundleId");
    List<String> bundleIds = new ArrayList<String>();
    for (BundleJobBean bundle : bundles) {
        bundleIds.add(bundle.getId());
    }
    // Query: select COUNT(a) from CoordinatorActionBean a, CoordinatorJobBean c WHERE ...
    // AND c.bundleId IN (... list of bundle ids) i.e. replace single :bundleId with list
    getTotal = getTotal.replace(offset - 6, offset + 20, inClause(bundleIds.size(), "bundleId", 'c', "count").toString());
    q = em.createQuery(getTotal.toString());
    fillParameters(q, "count", bundleIds);
    if (statuses != null) {
        fillParameters(q, "status", statuses);
    }
    if (params != null) {
        fillParameters(q, "param", params);
    }
    Iterator<Entry<String, Timestamp>> iter = times.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, Timestamp> time = iter.next();
        q.setParameter(time.getKey(), time.getValue());
    }
    long total = ((Long) q.getSingleResult()).longValue();
    return total;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) Entry(java.util.Map.Entry) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 69 with BundleJobBean

use of org.apache.oozie.BundleJobBean in project oozie by apache.

the class BundleJobGetJPAExecutor method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
     */
@Override
@SuppressWarnings("unchecked")
public BundleJobBean execute(EntityManager em) throws JPAExecutorException {
    List<BundleJobBean> bdBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_JOB");
        q.setParameter("id", bundleJobId);
        bdBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    BundleJobBean bean = null;
    if (bdBeans != null && bdBeans.size() > 0) {
        bean = bdBeans.get(0);
        bean.setStatus(bean.getStatus());
        return bean;
    } else {
        throw new JPAExecutorException(ErrorCode.E0604, bundleJobId);
    }
}
Also used : Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 70 with BundleJobBean

use of org.apache.oozie.BundleJobBean in project oozie by apache.

the class BundleJobsGetNeedStartJPAExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public List<BundleJobBean> execute(EntityManager em) throws JPAExecutorException {
    List<BundleJobBean> bjBeans;
    try {
        Query q = em.createNamedQuery("GET_BUNDLE_JOBS_NEED_START");
        q.setParameter("currentTime", new Timestamp(date.getTime()));
        bjBeans = q.getResultList();
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
    return bjBeans;
}
Also used : Query(javax.persistence.Query) BundleJobBean(org.apache.oozie.BundleJobBean) Timestamp(java.sql.Timestamp)

Aggregations

BundleJobBean (org.apache.oozie.BundleJobBean)159 JPAService (org.apache.oozie.service.JPAService)78 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)69 BundleActionBean (org.apache.oozie.BundleActionBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)46 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)44 Date (java.util.Date)35 ArrayList (java.util.ArrayList)24 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 List (java.util.List)21 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 HashMap (java.util.HashMap)20 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)18 IOException (java.io.IOException)16 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 XConfiguration (org.apache.oozie.util.XConfiguration)16 Query (javax.persistence.Query)14 CommandException (org.apache.oozie.command.CommandException)14