HADOOP-6964. Allow compact property description in xml (Kengo Seki via aw)
This commit is contained in:
parent
6583ad148b
commit
af3aadf04f
|
@ -160,6 +160,9 @@ Trunk (Unreleased)
|
||||||
HADOOP-7713. dfs -count -q should label output column (Jonathan Allen
|
HADOOP-7713. dfs -count -q should label output column (Jonathan Allen
|
||||||
via aw)
|
via aw)
|
||||||
|
|
||||||
|
HADOOP-6964. Allow compact property description in xml (Kengo Seki
|
||||||
|
via aw)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HADOOP-11473. test-patch says "-1 overall" even when all checks are +1
|
HADOOP-11473. test-patch says "-1 overall" even when all checks are +1
|
||||||
|
|
|
@ -90,6 +90,7 @@ import org.apache.hadoop.util.StringInterner;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
import org.codehaus.jackson.JsonFactory;
|
import org.codehaus.jackson.JsonFactory;
|
||||||
import org.codehaus.jackson.JsonGenerator;
|
import org.codehaus.jackson.JsonGenerator;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
import org.w3c.dom.DOMException;
|
import org.w3c.dom.DOMException;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -2514,11 +2515,26 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
}
|
}
|
||||||
if (!"property".equals(prop.getTagName()))
|
if (!"property".equals(prop.getTagName()))
|
||||||
LOG.warn("bad conf file: element not <property>");
|
LOG.warn("bad conf file: element not <property>");
|
||||||
NodeList fields = prop.getChildNodes();
|
|
||||||
String attr = null;
|
String attr = null;
|
||||||
String value = null;
|
String value = null;
|
||||||
boolean finalParameter = false;
|
boolean finalParameter = false;
|
||||||
LinkedList<String> source = new LinkedList<String>();
|
LinkedList<String> source = new LinkedList<String>();
|
||||||
|
|
||||||
|
Attr propAttr = prop.getAttributeNode("name");
|
||||||
|
if (propAttr != null)
|
||||||
|
attr = StringInterner.weakIntern(propAttr.getValue());
|
||||||
|
propAttr = prop.getAttributeNode("value");
|
||||||
|
if (propAttr != null)
|
||||||
|
value = StringInterner.weakIntern(propAttr.getValue());
|
||||||
|
propAttr = prop.getAttributeNode("final");
|
||||||
|
if (propAttr != null)
|
||||||
|
finalParameter = "true".equals(propAttr.getValue());
|
||||||
|
propAttr = prop.getAttributeNode("source");
|
||||||
|
if (propAttr != null)
|
||||||
|
source.add(StringInterner.weakIntern(propAttr.getValue()));
|
||||||
|
|
||||||
|
NodeList fields = prop.getChildNodes();
|
||||||
for (int j = 0; j < fields.getLength(); j++) {
|
for (int j = 0; j < fields.getLength(); j++) {
|
||||||
Node fieldNode = fields.item(j);
|
Node fieldNode = fields.item(j);
|
||||||
if (!(fieldNode instanceof Element))
|
if (!(fieldNode instanceof Element))
|
||||||
|
|
|
@ -209,6 +209,31 @@ public class TestConfiguration extends TestCase {
|
||||||
assertNull("my var is not final", conf2.get("my.var"));
|
assertNull("my var is not final", conf2.get("my.var"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCompactFormat() throws IOException {
|
||||||
|
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||||
|
startConfig();
|
||||||
|
appendCompactFormatProperty("a", "b");
|
||||||
|
appendCompactFormatProperty("c", "d", true);
|
||||||
|
appendCompactFormatProperty("e", "f", false, "g");
|
||||||
|
endConfig();
|
||||||
|
Path fileResource = new Path(CONFIG);
|
||||||
|
Configuration conf = new Configuration(false);
|
||||||
|
conf.addResource(fileResource);
|
||||||
|
|
||||||
|
assertEquals("b", conf.get("a"));
|
||||||
|
|
||||||
|
assertEquals("d", conf.get("c"));
|
||||||
|
Set<String> s = conf.getFinalParameters();
|
||||||
|
assertEquals(1, s.size());
|
||||||
|
assertTrue(s.contains("c"));
|
||||||
|
|
||||||
|
assertEquals("f", conf.get("e"));
|
||||||
|
String[] sources = conf.getPropertySources("e");
|
||||||
|
assertEquals(2, sources.length);
|
||||||
|
assertEquals("g", sources[0]);
|
||||||
|
assertEquals(fileResource.toString(), sources[1]);
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertEq(Object a, Object b) {
|
public static void assertEq(Object a, Object b) {
|
||||||
System.out.println("assertEq: " + a + ", " + b);
|
System.out.println("assertEq: " + a + ", " + b);
|
||||||
assertEquals(a, b);
|
assertEquals(a, b);
|
||||||
|
@ -264,6 +289,36 @@ public class TestConfiguration extends TestCase {
|
||||||
out.write("</property>\n");
|
out.write("</property>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void appendCompactFormatProperty(String name, String val) throws IOException {
|
||||||
|
appendCompactFormatProperty(name, val, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendCompactFormatProperty(String name, String val, boolean isFinal)
|
||||||
|
throws IOException {
|
||||||
|
appendCompactFormatProperty(name, val, isFinal, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendCompactFormatProperty(String name, String val, boolean isFinal,
|
||||||
|
String source)
|
||||||
|
throws IOException {
|
||||||
|
out.write("<property ");
|
||||||
|
out.write("name=\"");
|
||||||
|
out.write(name);
|
||||||
|
out.write("\" ");
|
||||||
|
out.write("value=\"");
|
||||||
|
out.write(val);
|
||||||
|
out.write("\" ");
|
||||||
|
if (isFinal) {
|
||||||
|
out.write("final=\"true\" ");
|
||||||
|
}
|
||||||
|
if (source != null) {
|
||||||
|
out.write("source=\"");
|
||||||
|
out.write(source);
|
||||||
|
out.write("\" ");
|
||||||
|
}
|
||||||
|
out.write("/>\n");
|
||||||
|
}
|
||||||
|
|
||||||
public void testOverlay() throws IOException{
|
public void testOverlay() throws IOException{
|
||||||
out=new BufferedWriter(new FileWriter(CONFIG));
|
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||||
startConfig();
|
startConfig();
|
||||||
|
|
Loading…
Reference in New Issue