use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestReRunXCommand method testRerunDisableForChild.
/**
* Rerun workflow should run by parent only if configuration has been set to
* true for oozie.wf.child.disable.rerun , Default it is disabled.
* @throws Exception
*/
public void testRerunDisableForChild() throws Exception {
final OozieClient wfClient = LocalOozie.getClient();
Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
String actionId = action.getId();
new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
final JPAService jpaService = Services.get().get(JPAService.class);
action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
}
final String wfId = action.getExternalId();
wfClient.kill(wfId);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.KILLED;
}
});
Properties newConf = wfClient.createConfiguration();
newConf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, true);
try {
wfClient.reRun(wfId, newConf);
fail("OozieClientException should have been thrown (" + ErrorCode.E0755 + " Rerun is not allowed through child workflow, please re-run through the parent)");
} catch (OozieClientException ex) {
assertEquals(ErrorCode.E0755.toString(), ex.getErrorCode());
}
Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, false);
wfClient.reRun(wfId, newConf);
waitFor(15 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(wfId).getStatus());
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class CoordUtils method getCoordActionsFromIds.
/**
* Get the list of actions for given id ranges
*
* @param jobId coordinator job id
* @param scope a comma-separated list of action ranges. The action range is specified with two action numbers separated by '-'
* @return the list of all Coordinator actions for action range
* @throws CommandException thrown if failed to get coordinator actions by given id range
*/
@VisibleForTesting
public static List<CoordinatorActionBean> getCoordActionsFromIds(String jobId, String scope) throws CommandException {
JPAService jpaService = Services.get().get(JPAService.class);
Set<String> actions = getActionsIds(jobId, scope);
// Retrieve the actions using the corresponding actionIds
List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
for (String id : actions) {
CoordinatorActionBean coordAction = null;
try {
coordAction = jpaService.execute(new CoordActionGetJPAExecutor(id));
} catch (JPAExecutorException je) {
if (je.getErrorCode().equals(ErrorCode.E0605)) {
// ignore retrieval of non-existent actions in range
XLog.getLog(XLogService.class).warn("Coord action ID num [{0}] not yet materialized. Hence skipping over it for Kill action", id.substring(id.indexOf("@") + 1));
continue;
} else {
throw new CommandException(je);
}
}
coordActions.add(coordAction);
}
return coordActions;
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillWaiting.
/**
* Test: Kill a waiting coord action
* @throws Exception
*/
public void testCoordKillWaiting() throws Exception {
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, true, 0);
// Create a workflow job with RUNNING status
WorkflowJobBean wfJob1 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
// Create a coordinator job with RUNNING status
CoordinatorActionBean action1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1.getId(), "RUNNING", 0);
// Create a coordinator job with WAITING status
CoordinatorActionBean action2 = addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.WAITING, "coord-action-get.xml", null, null, 0);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
CoordActionGetJPAExecutor coordActionGetCmd1 = new CoordActionGetJPAExecutor(action1.getId());
CoordActionGetJPAExecutor coordActionGetCmd2 = new CoordActionGetJPAExecutor(action2.getId());
coordJob = jpaService.execute(coordJobGetCmd);
action1 = jpaService.execute(coordActionGetCmd1);
action2 = jpaService.execute(coordActionGetCmd2);
// Make sure the status is updated
assertEquals(coordJob.getStatus(), CoordinatorJob.Status.RUNNING);
assertEquals(action1.getStatus(), CoordinatorAction.Status.RUNNING);
assertEquals(action2.getStatus(), CoordinatorAction.Status.WAITING);
// Issue the kill command
new CoordKillXCommand(coordJob.getId()).call();
coordJob = jpaService.execute(coordJobGetCmd);
action1 = jpaService.execute(coordActionGetCmd1);
action2 = jpaService.execute(coordActionGetCmd2);
// Check the status and pending flag after kill command is issued
assertEquals(coordJob.getStatus(), CoordinatorJob.Status.KILLED);
assertEquals(action1.getStatus(), CoordinatorAction.Status.KILLED);
// The wf job is running and can be killed, so pending for coord action
// kill should be true
assertEquals(action1.getPending(), 1);
assertEquals(action2.getStatus(), CoordinatorAction.Status.KILLED);
// The coord job is waiting and no wf created yet, so pending for coord
// action kill should be false
assertEquals(action2.getPending(), 0);
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillForBackwardSupport.
/**
* Test : kill SUCCEEDED job successfully when CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS is true and coordinator schema
* is 0.1
*
* @throws Exception
*/
public void testCoordKillForBackwardSupport() throws Exception {
Services.get().destroy();
setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS, "true");
services = new Services();
setClassesToBeExcluded(services.getConf(), excludedServices);
services.init();
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, true);
CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
job.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_APPNAMESPACE, job);
CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(CoordinatorJob.Status.SUCCEEDED, job.getStatus());
assertEquals(CoordinatorAction.Status.RUNNING, action.getStatus());
new CoordKillXCommand(job.getId()).call();
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(CoordinatorJob.Status.KILLED, job.getStatus());
assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor 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.
}
}
Aggregations