use of org.apache.oozie.command.coord.CoordActionCheckXCommand in project oozie by apache.
the class TestEventGeneration method testCoordinatorActionEvent.
@Test
public void testCoordinatorActionEvent() throws Exception {
// avoid noise from other apptype events by setting it to only
// coord action
ehs.setAppTypes(new HashSet<String>(Arrays.asList("coordinator_action")));
assertEquals(queue.size(), 0);
Date startTime = DateUtils.parseDateOozieTZ("2013-01-01T10:00Z");
Date endTime = DateUtils.parseDateOozieTZ("2013-01-01T10:01Z");
CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
modifyCoordForRunning(coord);
// Action WAITING on materialization
new CoordMaterializeTransitionXCommand(coord.getId(), 3600).call();
final CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(coord.getId() + "@1");
CoordinatorActionBean action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.WAITING, action.getStatus());
assertEquals(1, queue.size());
JobEvent event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.WAITING, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(action.getJobId(), event.getParentId());
assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
assertNull(event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
assertEquals(0, queue.size());
// Make Action ready
// In this case it will proceed to Running since n(ready_actions) < concurrency
new CoordActionInputCheckXCommand(action.getId(), coord.getId()).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.RUNNING, action.getStatus());
event = (JobEvent) queue.poll();
assertEquals(EventStatus.STARTED, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(action.getJobId(), event.getParentId());
assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(action.getExternalId()));
assertEquals(wfJob.getStartTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
sleep(2000);
// Action Success
wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
action.setStatus(CoordinatorAction.Status.RUNNING);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
new CoordActionCheckXCommand(action.getId(), 0).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.SUCCEEDED, action.getStatus());
List<Event> list = queue.pollBatch();
event = (JobEvent) list.get(list.size() - 1);
assertEquals(EventStatus.SUCCESS, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(action.getJobId(), event.getParentId());
assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
assertEquals(wfJob.getStartTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
// Action Failure
wfJob.setStatus(WorkflowJob.Status.FAILED);
action.setStatus(CoordinatorAction.Status.RUNNING);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
new CoordActionCheckXCommand(action.getId(), 0).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.FAILED, action.getStatus());
event = (JobEvent) queue.poll();
assertEquals(EventStatus.FAILURE, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(action.getJobId(), event.getParentId());
assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
assertEquals(wfJob.getStartTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
// Action Suspended
wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
action.setStatus(CoordinatorAction.Status.RUNNING);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
new CoordActionCheckXCommand(action.getId(), 0).call();
action = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorAction.Status.SUSPENDED, action.getStatus());
event = (JobEvent) queue.poll();
assertEquals(EventStatus.SUSPEND, event.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
assertEquals(action.getId(), event.getId());
assertEquals(action.getJobId(), event.getParentId());
assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
assertEquals(wfJob.getStartTime(), event.getStartTime());
assertEquals(coord.getUser(), event.getUser());
assertEquals(coord.getAppName(), event.getAppName());
// Action start on Coord Resume
coord.setStatus(CoordinatorJobBean.Status.SUSPENDED);
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, coord);
action.setStatus(CoordinatorAction.Status.SUSPENDED);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.SUSPENDED);
wfJob.setWorkflowInstance(wfInstance);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, wfJob);
queue.clear();
new CoordResumeXCommand(coord.getId()).call();
waitForEventGeneration(1000);
CoordinatorActionEvent cevent = (CoordinatorActionEvent) queue.poll();
assertEquals(EventStatus.STARTED, cevent.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
assertEquals(action.getId(), cevent.getId());
assertEquals(action.getJobId(), cevent.getParentId());
assertEquals(action.getNominalTime(), cevent.getNominalTime());
coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
assertEquals(coord.getLastModifiedTime(), cevent.getStartTime());
// Action going to WAITING on Coord Rerun
action.setStatus(CoordinatorAction.Status.KILLED);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
queue.clear();
new CoordRerunXCommand(coord.getId(), RestConstants.JOB_COORD_SCOPE_ACTION, "1", false, true, false, null).call();
waitFor(3 * 100, new Predicate() {
@Override
public boolean evaluate() throws Exception {
return jpaService.execute(coordGetCmd).getStatus() == CoordinatorAction.Status.WAITING;
}
});
cevent = (CoordinatorActionEvent) queue.poll();
assertEquals(EventStatus.WAITING, cevent.getEventStatus());
assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
assertEquals(action.getId(), cevent.getId());
assertEquals(action.getJobId(), cevent.getParentId());
assertEquals(action.getNominalTime(), cevent.getNominalTime());
assertEquals(wfJob.getStartTime(), event.getStartTime());
assertNotNull(cevent.getMissingDeps());
}
use of org.apache.oozie.command.coord.CoordActionCheckXCommand in project oozie by apache.
the class TestEventGeneration method testCoordinatorActionEventDependencies.
@Test
public void testCoordinatorActionEventDependencies() throws Exception {
final CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
final CoordinatorActionBean action = addRecordToCoordActionTable(coord.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId(action.getExternalId());
wjb.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().insert(wjb);
CoordinatorXCommand<Void> myCmd = new CoordActionCheckXCommand(action.getId(), 0) {
@Override
protected Void execute() {
CoordinatorXCommand.generateEvent(action, coord.getUser(), coord.getAppName(), null);
return null;
}
};
// CASE 1: Only pull missing deps
action.setMissingDependencies("pull");
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_DEPENDENCIES, action);
myCmd.call();
CoordinatorActionEvent event = (CoordinatorActionEvent) queue.poll();
assertNotNull(event);
assertEquals("pull", event.getMissingDeps());
// CASE 2: Only hcat (push) missing deps
action.setMissingDependencies(null);
action.setPushMissingDependencies("push");
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_DEPENDENCIES, action);
myCmd.call();
event = (CoordinatorActionEvent) queue.poll();
assertNotNull(event);
assertEquals("push", event.getMissingDeps());
// CASE 3: Both types
action.setMissingDependencies("pull");
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_DEPENDENCIES, action);
myCmd.call();
event = (CoordinatorActionEvent) queue.poll();
assertNotNull(event);
assertEquals("pull" + CoordELFunctions.INSTANCE_SEPARATOR + "push", event.getMissingDeps());
}
Aggregations