Search in sources :

Example 1 with StartXCommand

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());
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) SignalXCommand(org.apache.oozie.command.wf.SignalXCommand) ActionNodeDef(org.apache.oozie.workflow.lite.ActionNodeDef) ActionKillXCommand(org.apache.oozie.command.wf.ActionKillXCommand) KillXCommand(org.apache.oozie.command.wf.KillXCommand) StartXCommand(org.apache.oozie.command.wf.StartXCommand) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) JobEvent(org.apache.oozie.client.event.JobEvent) TestLiteWorkflowLib(org.apache.oozie.workflow.lite.TestLiteWorkflowLib) ResumeXCommand(org.apache.oozie.command.wf.ResumeXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) Test(org.junit.Test)

Example 2 with StartXCommand

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"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) FileWriter(java.io.FileWriter) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Element(org.jdom.Element) StartXCommand(org.apache.oozie.command.wf.StartXCommand) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) SequenceFile(org.apache.hadoop.io.SequenceFile) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter)

Example 3 with StartXCommand

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();
}
Also used : CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) SubmitXCommand(org.apache.oozie.command.wf.SubmitXCommand) StartXCommand(org.apache.oozie.command.wf.StartXCommand) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) Date(java.util.Date)

Aggregations

StartXCommand (org.apache.oozie.command.wf.StartXCommand)3 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 SubmitXCommand (org.apache.oozie.command.wf.SubmitXCommand)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 Date (java.util.Date)1 JarOutputStream (java.util.jar.JarOutputStream)1 Configuration (org.apache.hadoop.conf.Configuration)1 SequenceFile (org.apache.hadoop.io.SequenceFile)1 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 JobEvent (org.apache.oozie.client.event.JobEvent)1 CoordActionStartXCommand (org.apache.oozie.command.coord.CoordActionStartXCommand)1 CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)1 CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)1 ActionKillXCommand (org.apache.oozie.command.wf.ActionKillXCommand)1