Search in sources :

Example 66 with CoordJobGetJPAExecutor

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

the class TestCoordKillXCommand method testCoordKillFailed.

/**
 * Test : kill job failed. Job does not exist.
 *
 * @throws Exception
 */
public void testCoordKillFailed() throws Exception {
    final String testJobId = "0000001-" + new Date().getTime() + "-testCoordKill-C";
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, true);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
    try {
        new CoordKillXCommand(testJobId).call();
        fail("Job doesn't exist. Should fail.");
    } catch (CommandException ce) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 67 with CoordJobGetJPAExecutor

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

the class TestCoordKillXCommand method testCoordKillFailedOnAction.

/**
 * Test : kill job successfully but failed to kill an already successful action
 *
 * @throws Exception
 */
public void testCoordKillFailedOnAction() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, true);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.SUCCEEDED);
    new CoordKillXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    action = jpaService.execute(coordActionGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.SUCCEEDED);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 68 with CoordJobGetJPAExecutor

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

the class TestCoordMaterializeTransitionXCommand method testActionMaterWithCronFrequency6.

public void testActionMaterWithCronFrequency6() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-07-18T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-07-18T01:00Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, null, "20");
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    Date[] nominalTimes = new Date[] { DateUtils.parseDateOozieTZ("2013-07-18T00:00Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:20Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:40Z") };
    final int expectedNominalTimeCount = 3;
    checkCoordActionsNominalTime(job.getId(), expectedNominalTimeCount, nominalTimes);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
        assertTrue(job.isDoneMaterialization());
        assertEquals(job.getLastActionNumber(), expectedNominalTimeCount);
        assertEquals(job.getNextMaterializedTime(), DateUtils.parseDateOozieTZ("2013-07-18T01:00Z"));
    } catch (JPAExecutorException se) {
        se.printStackTrace();
        fail("Job ID " + job.getId() + " was not stored properly in db");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 69 with CoordJobGetJPAExecutor

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

the class TestCoordMaterializeTransitionXCommand method testMaterizationLookup.

/**
 * Test lookup materialization for catchup jobs
 *
 * @throws Exception
 */
public void testMaterizationLookup() throws Exception {
    long TIME_IN_MIN = 60 * 1000;
    long TIME_IN_HOURS = TIME_IN_MIN * 60;
    long TIME_IN_DAY = TIME_IN_HOURS * 24;
    JPAService jpaService = Services.get().get(JPAService.class);
    // test with days
    Date startTime = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2009-05-03T23:59Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(3);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    assertEquals(new Date(startTime.getTime() + TIME_IN_DAY * 3), job.getNextMaterializedTime());
    // test with hours
    startTime = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
    endTime = DateUtils.parseDateOozieTZ("2009-05-03T23:59Z");
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(10);
    job.setFrequency("1");
    job.setTimeUnitStr("HOUR");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    assertEquals(new Date(startTime.getTime() + TIME_IN_HOURS * 10), job.getNextMaterializedTime());
    // test with hours, time should not pass the current time.
    startTime = new Date(new Date().getTime() - TIME_IN_DAY * 3);
    endTime = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(10);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    Date next = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    TimeZone tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
    // test with hours, time should not pass the current time.
    startTime = new Date(new Date().getTime());
    endTime = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(10);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    next = new Date(startTime.getTime() + TIME_IN_DAY);
    tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
    // for current job in min, should not exceed hour windows
    startTime = new Date(new Date().getTime());
    endTime = new Date(startTime.getTime() + TIME_IN_HOURS * 24);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setMatThrottling(20);
    job.setFrequency("5");
    job.setTimeUnitStr("MINUTE");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    next = new Date(startTime.getTime() + TIME_IN_HOURS);
    tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
    // for current job in hour, should not exceed hour windows
    startTime = new Date(new Date().getTime());
    endTime = new Date(startTime.getTime() + TIME_IN_DAY * 24);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setMatThrottling(20);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    next = new Date(startTime.getTime() + TIME_IN_DAY);
    tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
    // Case: job started in Daylight time, and materialization is in
    // Standard time
    startTime = getDaylightCalendar().getTime();
    endTime = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(10);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in
    // "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    next = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
    // Case: job started in Standard time, and materialization is in
    // Daylight time
    Calendar c = getStandardCalendar();
    startTime = c.getTime();
    endTime = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, startTime, endTime, false, false, 0);
    job.setNextMaterializedTime(startTime);
    job.setMatThrottling(10);
    job.setFrequency("1");
    job.setTimeUnitStr("DAY");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job, hoursToSeconds(1), startTime, endTime).call();
    job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
    // If the startTime and endTime straddle a DST shift (the Coord is in
    // "America/Los_Angeles"), then we need to adjust for
    // that because startTime and endTime assume GMT
    next = new Date(startTime.getTime() + TIME_IN_DAY * 3);
    tz = TimeZone.getTimeZone(job.getTimeZone());
    next.setTime(next.getTime() + DaylightOffsetCalculator.getDSTOffset(tz, startTime, next));
    assertEquals(next, job.getNextMaterializedTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) TimeZone(java.util.TimeZone) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) Calendar(java.util.Calendar) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 70 with CoordJobGetJPAExecutor

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

the class TestCoordMaterializeTransitionXCommand method testActionMaterwithCronFrequencyWithThrottle.

public void testActionMaterwithCronFrequencyWithThrottle() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-07-18T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-07-18T01:00Z");
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, null, "0/10 * * * *");
    job.setMatThrottling(3);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    new CoordMaterializeTransitionXCommand(job.getId(), hoursToSeconds(1)).call();
    Date[] nominalTimes = new Date[] { DateUtils.parseDateOozieTZ("2013-07-18T00:00Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:10Z"), DateUtils.parseDateOozieTZ("2013-07-18T00:20Z") };
    final int expectedNominalTimeCount = 3;
    checkCoordActionsNominalTime(job.getId(), expectedNominalTimeCount, nominalTimes);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        job = jpaService.execute(new CoordJobGetJPAExecutor(job.getId()));
        assertFalse(job.isDoneMaterialization());
        assertEquals(expectedNominalTimeCount, job.getLastActionNumber());
        assertEquals(DateUtils.parseDateOozieTZ("2013-07-18T00:30Z"), job.getNextMaterializedTime());
    } catch (JPAExecutorException se) {
        se.printStackTrace();
        fail("Job ID " + job.getId() + " was not stored properly in db");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

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