Search in sources :

Example 76 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class TestCoordSubmitXCommand method testDuplicateDatasetNameInIncludeFile.

/**
 * https://issues.apache.org/jira/browse/OOZIE-1211
 * If a datasets include file has a dataset name as in one defined in coordinator.xml,
 * the one in coordinator.xml should be honored.
 * http://oozie.apache.org/docs/3.3.1/CoordinatorFunctionalSpec.html#a10.1.1._Dataset_Names_Collision_Resolution
 *
 * @throws Exception
 */
public void testDuplicateDatasetNameInIncludeFile() throws Exception {
    Configuration conf = new XConfiguration();
    final File includePathFile = new File(getTestCaseDir(), "include1.xml");
    final String URI_TEMPLATE_INCLUDE_XML = "file:///tmp/include_xml/workflows/${YEAR}/${DAY}";
    final String URI_TEMPLATE_COORD_XML = "file:///tmp/coord_xml/workflows/${YEAR}/${DAY}";
    String includeXml = "<datasets> " + "<dataset name=\"B\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" timezone=\"UTC\">" + "<uri-template>" + URI_TEMPLATE_INCLUDE_XML + "</uri-template>" + "</dataset> " + "</datasets>";
    writeToFile(includeXml, includePathFile);
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"${appName}-foo\" frequency=\"${coord:days(1)}\" start=\"2009-02-01T01:00Z\" " + "end=\"2009-02-03T23:59Z\" timezone=\"UTC\" xmlns=\"uri:oozie:coordinator:0.2\">" + "<controls> " + "<execution>LIFO</execution>" + "</controls>" + "<datasets> " + "<include>" + includePathFile.toURI() + "</include>" + "<dataset name=\"B\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" timezone=\"UTC\">" + "<uri-template>" + URI_TEMPLATE_COORD_XML + "</uri-template>" + "</dataset> " + "</datasets>" + " <input-events> " + "<data-in name=\"inputB\" dataset=\"B\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<action>" + "<workflow>" + "<app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration>" + "<property> <name>inputB</name> <value>${coord:dataIn('inputB')}</value> </property> " + "</configuration>" + "</workflow>" + "</action>" + " </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    String jobId = sc.call();
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    CoordinatorJobBean job = checkCoordJobs(jobId);
    assertNotNull(job);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    @SuppressWarnings("unchecked") List<Element> datasetElements = processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("dataset", namespace);
    assertTrue("<dataset> should not be duplicate", datasetElements.size() == 1);
    assertEquals(URI_TEMPLATE_COORD_XML, datasetElements.get(0).getChildText("uri-template", namespace));
    assertFalse("<uri-template> should not contain one from the include file", job.getJobXml().contains(URI_TEMPLATE_INCLUDE_XML));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) File(java.io.File) Namespace(org.jdom.Namespace)

Example 77 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class TestCoordSubmitXCommand method testBasicSubmitWithIncludeFile.

/**
 * Basic submit with include file
 * @throws Exception
 */
public void testBasicSubmitWithIncludeFile() throws Exception {
    Configuration conf = new XConfiguration();
    final File includePathFile = new File(getTestCaseDir(), "include1.xml");
    final String URI_TEMPLATE_INCLUDE_XML = "file:///tmp/include_xml/workflows/${YEAR}/${DAY}";
    final String URI_TEMPLATE_COORD_XML = "file:///tmp/coord_xml/workflows/${YEAR}/${DAY}";
    String includeXml = "<datasets> " + "<dataset name=\"A\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" timezone=\"UTC\">" + "<uri-template>" + URI_TEMPLATE_INCLUDE_XML + "</uri-template>" + "</dataset> " + "</datasets>";
    writeToFile(includeXml, includePathFile);
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"${appName}-foo\" frequency=\"${coord:days(1)}\" start=\"2009-02-01T01:00Z\" " + "end=\"2009-02-03T23:59Z\" timezone=\"UTC\" xmlns=\"uri:oozie:coordinator:0.2\">" + "<controls> " + "<execution>LIFO</execution>" + "</controls>" + "<datasets> " + "<include>" + includePathFile.toURI() + "</include>" + "<dataset name=\"B\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" timezone=\"UTC\">" + "<uri-template>" + URI_TEMPLATE_COORD_XML + "</uri-template>" + "</dataset> " + "</datasets>" + " <input-events> " + "<data-in name=\"inputA\" dataset=\"A\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "<data-in name=\"inputB\" dataset=\"B\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<action>" + "<workflow>" + "<app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration>" + "<property> <name>inputA</name> <value>${coord:dataIn('inputB')}</value> </property> " + "</configuration>" + "</workflow>" + "</action>" + " </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    String jobId = sc.call();
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    CoordinatorJobBean job = checkCoordJobs(jobId);
    assertNotNull(job);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    @SuppressWarnings("unchecked") List<Element> datainElements = processedJobXml.getChild("input-events", namespace).getChildren("data-in", namespace);
    assertTrue("<data-in> should be 2. One from coordinator.xml and the other from the include file", datainElements.size() == 2);
    assertEquals(URI_TEMPLATE_INCLUDE_XML, datainElements.get(0).getChild("dataset", namespace).getChildText("uri-template", namespace));
    assertEquals(URI_TEMPLATE_COORD_XML, datainElements.get(1).getChild("dataset", namespace).getChildText("uri-template", namespace));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) File(java.io.File) Namespace(org.jdom.Namespace)

Example 78 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class TestCoordUpdateXCommand method testCoordDefinitionChangeError.

// test fail... error in coord definition
public void testCoordDefinitionChangeError() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile1 = new File(getTestCaseDir(), "coordinator.xml");
    String jobId = setupCoord(conf, "coord-multiple-input-instance3.xml");
    CoordinatorJobBean job = getCoordJobs(jobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:latest(0)}");
    Reader reader = IOUtils.getResourceAsReader("coord-multiple-input-instance1.xml", -1);
    Writer writer = new FileWriter(appPathFile1);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile1.toURI().toString());
    job = getCoordJobs(jobId);
    CoordUpdateXCommand update = new CoordUpdateXCommand(false, conf, jobId);
    try {
        update.call();
        fail(" should not come here");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("E1021: Coord Action Input Check Error"));
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) FileWriter(java.io.FileWriter) Reader(java.io.Reader) StringReader(java.io.StringReader) File(java.io.File) Namespace(org.jdom.Namespace) FileWriter(java.io.FileWriter) Writer(java.io.Writer) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 79 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class TestCoordUpdateXCommand method testDefinitionChange.

// test definition change
public void testDefinitionChange() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile1 = new File(getTestCaseDir(), "coordinator.xml");
    String jobId = setupCoord(conf, "coord-multiple-input-instance3.xml");
    CoordinatorJobBean job = getCoordJobs(jobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:latest(0)}");
    Reader reader = IOUtils.getResourceAsReader("coord-multiple-input-instance4.xml", -1);
    Writer writer = new FileWriter(appPathFile1);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile1.toURI().toString());
    job = getCoordJobs(jobId);
    CoordUpdateXCommand update = new CoordUpdateXCommand(false, conf, jobId);
    update.call();
    job = getCoordJobs(jobId);
    processedJobXml = XmlUtils.parseXml(job.getJobXml());
    namespace = processedJobXml.getNamespace();
    text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:future(0, 1)}");
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) FileWriter(java.io.FileWriter) Reader(java.io.Reader) StringReader(java.io.StringReader) File(java.io.File) Namespace(org.jdom.Namespace) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 80 with Namespace

use of org.jdom.Namespace in project oozie by apache.

the class TestSubmitMRXCommand method testWFXmlGenerationNewConfigProps.

public void testWFXmlGenerationNewConfigProps() throws Exception {
    try {
        Configuration conf = new Configuration(false);
        conf.set(XOozieClient.NN, "new_NN");
        conf.set(XOozieClient.RM, "new_JT");
        conf.set("mapred.mapper.class", "TestMapper");
        conf.set("mapred.reducer.class", "TestReducer");
        conf.set("mapred.input.dir", "testInput");
        conf.set("mapred.output.dir", "testOutput");
        conf.set(OozieClient.LIBPATH, "libpath");
        conf.set("mapreduce.job.user.name", "test_user");
        SubmitMRXCommand submitMRCmd = new SubmitMRXCommand(conf);
        String xml = submitMRCmd.getWorkflowXml(conf);
        // verifying is a valid WF
        WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
        wps.parseDef(xml, conf);
        Element wfE = XmlUtils.parseXml(xml);
        Namespace ns = wfE.getNamespace();
        Element actionE = wfE.getChild("action", ns).getChild("map-reduce", ns);
        Element nnE = actionE.getChild("name-node", ns);
        assertEquals(nnE.getTextTrim(), "new_NN");
        Element jtE = actionE.getChild("job-tracker", ns);
        assertEquals(jtE.getTextTrim(), "new_JT");
    } catch (Exception e) {
        fail("should have passed");
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Aggregations

Namespace (org.jdom.Namespace)102 Element (org.jdom.Element)85 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)15 Configuration (org.apache.hadoop.conf.Configuration)15 JDOMException (org.jdom.JDOMException)15 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)13 ArrayList (java.util.ArrayList)12 Path (org.apache.hadoop.fs.Path)11 Document (org.jdom.Document)11 List (java.util.List)9 File (java.io.File)7 HashMap (java.util.HashMap)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 SAXBuilder (org.jdom.input.SAXBuilder)6 XMLOutputter (org.jdom.output.XMLOutputter)6 Writer (java.io.Writer)5 Attribute (org.jdom.Attribute)5 Format (org.jdom.output.Format)5