Search in sources :

Example 21 with BundleActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor in project oozie by apache.

the class TestStatusTransitService method testBundleStatusTransitRunningFromKilled.

// Test bundle transition from killed to running when one action is rerun.
public void testBundleStatusTransitRunningFromKilled() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    final String bundleId = bundleJob.getId();
    CoordinatorJobBean coord1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    BundleActionBean bundleAction1 = addRecordToBundleActionTable(bundleId, coord1.getId(), "action1-C", 1, Job.Status.RUNNING);
    bundleJob.setPending();
    bundleAction1.setStatus(Job.Status.KILLED);
    bundleAction1.setPending(0);
    BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_STATUS_PENDING_MODTIME_COORDID, bundleAction1);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, bundleJob);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.KILLED, bundleJob.getStatus());
    bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertEquals(Job.Status.KILLED, bundleAction1.getStatus());
    bundleAction1.setPending(1);
    bundleAction1.setStatus(Job.Status.RUNNING);
    bundleAction1.setLastModifiedTime(new Date());
    bundleJob.setPending();
    bundleJob.setLastModifiedTime(new Date());
    BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_STATUS_PENDING_MODTIME_COORDID, bundleAction1);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, bundleJob);
    runnable.run();
    sleep(1000);
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(CoordinatorJob.Status.RUNNING, bundleJob.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean) Date(java.util.Date)

Example 22 with BundleActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor in project oozie by apache.

the class TestStatusTransitService method testBundleStatusTransitServiceKilled.

/**
 * Test : kill 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 testBundleStatusTransitServiceKilled() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.KILLED, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.KILLED);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.KILLED);
    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, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 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 CoordKillXCommand("action1-C").call();
    new CoordKillXCommand("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.KILLED);
        }
    });
    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.KILLED, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.KILLED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.KILLED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertFalse(bundleAction2.isPending());
    assertEquals(Job.Status.KILLED, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertFalse(coordJob2.isPending());
    assertEquals(Job.Status.KILLED, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) 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)

Example 23 with BundleActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor 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)

Example 24 with BundleActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor in project oozie by apache.

the class TestPauseTransitService method testPauseBundleAndCoordinator.

/**
 * Test : Pause a RUNNING bundle, then check bundle action has been updated to PAUSED by BundleStatusUpdateXCommand
 *
 * @throws Exception
 */
public void testPauseBundleAndCoordinator() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Date pauseTime = new Date(new Date().getTime() - 30 * 1000);
    job.setPauseTime(pauseTime);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_PAUSE_KICKOFF, job);
    BundleActionBean bundleAction1 = this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.RUNNING);
    BundleActionBean bundleAction2 = this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.RUNNING);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable("action1", CoordinatorJob.Status.RUNNING, start, end, false);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable("action2", CoordinatorJob.Status.RUNNING, start, end, false);
    coordJob1.setPauseTime(pauseTime);
    coordJob1.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob1);
    coordJob2.setPauseTime(pauseTime);
    coordJob2.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob2);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.RUNNING, job.getStatus());
    Runnable pauseStartRunnable = new PauseTransitRunnable();
    pauseStartRunnable.run();
    final String jobId = job.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bJob1 = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
            return bJob1.getStatus() == Job.Status.PAUSED;
        }
    });
    final String coordJobId1 = coordJob1.getId();
    final String coordJobId2 = coordJob2.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean cJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
            CoordinatorJobBean cJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
            return cJob1.getStatus() == Job.Status.PAUSED && cJob2.getStatus() == Job.Status.PAUSED;
        }
    });
    job = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
    assertEquals(Job.Status.PAUSED, job.getStatus());
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
    assertEquals(Job.Status.PAUSED, coordJob1.getStatus());
    coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
    assertEquals(Job.Status.PAUSED, coordJob2.getStatus());
    bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action1"));
    assertEquals(Job.Status.PAUSED, bundleAction1.getStatus());
    bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action2"));
    assertEquals(Job.Status.PAUSED, bundleAction2.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleActionBean (org.apache.oozie.BundleActionBean)24 BundleJobBean (org.apache.oozie.BundleJobBean)24 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)22 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)21 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)16 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)16 JPAService (org.apache.oozie.service.JPAService)16 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)12 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)12 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 Date (java.util.Date)7 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)5 IOException (java.io.IOException)2 CoordKillXCommand (org.apache.oozie.command.coord.CoordKillXCommand)2 PauseTransitRunnable (org.apache.oozie.service.PauseTransitService.PauseTransitRunnable)2 RecoveryRunnable (org.apache.oozie.service.RecoveryService.RecoveryRunnable)2