Search in sources :

Example 46 with BundleJobGetJPAExecutor

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

the class TestBundleJobXCommand method testBundleJobInfo1.

/**
 * Test: submit bundle job, then check job info
 *
 * @throws Exception
 */
public void testBundleJobInfo1() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetjpa = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetjpa);
    assertEquals(job.getStatus(), Job.Status.PREP);
    BundleJobBean bundleJob = (new BundleJobXCommand(job.getId())).call();
    assertEquals(0, bundleJob.getCoordinators().size());
    assertEquals(bundleJob.getStatus(), Job.Status.PREP);
    assertEquals(bundleJob.getId(), job.getId());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService)

Example 47 with BundleJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor 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 48 with BundleJobGetJPAExecutor

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

the class TestBundlePauseUnpauseXCommand method testBundlePauseUnpauseNeg1.

/**
 * Test : Negative case - pause a suspended bundle
 *
 * @throws Exception
 */
public void testBundlePauseUnpauseNeg1() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.SUSPENDED, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.SUSPENDED);
    try {
        new BundlePauseXCommand(job).call();
        fail("should not reach here.");
    } catch (Exception ex) {
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService)

Example 49 with BundleJobGetJPAExecutor

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

the class TestBundlePauseUnpauseXCommand method testBundlePauseUnpause1.

/**
 * Test : Pause a PREP bundle
 *
 * @throws Exception
 */
public void testBundlePauseUnpause1() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.PREP);
    new BundlePauseXCommand(job).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.PREPPAUSED);
    new BundleUnpauseXCommand(job).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.PREP);
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService)

Example 50 with BundleJobGetJPAExecutor

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

the class TestBundlePauseUnpauseXCommand method testBundlePauseUnpause2.

/**
 * Test : Pause a RUNNING bundle
 *
 * @throws Exception
 */
public void testBundlePauseUnpause2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.RUNNING);
    new BundlePauseXCommand(job).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.PAUSED);
    new BundleUnpauseXCommand(job).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getStatus(), Job.Status.RUNNING);
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService)

Aggregations

BundleJobBean (org.apache.oozie.BundleJobBean)69 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)69 JPAService (org.apache.oozie.service.JPAService)54 BundleActionBean (org.apache.oozie.BundleActionBean)33 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)32 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)30 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 Date (java.util.Date)18 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)14 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)14 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)13 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 IOException (java.io.IOException)8 CommandException (org.apache.oozie.command.CommandException)8 Configuration (org.apache.hadoop.conf.Configuration)7 XConfiguration (org.apache.oozie.util.XConfiguration)7