Search in sources :

Example 36 with StatusTransitRunnable

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

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

the class TestStatusTransitService method testBundleStatusTransitServicePausedWithError.

/**
 * Test : Check the transition of a PAUSED bundle job to PAUSEDWITHERROR
 * @throws Exception
 */
public void testBundleStatusTransitServicePausedWithError() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    BundleJobBean bundleJob = createBundleJob(Job.Status.PAUSED, true);
    bundleJob.setPauseTime(DateUtils.parseDateOozieTZ("2009-02-01T01:00Z"));
    final JPAService jpaService = Services.get().get(JPAService.class);
    BundleJobInsertJPAExecutor bundleInsertjpa = new BundleJobInsertJPAExecutor(bundleJob);
    jpaService.execute(bundleInsertjpa);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1", 1, Job.Status.PAUSED);
    addRecordToBundleActionTable(bundleId, "action2", 1, Job.Status.PAUSED);
    BundleActionBean bundleAction = addRecordToBundleActionTable(bundleId, "action3", 0, Job.Status.FAILED);
    bundleAction.setCoordId("test");
    BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_STATUS_PENDING_MODTIME_COORDID, bundleAction);
    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.getStatus() == Job.Status.PAUSEDWITHERROR;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.PAUSEDWITHERROR, bundleJob.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleJobInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleJobInsertJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 38 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServicePausedWithError.

/**
 * Test : all coord actions are running, job pending is reset
 *
 * @throws Exception
 */
public void testCoordStatusTransitServicePausedWithError() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = createCoordJob(CoordinatorJob.Status.PAUSEDWITHERROR, start, end, true, false, 3);
    // set the pause time explicity to make sure the job is not unpaused
    job.setPauseTime(DateUtils.parseDateOozieTZ("2009-02-01T01:00Z"));
    final JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(job);
    jpaService.execute(coordInsertCmd);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    final String jobId = job.getId();
    assertNotNull(jpaService);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(jobId));
            return coordJob.isPending() == false;
        }
    });
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordGetCmd);
    assertFalse(job.isPending());
    assertEquals(CoordinatorJob.Status.PAUSED, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 39 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServiceBackwardSupport.

/**
 * Test : Keep the backward support for states on. 2 coord actions are running, 1 killed, check if job pending is reset
 *  and state changed to
 * RUNNING. Make sure the status is not RUNNINGWITHERROR
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceBackwardSupport() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "true");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, false, 3);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    final String jobId = job.getId();
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(jobId));
            return coordJob.isPending() == false;
        }
    });
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordGetCmd);
    assertFalse(job.isPending());
    assertEquals(job.getStatus(), Job.Status.RUNNING);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) 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 40 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServiceUpdateLastModifiedTime.

public void testCoordStatusTransitServiceUpdateLastModifiedTime() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, false, 3);
    Date lastModifiedDate = job.getLastModifiedTime();
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 1);
    final JPAService jpaService = Services.get().get(JPAService.class);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordGetCmd);
    // As state of job has not changed, lastModified should not be updated
    assertEquals(lastModifiedDate.getTime(), job.getLastModifiedTime().getTime());
    assertEquals(Job.Status.RUNNING, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) 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)

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