use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testWorkflowActionRecoveryService.
/**
* Tests functionality of the Recovery Service Runnable command. </p> Starts an action which behaves like an Async
* Action (Action and Job state set to Running). Changes the action configuration to run in sync mode and updates
* the store. Runs the recovery runnable, and ensures the state of the action and job have not changed. </p> Changes
* the state of the action from RUNNING to PREP and updates the store. Again, runs the recovery runnable and ensures
* the state changes to OK and the job completes successfully.
*
* @throws Exception
*/
public void testWorkflowActionRecoveryService() throws Exception {
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
createTestCaseSubDir("lib");
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine(getTestUser());
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("external-status", "ok");
conf.set("signal-value", "based_on_action_status");
conf.set("running-mode", "async");
// TODO CHECK, without this we get JPA concurrency exceptions, ODD
sleep(1000);
final String jobId = engine.submitJob(conf, true);
// TODO CHECK, without this we get JPA concurrency exceptions, ODD
sleep(1000);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
}
});
sleep(1000);
final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
store.beginTrx();
List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
final String actionId = action.getId();
assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
String actionConf = action.getConf();
String fixedActionConf = actionConf.replaceAll("async", "sync");
action.setConf(fixedActionConf);
action.setPending();
store.updateAction(action);
store.commitTrx();
store.closeTrx();
Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
recoveryRunnable.run();
sleep(3000);
final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
store2.beginTrx();
WorkflowActionBean action2 = store2.getAction(actionId, false);
assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
action2.setStatus(WorkflowActionBean.Status.PREP);
action2.setPending();
store2.updateAction(action2);
store2.commitTrx();
store2.closeTrx();
sleep(1000);
recoveryRunnable.run();
sleep(3000);
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getWorkflowAction(actionId).getStatus() == WorkflowActionBean.Status.OK);
}
});
// getPendingActions works correctly only with MYSQL - following assertsfail with hsql - to be investigated
// assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
final WorkflowStore store3 = Services.get().get(WorkflowStoreService.class).create();
store3.beginTrx();
WorkflowActionBean action3 = store3.getAction(actionId, false);
assertEquals(WorkflowActionBean.Status.OK, action3.getStatus());
store3.commitTrx();
store3.closeTrx();
}
use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testCoordActionRecoveryServiceForSuspended.
/**
* Tests functionality of the Recovery Service Runnable command. </p> Insert a coordinator job with SUSPENDED and
* action with SUSPENDED and workflow with RUNNING. Then, runs the recovery runnable and ensures the workflow status
* changes to SUSPENDED.
*
* @throws Exception
*/
public void testCoordActionRecoveryServiceForSuspended() throws Exception {
Date start = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
Date end = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUSPENDED, start, end, false, false, 1);
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
final String wfJobId = wfJob.getId();
addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUSPENDED, "coord-action-get.xml", wfJobId, "RUNNING", 2);
sleep(3000);
Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
recoveryRunnable.run();
final JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
WorkflowJobBean ret = jpaService.execute(wfGetCmd);
return (ret.getStatus() == WorkflowJob.Status.SUSPENDED);
}
});
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
WorkflowJobBean ret = jpaService.execute(wfGetCmd);
assertEquals(WorkflowJob.Status.SUSPENDED, ret.getStatus());
}
use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testCoordActionRecoveryServiceForWaitingRegisterPartition.
public void testCoordActionRecoveryServiceForWaitingRegisterPartition() throws Exception {
services.destroy();
services = super.setupServicesForHCatalog();
services.getConf().set(URIHandlerService.URI_HANDLERS, FSURIHandler.class.getName() + "," + HCatURIHandler.class.getName());
services.getConf().setLong(RecoveryService.CONF_PUSH_DEPENDENCY_INTERVAL, 1);
services.init();
String db = "default";
String table = "tablename";
// dep1 is not available and dep2 is available
String newHCatDependency1 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=brazil";
String newHCatDependency2 = "hcat://" + server + "/" + db + "/" + table + "/dt=20120430;country=usa";
String newHCatDependency = newHCatDependency1 + CoordELFunctions.INSTANCE_SEPARATOR + newHCatDependency2;
HCatAccessorService hcatService = services.get(HCatAccessorService.class);
JMSAccessorService jmsService = services.get(JMSAccessorService.class);
PartitionDependencyManagerService pdms = services.get(PartitionDependencyManagerService.class);
assertFalse(jmsService.isListeningToTopic(hcatService.getJMSConnectionInfo(new URI(newHCatDependency1)), db + "." + table));
populateTable(db, table);
String actionId = addInitRecords(newHCatDependency);
CoordinatorAction ca = checkCoordActionDependencies(actionId, newHCatDependency);
assertEquals(CoordinatorAction.Status.WAITING, ca.getStatus());
// Register the missing dependencies to PDMS assuming CoordPushDependencyCheckCommand did this.
pdms.addMissingDependency(new HCatURI(newHCatDependency1), actionId);
pdms.addMissingDependency(new HCatURI(newHCatDependency2), actionId);
sleep(2000);
Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
recoveryRunnable.run();
sleep(2000);
// Recovery service should have discovered newHCatDependency2 and JMS Connection should exist
// and newHCatDependency1 should be in PDMS waiting list
assertTrue(jmsService.isListeningToTopic(hcatService.getJMSConnectionInfo(new URI(newHCatDependency2)), "hcat." + db + "." + table));
checkCoordActionDependencies(actionId, newHCatDependency1);
assertNull(pdms.getWaitingActions(new HCatURI(newHCatDependency2)));
Collection<String> waitingActions = pdms.getWaitingActions(new HCatURI(newHCatDependency1));
assertEquals(1, waitingActions.size());
assertTrue(waitingActions.contains(actionId));
}
use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testBundleRecoveryCoordCreate.
/**
* If the bundle action is in PREP state and coord is not yet created, recovery should submit new coord
* @throws Exception
*/
public void testBundleRecoveryCoordCreate() throws Exception {
final BundleJobBean bundle = addRecordToBundleJobTable(Job.Status.RUNNING, false);
addRecordToBundleActionTable(bundle.getId(), "coord1", 1, Job.Status.PREP);
final JPAService jpaService = Services.get().get(JPAService.class);
sleep(3000);
Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
recoveryRunnable.run();
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
try {
if (mybundleAction.getCoordId() != null) {
jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
return true;
}
} catch (Exception e) {
}
return false;
}
});
BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
assertNotNull(mybundleAction.getCoordId());
try {
jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
} catch (Exception e) {
e.printStackTrace();
fail("Expected coord " + mybundleAction.getCoordId() + " to be created");
}
}
use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testCoordActionRecoveryServiceForSubmitted.
/**
* Tests functionality of the Recovery Service Runnable command. </p> Insert a coordinator job with RUNNING and
* action with SUBMITTED. Then, runs the recovery runnable and ensures the action status changes to RUNNING.
*
* @throws Exception
*/
public void testCoordActionRecoveryServiceForSubmitted() throws Exception {
final String jobId = "0000000-" + new Date().getTime() + "-testCoordRecoveryService-C";
final int actionNum = 1;
final String actionId = jobId + "@" + actionNum;
final CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
createTestCaseSubDir("one-op");
createTestCaseSubDir("one-op", "lib");
createTestCaseSubDir("workflows");
createTestCaseSubDir("in");
addRecordToJobTable(jobId, getTestCaseDir());
addRecordToActionTable(jobId, actionNum, actionId, getTestCaseDir());
sleep(3000);
Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
recoveryRunnable.run();
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorActionBean bean = ce.getCoordAction(actionId);
return (bean.getStatus() == CoordinatorAction.Status.RUNNING || bean.getStatus() == CoordinatorAction.Status.SUCCEEDED);
}
});
CoordinatorActionBean action = getCoordinatorAction(actionId);
if (action.getStatus() == CoordinatorAction.Status.RUNNING || action.getStatus() == CoordinatorAction.Status.SUCCEEDED) {
} else {
fail();
}
}
Aggregations