use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.
the class TestCoordChangeXCommand method testProcessLookaheadActions.
// Testcase to test deletion of lookahead action in case of end-date change
// Added one more test case to test processLookaheadActions with day frequency and SUSPENDED status.
public void testProcessLookaheadActions() throws Exception {
Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
Date endTime = DateUtils.parseDateOozieTZ("2013-08-29T00:00Z");
Date changeEndTime = DateUtils.parseDateOozieTZ("2013-08-05T00:00Z");
String endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(changeEndTime);
final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.SUSPENDED, startTime, endTime, endTime, true, false, 6);
addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T00:00Z"));
addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-02T00:00Z"));
addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-03T00:00Z"));
addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-04T00:00Z"));
addRecordToCoordActionTable(job.getId(), 5, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"));
addRecordToCoordActionTable(job.getId(), 6, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-06T00:00Z"));
job.setFrequency("1");
job.setTimeUnit(Timeunit.DAY);
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
JPAService jpaService = Services.get().get(JPAService.class);
new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
assertEquals(coordJob.getEndTime(), changeEndTime);
assertEquals(Job.Status.SUSPENDED, coordJob.getStatus());
assertEquals(4, coordJob.getLastActionNumber());
assertEquals(DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"), coordJob.getNextMaterializedTime());
assertEquals(DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"), coordJob.getLastActionTime());
assertEquals(changeEndTime, coordJob.getEndTime());
}
use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.
the class TestCoordChangeXCommand method testCoordChangeEndTime1.
/**
* Testcase when changing end-time == nextMaterializedTime
* reflects correct job status via StatusTransit
*
* @throws Exception
*/
public void testCoordChangeEndTime1() 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);
addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
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());
}
use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.
the class TestCoordChangeXCommand method testCoordChangeEndTime2.
/**
* Testcase when changing end-time > nextMaterializedTime, but < original end
* reflects correct job state and values
*
* @throws Exception
*/
public void testCoordChangeEndTime2() 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);
addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
// checking initial condition before change
assertTrue(coordJob.isDoneMaterialization());
Runnable runnable = new StatusTransitService.StatusTransitRunnable();
// dummy run so we get to the interval check following coord job change
runnable.run();
sleep(1000);
String newEndTime = convertDateToString(startTime.getTime() + 40 * 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());
assertTrue(coordJob.isPending());
// <-- changed
assertFalse(coordJob.isDoneMaterialization());
assertEquals(newEndTime, convertDateToString(coordJob.getEndTime().getTime()));
}
use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillSuccess1.
/**
* Test : kill job and action (READY) successfully
*
* @throws Exception
*/
public void testCoordKillSuccess1() throws Exception {
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 0);
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.RUNNING);
assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
assertFalse(job.isDoneMaterialization());
new CoordKillXCommand(job.getId()).call();
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertTrue(job.isDoneMaterialization());
assertNotNull(job.getLastModifiedTime());
assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
// Change job status to RUNNINGWITHERROR to simulate StatusTransitService changing it to
// RUNNINGWITHERROR if it had loaded status and had it as RUNNING in memory when CoordKill
// executes and updates status to KILLED in database.
job.setStatus(CoordinatorJob.Status.RUNNINGWITHERROR);
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, job);
job = jpaService.execute(coordJobGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNINGWITHERROR);
final CoordMaterializeTransitionXCommand transitionCmd = new CoordMaterializeTransitionXCommand(job.getId(), 3600);
try {
transitionCmd.loadState();
transitionCmd.verifyPrecondition();
fail();
} catch (PreconditionException e) {
// Materialization should not happen as done materialization is set to true by coord kill
}
StatusTransitService.StatusTransitRunnable statusTransit = new StatusTransitService.StatusTransitRunnable();
statusTransit.run();
// StatusTransitService should change the job back to KILLED
job = jpaService.execute(coordJobGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertTrue(job.isDoneMaterialization());
assertNotNull(job.getLastModifiedTime());
}
use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillSuccess2.
/**
* Test : kill job and action (RUNNING) successfully
*
* @throws Exception
*/
public void testCoordKillSuccess2() throws Exception {
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, true, 0);
CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "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.RUNNING);
assertEquals(action.getStatus(), CoordinatorAction.Status.RUNNING);
new CoordKillXCommand(job.getId()).call();
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertNotNull(job.getLastModifiedTime());
assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
}
Aggregations