Author: kamrul
Date: Mon Apr 2 23:34:22 2012
New Revision: 1308622
URL: http://svn.apache.org/viewvc?rev=1308622&view=rev
Log:
OOZIE-780: XConfiguration parser can't parse XML file with <include> element
(Virag via Mohammad)
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/XConfiguration.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
incubator/oozie/trunk/core/src/test/resources/test-hadoop-config.xml
incubator/oozie/trunk/core/src/test/resources/test-oozie-default.xml
incubator/oozie/trunk/release-log.txt
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/XConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/XConfiguration.java?rev=1308622&r1=1308621&r2=1308622&view=diff
==============================================================================
---
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/XConfiguration.java
(original)
+++
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/XConfiguration.java
Mon Apr 2 23:34:22 2012
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -237,11 +237,15 @@ public class XConfiguration extends Conf
private void parse(InputStream is) throws IOException {
try {
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
+ // support for includes in the xml file
+ docBuilderFactory.setNamespaceAware(true);
+ docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(is);
parseDocument(doc);
+
}
catch (SAXException e) {
throw new IOException(e);
@@ -255,6 +259,9 @@ public class XConfiguration extends Conf
private void parse(Reader reader) throws IOException {
try {
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
+ // support for includes in the xml file
+ docBuilderFactory.setNamespaceAware(true);
+ docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
@@ -271,11 +278,16 @@ public class XConfiguration extends Conf
// Canibalized from Hadoop <code>Configuration.loadResource()</code>.
private void parseDocument(Document doc) throws IOException {
+ Element root = doc.getDocumentElement();
+ if (!"configuration".equals(root.getTagName())) {
+ throw new IOException("bad conf file: top-level element not
<configuration>");
+ }
+ processNodes(root);
+ }
+
+ // Canibalized from Hadoop <code>Configuration.loadResource()</code>.
+ private void processNodes(Element root) throws IOException {
try {
- Element root = doc.getDocumentElement();
- if (!"configuration".equals(root.getTagName())) {
- throw new IOException("bad conf file: top-level element not
<configuration>");
- }
NodeList props = root.getChildNodes();
for (int i = 0; i < props.getLength(); i++) {
Node propNode = props.item(i);
@@ -283,6 +295,10 @@ public class XConfiguration extends Conf
continue;
}
Element prop = (Element) propNode;
+ if (prop.getTagName().equals("configuration")) {
+ processNodes(prop);
+ continue;
+ }
if (!"property".equals(prop.getTagName())) {
throw new IOException("bad conf file: element not
<property>");
}
@@ -302,7 +318,6 @@ public class XConfiguration extends Conf
value = ((Text) field.getFirstChild()).getData();
}
}
-
if (attr != null && value != null) {
set(attr, value);
}
Modified:
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java?rev=1308622&r1=1308621&r2=1308622&view=diff
==============================================================================
---
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
(original)
+++
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
Mon Apr 2 23:34:22 2012
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,17 @@
*/
package org.apache.oozie.util;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.IOException;
+import java.net.URL;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.MapFile;
@@ -42,6 +49,62 @@ public class TestXConfiguration extends
assertEquals("DEFAULT", conf.get("oozie.dummy"));
}
+ public void testAddXIncludeFromStream() throws IOException {
+ String parentXml = "parentXml";
+ prepareXmlWithInclude(parentXml);
+ try {
+ XConfiguration conf = new XConfiguration(new FileInputStream(new
File(getTestCaseDir(), parentXml)));
+ assertEquals("DEFAULT", conf.get("oozie.dummy"));
+ // verify the properties from include file
+ assertEquals("bar", conf.get("foo"));
+ assertEquals("def", conf.get("abc"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("XInclude failed");
+ }
+
+ }
+
+ public void testAddXIncludeFromReader() throws IOException {
+ String parentXml = "parentXml";
+ prepareXmlWithInclude(parentXml);
+ try {
+ XConfiguration conf = new XConfiguration(new FileReader(new
File(getTestCaseDir(), parentXml)));
+ assertEquals("DEFAULT", conf.get("oozie.dummy"));
+ // verify the properties from include file
+ assertEquals("bar", conf.get("foo"));
+ assertEquals("def", conf.get("abc"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("XInclude failed");
+ }
+
+ }
+
+ // Copy the parent xml to testCaseDir and add the include element
+ private void prepareXmlWithInclude(String parentXml) throws IOException {
+ // Get the path for the file to be included
+ String targetPath =
Thread.currentThread().getContextClassLoader().getResource("test-hadoop-config.xml")
+ .getFile();
+ // Get the parent file which will contain the include element
+ URL url =
Thread.currentThread().getContextClassLoader().getResource("test-oozie-default.xml");
+ BufferedReader br = new BufferedReader(new FileReader(url.getFile()));
+ // Copy the parent file to testcase dir
+ BufferedWriter bw = new BufferedWriter(new FileWriter(new
File(getTestCaseDir(), parentXml)));
+ // While copying, add the path for xml to be included
+ // Make sure the path is absolute
+ while (br.ready()) {
+ String s = br.readLine();
+ bw.write(s);
+ if (s.contains("configuration xmlns")) {
+ bw.write("<xi:include href=" + "\"" + targetPath + "\"" +
"/>");
+ }
+ }
+ br.close();
+ bw.close();
+ }
+
+
public void testInvalidParsing() throws Exception {
try {
new XConfiguration(new
StringReader("<configurationx></configurationx>"));
Modified: incubator/oozie/trunk/core/src/test/resources/test-hadoop-config.xml
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/resources/test-hadoop-config.xml?rev=1308622&r1=1308621&r2=1308622&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/resources/test-hadoop-config.xml
(original)
+++ incubator/oozie/trunk/core/src/test/resources/test-hadoop-config.xml Mon
Apr 2 23:34:22 2012
@@ -24,4 +24,9 @@
<value>bar</value>
</property>
+ <property>
+ <name>abc</name>
+ <value>def</value>
+ </property>
+
</configuration>
Modified: incubator/oozie/trunk/core/src/test/resources/test-oozie-default.xml
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/resources/test-oozie-default.xml?rev=1308622&r1=1308621&r2=1308622&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/resources/test-oozie-default.xml
(original)
+++ incubator/oozie/trunk/core/src/test/resources/test-oozie-default.xml Mon
Apr 2 23:34:22 2012
@@ -16,7 +16,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<configuration>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+
+ <configuration xmlns:xi="http://www.w3.org/2001/XInclude">
<property>
<name>oozie.dummy</name>
Modified: incubator/oozie/trunk/release-log.txt
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1308622&r1=1308621&r2=1308622&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Mon Apr 2 23:34:22 2012
@@ -1,5 +1,6 @@
-- Oozie 3.2.0 release
+OOZIE-780: XConfiguration parser can't parse XML file with <include> element
(Virag via Mohammad)
OOZIE-794: oozie job -info -filter should error out on bundle job and workflow
job (virag via Mohammad)
OOZIE-799: Testcases failing due to missing action-conf dir. (Virag via
Mohammad)
OOZIE-798 it would be nice to keep action specific configs in action-conf
instead of hadoop-conf (rvs via tucu)