Author: suresh
Date: Fri Oct 26 19:56:39 2012
New Revision: 1402639
URL: http://svn.apache.org/viewvc?rev=1402639&view=rev
Log:
HADOOP-8567. Port conf servlet to dump running configuration to branch 1.x.
Contributed by Jing Zhao.
Modified:
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/Configuration.java
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/http/HttpServer.java
Modified:
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/Configuration.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/Configuration.java?rev=1402639&r1=1402638&r2=1402639&view=diff
==============================================================================
---
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/Configuration.java
(original)
+++
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/conf/Configuration.java
Fri Oct 26 19:56:39 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,30 +226,13 @@ public class Configuration implements It
*/
public Configuration(boolean loadDefaults) {
this.loadDefaults = loadDefaults;
+ updatingResource = new HashMap<String, String>();
if (LOG.isDebugEnabled()) {
LOG.debug(StringUtils.stringifyException(new IOException("config()")));
}
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>();
- }
}
/**
@@ -260,20 +246,23 @@ public class Configuration implements It
LOG.debug(StringUtils.stringifyException
(new IOException("config(config)")));
}
-
- 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);
}
}
@@ -437,6 +426,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);
}
/**
@@ -1071,10 +1061,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);
}
}
}
@@ -1246,9 +1234,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.");
@@ -1276,12 +1262,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 =
@@ -1300,7 +1296,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);
@@ -1317,8 +1317,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);
}
}
@@ -1333,26 +1335,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/src/core/org/apache/hadoop/http/HttpServer.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/core/org/apache/hadoop/http/HttpServer.java?rev=1402639&r1=1402638&r2=1402639&view=diff
==============================================================================
---
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/http/HttpServer.java
(original)
+++
hadoop/common/branches/branch-1/src/core/org/apache/hadoop/http/HttpServer.java
Fri Oct 26 19:56:39 2012
@@ -85,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";