Search in sources :

Example 41 with StatusTransitRunnable

use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.

the class TestStatusTransitService method testBundleStatusNotTransitionFromKilled.

/**
 * Test : kill a bundle job with coord jobs as DONEWITHERROR
 * <p/>
 * Bundle status should be kill.
 *
 * @throws Exception
 */
public void testBundleStatusNotTransitionFromKilled() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1", 0, Job.Status.DONEWITHERROR);
    addRecordToBundleActionTable(bundleId, "action2", 0, Job.Status.DONEWITHERROR);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1", CoordinatorJob.Status.DONEWITHERROR, start, end, false, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2", CoordinatorJob.Status.DONEWITHERROR, start, end, false, true, 2);
    new BundleKillXCommand(bundleId).call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.getStatus() == Job.Status.KILLED;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.KILLED, bundleJob.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.getStatus() == Job.Status.KILLED;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.KILLED, bundleJob.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date) BundleKillXCommand(org.apache.oozie.command.bundle.BundleKillXCommand) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 42 with StatusTransitRunnable

use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable 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

StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)42 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)34 Date (java.util.Date)30 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)29 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)25 BundleJobBean (org.apache.oozie.BundleJobBean)18 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)14 BundleActionBean (org.apache.oozie.BundleActionBean)10 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)6 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)5 CoordKillXCommand (org.apache.oozie.command.coord.CoordKillXCommand)4 CoordSuspendXCommand (org.apache.oozie.command.coord.CoordSuspendXCommand)4 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)4 JPAService (org.apache.oozie.service.JPAService)4 CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)3 CoordJobInsertJPAExecutor (org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor)3 Configuration (org.apache.hadoop.conf.Configuration)2 BundleJobInsertJPAExecutor (org.apache.oozie.executor.jpa.BundleJobInsertJPAExecutor)2 CoordActionGetForCheckJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetForCheckJPAExecutor)2