Search in sources :

Example 51 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestPurgeXCommand method testPurgeBundleWithCoordChildWithWFChild2.

/**
 * Test : The workflow and coordinator should not get purged, but the bundle parent should get purged --> none will get purged
 *
 * @throws Exception
 */
public void testPurgeBundleWithCoordChildWithWFChild2() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobBean bundleJob = addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ("2011-01-01T01:00Z"));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob.getId(), "SUCCEEDED", 0);
    BundleActionBean bundleAction = addRecordToBundleActionTable(bundleJob.getId(), coordJob.getId(), coordJob.getAppName(), 0, Job.Status.SUCCEEDED);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(wfAction.getId());
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    BundleActionGetJPAExecutor bundleActionGetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob.getAppName());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction = jpaService.execute(wfActionGetCmd);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    bundleJob = jpaService.execute(bundleJobGetCmd);
    bundleAction = jpaService.execute(bundleActionGetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleJob.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction.getStatus());
    new PurgeXCommand(getNumDaysToNotBePurged(wfJob.getEndTime()), getNumDaysToNotBePurged(coordJob.getLastModifiedTime()), 7, 10).call();
    try {
        jpaService.execute(bundleJobGetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Job should not have been purged");
    }
    try {
        jpaService.execute(bundleActionGetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action should not have been purged");
    }
    try {
        jpaService.execute(coordJobGetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job should not have been purged");
    }
    try {
        jpaService.execute(coordActionGetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action should not have been purged");
    }
    try {
        jpaService.execute(wfJobGetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job should not have been purged");
    }
    try {
        jpaService.execute(wfActionGetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action should not have been purged");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 52 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestBulkBundleXCommand method verifyChildrenStatus.

private void verifyChildrenStatus(String jobId, CoordinatorJob.Status status) throws Exception {
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    for (BundleActionBean action : actions) {
        String coordId = action.getCoordId();
        CoordinatorJobBean coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
        assertEquals(status, coordJob.getStatus());
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 53 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestBundleChangeXCommand method testCheckBundleActionStatus.

// Check partial update.
// 3 coord job with status SUCCEEDED, PREP, RUNNING.
// Changing endtime of running coord will fail because end time is before one of running action nominal time.
public void testCheckBundleActionStatus() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob1.setBundleId(bundleJob.getId());
    coordJob1.setAppName("COORD-TEST1");
    coordJob1.setEndTime(DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    coordJob1.setStartTime(DateUtils.parseDateOozieTZ("2013-08-01T00:00Z"));
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob1);
    BundleActionBean bundleAction1 = new BundleActionBean();
    bundleAction1.setBundleActionId(bundleJob.getId() + "_COORD-TEST1");
    bundleAction1.setCoordId(coordJob1.getId());
    bundleAction1.setBundleId(bundleJob.getId());
    bundleAction1.setStatus(Job.Status.SUCCEEDED);
    jpaService.execute(new BundleActionInsertJPAExecutor(bundleAction1));
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, false, false);
    coordJob2.setBundleId(bundleJob.getId());
    coordJob2.setAppName("COORD-TEST2");
    coordJob2.setStartTime(DateUtils.parseDateOozieTZ("2099-08-01T02:00Z"));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob2);
    BundleActionBean bundleAction2 = new BundleActionBean();
    bundleAction2.setBundleActionId(bundleJob.getId() + "_COORD-TEST2");
    bundleAction2.setCoordId(coordJob2.getId());
    bundleAction2.setBundleId(bundleJob.getId());
    bundleAction2.setStatus(Job.Status.PREP);
    jpaService.execute(new BundleActionInsertJPAExecutor(bundleAction2));
    CoordinatorJobBean coordJob3 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    addRecordToCoordActionTable(coordJob3.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(coordJob3.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    addRecordToCoordActionTable(coordJob3.getId(), 3, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
    addRecordToCoordActionTable(coordJob3.getId(), 4, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
    coordJob3.setBundleId(bundleJob.getId());
    coordJob3.setAppName("COORD-TEST3");
    coordJob3.setLastActionNumber(4);
    coordJob3.setEndTime(DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
    coordJob3.setStartTime(DateUtils.parseDateOozieTZ("2013-08-01T00:00Z"));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob3);
    BundleActionBean bundleAction3 = new BundleActionBean();
    bundleAction3.setBundleActionId(bundleJob.getId() + "_COORD-TEST3");
    bundleAction3.setPending(1);
    bundleAction3.setCoordId(coordJob3.getId());
    bundleAction3.setBundleId(bundleJob.getId());
    bundleAction3.setStatus(Job.Status.RUNNING);
    jpaService.execute(new BundleActionInsertJPAExecutor(bundleAction3));
    String dateStr = "2013-08-01T03:00Z";
    try {
        new BundleJobChangeXCommand(bundleJob.getId(), "endtime=" + dateStr).call();
        fail("should throw exception");
    } catch (Exception e) {
        String reports = e.getMessage();
        assertTrue(reports.contains(coordJob3.getId() + " : E1022: Cannot delete running/completed coordinator action"));
    }
    BundleActionBean action1 = BundleActionQueryExecutor.getInstance().get(BundleActionQuery.GET_BUNDLE_ACTION, bundleJob.getId() + "_COORD-TEST1");
    assertEquals(CoordinatorJob.Status.RUNNING, action1.getStatus());
    BundleActionBean action2 = BundleActionQueryExecutor.getInstance().get(BundleActionQuery.GET_BUNDLE_ACTION, bundleJob.getId() + "_COORD-TEST2");
    assertEquals(CoordinatorJob.Status.SUCCEEDED, action2.getStatus());
    BundleActionBean action3 = BundleActionQueryExecutor.getInstance().get(BundleActionQuery.GET_BUNDLE_ACTION, bundleJob.getId() + "_COORD-TEST3");
    // No change in running
    assertEquals(CoordinatorJob.Status.RUNNING, action3.getStatus());
    assertEquals(action3.getPending(), 1);
}
Also used : BundleActionInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleActionInsertJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean) XException(org.apache.oozie.XException)

Example 54 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestBundleChangeXCommand method testBundlePauseExtendMaterializesCoordinator.

public void testBundlePauseExtendMaterializesCoordinator() throws Exception {
    BundleJobBean bundle = this.addRecordToBundleJobTable(Job.Status.PAUSED, false);
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (20 * 60 * 1000));
    // coord job with num actions materialized = 1
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.PAUSED, startTime, endTime, true, false, 1);
    // setting dummy old pause time
    coord.setPauseTime(startTime);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_CHANGE, coord);
    // persist corresponding bundle action bean
    BundleActionBean bundleAction = this.addRecordToBundleActionTable(bundle.getId(), "COORD-TEST", 1, Job.Status.PAUSED);
    coord.setBundleId(bundle.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID, coord);
    bundleAction.setCoordId(coord.getId());
    BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_STATUS_PENDING_MODTIME_COORDID, bundleAction);
    // 20 sec later
    Date later = new Date(System.currentTimeMillis() + 20 * 1000);
    // 10 min later
    Date evenLater = new Date(later.getTime() + 10 * 60 * 1000);
    bundle = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, bundle.getId());
    assertEquals(Job.Status.PAUSED, bundle.getStatus());
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.PAUSED, coord.getStatus());
    // coordinator has previous actions
    // before the new pausetime
    coord.setNextMaterializedTime(new Date(startTime.getTime() + (300 * 1000)));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coord);
    Date lastMod = coord.getLastModifiedTime();
    addRecordToCoordActionTable(coord.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    // change pausetime to even later
    new BundleJobChangeXCommand(bundle.getId(), "pausetime=" + DateUtils.formatDateOozieTZ(evenLater)).call();
    // time for the queued CoordChangeXCommand to complete
    sleep(1000);
    Runnable runnable = new PauseTransitRunnable();
    // simulating run which would happen usually after interval
    runnable.run();
    Thread.sleep(1000);
    bundle = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, bundle.getId());
    assertEquals(Job.Status.RUNNING, bundle.getStatus());
    assertEquals(DateUtils.formatDateOozieTZ(evenLater), DateUtils.formatDateOozieTZ(bundle.getPauseTime()));
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.RUNNING, coord.getStatus());
    assertEquals(DateUtils.formatDateOozieTZ(evenLater), DateUtils.formatDateOozieTZ(coord.getPauseTime()));
    assertTrue(coord.getLastModifiedTime().after(lastMod));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean) Date(java.util.Date)

Example 55 with BundleActionBean

use of org.apache.oozie.BundleActionBean in project oozie by apache.

the class TestBundleJobSuspendXCommand method testBundleSuspend2.

/**
 * Test : Suspend bundle job
 *
 * @throws Exception
 */
public void testBundleSuspend2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    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());
    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 BundleJobSuspendXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.SUSPENDED, 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.SUSPENDED);
        }
    });
    CoordinatorJobBean job1 = jpaService.execute(coordGetCmd1);
    assertEquals(CoordinatorJobBean.Status.SUSPENDED, job1.getStatus());
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
            return job2.getStatus().equals(CoordinatorJobBean.Status.SUSPENDED);
        }
    });
    CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
    assertEquals(CoordinatorJobBean.Status.SUSPENDED, job2.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) StringReader(java.io.StringReader) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

BundleActionBean (org.apache.oozie.BundleActionBean)76 BundleJobBean (org.apache.oozie.BundleJobBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAService (org.apache.oozie.service.JPAService)35 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)33 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)30 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 Date (java.util.Date)19 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)19 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)13 IOException (java.io.IOException)10 CommandException (org.apache.oozie.command.CommandException)10 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)10 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)9 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)9 XConfiguration (org.apache.oozie.util.XConfiguration)8 ArrayList (java.util.ArrayList)6