HADOOP-10625. Trim configuration names when putting/getting them to properties
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1598072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
edfbc8ad4a
commit
fc1e525da0
@ -334,6 +334,9 @@ Trunk (Unreleased)
|
|||||||
|
|
||||||
HADOOP-10586. KeyShell doesn't allow setting Options via CLI. (clamb via tucu)
|
HADOOP-10586. KeyShell doesn't allow setting Options via CLI. (clamb via tucu)
|
||||||
|
|
||||||
|
HADOOP-10625. Trim configuration names when putting/getting them
|
||||||
|
to properties. (Wangda Tan via xgong)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-7761. Improve the performance of raw comparisons. (todd)
|
HADOOP-7761. Improve the performance of raw comparisons. (todd)
|
||||||
|
@ -566,6 +566,9 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
*/
|
*/
|
||||||
private String[] handleDeprecation(DeprecationContext deprecations,
|
private String[] handleDeprecation(DeprecationContext deprecations,
|
||||||
String name) {
|
String name) {
|
||||||
|
if (null != name) {
|
||||||
|
name = name.trim();
|
||||||
|
}
|
||||||
ArrayList<String > names = new ArrayList<String>();
|
ArrayList<String > names = new ArrayList<String>();
|
||||||
if (isDeprecated(name)) {
|
if (isDeprecated(name)) {
|
||||||
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
||||||
@ -843,12 +846,12 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
/**
|
/**
|
||||||
* Get the value of the <code>name</code> property, <code>null</code> if
|
* Get the value of the <code>name</code> property, <code>null</code> if
|
||||||
* no such property exists. If the key is deprecated, it returns the value of
|
* no such property exists. If the key is deprecated, it returns the value of
|
||||||
* the first key which replaces the deprecated key and is not null
|
* the first key which replaces the deprecated key and is not null.
|
||||||
*
|
*
|
||||||
* Values are processed for <a href="#VariableExpansion">variable expansion</a>
|
* Values are processed for <a href="#VariableExpansion">variable expansion</a>
|
||||||
* before being returned.
|
* before being returned.
|
||||||
*
|
*
|
||||||
* @param name the property name.
|
* @param name the property name, will be trimmed before get value.
|
||||||
* @return the value of the <code>name</code> or its replacing property,
|
* @return the value of the <code>name</code> or its replacing property,
|
||||||
* or null if no such property exists.
|
* or null if no such property exists.
|
||||||
*/
|
*/
|
||||||
@ -952,7 +955,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
/**
|
/**
|
||||||
* Set the <code>value</code> of the <code>name</code> property. If
|
* Set the <code>value</code> of the <code>name</code> property. If
|
||||||
* <code>name</code> is deprecated or there is a deprecated name associated to it,
|
* <code>name</code> is deprecated or there is a deprecated name associated to it,
|
||||||
* it sets the value to both names.
|
* it sets the value to both names. Name will be trimmed before put into
|
||||||
|
* configuration.
|
||||||
*
|
*
|
||||||
* @param name property name.
|
* @param name property name.
|
||||||
* @param value property value.
|
* @param value property value.
|
||||||
@ -964,7 +968,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
/**
|
/**
|
||||||
* Set the <code>value</code> of the <code>name</code> property. If
|
* Set the <code>value</code> of the <code>name</code> property. If
|
||||||
* <code>name</code> is deprecated, it also sets the <code>value</code> to
|
* <code>name</code> is deprecated, it also sets the <code>value</code> to
|
||||||
* the keys that replace the deprecated key.
|
* the keys that replace the deprecated key. Name will be trimmed before put
|
||||||
|
* into configuration.
|
||||||
*
|
*
|
||||||
* @param name property name.
|
* @param name property name.
|
||||||
* @param value property value.
|
* @param value property value.
|
||||||
@ -979,6 +984,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
value != null,
|
value != null,
|
||||||
"The value of property " + name + " must not be null");
|
"The value of property " + name + " must not be null");
|
||||||
|
name = name.trim();
|
||||||
DeprecationContext deprecations = deprecationContext.get();
|
DeprecationContext deprecations = deprecationContext.get();
|
||||||
if (deprecations.getDeprecatedKeyMap().isEmpty()) {
|
if (deprecations.getDeprecatedKeyMap().isEmpty()) {
|
||||||
getProps();
|
getProps();
|
||||||
@ -1064,7 +1070,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||||||
* If no such property exists,
|
* If no such property exists,
|
||||||
* then <code>defaultValue</code> is returned.
|
* then <code>defaultValue</code> is returned.
|
||||||
*
|
*
|
||||||
* @param name property name.
|
* @param name property name, will be trimmed before get value.
|
||||||
* @param defaultValue default value.
|
* @param defaultValue default value.
|
||||||
* @return property value, or <code>defaultValue</code> if the property
|
* @return property value, or <code>defaultValue</code> if the property
|
||||||
* doesn't exist.
|
* doesn't exist.
|
||||||
|
@ -1003,6 +1003,14 @@ public class TestConfiguration extends TestCase {
|
|||||||
String resource;
|
String resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetSetTrimmedNames() throws IOException {
|
||||||
|
Configuration conf = new Configuration(false);
|
||||||
|
conf.set(" name", "value");
|
||||||
|
assertEquals("value", conf.get("name"));
|
||||||
|
assertEquals("value", conf.get(" name"));
|
||||||
|
assertEquals("value", conf.getRaw(" name "));
|
||||||
|
}
|
||||||
|
|
||||||
public void testDumpConfiguration () throws IOException {
|
public void testDumpConfiguration () throws IOException {
|
||||||
StringWriter outWriter = new StringWriter();
|
StringWriter outWriter = new StringWriter();
|
||||||
Configuration.dumpConfiguration(conf, outWriter);
|
Configuration.dumpConfiguration(conf, outWriter);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user