hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r739420 - in /hadoop/core/branches/branch-0.20: CHANGES.txt src/core/org/apache/hadoop/conf/Configuration.java src/test/org/apache/hadoop/conf/TestConfiguration.java
Date Fri, 30 Jan 2009 21:56:13 GMT
Author: dhruba
Date: Fri Jan 30 21:56:12 2009
New Revision: 739420

URL: http://svn.apache.org/viewvc?rev=739420&view=rev
Log:
HADOOP-4944. A configuration file can include other configuration
files. (Rama Ramasamy via dhruba)


Modified:
    hadoop/core/branches/branch-0.20/CHANGES.txt   (contents, props changed)
    hadoop/core/branches/branch-0.20/src/core/org/apache/hadoop/conf/Configuration.java
    hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/conf/TestConfiguration.java

Modified: hadoop/core/branches/branch-0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/CHANGES.txt?rev=739420&r1=739419&r2=739420&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.20/CHANGES.txt Fri Jan 30 21:56:12 2009
@@ -319,6 +319,9 @@
 
     HADOOP-4920.  Stop storing Forrest output in Subversion. (cutting)
 
+    HADOOP-4944. A configuration file can include other configuration
+    files. (Rama Ramasamy via dhruba)
+
   OPTIMIZATIONS
 
     HADOOP-3293. Fixes FileInputFormat to do provide locations for splits

Propchange: hadoop/core/branches/branch-0.20/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 30 21:56:12 2009
@@ -1,3 +1,3 @@
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
-/hadoop/core/trunk/CHANGES.txt:727001,727117,727191,727212,727228,727255,727869,728187,729052,729987,732385,732572,732777,732838,732869,733887,734870,734916,735082,736426,738602,738697
+/hadoop/core/trunk/CHANGES.txt:727001,727117,727191,727212,727228,727255,727869,728187,729052,729987,732385,732572,732777,732838,732869,733887,734870,734916,735082,736426,738602,738697,739416

Modified: hadoop/core/branches/branch-0.20/src/core/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/src/core/org/apache/hadoop/conf/Configuration.java?rev=739420&r1=739419&r2=739420&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/src/core/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/core/branches/branch-0.20/src/core/org/apache/hadoop/conf/Configuration.java Fri
Jan 30 21:56:12 2009
@@ -1046,9 +1046,13 @@
         = DocumentBuilderFactory.newInstance();
       //ignore all comments inside the xml file
       docBuilderFactory.setIgnoringComments(true);
+
+      //allow includes in the xml file
+      docBuilderFactory.setNamespaceAware(true);
+      docBuilderFactory.setXIncludeAware(true);
       DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
       Document doc = null;
-
+      Element root = null;
 
       if (name instanceof URL) {                  // an URL resource
         URL url = (URL)name;
@@ -1088,15 +1092,19 @@
         } finally {
           ((InputStream)name).close();
         }
+      } else if (name instanceof Element) {
+        root = (Element)name;
       }
 
-      if (doc == null) {
+      if (doc == null && root == null) {
         if (quiet)
           return;
         throw new RuntimeException(name + " not found");
       }
 
-      Element root = doc.getDocumentElement();
+      if (root == null) {
+        root = doc.getDocumentElement();
+      }
       if (!"configuration".equals(root.getTagName()))
         LOG.fatal("bad conf file: top-level element not <configuration>");
       NodeList props = root.getChildNodes();
@@ -1105,6 +1113,10 @@
         if (!(propNode instanceof Element))
           continue;
         Element prop = (Element)propNode;
+        if ("configuration".equals(prop.getTagName())) {
+          loadResource(properties, prop, quiet);
+          continue;
+        }
         if (!"property".equals(prop.getTagName()))
           LOG.warn("bad conf file: element not <property>");
         NodeList fields = prop.getChildNodes();

Modified: hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/conf/TestConfiguration.java?rev=739420&r1=739419&r2=739420&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/conf/TestConfiguration.java
(original)
+++ hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/conf/TestConfiguration.java
Fri Jan 30 21:56:12 2009
@@ -62,7 +62,11 @@
     out.write("</configuration>\n");
     out.close();
   }
-  
+
+  private void addInclude(String filename) throws IOException{
+    out.write("<xi:include href=\"" + filename + "\" xmlns:xi=\"http://www.w3.org/2001/XInclude\"
 />\n ");
+  }
+
   public void testVariableSubstitution() throws IOException {
     out=new BufferedWriter(new FileWriter(CONFIG));
     startConfig();
@@ -228,6 +232,32 @@
       fileResource.toString();
     assertEquals(expectedOutput, conf.toString());
   }
+  
+  public void testIncludes() throws Exception {
+    tearDown();
+    System.out.println("XXX testIncludes");
+    out=new BufferedWriter(new FileWriter(CONFIG2));
+    startConfig();
+    appendProperty("a","b");
+    appendProperty("c","d");
+    endConfig();
+
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    addInclude(CONFIG2);
+    appendProperty("e","f");
+    appendProperty("g","h");
+    endConfig();
+
+    // verify that the includes file contains all properties
+    Path fileResource = new Path(CONFIG);
+    conf.addResource(fileResource);
+    assertEquals(conf.get("a"), "b"); 
+    assertEquals(conf.get("c"), "d"); 
+    assertEquals(conf.get("e"), "f"); 
+    assertEquals(conf.get("g"), "h"); 
+    tearDown();
+  }
 
   BufferedWriter out;
 	



Mime
View raw message