use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class CoordActionsInDateRange method getCoordActionsFromDateRange.
/**
* Get the coordinator actions for a given date range
* @param jobId the coordinator job id
* @param range the date range separated by '::'
* @param active to list only active (non-terminated) actions
* @return the list of Coordinator actions for the date range
* @throws XException if range is not well formatted or invalid
*/
public static List<CoordinatorActionBean> getCoordActionsFromDateRange(String jobId, String range, boolean active) throws XException {
String[] dateRange = range.split("::");
// This block checks for errors in the format of specifying date range
if (dateRange.length != 2) {
throw new XException(ErrorCode.E0308, "'" + range + "'. Date value expected on both sides of the scope resolution operator '::' to signify start and end of range");
}
Date start;
Date end;
try {
// Get the start and end dates for the range
start = DateUtils.parseDateOozieTZ(dateRange[0].trim());
end = DateUtils.parseDateOozieTZ(dateRange[1].trim());
} catch (ParseException dx) {
throw new XException(ErrorCode.E0308, "Error in parsing start or end date. " + dx);
}
if (start.after(end)) {
throw new XException(ErrorCode.E0308, "'" + range + "'. Start date '" + start + "' is older than end date: '" + end + "'");
}
List<CoordinatorActionBean> listOfActions = getActionsFromDateRange(jobId, start, end, active);
return listOfActions;
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestSLACalculatorMemory method testWFEndNotCoord.
public void testWFEndNotCoord() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
SLARegistrationBean slaRegBean = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
String coordActionId = slaRegBean.getId();
slaRegBean.setExpectedEnd(sdf.parse("2013-03-07"));
slaRegBean.setExpectedStart(sdf.parse("2012-03-07"));
slaCalcMemory.addRegistration(coordActionId, slaRegBean);
SLACalcStatus calc1 = slaCalcMemory.get(coordActionId);
calc1.setEventProcessed(1);
calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
calc1.setLastModifiedTime(new Date());
SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
// Simulate a lost failed event
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId(coordActionId);
coordAction.setStatus(CoordinatorAction.Status.RUNNING);
coordAction.setLastModifiedTime(sdf.parse("2013-02-07"));
coordAction.setExternalId("wf_job-W");
CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(coordAction);
jpaService.execute(caInsertCmd);
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId("wf_job-W");
wjb.setStartTime(sdf.parse("2012-02-07"));
wjb.setLastModifiedTime(new Date());
wjb.setStatus(WorkflowJob.Status.SUCCEEDED);
WorkflowJobQueryExecutor.getInstance().insert(wjb);
calc1 = slaCalcMemory.get(coordActionId);
slaCalcMemory.updateJobSla(coordActionId);
slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
// cord action is running and wf job is completed
assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.RUNNING.name());
coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction);
slaCalcMemory.addJobStatus(coordActionId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-02-07"), sdf.parse("2012-03-07"));
slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, coordActionId);
assertEquals(slaSummaryBean.getJobStatus(), WorkflowInstance.Status.SUCCEEDED.toString());
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestSLACalculatorMemory method testCoordinatorActionSLAStatusOnRestart.
@Test
public void testCoordinatorActionSLAStatusOnRestart() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
SLARegistrationBean slaRegBean1 = _createSLARegistration("job-C@1", AppType.COORDINATOR_ACTION);
String jobId1 = slaRegBean1.getId();
slaRegBean1.setExpectedEnd(sdf.parse("2013-03-07"));
slaRegBean1.setExpectedStart(sdf.parse("2012-03-07"));
slaCalcMemory.addRegistration(jobId1, slaRegBean1);
SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
calc1.setEventProcessed(1);
calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
calc1.setJobStatus(WorkflowAction.Status.RUNNING.name());
calc1.setLastModifiedTime(new Date());
SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
// Simulate a lost failed event
CoordinatorActionBean cab = new CoordinatorActionBean();
cab.setId(jobId1);
cab.setStatus(CoordinatorAction.Status.FAILED);
cab.setLastModifiedTime(sdf.parse("2013-02-07"));
cab.setExternalId("wf_job-W");
CoordActionInsertJPAExecutor caInsertCmd = new CoordActionInsertJPAExecutor(cab);
jpaService.execute(caInsertCmd);
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId("wf_job-W");
wjb.setStartTime(sdf.parse("2012-02-07"));
wjb.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().insert(wjb);
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
slaCalcMemory.updateAllSlaStatus();
// As job succeeded, it should not be in memory
assertEquals(0, slaCalcMemory.size());
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
assertEquals("job-C@1", slaSummary.getId());
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(AppType.COORDINATOR_ACTION, slaSummary.getAppType());
assertEquals("FAILED", slaSummary.getJobStatus());
assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
assertEquals(sdf.parse("2013-02-07").getTime() - sdf.parse("2012-02-07").getTime(), slaSummary.getActualDuration());
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestSLACalculatorMemory method _setupSlaMap.
private String _setupSlaMap(SLACalculator slaCalculator, String id, int actionNum) throws Exception {
CoordinatorActionBean action = addRecordToCoordActionTable(id, actionNum, CoordinatorAction.Status.TIMEDOUT, "coord-action-get.xml", 0);
action.setExternalId(null);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_FOR_START, action);
SLARegistrationBean slaRegBean = _createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION);
Date startTime = new Date(System.currentTimeMillis() - 2 * 3600 * 1000);
// 2 hours back
slaRegBean.setExpectedStart(startTime);
slaRegBean.setExpectedDuration(1000);
// 1 hr back
slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 3600 * 1000));
slaRegBean.setParentId(id);
slaCalculator.addRegistration(slaRegBean.getId(), slaRegBean);
return action.getId();
}
use of org.apache.oozie.CoordinatorActionBean 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());
}
Aggregations