Search in sources :

Example 96 with CoordJobGetJPAExecutor

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

the class TestCoordChangeXCommand method testCoordChangePauseTime.

/**
 * test pause time change : pending should mark false if job is running with
 * pending true. two actions should be removed for pause time changes.
 *
 * @throws Exception
 */
public void testCoordChangePauseTime() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T04:59Z");
    // 2 hrs
    Date pauseTime = new Date(startTime.getTime() + (3 * HOURS_IN_MS));
    String pauseTimeChangeStr = "pausetime=" + DateUtils.formatDateOozieTZ(pauseTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
    CoordinatorActionBean ca1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    CoordinatorActionBean ca2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
    CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));
    SLARegistrationBean slaRegBean1 = new SLARegistrationBean();
    slaRegBean1.setId(ca1.getId());
    SLARegistrationBean slaRegBean2 = new SLARegistrationBean();
    slaRegBean2.setId(ca2.getId());
    SLARegistrationBean slaRegBean3 = new SLARegistrationBean();
    slaRegBean3.setId(ca3.getId());
    SLARegistrationBean slaRegBean4 = new SLARegistrationBean();
    slaRegBean4.setId(ca4.getId());
    SLASummaryBean slaSummaryBean1 = new SLASummaryBean();
    slaSummaryBean1.setId(ca1.getId());
    SLASummaryBean slaSummaryBean3 = new SLASummaryBean();
    slaSummaryBean3.setId(ca3.getId());
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(slaRegBean1);
    insertList.add(slaRegBean2);
    insertList.add(slaRegBean3);
    insertList.add(slaRegBean4);
    insertList.add(slaSummaryBean1);
    insertList.add(slaSummaryBean3);
    JPAService jpaService = Services.get().get(JPAService.class);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    new CoordChangeXCommand(job.getId(), pauseTimeChangeStr).call();
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getPauseTime()), DateUtils.formatDateOozieTZ(pauseTime));
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    assertEquals(2, coordJob.getLastActionNumber());
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
        fail("Expected to fail as action 3 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 4));
        fail("Expected to fail as action 4 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    slaRegBean1 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean1.getId());
    assertNotNull(slaRegBean1);
    slaRegBean2 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean2.getId());
    assertNotNull(slaRegBean2);
    slaRegBean3 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean3.getId());
    assertNull(slaRegBean3);
    slaRegBean4 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean4.getId());
    assertNull(slaRegBean4);
    slaSummaryBean3 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean3.getId());
    assertNull(slaSummaryBean3);
    slaSummaryBean1 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean1.getId());
    assertNotNull(slaSummaryBean1);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordJobGetActionByActionNumberJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionByActionNumberJPAExecutor) JPAService(org.apache.oozie.service.JPAService) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 97 with CoordJobGetJPAExecutor

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

the class TestCoordChangeXCommand method testCoordChangeEndTime4.

/**
 * Testcase when no actions are added to coord action table
 * reflects correct job state and values
 *
 * @throws Exception
 */
public void testCoordChangeEndTime4() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (50 * 60 * 1000));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, true, true, 1);
    coordJob.setNextMaterializedTime(new Date(startTime.getTime() + (30 * 60 * 1000)));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob);
    Runnable runnable = new StatusTransitService.StatusTransitRunnable();
    // dummy run so we get to the interval check following coord job change
    runnable.run();
    sleep(1000);
    // checking before change
    assertEquals(endTime.getTime(), coordJob.getEndTime().getTime());
    String newEndTime = convertDateToString(startTime.getTime() + 30 * 60 * 1000);
    new CoordChangeXCommand(coordJob.getId(), "endtime=" + newEndTime).call();
    try {
        checkCoordJobs(coordJob.getId(), DateUtils.parseDateOozieTZ(newEndTime), null, null, false);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Invalid date" + ex);
    }
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    // checking after change
    assertEquals(newEndTime, convertDateToString(coordJob.getEndTime().getTime()));
    assertTrue(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
    runnable.run();
    sleep(1000);
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
    assertFalse(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) StoreException(org.apache.oozie.store.StoreException) CommandException(org.apache.oozie.command.CommandException)

Example 98 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor 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)

Example 99 with CoordJobGetJPAExecutor

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

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

the class TestCoordJobGetJPAExecutor method _testGetJob.

private void _testGetJob(String jobId) throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(jobId);
    CoordinatorJobBean ret = jpaService.execute(coordGetCmd);
    assertNotNull(ret);
    assertEquals(ret.getId(), jobId);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Aggregations

CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)121 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)114 JPAService (org.apache.oozie.service.JPAService)85 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)79 Date (java.util.Date)66 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)42 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)32 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)30 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)29 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)25 BundleJobBean (org.apache.oozie.BundleJobBean)21 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)21 BundleActionBean (org.apache.oozie.BundleActionBean)20 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)20 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)20 CommandException (org.apache.oozie.command.CommandException)18 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)16 IOException (java.io.IOException)5 CoordMaterializeTriggerRunnable (org.apache.oozie.service.CoordMaterializeTriggerService.CoordMaterializeTriggerRunnable)5 Services (org.apache.oozie.service.Services)5