Search in sources :

Example 16 with StatusTransitRunnable

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

the class TestBundleStartXCommand method testBundleStartWithFailedCoordinator.

public void testBundleStartWithFailedCoordinator() throws Exception {
    services.destroy();
    services = new Services();
    String[] excludeServices = { "org.apache.oozie.service.UUIDService", "org.apache.oozie.service.StatusTransitService" };
    Configuration conf = services.getConf();
    setClassesToBeExcluded(conf, excludeServices);
    conf.set(Services.CONF_SERVICE_CLASSES, conf.get(Services.CONF_SERVICE_CLASSES) + "," + DummyUUIDService.class.getName());
    services.init();
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId("dummy-coord-id");
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(coordJob);
    jpaService.execute(coordInsertCmd);
    BundleJobBean job = addRecordToBundleJobTable(Job.Status.PREP, false);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(job.getStatus(), Job.Status.PREP);
    new BundleStartXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(job.getStatus(), Job.Status.RUNNING);
    sleep(2000);
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    assertNull(actions.get(0).getCoordId());
    assertEquals(Job.Status.FAILED, actions.get(0).getStatus());
    Runnable runnable = new StatusTransitRunnable();
    // 1st run of StatusTransitionService changes bundle to running
    runnable.run();
    sleep(2000);
    // 2nd run changes bundle to DoneWithError
    runnable.run();
    sleep(2000);
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(job.getStatus(), Job.Status.DONEWITHERROR);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) Services(org.apache.oozie.service.Services) BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 17 with StatusTransitRunnable

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

the class TestCoordActionsKillXCommand method testActionKillCommandDate.

/**
 * Test the working of CoordActionKillXCommand by passing range
 * as date
 *
 * @throws Exception
 */
public void testActionKillCommandDate() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    String[] ids = createDBRecords();
    System.out.println(DateUtils.parseDateOozieTZ("2009-12-15T01:00Z"));
    System.out.println(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    new CoordActionsKillXCommand(ids[0], "date", "2009-12-15T01:00Z::2009-12-15T02:00Z").call();
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetForCheckJPAExecutor(ids[1]));
    System.out.println(action.getNominalTime());
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
    action = jpaService.execute(new CoordActionGetForCheckJPAExecutor(ids[2]));
    System.out.println(action.getNominalTime());
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
    sleep(100);
    WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_FOR_SLA, ids[3]);
    assertEquals(WorkflowJob.Status.KILLED, wf.getStatus());
    CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.RUNNING, job.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.KILLED, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) 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) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) CoordActionGetForCheckJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForCheckJPAExecutor)

Example 18 with StatusTransitRunnable

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

the class TestBundleKillXCommand method testBundleKill2.

/**
 * Test : Kill bundle job
 *
 * @throws Exception
 */
public void testBundleKill2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    new BundleKillXCommand(job.getId()).call();
    BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
    submitCmd.call();
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.PREP, job.getStatus());
    new BundleStartXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.RUNNING, job.getStatus());
    sleep(2000);
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    assertEquals(2, actions.size());
    assertNotNull(actions.get(0).getCoordId());
    assertNotNull(actions.get(1).getCoordId());
    new BundleKillXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    assertEquals(true, actions.get(0).isPending());
    assertEquals(true, actions.get(1).isPending());
    final CoordJobGetJPAExecutor coordGetCmd1 = new CoordJobGetJPAExecutor(actions.get(0).getCoordId());
    final CoordJobGetJPAExecutor coordGetCmd2 = new CoordJobGetJPAExecutor(actions.get(1).getCoordId());
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean job1 = jpaService.execute(coordGetCmd1);
            return job1.getStatus().equals(CoordinatorJobBean.Status.KILLED);
        }
    });
    CoordinatorJobBean job1 = jpaService.execute(coordGetCmd1);
    assertEquals(CoordinatorJobBean.Status.KILLED, job1.getStatus());
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
            return job2.getStatus().equals(CoordinatorJobBean.Status.KILLED);
        }
    });
    CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
    assertEquals(CoordinatorJobBean.Status.KILLED, job2.getStatus());
    final Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    for (BundleActionBean action : actions) {
        assertEquals(0, action.getPending());
        assertEquals(CoordinatorJobBean.Status.KILLED, action.getStatus());
    }
    // If bundle kill + Status Transit service left the bundle action with Pending=1
    // due to race condition, killing the bundle again should reset the pending.
    job.setPending();
    job.setStatus(Status.RUNNING);
    actions.get(0).incrementAndGetPending();
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, job);
    BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_PENDING_MODTIME, actions.get(0));
    runnable.run();
    sleep(1000);
    new BundleKillXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
    runnable.run();
    sleep(1000);
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    for (BundleActionBean action : actions) {
        assertEquals(0, action.getPending());
        assertEquals(CoordinatorJobBean.Status.KILLED, action.getStatus());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StringReader(java.io.StringReader) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 19 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServiceRunning2.

/**
 * Test : 2 coord actions are running, 1 suspended and 1 succeeded, check job pending is reset
 * and status changed to RUNNING
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceRunning2() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNINGWITHERROR, start, end, true, false, 4);
    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);
    addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.SUSPENDED, "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(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor(jobId));
            return coordJob.getStatus() == Job.Status.RUNNING;
        }
    });
    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 20 with StatusTransitRunnable

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

the class TestStatusTransitService method testCoordStatusTransitServiceSucceeded.

/**
 * Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
 * pending true and coordinator actions with pending false. Then, runs the StatusTransitService runnable and ensures
 * the job status changes to SUCCEEDED.
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceSucceeded() 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, true, 3);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, 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.SUCCEEDED, 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