use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestRecoveryService method testWorkflowActionRecoveryUserRetry.
/**
* Tests functionality of the Recovery Service Runnable command. </p> Starts an action with USER_RETRY status.
* Runs the recovery runnable, and ensures the state changes to OK and the job completes successfully.
*
* @throws Exception
*/
public void testWorkflowActionRecoveryUserRetry() throws Exception {
final JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobBean job1 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action1 = this.addRecordToWfActionTable(job1.getId(), "1", WorkflowAction.Status.USER_RETRY);
WorkflowJobBean job2 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action2 = createWorkflowActionSetPending(job2.getId(), WorkflowAction.Status.USER_RETRY);
// Default recovery created time is 7 days.
action2.setCreatedTime(new Date(new Date().getTime() - 8 * RecoveryService.ONE_DAY_MILLISCONDS));
WorkflowActionInsertJPAExecutor actionInsertCmd = new WorkflowActionInsertJPAExecutor(action2);
jpaService.execute(actionInsertCmd);
Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
recoveryRunnable.run();
sleep(3000);
final WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowActionBean a = jpaService.execute(wfActionGetCmd);
return a.getExternalId() != null;
}
});
action1 = jpaService.execute(wfActionGetCmd);
assertNotNull(action1.getExternalId());
assertEquals(WorkflowAction.Status.RUNNING, action1.getStatus());
// Action 2 should not get recover as it's created time is older then 7 days
action2 = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action2.getId());
assertNull(action2.getExternalId());
assertEquals(WorkflowAction.Status.USER_RETRY, action2.getStatus());
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(job1, action1, false, false);
MapReduceActionExecutor actionExecutor = new MapReduceActionExecutor();
Configuration conf = actionExecutor.createBaseHadoopConf(context, XmlUtils.parseXml(action1.getConf()));
String launcherId = action1.getExternalId();
waitUntilYarnAppDoneAndAssertSuccess(launcherId);
Map<String, String> actionData = LauncherHelper.getActionData(getFileSystem(), context.getActionDir(), conf);
assertTrue(LauncherHelper.hasIdSwap(actionData));
}
use of org.apache.oozie.service.RecoveryService.RecoveryRunnable in project oozie by apache.
the class TestHAPartitionDependencyManagerService method testDependencyCacheWithHA.
public void testDependencyCacheWithHA() throws Exception {
db = "default";
table1 = "mytbl";
table2 = "mytb2";
part1 = "dt=20120101;country=us";
part2 = "dt=20120102;country=us";
part3 = "dt=20120103;country=us";
String newHCatDependency1 = "hcat://" + server + "/" + db + "/" + table1 + "/" + part1;
String newHCatDependency2 = "hcat://" + server + "/" + db + "/" + table1 + "/" + part2;
String newHCatDependency3 = "hcat://" + server + "/" + db + "/" + table2 + "/" + part3;
HCatURI dep1 = new HCatURI(newHCatDependency1);
HCatURI dep2 = new HCatURI(newHCatDependency2);
HCatURI dep3 = new HCatURI(newHCatDependency3);
// create db, table and partitions
populateTable();
String actionId1 = addInitRecords(newHCatDependency1);
String actionId2 = addInitRecords(newHCatDependency2);
String actionId3 = addInitRecords(newHCatDependency3);
// Assume dependency cache on dummy server with missing push dependencies registered
PartitionDependencyManagerService dummyPdms = new PartitionDependencyManagerService();
PartitionDependencyManagerService pdms = Services.get().get(PartitionDependencyManagerService.class);
dummyPdms.init(Services.get());
dummyPdms.addMissingDependency(dep1, actionId1);
dummyPdms.addMissingDependency(dep2, actionId2);
dummyPdms.addMissingDependency(dep3, actionId3);
Collection<String> waitingActions = (Collection<String>) dummyPdms.getWaitingActions(dep1);
assertEquals(1, waitingActions.size());
waitingActions = (Collection<String>) dummyPdms.getWaitingActions(dep2);
assertEquals(1, waitingActions.size());
waitingActions = (Collection<String>) dummyPdms.getWaitingActions(dep3);
assertEquals(1, waitingActions.size());
// Dependency cache on living server doesn't have these partitions registered at this point
waitingActions = (Collection<String>) pdms.getWaitingActions(dep1);
assertNull(waitingActions);
waitingActions = (Collection<String>) pdms.getWaitingActions(dep2);
assertNull(waitingActions);
waitingActions = (Collection<String>) pdms.getWaitingActions(dep3);
assertNull(waitingActions);
// Assume dummy server is down, and recovery service on living server pick up these jobs
dummyPdms.destroy();
Runnable recoveryRunnable = new RecoveryRunnable(60, 0, 60);
recoveryRunnable.run();
waitFor(30 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
Collection<String> waitingActions;
PartitionDependencyManagerService pdms = Services.get().get(PartitionDependencyManagerService.class);
HCatURI dep1 = new HCatURI("hcat://" + server + "/" + db + "/" + table1 + "/" + part1);
HCatURI dep2 = new HCatURI("hcat://" + server + "/" + db + "/" + table1 + "/" + part2);
HCatURI dep3 = new HCatURI("hcat://" + server + "/" + db + "/" + table2 + "/" + part3);
waitingActions = pdms.getWaitingActions(dep1);
if (waitingActions == null) {
return false;
}
waitingActions = pdms.getWaitingActions(dep2);
if (waitingActions == null) {
return false;
}
waitingActions = pdms.getWaitingActions(dep3);
if (waitingActions == null) {
return false;
}
return true;
}
});
// Dependency cache on living server has missing partitions added
waitingActions = (Collection<String>) pdms.getWaitingActions(dep1);
assertEquals(1, waitingActions.size());
assertTrue(waitingActions.contains(actionId1));
waitingActions = (Collection<String>) pdms.getWaitingActions(dep2);
assertEquals(1, waitingActions.size());
assertTrue(waitingActions.contains(actionId2));
waitingActions = (Collection<String>) pdms.getWaitingActions(dep3);
assertEquals(1, waitingActions.size());
assertTrue(waitingActions.contains(actionId3));
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
// mytbl and mytb2 registered to topic map to receive notification
assertTrue(hcatService.isRegisteredForNotification(dep1));
assertTrue(hcatService.isRegisteredForNotification(dep2));
assertTrue(hcatService.isRegisteredForNotification(dep3));
}
Aggregations