OozieScheduling { public static void writeWorkFlow(Schedule schedule, AppContext context, OutputStream output) throws IOException { XmlStreamWriter streamWriter = WriterFactory.newXmlWriter(output); PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(streamWriter); writer.startElement(WORKFLOW_ELEMENT); writer.addAttribute("name", schedule.getName()); writer.addAttribute("xmlns", OOZIE_WORKFLOW_NS); element(writer, "start", "to", schedule.getName()); writer.startElement("action"); writer.addAttribute("name", schedule.getName()); writer.addAttribute("retry-max", "2"); writer.addAttribute("retry-interval", "1"); SchedulableJobManager manager = JobManagers.createSchedulable(schedule, context); manager.writeOozieActionBlock(writer, schedule); element(writer, "ok", "to", "end"); element(writer, "error", "to", "kill"); writer.endElement(); writer.startElement("kill"); writer.addAttribute("name", "kill"); element(writer, "message", "Error in workflow for " + schedule.getName()); writer.endElement(); element(writer, "end", "name", "end"); writer.endElement(); streamWriter.flush(); }  static String workflowPath(Schedule schedule); static String coordPath(Schedule schedule); static Instant getNominalTime(Configuration conf); static void element(XMLWriter writer, String name, String attributeName,
                              String attributeValue); static void element(XMLWriter writer, String name, String text); static void writeWorkFlow(Schedule schedule,
                                   AppContext context,
                                   OutputStream output); static void writeCoordinator(Schedule schedule,
                                      SchedulableJobManager manager,
                                      OutputStream output); static void property(XMLWriter writer, String name, String value); static void writeBundle(Class appClass,
                                 AppContext context,
                                 Path appPath,
                                 List<Schedule> schedules,
                                 OutputStream output); static Map<String,View> loadViews(SchedulableJobManager manager, Configuration conf); static Map<String,String> getJobSettings(Schedule schedule, Configuration conf); static void writeJobConfiguration(XMLWriter writer, Schedule schedule, Configuration conf);  }
@Test public void testWriteWorkflow() throws Exception { ByteArrayOutputStream output = new ByteArrayOutputStream(); OozieScheduling.writeWorkFlow(testSchedule, context, output); Document workflow = XMLUtil.toDom(output); XPath xpath = XMLUtil.getXPath(); assertEquals(testSchedule.getName(), xpath.evaluate("wf:workflow-app/@name", workflow)); assertEquals(OozieScheduledJobMain.class.getName(), xpath.evaluate("wf:workflow-app/wf:action/wf:java/wf:main-class", workflow)); assertEquals(testSchedule.getName(), xpath.evaluate("wf:workflow-app/wf:action/wf:java/wf:arg", workflow)); assertEquals("${coordNominalTime}", xpath.evaluate("wf:workflow-app/wf:action/wf:java/wf:configuration/" + "wf:property/wf:value[../wf:name/text() = \"workflowNominalTime\"]", workflow)); assertEquals("${coord_source_users}", xpath.evaluate("wf:workflow-app/wf:action/wf:java/wf:configuration/" + "wf:property/wf:value[../wf:name/text() = \"wf_source_users\"]", workflow)); assertEquals("${coord_target_users}", xpath.evaluate("wf:workflow-app/wf:action/wf:java/wf:configuration/" + "wf:property/wf:value[../wf:name/text() = \"wf_target_users\"]", workflow)); }