Search in sources :

Example 1 with CoordSuspendXCommand

use of org.apache.oozie.command.coord.CoordSuspendXCommand in project oozie by apache.

the class BundleJobSuspendXCommand method suspendChildren.

@Override
public void suspendChildren() throws CommandException {
    for (BundleActionBean action : this.bundleActions) {
        if (action.getStatus() == Job.Status.RUNNING || action.getStatus() == Job.Status.RUNNINGWITHERROR || action.getStatus() == Job.Status.PREP || action.getStatus() == Job.Status.PAUSED || action.getStatus() == Job.Status.PAUSEDWITHERROR) {
            // queue a CoordSuspendXCommand
            if (action.getCoordId() != null) {
                queue(new CoordSuspendXCommand(action.getCoordId()));
                updateBundleAction(action);
                LOG.debug("Suspend bundle action = [{0}], new status = [{1}], pending = [{2}] and queue CoordSuspendXCommand" + " for [{3}]", action.getBundleActionId(), action.getStatus(), action.getPending(), action.getCoordId());
            } else {
                updateBundleAction(action);
                LOG.debug("Suspend bundle action = [{0}], new status = [{1}], pending = [{2}] and coord id is null", action.getBundleActionId(), action.getStatus(), action.getPending());
            }
        }
    }
    LOG.debug("Suspended bundle actions for the bundle=[{0}]", jobId);
}
Also used : CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 2 with CoordSuspendXCommand

use of org.apache.oozie.command.coord.CoordSuspendXCommand in project oozie by apache.

the class TestStatusTransitService method testFoo.

/**
 * If you have a PREP coordinator job (with no actions) and you suspend it, it goes into PREPSUSPENDED.
 * The StatusTransitService should not transition it to RUNNING automatically.  This test verifies that the job remains in
 * PREPSUSPENDED; and transitions back to PREP after a resume command.
 *
 * @throws Exception
 */
public void testFoo() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, start, end, true, false, 0);
    final String coordJobId = coordJob.getId();
    new CoordSuspendXCommand(coordJobId).call();
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.PREPSUSPENDED, coordJob.getStatus());
    new StatusTransitRunnable().run();
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertEquals(Job.Status.PREPSUSPENDED, coordJob1.getStatus());
    new CoordResumeXCommand(coordJobId).call();
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.PREP, coordJob.getStatus());
    new StatusTransitRunnable().run();
    waitFor(20 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
            return job.getStatus().equals(Job.Status.PREP);
        }
    });
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertEquals(Job.Status.PREP, coordJob1.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 3 with CoordSuspendXCommand

use of org.apache.oozie.command.coord.CoordSuspendXCommand in project oozie by apache.

the class TestStatusTransitService method testBundleRunningAfterCoordResume.

public void testBundleRunningAfterCoordResume() throws Exception {
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, coord.getId(), "COORD-TEST", 0, Job.Status.RUNNING);
    new CoordSuspendXCommand(coord.getId()).call();
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.SUSPENDED, coord.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.SUSPENDED, bundleJob.getStatus());
    new CoordResumeXCommand(coord.getId()).call();
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.RUNNING, coord.getStatus());
    runnable = new StatusTransitRunnable();
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.RUNNING, bundleJob.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)

Example 4 with CoordSuspendXCommand

use of org.apache.oozie.command.coord.CoordSuspendXCommand in project oozie by apache.

the class TestStatusTransitService method testCoordStatusTransitServiceSuspendAndResume.

/**
 * Test : Suspend and resume a coordinator job which has finished materialization and all actions are succeeded.
 * </p>
 * Coordinator job changes to succeeded after resume
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceSuspendAndResume() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    final String coordJobId = coordJob.getId();
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable(coordJobId, 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable(coordJobId, 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    this.addRecordToWfJobTable(coordAction1_1.getExternalId(), WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    this.addRecordToWfJobTable(coordAction1_2.getExternalId(), WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    new CoordSuspendXCommand(coordJobId).call();
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.SUSPENDED, coordJob.getStatus());
    sleep(3000);
    new CoordResumeXCommand(coordJobId).call();
    coordJob = jpaService.execute(coordJobGetCmd);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
            return job.getStatus().equals(Job.Status.SUCCEEDED);
        }
    });
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.SUCCEEDED, coordJob1.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 5 with CoordSuspendXCommand

use of org.apache.oozie.command.coord.CoordSuspendXCommand in project oozie by apache.

the class TestStatusTransitService method testBundleStatusTransitServiceSuspended.

/**
 * Test : Suspend a bundle job - bundle job's pending will be updated to false.
 * <p/>
 * The pending is updated bottom-up. workflow job -> coordinator action -> coordinator job -> bundle action ->
 * bundle job
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceSuspended() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.SUSPENDED, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.SUSPENDED);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.SUSPENDED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1-C", CoordinatorJob.Status.RUNNING, start, end, false, false, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, false, false, 2);
    WorkflowJobBean wfJob1_1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable("action1-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_1.getId(), wfJob1_1.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable("action1-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_2.getId(), wfJob1_2.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_3 = addRecordToCoordActionTable("action2-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_3.getId(), wfJob1_3.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_4 = addRecordToCoordActionTable("action2-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_4.getId(), wfJob1_4.getStatusStr(), 0);
    new CoordSuspendXCommand("action1-C").call();
    new CoordSuspendXCommand("action2-C").call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(coordAction1_4.getExternalId()));
            return wfJob.getStatus().equals(Job.Status.SUSPENDED);
        }
    });
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.isPending() == false;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertFalse(bundleJob.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.SUSPENDED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertFalse(bundleAction2.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertFalse(coordJob2.isPending());
    assertEquals(Job.Status.SUSPENDED, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

CoordSuspendXCommand (org.apache.oozie.command.coord.CoordSuspendXCommand)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)4 Date (java.util.Date)3 CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)3 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)3 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 BundleActionBean (org.apache.oozie.BundleActionBean)2 BundleJobBean (org.apache.oozie.BundleJobBean)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)1 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)1 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)1