Search in sources :

Example 16 with BundleActionBean

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

the class TestPurgeXCommand method testPurgeBundleWithCoordChildWithWFChild1.

/**
 * Test : The workflow and coordinator should get purged, but the bundle parent shouldn't get purged --> none will get purged
 *
 * @throws Exception
 */
public void testPurgeBundleWithCoordChildWithWFChild1() 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(7, 7, getNumDaysToNotBePurged(bundleJob.getLastModifiedTime()), 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 17 with BundleActionBean

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

the class TestBundleSubmitXCommand method testMultipleCoordSubmit.

public void testMultipleCoordSubmit() throws Exception {
    final XConfiguration jobConf = setUpBundle();
    jobConf.set("coordName1", "coord1");
    jobConf.set("coordName2", "coord2");
    jobConf.set("coord1.starttime", "2009-02-01T00:00Z");
    BundleSubmitXCommand command = new BundleSubmitXCommand(jobConf);
    final BundleJobBean bundleBean = (BundleJobBean) command.getJob();
    bundleBean.setStartTime(new Date());
    bundleBean.setEndTime(new Date());
    final String jobId = command.call();
    sleep(2000);
    new BundleStartXCommand(jobId).call();
    waitFor(2000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
            return actions.get(0).getStatus().equals(Job.Status.RUNNING);
        }
    });
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    assertEquals(actions.size(), 2);
    assertEquals(actions.get(0).getCoordName(), "coord1");
    assertEquals(actions.get(1).getCoordName(), "coord2");
    try {
        new BundleCoordSubmitXCommand(jobConf, jobId, "coord1").call();
        fail("Should fail. Coord job is already created");
    } catch (CommandException e) {
        assertEquals(e.getErrorCode(), ErrorCode.E1304);
    }
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
    assertEquals(actions.size(), 2);
    assertEquals(actions.get(0).getStatusStr(), "RUNNING");
    assertEquals(actions.get(1).getStatusStr(), "RUNNING");
}
Also used : CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XConfiguration(org.apache.oozie.util.XConfiguration) BundleJobBean(org.apache.oozie.BundleJobBean) List(java.util.List) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 18 with BundleActionBean

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

the class TestBundleChangeXCommand method testBundleChangeReport.

// check command report
public void testBundleChangeReport() 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");
    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.KILLED, false, false);
    coordJob2.setBundleId(bundleJob.getId());
    coordJob2.setAppName("COORD-TEST2");
    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.KILLED);
    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.WAITING, "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.setCoordId(coordJob3.getId());
    bundleAction3.setBundleId(bundleJob.getId());
    bundleAction3.setStatus(Job.Status.RUNNING);
    jpaService.execute(new BundleActionInsertJPAExecutor(bundleAction3));
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    String dateStr = "2099-01-01T01:00Z";
    bundleJob = jpaService.execute(bundleJobGetCmd);
    assertEquals(bundleJob.getPauseTime(), null);
    String reports = null;
    try {
        new BundleJobChangeXCommand(bundleJob.getId(), "pausetime=" + dateStr).call();
    } catch (Exception e) {
        reports = e.getMessage();
    }
    assertTrue(reports.contains(coordJob2.getId() + " : Coord is in killed state"));
    bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    dateStr = "2013-08-01T03:00Z";
    bundleJob = jpaService.execute(bundleJobGetCmd);
    try {
        new BundleJobChangeXCommand(bundleJob.getId(), "endtime=" + dateStr).call();
    } catch (Exception e) {
        reports = e.getMessage();
    }
    assertTrue(reports.contains(coordJob2.getId() + " : Coord is in killed state"));
    assertTrue(reports.contains(coordJob3.getId() + " : E1022: Cannot delete running/completed coordinator action"));
}
Also used : BundleActionInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleActionInsertJPAExecutor) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) 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 19 with BundleActionBean

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

the class TestBundleChangeXCommand method testBundleChange2.

/**
 * Test : Change pause time of a bundle that contains a SUCCEEDED coordinator job,
 * The coordinator should also change its pause time.
 *
 * @throws Exception
 */
public void testBundleChange2() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob.setBundleId(bundleJob.getId());
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID, coordJob);
    coordJob.setAppName("COORD-TEST1");
    assertNotNull(jpaService);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob);
    BundleActionBean bundleAction = new BundleActionBean();
    bundleAction.setBundleActionId(bundleJob.getId() + "_COORD-TEST1");
    bundleAction.setCoordId(coordJob.getId());
    bundleAction.setBundleId(bundleJob.getId());
    bundleAction.setStatus(Job.Status.SUCCEEDED);
    jpaService.execute(new BundleActionInsertJPAExecutor(bundleAction));
    String dateStr = "2099-01-01T01:00Z";
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    bundleJob = jpaService.execute(bundleJobGetCmd);
    assertEquals(bundleJob.getPauseTime(), null);
    new BundleJobChangeXCommand(bundleJob.getId(), "pausetime=" + dateStr).call();
    bundleJob = jpaService.execute(bundleJobGetCmd);
    assertEquals(DateUtils.parseDateOozieTZ(dateStr), bundleJob.getPauseTime());
    final String coordJobId = coordJob.getId();
    waitFor(60000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
            return (coordJob1.getPauseTime() != null);
        }
    });
    coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
    assertEquals(DateUtils.parseDateOozieTZ(dateStr), coordJob.getPauseTime());
}
Also used : BundleActionInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleActionInsertJPAExecutor) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean) XException(org.apache.oozie.XException)

Example 20 with BundleActionBean

use of org.apache.oozie.BundleActionBean 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)

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