Search in sources :

Example 21 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServiceKilledByUser1.

/**
 * Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
 * pending false and coordinator actions with pending false. Then, runs the CoordKillXCommand and
 * StatusTransitService runnable and ensures the job pending changes to false.
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceKilledByUser1() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final String wfJobId = wfJob.getId();
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJobId, "RUNNING", 0);
    new CoordKillXCommand(coordJob.getId()).call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
            WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
            return wfBean.getStatusStr().equals("KILLED");
        }
    });
    assertNotNull(jpaService);
    final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    wfJob = jpaService.execute(wfGetCmd);
    assertEquals(CoordinatorJob.Status.KILLED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.KILLED, coordAction.getStatus());
    assertEquals(WorkflowJob.Status.KILLED, wfJob.getStatus());
    assertEquals(false, coordAction.isPending());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    // Status of coordJobBean is being updated asynchronously.
    // Increasing wait time to atmost 10s to make sure there is
    // sufficient time for the status to get updated. Thus, resulting
    // in following assertion not failing.
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJobBean = jpaService.execute(coordJobGetCmd);
            return !coordJobBean.isPending();
        }
    });
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(false, coordJob.isPending());
}
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) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)

Example 22 with StatusTransitRunnable

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

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

the class TestStatusTransitService method testBundleStatusTransitWithLock.

public void testBundleStatusTransitWithLock() throws Exception {
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final String jobId = bundleJob.getId();
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 0, Job.Status.PREP);
    addRecordToBundleActionTable(bundleId, "action2-C", 0, Job.Status.RUNNING);
    addRecordToBundleActionTable(bundleId, "action3-C", 0, Job.Status.DONEWITHERROR);
    JobLock lockThread = new JobLock(jobId);
    new Thread(lockThread).start();
    sleep(1000);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.RUNNING, bundleJob.getStatus());
    synchronized (lockThread) {
        lockThread.notifyAll();
    }
    sleep(1000);
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.RUNNINGWITHERROR, bundleJob.getStatus());
}
Also used : BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)

Example 24 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordNotTransitionfromKilled.

/**
 * Inserts a coordinator job in KILLED state with pending materialization.
 * Make sure the status doesn't change to DONEWITHERROR
 *
 * @throws Exception
 */
public void testCoordNotTransitionfromKilled() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, true, false);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorJob.Status.KILLED, coordJob.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)

Example 25 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitWithLock.

public void testCoordStatusTransitWithLock() throws Exception {
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    final JPAService jpaService = Services.get().get(JPAService.class);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, false, 1);
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", null, "KILLED", 0);
    final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    JobLock lockThread = new JobLock(coordJob.getId());
    new Thread(lockThread).start();
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(CoordinatorJob.Status.RUNNING, coordJob.getStatus());
    synchronized (lockThread) {
        lockThread.notifyAll();
    }
    runnable.run();
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(CoordinatorJob.Status.RUNNINGWITHERROR, coordJob.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