Search in sources :

Example 56 with BundleJobGetJPAExecutor

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

the class TestBundleStartXCommand method testBundleStart2.

/**
 * Test : Start bundle job
 *
 * @throws Exception
 */
public void testBundleStart2() 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 bundleJobGetExecutor = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals("bundle-app-name", job.getAppName());
    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());
    assertEquals(2, actions.size());
    final String jobId = job.getId();
    waitFor(200000, 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) && actions.get(1).getStatus().equals(Job.Status.RUNNING);
        }
    });
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    assertEquals(Job.Status.RUNNING, actions.get(0).getStatus());
    assertEquals(true, actions.get(0).isCritical());
    assertEquals(job.getId(), actions.get(0).getBundleId());
    assertEquals(Job.Status.RUNNING, actions.get(1).getStatus());
    assertEquals(false, actions.get(1).isCritical());
    assertEquals(job.getId(), actions.get(1).getBundleId());
}
Also used : Path(org.apache.hadoop.fs.Path) 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) StringReader(java.io.StringReader) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 57 with BundleJobGetJPAExecutor

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

the class TestBundleStartXCommand method testBundleStartNegative2.

/**
 * Test : Start bundle job that contains bad coordinator job
 *
 * @throws Exception
 */
public void testBundleStartNegative2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTableNegative(Job.Status.PREP);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(job.getStatus(), Job.Status.PREP);
    new BundleStartXCommand(job.getId()).call();
    waitFor(120000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean job1 = jpaService.execute(bundleJobGetExecutor);
            return job1.getStatus().equals(Job.Status.FAILED);
        }
    });
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.FAILED, job.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 58 with BundleJobGetJPAExecutor

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

the class TestBundleStartXCommand method testBundleStart1.

/**
 * Test : Start bundle job
 *
 * @throws Exception
 */
public void testBundleStart1() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    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());
    assertEquals(2, actions.size());
    assertEquals(true, actions.get(0).isCritical());
    assertEquals(job.getId(), actions.get(0).getBundleId());
    assertEquals(false, actions.get(1).isCritical());
    assertEquals(job.getId(), actions.get(0).getBundleId());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 59 with BundleJobGetJPAExecutor

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

the class TestPurgeService method testPurgeServiceForBundle.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates a new Bundle job. Attempts to purge jobs older than a day.
 * Verifies the presence of the job in the system.
 * </p>
 * Sets the end date for the same job to make it qualify for the purge criteria.
 * Calls the purge service, and ensure the job does not exist in the system.
 */
public void testPurgeServiceForBundle() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ("2011-01-01T01:00Z"));
    final String jobId = job.getId();
    this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.SUCCEEDED);
    this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.SUCCEEDED);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.SUCCEEDED, job.getStatus());
    BundleActionGetJPAExecutor bundleActionGetExecutor1 = new BundleActionGetJPAExecutor(job.getId(), "action1");
    BundleActionBean action1 = jpaService.execute(bundleActionGetExecutor1);
    assertEquals(Job.Status.SUCCEEDED, action1.getStatus());
    BundleActionGetJPAExecutor bundleActionGetExecutor2 = new BundleActionGetJPAExecutor(job.getId(), "action2");
    BundleActionBean action2 = jpaService.execute(bundleActionGetExecutor2);
    assertEquals(Job.Status.SUCCEEDED, action2.getStatus());
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    final BundleEngine engine = new BundleEngine("u");
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getBundleJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        job = jpaService.execute(bundleJobGetExecutor);
        fail("Job should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(bundleActionGetExecutor1);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(bundleActionGetExecutor2);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) BundleEngine(org.apache.oozie.BundleEngine) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException)

Example 60 with BundleJobGetJPAExecutor

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

the class TestStatusTransitService method testBundleStatusTransitServiceSucceeded3.

/**
 * Test : all coord jobs are succeeded - bundle job's status will be updated to succeeded after suspend and resume.
 * coordinator action -> coordinator job -> bundle action -> bundle job
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceSucceeded3() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = job.getId();
    addRecordToBundleActionTable(bundleId, "action1", 1, Job.Status.RUNNING);
    addRecordToBundleActionTable(bundleId, "action2", 0, Job.Status.RUNNING);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1", CoordinatorJob.Status.RUNNING, start, end, true, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2", CoordinatorJob.Status.RUNNING, start, end, true, true, 2);
    addRecordToCoordActionTable("action1", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable("action1", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable("action2", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable("action2", 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    new BundleJobSuspendXCommand(bundleId).call();
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.SUSPENDED, job.getStatus());
    sleep(3000);
    new BundleJobResumeXCommand(bundleId).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.RUNNING, job.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobResumeXCommand(org.apache.oozie.command.bundle.BundleJobResumeXCommand) BundleJobBean(org.apache.oozie.BundleJobBean) BundleJobSuspendXCommand(org.apache.oozie.command.bundle.BundleJobSuspendXCommand) Date(java.util.Date)

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