use of org.apache.oozie.command.wf.StartXCommand in project oozie by apache.
the class TestEventGeneration method testWorkflowJobEvent.
@Test
public void testWorkflowJobEvent() throws Exception {
assertEquals(0, queue.size());
WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "fs-node")).addNode(new ActionNodeDef("fs-node", "", TestLiteWorkflowLib.TestActionNodeHandler.class, "end", "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
WorkflowJobBean job = addRecordToWfJobTable(app, WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
// Starting job
new StartXCommand(job.getId()).call();
WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
assertEquals(1, queue.size());
JobEvent event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.STARTED, event.getEventStatus());
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(0, queue.size());
// Suspending job
new SuspendXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
assertEquals(1, queue.size());
event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.SUSPEND, event.getEventStatus());
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(0, queue.size());
// Resuming job
new ResumeXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.RUNNING, job.getStatus());
assertEquals(1, queue.size());
event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(0, queue.size());
// Killing job
new KillXCommand(job.getId()).call();
job = jpaService.execute(wfJobGetCmd);
assertEquals(WorkflowJob.Status.KILLED, job.getStatus());
assertEquals(1, queue.size());
event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(EventStatus.FAILURE, event.getEventStatus());
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(job.getEndTime(), event.getEndTime());
assertEquals(0, queue.size());
// Successful job (testing SignalX)
job = _createWorkflowJob();
LiteWorkflowInstance wfInstance = (LiteWorkflowInstance) job.getWorkflowInstance();
wfInstance.start();
job.setWorkflowInstance(wfInstance);
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, job);
WorkflowActionBean wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(job.getId() + "@one"));
new SignalXCommand(job.getId(), wfAction.getId()).call();
job = jpaService.execute(new WorkflowJobGetJPAExecutor(job.getId()));
assertEquals(WorkflowJob.Status.SUCCEEDED, job.getStatus());
assertEquals(1, queue.size());
event = (JobEvent) queue.poll();
assertNotNull(event);
assertEquals(AppType.WORKFLOW_JOB, event.getAppType());
assertEquals(job.getId(), event.getId());
assertEquals(job.getUser(), event.getUser());
assertEquals(job.getAppName(), event.getAppName());
assertEquals(job.getStartTime(), event.getStartTime());
assertEquals(job.getEndTime(), event.getEndTime());
}
use of org.apache.oozie.command.wf.StartXCommand in project oozie by apache.
the class TestMapReduceActionExecutor method testConfigDefaultPropsToAction.
public void testConfigDefaultPropsToAction() throws Exception {
String actionXml = "<map-reduce>" + " <prepare>" + " <delete path=\"${nameNode}/user/${wf:user()}/mr/${outputDir}\"/>" + " </prepare>" + " <configuration>" + " <property><name>bb</name><value>BB</value></property>" + " <property><name>cc</name><value>from_action</value></property>" + " </configuration>" + " </map-reduce>";
String wfXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"map-reduce-wf\">" + "<global>" + "<job-tracker>${jobTracker}</job-tracker>" + "<name-node>${nameNode}</name-node>" + "<configuration><property><name>aa</name><value>AA</value></property></configuration>" + "</global>" + " <start to=\"mr-node\"/>" + " <action name=\"mr-node\">" + actionXml + " <ok to=\"end\"/>" + " <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + " <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
Writer writer = new FileWriter(getTestCaseDir() + "/workflow.xml");
IOUtils.copyCharStream(new StringReader(wfXml), writer);
Configuration conf = new XConfiguration();
conf.set("nameNode", getNameNodeUri());
conf.set("jobTracker", getJobTrackerUri());
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.APP_PATH, new File(getTestCaseDir(), "workflow.xml").toURI().toString());
conf.set(OozieClient.LOG_TOKEN, "t");
OutputStream os = new FileOutputStream(getTestCaseDir() + "/config-default.xml");
XConfiguration defaultConf = new XConfiguration();
defaultConf.set("outputDir", "default-output-dir");
defaultConf.set("mapred.mapper.class", "MM");
defaultConf.set("mapred.reducer.class", "RR");
defaultConf.set("cc", "from_default");
defaultConf.writeXml(os);
os.close();
String wfId = new SubmitXCommand(conf).call();
new StartXCommand(wfId).call();
waitForWorkflowAction(wfId + "@mr-node");
WorkflowActionBean mrAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfId + "@mr-node");
// check NN and JT settings
Element eAction = XmlUtils.parseXml(mrAction.getConf());
Element eConf = eAction.getChild("name-node", eAction.getNamespace());
assertEquals(getNameNodeUri(), eConf.getText());
eConf = eAction.getChild("job-tracker", eAction.getNamespace());
assertEquals(getJobTrackerUri(), eConf.getText());
// check other m-r settings
eConf = eAction.getChild("configuration", eAction.getNamespace());
Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(eConf).toString()));
assertEquals("default-output-dir", actionConf.get("outputDir"));
assertEquals("MM", actionConf.get("mapred.mapper.class"));
assertEquals("RR", actionConf.get("mapred.reducer.class"));
// check that default did not overwrite same property explicit in action conf
assertEquals("from_action", actionConf.get("cc"));
// check that original conf and from global was not deleted
assertEquals("AA", actionConf.get("aa"));
assertEquals("BB", actionConf.get("bb"));
// test no infinite recursion by param referring to itself e.g. path = ${path}/sub-path
actionXml = "<map-reduce>" + " <prepare>" + " <delete path=\"${nameNode}/user/${wf:user()}/mr/${outputDir}\"/>" + " </prepare>" + " <configuration>" + " <property><name>cc</name><value>${cc}/action_cc</value></property>" + " </configuration>" + " </map-reduce>";
wfXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"map-reduce-wf\">" + "<global>" + "<job-tracker>${jobTracker}</job-tracker>" + "<name-node>${nameNode}</name-node>" + "<configuration><property><name>outputDir</name><value>global-output-dir</value></property></configuration>" + "</global>" + " <start to=\"mr-node\"/>" + " <action name=\"mr-node\">" + actionXml + " <ok to=\"end\"/>" + " <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + " <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
writer = new FileWriter(getTestCaseDir() + "/workflow.xml");
IOUtils.copyCharStream(new StringReader(wfXml), writer);
wfId = new SubmitXCommand(conf).call();
new StartXCommand(wfId).call();
waitForWorkflowAction(wfId + "@mr-node");
mrAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfId + "@mr-node");
// check param
eAction = XmlUtils.parseXml(mrAction.getConf());
eConf = eAction.getChild("configuration", eAction.getNamespace());
actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(eConf).toString()));
// action param referring to same param name given in defaults cc = ${cc}/action_cc
assertEquals("from_default/action_cc", actionConf.get("cc"));
// check global is retained and has precedence over config-default
eConf = eAction.getChild("name-node", eAction.getNamespace());
assertEquals(getNameNodeUri(), eConf.getText());
assertEquals("global-output-dir", actionConf.get("outputDir"));
}
use of org.apache.oozie.command.wf.StartXCommand in project oozie by apache.
the class TestSLAEventGeneration method _testWorkflowJobSubmitStart.
private void _testWorkflowJobSubmitStart(Configuration conf, SLAService slas, boolean isNew) throws Exception {
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);
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());
// testing creation of new sla registration via Submit command
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()));
if (isNew) {
assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
assertEquals(alert_events, slaEvent.getAlertEvents());
}
slas.runSLAWorker();
slaEvent = skipToSLAEvent();
assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
// test that sla processes the Job Event from Start command
new StartXCommand(jobId).call();
slaEvent = slas.getSLACalculator().get(jobId);
// resetting to receive sla events
slaEvent.setEventProcessed(0);
SLASummaryBean suBean = new SLASummaryBean();
suBean.setId(jobId);
suBean.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, suBean);
waitForEventGeneration(200);
ehs.new EventWorker().run();
waitForEventGeneration(300);
slaEvent = skipToSLAEvent();
assertEquals(jobId, slaEvent.getId());
assertNotNull(slaEvent.getActualStart());
assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
assertEquals(WorkflowJob.Status.RUNNING.name(), slaEvent.getJobStatus());
ehs.getEventQueue().clear();
}
Aggregations