use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.
the class TestCoordChangeXCommand method addRecordToCoordJobTableForPauseTimeTest.
protected CoordinatorJobBean addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status status, Date start, Date end, Date lastActionTime, boolean pending, boolean doneMatd, int lastActionNum) throws Exception {
CoordinatorJobBean coordJob = createCoordJob(status, start, end, pending, doneMatd, lastActionNum);
coordJob.setFrequency("1");
coordJob.setTimeUnit(Timeunit.HOUR);
coordJob.setLastActionNumber(lastActionNum);
coordJob.setLastActionTime(lastActionTime);
try {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(coordJob);
jpaService.execute(coordInsertCmd);
} catch (JPAExecutorException je) {
je.printStackTrace();
fail("Unable to insert the test coord job record to table");
throw je;
}
return coordJob;
}
use of org.apache.oozie.CoordinatorJobBean 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.CoordinatorJobBean 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.CoordinatorJobBean in project oozie by apache.
the class TestCoordCommandUtils method testGetNextValidActionTime.
public void testGetNextValidActionTime() 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, "10,20 * * * *");
Date actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:15Z");
Date expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
Date retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "10/20 * * 5-7 4,5");
actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:15Z");
expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:30Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 * 20 5-7 4,5");
actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
expectedDate = DateUtils.parseDateOozieTZ("2013-07-18T00:21Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "30 * 20 5-7 ?");
actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
expectedDate = DateUtils.parseDateOozieTZ("2013-07-20T00:30Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "0 9-16 * * 2-6");
actionTime = DateUtils.parseDateOozieTZ("2013-07-20T00:20Z");
expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T09:00Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(retDate, job);
expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T10:00Z");
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 * * 1 *");
actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
expectedDate = DateUtils.parseDateOozieTZ("2014-01-01T00:20Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, "20-30 10 * * MON,WED");
actionTime = DateUtils.parseDateOozieTZ("2013-07-18T00:20Z");
expectedDate = DateUtils.parseDateOozieTZ("2013-07-22T10:20Z");
retDate = CoordCommandUtils.getNextValidActionTimeForCronFrequency(actionTime, job);
assertEquals(expectedDate, retDate);
}
use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.
the class TestCoordCommandUtils method testCoordOffset.
@Test
public void testCoordOffset() throws Exception {
CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-dataset-offset.xml", CoordinatorJob.Status.RUNNING, false, true);
Path appPath = new Path(getFsTestCaseDir(), "coord");
String actionXml = getCoordActionXml(appPath, "coord-dataset-offset.xml");
actionXml = actionXml.replace("-unit-", "DAY");
actionXml = actionXml.replace("-frequency-", "1");
CoordinatorActionBean actionBean = createCoordinatorActionBean(job);
Configuration jobConf = new XConfiguration(new StringReader(job.getConf()));
Element eAction = createActionElement(actionXml);
jobConf.set("startInstance", "coord:offset(-4,DAY)");
jobConf.set("endInstance", "coord:offset(0,DAY)");
String output = CoordCommandUtils.materializeOneInstance("jobId", true, eAction, DateUtils.parseDateOozieTZ("2009-08-20T10:00Z"), DateUtils.parseDateOozieTZ("2009-08-20T10:00Z"), 1, jobConf, actionBean);
eAction = XmlUtils.parseXml(output);
Element e = (Element) ((Element) eAction.getChildren("input-events", eAction.getNamespace()).get(0)).getChildren().get(0);
assertEquals(e.getChild("uris", e.getNamespace()).getTextTrim(), "hdfs:///tmp/workflows/2009/08/20/01;region=us#hdfs:///tmp/workflows/2009/08/19/01;region=us#" + "hdfs:///tmp/workflows/2009/08/18/01;region=us#hdfs:///tmp/workflows/2009/08/17/01;" + "region=us#hdfs:///tmp/workflows/2009/08/16/01;region=us");
jobConf.set("startInstance", "coord:offset(-4,HOUR)");
jobConf.set("endInstance", "coord:offset(0,HOUR)");
actionXml = getCoordActionXml(appPath, "coord-dataset-offset.xml");
actionXml = actionXml.replace("-unit-", "MINUTE");
actionXml = actionXml.replace("-frequency-", "60");
eAction = createActionElement(actionXml);
output = CoordCommandUtils.materializeOneInstance("jobId", true, eAction, DateUtils.parseDateOozieTZ("2009-08-20T01:00Z"), DateUtils.parseDateOozieTZ("2009-08-20T01:00Z"), 1, jobConf, actionBean);
eAction = XmlUtils.parseXml(output);
e = (Element) ((Element) eAction.getChildren("input-events", eAction.getNamespace()).get(0)).getChildren().get(0);
assertEquals(e.getChild("uris", e.getNamespace()).getTextTrim(), "hdfs:///tmp/workflows/2009/08/20/01;region=us#hdfs:///tmp/workflows/2009/08/20/00;region=us#" + "hdfs:///tmp/workflows/2009/08/19/23;region=us#hdfs:///tmp/workflows/2009/08/19/22;region=us#" + "hdfs:///tmp/workflows/2009/08/19/21;region=us");
}
Aggregations