Search in sources :

Example 31 with BundleActionBean

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

the class TestCoordJobsGetFromParentIdJPAExecutor method testGetBundleParent.

public void testGetBundleParent() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobBean bundleJobA = addRecordToBundleJobTable(Job.Status.SUCCEEDED, false);
    BundleJobBean bundleJobB = addRecordToBundleJobTable(Job.Status.SUCCEEDED, false);
    CoordinatorJobBean coordJobA1 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    CoordinatorJobBean coordJobA2 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJobA2.setAppName("something_different");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJobA2);
    CoordinatorJobBean coordJobB = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    CoordinatorActionBean coordActionA1 = addRecordToCoordActionTable(coordJobA1.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordActionA2 = addRecordToCoordActionTable(coordJobA2.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean coordActionB = addRecordToCoordActionTable(coordJobB.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    BundleActionBean bundleActionA1 = addRecordToBundleActionTable(bundleJobA.getId(), coordJobA1.getId(), coordJobA1.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleActionA2 = addRecordToBundleActionTable(bundleJobA.getId(), coordJobA2.getId(), coordJobA2.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleActionB = addRecordToBundleActionTable(bundleJobB.getId(), coordJobB.getId(), coordJobB.getAppName(), 0, Job.Status.SUCCEEDED);
    List<String> children = new ArrayList<String>();
    children.addAll(jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleJobA.getId(), 10)));
    checkChildren(children, coordJobA1.getId(), coordJobA2.getId());
    children = new ArrayList<String>();
    children.addAll(jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleJobB.getId(), 10)));
    checkChildren(children, coordJobB.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 32 with BundleActionBean

use of org.apache.oozie.BundleActionBean 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 33 with BundleActionBean

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

the class BundleActionQueryExecutor method getList.

@Override
public List<BundleActionBean> getList(BundleActionQuery namedQuery, Object... parameters) throws JPAExecutorException {
    JPAService jpaService = Services.get().get(JPAService.class);
    EntityManager em = jpaService.getEntityManager();
    Query query = getSelectQuery(namedQuery, em, parameters);
    List<?> retList = (List<?>) jpaService.executeGetList(namedQuery.name(), query, em);
    List<BundleActionBean> beanList = new ArrayList<BundleActionBean>();
    if (retList != null) {
        for (Object ret : retList) {
            beanList.add(constructBean(namedQuery, ret));
        }
    }
    return beanList;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 34 with BundleActionBean

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

the class BundleJobResumeXCommand method resumeChildren.

/* (non-Javadoc)
     * @see org.apache.oozie.command.ResumeTransitionXCommand#resumeChildren()
     */
@Override
public void resumeChildren() {
    for (BundleActionBean action : bundleActions) {
        if (action.getStatus() == Job.Status.SUSPENDED || action.getStatus() == Job.Status.SUSPENDEDWITHERROR || action.getStatus() == Job.Status.PREPSUSPENDED) {
            // queue a CoordResumeXCommand
            if (action.getCoordId() != null) {
                queue(new CoordResumeXCommand(action.getCoordId()));
                updateBundleAction(action);
                LOG.debug("Resume bundle action = [{0}], new status = [{1}], " + "pending = [{2}] and queue CoordResumeXCommand for [{3}]", action.getBundleActionId(), action.getStatus(), action.getPending(), action.getCoordId());
            } else {
                updateBundleAction(action);
                LOG.debug("Resume bundle action = [{0}], new status = [{1}], " + "pending = [{2}] and coord id is null", action.getBundleActionId(), action.getStatus(), action.getPending());
            }
        }
    }
    LOG.debug("Resume bundle actions for the bundle=[{0}]", bundleId);
}
Also used : CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 35 with BundleActionBean

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

the class BundleRerunXCommand method rerunChildren.

/* (non-Javadoc)
     * @see org.apache.oozie.command.RerunTransitionXCommand#rerunChildren()
     */
@Override
public void rerunChildren() throws CommandException {
    boolean isUpdateActionDone = false;
    Map<String, BundleActionBean> coordNameToBAMapping = new HashMap<String, BundleActionBean>();
    if (bundleActions != null) {
        for (BundleActionBean action : bundleActions) {
            if (action.getCoordName() != null) {
                coordNameToBAMapping.put(action.getCoordName(), action);
            }
        }
    }
    if (coordScope != null && !coordScope.isEmpty()) {
        String[] list = coordScope.split(",");
        for (String coordName : list) {
            coordName = coordName.trim();
            if (coordNameToBAMapping.keySet().contains(coordName)) {
                String coordId = coordNameToBAMapping.get(coordName).getCoordId();
                if (coordId == null) {
                    LOG.info("No coord id found. Therefore, nothing to queue for coord rerun for coordname: " + coordName);
                    continue;
                }
                CoordinatorJobBean coordJob = getCoordJob(coordId);
                String rerunDateScope;
                if (dateScope != null && !dateScope.isEmpty()) {
                    rerunDateScope = dateScope;
                } else {
                    String coordStart = DateUtils.formatDateOozieTZ(coordJob.getStartTime());
                    String coordEnd = DateUtils.formatDateOozieTZ(coordJob.getEndTime());
                    rerunDateScope = coordStart + "::" + coordEnd;
                }
                LOG.debug("Queuing rerun range [" + rerunDateScope + "] for coord id " + coordId + " of bundle " + bundleJob.getId());
                queue(new CoordRerunXCommand(coordId, RestConstants.JOB_COORD_SCOPE_DATE, rerunDateScope, refresh, noCleanup, false, null));
                updateBundleAction(coordNameToBAMapping.get(coordName));
                isUpdateActionDone = true;
            } else {
                LOG.info("Rerun for coord " + coordName + " NOT performed because it is not in bundle ", bundleJob.getId());
            }
        }
    } else if (dateScope != null && !dateScope.isEmpty()) {
        if (bundleActions != null) {
            for (BundleActionBean action : bundleActions) {
                if (action.getCoordId() == null) {
                    LOG.info("No coord id found. Therefore nothing to queue for coord rerun with coord name " + action.getCoordName());
                    continue;
                }
                LOG.debug("Queuing rerun range [" + dateScope + "] for coord id " + action.getCoordId() + " of bundle " + bundleJob.getId());
                queue(new CoordRerunXCommand(action.getCoordId(), RestConstants.JOB_COORD_SCOPE_DATE, dateScope, refresh, noCleanup, false, null));
                updateBundleAction(action);
                isUpdateActionDone = true;
            }
        }
    }
    if (!isUpdateActionDone) {
        transitToPrevious();
    }
    LOG.info("Rerun coord jobs for the bundle=[{0}]", jobId);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) HashMap(java.util.HashMap) CoordRerunXCommand(org.apache.oozie.command.coord.CoordRerunXCommand) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleActionBean (org.apache.oozie.BundleActionBean)76 BundleJobBean (org.apache.oozie.BundleJobBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAService (org.apache.oozie.service.JPAService)35 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)33 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)30 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 Date (java.util.Date)19 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)19 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)13 IOException (java.io.IOException)10 CommandException (org.apache.oozie.command.CommandException)10 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)10 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 XConfiguration (org.apache.oozie.util.XConfiguration)8 ArrayList (java.util.ArrayList)6