use of org.apache.oozie.CoordinatorActionBean 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");
}
use of org.apache.oozie.CoordinatorActionBean 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.CoordinatorActionBean 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);
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillRemovePushMissingDeps.
public void testCoordKillRemovePushMissingDeps() throws Exception {
try {
services.destroy();
services = super.setupServicesForHCatalog();
services.init();
String db = "default";
String table = "tablename";
String server = "hcatserver";
String newHCatDependency1 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=brazil";
String newHCatDependency2 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=usa";
String pushMissingDeps = newHCatDependency1 + CoordELFunctions.INSTANCE_SEPARATOR + newHCatDependency2;
PartitionDependencyManagerService pdms = Services.get().get(PartitionDependencyManagerService.class);
CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-job-for-action-input-check.xml", CoordinatorJob.Status.RUNNING, false, true);
CoordinatorActionBean action1 = addRecordToCoordActionTableForWaiting(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml", null, pushMissingDeps, "Z");
String newHCatDependency3 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=russia";
CoordinatorActionBean action2 = addRecordToCoordActionTableForWaiting(job.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml", null, newHCatDependency3, "Z");
HCatURI hcatURI1, hcatURI2, hcatURI3;
hcatURI1 = new HCatURI(newHCatDependency1);
hcatURI2 = new HCatURI(newHCatDependency2);
hcatURI3 = new HCatURI(newHCatDependency3);
pdms.addMissingDependency(hcatURI1, action1.getId());
pdms.addMissingDependency(hcatURI2, action1.getId());
pdms.addMissingDependency(hcatURI3, action2.getId());
assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency1)).contains(action1.getId()));
assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency2)).contains(action1.getId()));
assertTrue(pdms.getWaitingActions(new HCatURI(newHCatDependency3)).contains(action2.getId()));
new CoordKillXCommand(job.getId()).call();
assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency1)));
assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency2)));
assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency3)));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestCoordMaterializeTransitionXCommand method getCoordAction.
private CoordinatorActionBean getCoordAction(String actionId) throws JPAExecutorException {
JPAService jpaService = Services.get().get(JPAService.class);
CoordinatorActionBean actionBean;
actionBean = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
return actionBean;
}
Aggregations