use of org.apache.oozie.util.XConfiguration 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.util.XConfiguration in project oozie by apache.
the class TestSLAEventGeneration method testWorkflowJobSLARerun.
/**
* Test for SLA Events generated through wf rerun
*
* @throws Exception
*/
@Test
public void testWorkflowJobSLARerun() throws Exception {
SLAService slas = services.get(SLAService.class);
String wfXml = IOUtils.getResourceAsString("wf-job-sla.xml", -1);
Path appPath = getFsTestCaseDir();
writeToFile(wfXml, appPath, "workflow.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, appPath.toString());
conf.set(OozieClient.USER_NAME, getTestUser());
cal.setTime(new Date());
// for start_miss
cal.add(Calendar.MINUTE, -40);
Date nominal = cal.getTime();
String nominalTime = DateUtils.formatDateOozieTZ(nominal);
conf.set("nominal_time", nominalTime);
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());
// Call SubmitX
SubmitXCommand sc = new SubmitXCommand(conf);
String jobId = sc.call();
SLACalcStatus slaEvent = slas.getSLACalculator().get(jobId);
assertEquals(jobId, slaEvent.getId());
assertEquals("test-wf-job-sla", slaEvent.getAppName());
assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());
assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
slas.runSLAWorker();
slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
slas.getSLACalculator().clear();
JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
// set job status to succeeded, so rerun doesn't fail
wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfBean);
// change conf for rerun
cal.setTime(new Date());
// for start_miss
cal.add(Calendar.MINUTE, -20);
nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());
conf.set("nominal_time", nominalTime);
nominal = cal.getTime();
// as per the sla xml
cal.add(Calendar.MINUTE, 10);
expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
cal.setTime(nominal);
// as per the sla xml
cal.add(Calendar.MINUTE, 30);
expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
rerun.call();
slaEvent = slas.getSLACalculator().get(jobId);
// assert for new conf
assertNotNull(slaEvent);
assertEquals(jobId, slaEvent.getId());
assertEquals("test-wf-job-sla", slaEvent.getAppName());
assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());
// assert for new conf
assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
// assert for values in summary bean to be reset
SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
assertEquals(0, slaSummary.getEventProcessed());
assertEquals(-1, slaSummary.getActualDuration());
assertNull(slaSummary.getActualStart());
assertNull(slaSummary.getActualEnd());
assertEquals("PREP", slaSummary.getJobStatus());
assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
assertNull(slaEvent.getEventStatus());
ehs.getEventQueue().clear();
slas.runSLAWorker();
slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestSLAEventGeneration method testWorkflowActionSLARerun.
/**
* Test for SLA Events generated through wf action rerun
*
* @throws Exception
*/
@Test
public void testWorkflowActionSLARerun() throws Exception {
SLAService slas = services.get(SLAService.class);
String wfXml = IOUtils.getResourceAsString("wf-action-sla.xml", -1);
Path appPath = getFsTestCaseDir();
writeToFile(wfXml, appPath, "workflow.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, 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);
// Call SubmitX
SubmitXCommand sc = new SubmitXCommand(conf);
String jobId = sc.call();
String actionId = jobId + "@grouper";
slas.getSLACalculator().clear();
JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
// set job status to succeeded, so rerun doesn't fail
wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfBean);
// change conf for rerun
cal.setTime(new Date());
nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());
conf.set("nominal_time", nominalTime);
nominal = cal.getTime();
// 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());
ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
rerun.call();
SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
assertNotNull(slaEvent);
// assert for action configs
assertEquals(actionId, slaEvent.getId());
assertEquals("test-wf-action-sla", slaEvent.getAppName());
assertEquals(AppType.WORKFLOW_ACTION, slaEvent.getAppType());
// assert for new conf
assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestSLAEventGeneration method testSLASchema1BackwardCompatibilityKill.
@Test
public void testSLASchema1BackwardCompatibilityKill() throws Exception {
assertNotNull(ehs);
SLAService slas = services.get(SLAService.class);
assertNotNull(slas);
Path appPath = getFsTestCaseDir();
writeToFile(SLA_XML_1, appPath, "workflow.xml");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, 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);
_testWorkflowJobKillCommand(conf, slas);
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestLiteWorkflowAppParser method testParserGlobalLauncherAMOverridden.
public void testParserGlobalLauncherAMOverridden() throws Exception {
LiteWorkflowAppParser parser = newLiteWorkflowAppParser();
LiteWorkflowApp workflowApp = parser.validateAndParse(IOUtils.getResourceAsReader("wf-schema-global-launcherconf-override.xml", -1), new Configuration());
XConfiguration xconf = extractConfig(workflowApp, "a");
assertEquals("Vcores", 1, xconf.getInt(LauncherAM.OOZIE_LAUNCHER_VCORES_PROPERTY, Integer.MIN_VALUE));
assertEquals("Memory", 2048, xconf.getInt(LauncherAM.OOZIE_LAUNCHER_MEMORY_MB_PROPERTY, Integer.MIN_VALUE));
assertEquals("Java opts", "dummyJavaOpts", xconf.get(LauncherAM.OOZIE_LAUNCHER_JAVAOPTS_PROPERTY));
assertNull("Queue", xconf.get(LauncherAM.OOZIE_LAUNCHER_QUEUE_PROPERTY));
assertNull("Env", xconf.get(LauncherAM.OOZIE_LAUNCHER_ENV_PROPERTY));
assertNull("Sharelib", xconf.get(LauncherAM.OOZIE_LAUNCHER_SHARELIB_PROPERTY));
}
Aggregations