Author: szetszwo
Date: Wed Dec  5 00:07:45 2012
New Revision: 1417244

URL: http://svn.apache.org/viewvc?rev=1417244&view=rev
Log:
svn merge -c 1402728 from branch-1 for HADOOP-8567. Port conf servlet to dump 
running configuration to branch 1.x.

Added:
    
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/ConfServlet.java
      - copied unchanged from r1402728, 
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/ConfServlet.java
    
hadoop/common/branches/branch-1.1/src/test/org/apache/hadoop/conf/TestConfServlet.java
      - copied unchanged from r1402728, 
hadoop/common/branches/branch-1/src/test/org/apache/hadoop/conf/TestConfServlet.java
Modified:
    hadoop/common/branches/branch-1.1/   (props changed)
    hadoop/common/branches/branch-1.1/CHANGES.txt   (contents, props changed)
    
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
    
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/http/HttpServer.java

Propchange: hadoop/common/branches/branch-1.1/
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1:r1402728

Modified: hadoop/common/branches/branch-1.1/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/CHANGES.txt?rev=1417244&r1=1417243&r2=1417244&view=diff
==============================================================================
--- hadoop/common/branches/branch-1.1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1.1/CHANGES.txt Wed Dec  5 00:07:45 2012
@@ -1,6 +1,6 @@
 Hadoop Change Log
 
-Release 1.1.2 - 2012.11.18
+Release 1.1.2 - Unreleased
 
   INCOMPATIBLE CHANGES
 
@@ -11,6 +11,9 @@ Release 1.1.2 - 2012.11.18
     HDFS-4252. Improve confusing log message that prints exception when 
editlog 
     read is completed. (Jing Zhao via suresh)
 
+    HADOOP-8567. Port conf servlet to dump running configuration to branch 1.x.
+    (Jing Zhao via suresh)
+
   BUG FIXES
 
     MAPREDUCE-4798. Updated TestJobHistoryServer test case for startup

Propchange: hadoop/common/branches/branch-1.1/CHANGES.txt
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1/CHANGES.txt:r1402728

Modified: 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java?rev=1417244&r1=1417243&r2=1417244&view=diff
==============================================================================
--- 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
 (original)
+++ 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/conf/Configuration.java
 Wed Dec  5 00:07:45 2012
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.net.URL;
@@ -51,6 +52,7 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
@@ -65,6 +67,7 @@ import org.apache.hadoop.util.Reflection
 import org.apache.hadoop.util.StringUtils;
 import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonGenerator;
+import org.w3c.dom.Comment;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -171,10 +174,10 @@ public class Configuration implements It
     new CopyOnWriteArrayList<String>();
   
   /**
-   * Flag to indicate if the storage of resource which updates a key needs 
-   * to be stored for each key
+   * The value reported as the setting resource when a key is set
+   * by code rather than a file resource.
    */
-  private boolean storeResource;
+  static final String UNKNOWN_RESOURCE = "Unknown";
   
   /**
    * Stores the mapping of key to the resource which modifies or loads 
@@ -223,27 +226,10 @@ public class Configuration implements It
    */
   public Configuration(boolean loadDefaults) {
     this.loadDefaults = loadDefaults;
+    updatingResource = new HashMap<String, String>();
     synchronized(Configuration.class) {
       REGISTRY.put(this, null);
     }
-    this.storeResource = false;
-  }
-  
-  /**
-   * A new configuration with the same settings and additional facility for
-   * storage of resource to each key which loads or updates 
-   * the key most recently
-   * @param other the configuration from which to clone settings
-   * @param storeResource flag to indicate if the storage of resource to 
-   * each key is to be stored
-   */
-  private Configuration(Configuration other, boolean storeResource) {
-    this(other);
-    this.loadDefaults = other.loadDefaults;
-    this.storeResource = storeResource;
-    if (storeResource) {
-      updatingResource = new HashMap<String, String>();
-    }
   }
   
   /** 
@@ -253,19 +239,22 @@ public class Configuration implements It
    */
   @SuppressWarnings("unchecked")
   public Configuration(Configuration other) {
-   this.resources = (ArrayList)other.resources.clone();
-   synchronized(other) {
-     if (other.properties != null) {
-       this.properties = (Properties)other.properties.clone();
-     }
-
-     if (other.overlay!=null) {
-       this.overlay = (Properties)other.overlay.clone();
-     }
-   }
-   
+    this.resources = (ArrayList) other.resources.clone();
+    synchronized (other) {
+      if (other.properties != null) {
+        this.properties = (Properties) other.properties.clone();
+      }
+
+      if (other.overlay != null) {
+        this.overlay = (Properties) other.overlay.clone();
+      }
+
+      this.updatingResource = new HashMap<String, String>(
+          other.updatingResource);
+    }
+
     this.finalParameters = new HashSet<String>(other.finalParameters);
-    synchronized(Configuration.class) {
+    synchronized (Configuration.class) {
       REGISTRY.put(this, null);
     }
   }
@@ -429,6 +418,7 @@ public class Configuration implements It
   public void set(String name, String value) {
     getOverlay().setProperty(name, value);
     getProps().setProperty(name, value);
+    this.updatingResource.put(name, UNKNOWN_RESOURCE);
   }
   
   /**
@@ -1055,10 +1045,8 @@ public class Configuration implements It
       loadResources(properties, resources, quietmode);
       if (overlay!= null) {
         properties.putAll(overlay);
-        if (storeResource) {
-          for (Map.Entry<Object,Object> item: overlay.entrySet()) {
-            updatingResource.put((String) item.getKey(), "Unknown");
-          }
+        for (Map.Entry<Object,Object> item: overlay.entrySet()) {
+          updatingResource.put((String) item.getKey(), UNKNOWN_RESOURCE);
         }
       }
     }
@@ -1230,9 +1218,7 @@ public class Configuration implements It
           if (value != null) {
             if (!finalParameters.contains(attr)) {
               properties.setProperty(attr, value);
-              if (storeResource) {
-                updatingResource.put(attr, name.toString());
-              }
+              updatingResource.put(attr, name.toString());
             } else if (!value.equals(properties.getProperty(attr))) {
               LOG.warn(name+":a attempt to override final parameter: "+attr
                      +";  Ignoring.");
@@ -1260,12 +1246,22 @@ public class Configuration implements It
   }
 
   /** 
-   * Write out the non-default properties in this configuration to the give
+   * Write out the non-default properties in this configuration to the given
    * {@link OutputStream}.
    * 
    * @param out the output stream to write to.
    */
   public void writeXml(OutputStream out) throws IOException {
+    writeXml(new OutputStreamWriter(out));
+  }
+  
+  /**
+   * Write out the non-default properties in this configuration to the given
+   * {@link Writer}.
+   * 
+   * @param out the writer to write to.
+   */
+  public synchronized void writeXml(Writer out) throws IOException {
     Properties properties = getProps();
     try {
       Document doc =
@@ -1284,7 +1280,11 @@ public class Configuration implements It
         }
         Element propNode = doc.createElement("property");
         conf.appendChild(propNode);
-      
+        if (updatingResource != null) {
+          Comment commentNode = doc.createComment("Loaded from "
+              + updatingResource.get(name));
+          propNode.appendChild(commentNode);
+        }
         Element nameNode = doc.createElement("name");
         nameNode.appendChild(doc.createTextNode(name));
         propNode.appendChild(nameNode);
@@ -1301,8 +1301,10 @@ public class Configuration implements It
       TransformerFactory transFactory = TransformerFactory.newInstance();
       Transformer transformer = transFactory.newTransformer();
       transformer.transform(source, result);
-    } catch (Exception e) {
-      throw new RuntimeException(e);
+    } catch (TransformerException te) {
+      throw new IOException(te);
+    } catch (ParserConfigurationException pe) {
+      throw new IOException(pe);
     }
   }
 
@@ -1317,26 +1319,26 @@ public class Configuration implements It
    * @param out the Writer to write to
    * @throws IOException
    */
-  public static void dumpConfiguration(Configuration conf, 
+  public static void dumpConfiguration(Configuration config, 
       Writer out) throws IOException {
-    Configuration config = new Configuration(conf,true);
-    config.reloadConfiguration();
     JsonFactory dumpFactory = new JsonFactory();
     JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
     dumpGenerator.writeStartObject();
     dumpGenerator.writeFieldName("properties");
     dumpGenerator.writeStartArray();
     dumpGenerator.flush();
-    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
-      dumpGenerator.writeStartObject();
-      dumpGenerator.writeStringField("key", (String) item.getKey());
-      dumpGenerator.writeStringField("value", 
-          config.get((String) item.getKey()));
-      dumpGenerator.writeBooleanField("isFinal",
-          config.finalParameters.contains(item.getKey()));
-      dumpGenerator.writeStringField("resource",
-          config.updatingResource.get(item.getKey()));
-      dumpGenerator.writeEndObject();
+    synchronized (config) {
+      for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
+        dumpGenerator.writeStartObject();
+        dumpGenerator.writeStringField("key", (String) item.getKey());
+        dumpGenerator.writeStringField("value", 
+            config.get((String) item.getKey()));
+        dumpGenerator.writeBooleanField("isFinal",
+            config.finalParameters.contains(item.getKey()));
+        dumpGenerator.writeStringField("resource",
+            config.updatingResource.get(item.getKey()));
+        dumpGenerator.writeEndObject();
+      }
     }
     dumpGenerator.writeEndArray();
     dumpGenerator.writeEndObject();

Modified: 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/http/HttpServer.java
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/http/HttpServer.java?rev=1417244&r1=1417243&r2=1417244&view=diff
==============================================================================
--- 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/http/HttpServer.java
 (original)
+++ 
hadoop/common/branches/branch-1.1/src/core/org/apache/hadoop/http/HttpServer.java
 Wed Dec  5 00:07:45 2012
@@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.ConfServlet;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.jmx.JMXJsonServlet;
@@ -84,10 +85,10 @@ public class HttpServer implements Filte
 
   static final String FILTER_INITIALIZER_PROPERTY
       = "hadoop.http.filter.initializers";
-
+ 
   // The ServletContext attribute where the daemon Configuration
   // gets stored.
-  static final String CONF_CONTEXT_ATTRIBUTE = "hadoop.conf";
+  public static final String CONF_CONTEXT_ATTRIBUTE = "hadoop.conf";
   static final String ADMINS_ACL = "admins.acl";
   public static final String SPNEGO_FILTER = "SpnegoFilter";
   public static final String KRB5_FILTER = "krb5Filter";
@@ -266,6 +267,7 @@ public class HttpServer implements Filte
     addServlet("stacks", "/stacks", StackServlet.class);
     addServlet("logLevel", "/logLevel", LogLevel.Servlet.class);
     addServlet("jmx", "/jmx", JMXJsonServlet.class);
+    addServlet("conf", "/conf", ConfServlet.class);
   }
 
   public void addContext(Context ctxt, boolean isFiltered)


Reply via email to