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));
}
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));
}
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"));
}
}
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)}");
}
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");
}
}
Aggregations