use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestCoordActionInputCheckXCommand method testResolveCoordConfiguration.
public void testResolveCoordConfiguration() {
try {
CoordinatorJobBean job = addRecordToCoordJobTableForWaiting("coord-job-for-action-input-check.xml", CoordinatorJob.Status.RUNNING, false, true);
CoordinatorActionBean action = addRecordToCoordActionTableForWaiting(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-for-action-input-check.xml");
createTestCaseSubDir("2009/01/29/_SUCCESS".split("/"));
createTestCaseSubDir("2009/01/22/_SUCCESS".split("/"));
createTestCaseSubDir("2009/01/15/_SUCCESS".split("/"));
createTestCaseSubDir("2009/01/08/_SUCCESS".split("/"));
sleep(3000);
new CoordActionInputCheckXCommand(action.getId(), job.getId()).call();
sleep(3000);
final JPAService jpaService = Services.get().get(JPAService.class);
CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(action.getId());
CoordinatorActionBean caBean = jpaService.execute(coordGetCmd);
Element eAction = XmlUtils.parseXml(caBean.getActionXml());
Element configElem = eAction.getChild("action", eAction.getNamespace()).getChild("workflow", eAction.getNamespace()).getChild("configuration", eAction.getNamespace());
List<?> elementList = configElem.getChildren("property", configElem.getNamespace());
Element e1 = (Element) elementList.get(0);
Element e2 = (Element) elementList.get(1);
assertEquals("file://,testDir/2009/29,file://,testDir/2009/22,file://,testDir/2009/15,file://,testDir/2009/08", e1.getChild("value", e1.getNamespace()).getValue());
assertEquals("file://,testDir/2009/29", e2.getChild("value", e1.getNamespace()).getValue());
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestCoordActionInputCheckXCommand method testActionInputCheckFuture.
public void testActionInputCheckFuture() throws Exception {
String jobId = "0000000-" + new Date().getTime() + "-TestCoordActionInputCheckXCommand-C";
Date startTime = DateUtils.parseDateOozieTZ("2009-02-15T23:59" + TZ);
Date endTime = DateUtils.parseDateOozieTZ("2009-02-16T23:59" + TZ);
CoordinatorJobBean job = addRecordToCoordJobTable(jobId, startTime, endTime, "future");
new CoordMaterializeTransitionXCommand(job.getId(), 3600).call();
// providing some of the dataset dirs required as per coordinator specification with holes
createTestCaseSubDir("2009/02/12/_SUCCESS".split("/"));
createTestCaseSubDir("2009/02/26/_SUCCESS".split("/"));
createTestCaseSubDir("2009/03/05/_SUCCESS".split("/"));
// limit is 5. So this should be ignored
createTestCaseSubDir("2009/03/26/_SUCCESS".split("/"));
new CoordActionInputCheckXCommand(job.getId() + "@1", job.getId()).call();
CoordinatorActionBean action = null;
JPAService jpaService = Services.get().get(JPAService.class);
try {
action = jpaService.execute(new CoordActionGetJPAExecutor(job.getId() + "@1"));
} catch (JPAExecutorException se) {
fail("Action ID " + job.getId() + "@1" + " was not stored properly in db");
}
assertEquals(CoordCommandUtils.RESOLVED_UNRESOLVED_SEPARATOR + "${coord:futureRange(0,3,'5')}", action.getMissingDependencies());
createTestCaseSubDir("2009/03/12/_SUCCESS".split("/"));
new CoordActionInputCheckXCommand(job.getId() + "@1", job.getId()).call();
try {
action = jpaService.execute(new CoordActionGetJPAExecutor(job.getId() + "@1"));
} catch (JPAExecutorException se) {
fail("Action ID " + job.getId() + "@1" + " was not stored properly in db");
}
assertEquals("", action.getMissingDependencies());
String actionXML = action.getActionXml();
String resolvedList = getTestCaseFileUri("2009/02/12") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/02/26") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/03/05") + CoordELFunctions.INSTANCE_SEPARATOR + getTestCaseFileUri("2009/03/12");
assertEquals(resolvedList, actionXML.substring(actionXML.indexOf("<uris>") + 6, actionXML.indexOf("</uris>")));
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class TestSLAEventGeneration method testCoordinatorActionCommandsSubmitAndStart.
/**
* Test for SLA Events generated through Coordinator Action commands
* CoordSubmitX and CoordStartX
*
* @throws Exception
*/
@Test
public void testCoordinatorActionCommandsSubmitAndStart() throws Exception {
// reduce noise from WF Job events (also default) by setting it to only
// coord action
ehs.setAppTypes(new HashSet<String>(Arrays.asList(new String[] { "coordinator_action" })));
ehs.getEventQueue().clear();
SLAService slas = services.get(SLAService.class);
String coordXml = IOUtils.getResourceAsString("coord-action-sla.xml", -1);
Path appPath = getFsTestCaseDir();
writeToFile(coordXml, appPath, "coordinator.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.COORDINATOR_APP_PATH, appPath.toString());
String wfXml = IOUtils.getResourceAsString("wf-credentials.xml", -1);
writeToFile(wfXml, appPath, "workflow.xml");
conf.set("wfAppPath", appPath.toString());
conf.set(OozieClient.USER_NAME, getTestUser());
cal.setTime(new Date());
// for start_miss
cal.add(Calendar.MINUTE, -20);
Date nominal = cal.getTime();
String nominalTime = DateUtils.formatDateOozieTZ(nominal);
conf.set("nominal_time", nominalTime);
conf.set("start", "2009-01-02T08:01Z");
conf.set("frequency", "coord:days(1)");
conf.set("end", "2009-01-03T08:00Z");
cal.setTime(nominal);
// as per the sla xml
cal.add(Calendar.MINUTE, 10);
String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
cal.setTime(nominal);
// as per the sla xml
cal.add(Calendar.MINUTE, 30);
String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
String appName = "test-coord-sla";
// testing creation of new sla registration via Submit + Materialize
// command
String jobId = new CoordSubmitXCommand(conf).call();
// waiting for materialize command to run
Thread.sleep(500);
final CoordActionGetJPAExecutor getCmd = new CoordActionGetJPAExecutor(jobId + "@1");
CoordinatorActionBean action = jpa.execute(getCmd);
String actionId = action.getId();
SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
assertEquals(actionId, slaEvent.getId());
assertEquals(appName, slaEvent.getAppName());
assertEquals(AppType.COORDINATOR_ACTION, slaEvent.getAppType());
assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
assertEquals(alert_events, slaEvent.getAlertEvents());
slas.runSLAWorker();
slaEvent = skipToSLAEvent();
assertTrue(SLAStatus.NOT_STARTED == slaEvent.getSLAStatus());
assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
// test that sla processes the Job Event from Start command
ehs.getEventQueue().clear();
action.setStatus(CoordinatorAction.Status.SUBMITTED);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
new CoordActionStartXCommand(actionId, getTestUser(), appName, jobId).call();
slaEvent = slas.getSLACalculator().get(actionId);
// resetting for testing sla event
slaEvent.setEventProcessed(0);
SLASummaryBean suBean = new SLASummaryBean();
suBean.setId(actionId);
suBean.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, suBean);
ehs.new EventWorker().run();
slaEvent = skipToSLAEvent();
assertEquals(actionId, slaEvent.getId());
assertNotNull(slaEvent.getActualStart());
assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
assertEquals(CoordinatorAction.Status.RUNNING.name(), slaEvent.getJobStatus());
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor in project oozie by apache.
the class XDataTestCase method setCoordActionStatus.
protected void setCoordActionStatus(String actionId, CoordinatorAction.Status status) throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
action.setStatus(status);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
}
use of org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor 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());
}
Aggregations