HADOOP-7287. Configuration deprecation mechanism doesn't work properly for GenericOptionsParser and Tools. Contributed by Aaron T. Myers.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1126719 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
18ac8283b6
commit
f8841bea4d
@ -720,6 +720,9 @@ Release 0.22.0 - Unreleased
|
|||||||
HADOOP-7318. MD5Hash factory should reset the digester it returns.
|
HADOOP-7318. MD5Hash factory should reset the digester it returns.
|
||||||
(todd via eli)
|
(todd via eli)
|
||||||
|
|
||||||
|
HADOOP-7287. Configuration deprecation mechanism doesn't work properly for
|
||||||
|
GenericOptionsParser and Tools. (Aaron T. Myers via todd)
|
||||||
|
|
||||||
Release 0.21.1 - Unreleased
|
Release 0.21.1 - Unreleased
|
||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
|
@ -249,6 +249,12 @@ private final String getWarningMessage(String key) {
|
|||||||
private static Map<String, DeprecatedKeyInfo> deprecatedKeyMap =
|
private static Map<String, DeprecatedKeyInfo> deprecatedKeyMap =
|
||||||
new HashMap<String, DeprecatedKeyInfo>();
|
new HashMap<String, DeprecatedKeyInfo>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a mapping from superseding keys to the keys which they deprecate.
|
||||||
|
*/
|
||||||
|
private static Map<String, String> reverseDeprecatedKeyMap =
|
||||||
|
new HashMap<String, String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the deprecated key to the deprecation map.
|
* Adds the deprecated key to the deprecation map.
|
||||||
* It does not override any existing entries in the deprecation map.
|
* It does not override any existing entries in the deprecation map.
|
||||||
@ -269,6 +275,9 @@ public synchronized static void addDeprecation(String key, String[] newKeys,
|
|||||||
DeprecatedKeyInfo newKeyInfo;
|
DeprecatedKeyInfo newKeyInfo;
|
||||||
newKeyInfo = new DeprecatedKeyInfo(newKeys, customMessage);
|
newKeyInfo = new DeprecatedKeyInfo(newKeys, customMessage);
|
||||||
deprecatedKeyMap.put(key, newKeyInfo);
|
deprecatedKeyMap.put(key, newKeyInfo);
|
||||||
|
for (String newKey : newKeys) {
|
||||||
|
reverseDeprecatedKeyMap.put(newKey, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +310,11 @@ private static boolean isDeprecated(String key) {
|
|||||||
/**
|
/**
|
||||||
* Checks for the presence of the property <code>name</code> in the
|
* Checks for the presence of the property <code>name</code> in the
|
||||||
* deprecation map. Returns the first of the list of new keys if present
|
* deprecation map. Returns the first of the list of new keys if present
|
||||||
* in the deprecation map or the <code>name</code> itself.
|
* in the deprecation map or the <code>name</code> itself. If the property
|
||||||
|
* is not presently set but the property map contains an entry for the
|
||||||
|
* deprecated key, the value of the deprecated key is set as the value for
|
||||||
|
* the provided property name.
|
||||||
|
*
|
||||||
* @param name the property name
|
* @param name the property name
|
||||||
* @return the first property in the list of properties mapping
|
* @return the first property in the list of properties mapping
|
||||||
* the <code>name</code> or the <code>name</code> itself.
|
* the <code>name</code> or the <code>name</code> itself.
|
||||||
@ -319,6 +332,17 @@ private String handleDeprecation(String name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String deprecatedKey = reverseDeprecatedKeyMap.get(name);
|
||||||
|
if (deprecatedKey != null && !getOverlay().containsKey(name) &&
|
||||||
|
getOverlay().containsKey(deprecatedKey)) {
|
||||||
|
getProps().setProperty(name, getOverlay().getProperty(deprecatedKey));
|
||||||
|
getOverlay().setProperty(name, getOverlay().getProperty(deprecatedKey));
|
||||||
|
|
||||||
|
DeprecatedKeyInfo keyInfo = deprecatedKeyMap.get(deprecatedKey);
|
||||||
|
if (!keyInfo.accessed) {
|
||||||
|
LOG.warn(keyInfo.getWarningMessage(deprecatedKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@ public class TestConfigurationDeprecation {
|
|||||||
new File("./test-config3.xml").getAbsolutePath();
|
new File("./test-config3.xml").getAbsolutePath();
|
||||||
BufferedWriter out;
|
BufferedWriter out;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Configuration.addDefaultResource("test-fake-default.xml");
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
conf = new Configuration(false);
|
conf = new Configuration(false);
|
||||||
@ -249,4 +253,21 @@ public void testDeprecationForFinalParameters() throws IOException {
|
|||||||
assertNull(conf.get("I"));
|
assertNull(conf.get("I"));
|
||||||
assertNull(conf.get("J"));
|
assertNull(conf.get("J"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBeforeAndGetAfterDeprecation() {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.set("oldkey", "hello");
|
||||||
|
Configuration.addDeprecation("oldkey", new String[]{"newkey"});
|
||||||
|
assertEquals("hello", conf.get("newkey"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBeforeAndGetAfterDeprecationAndDefaults() {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.set("tests.fake-default.old-key", "hello");
|
||||||
|
Configuration.addDeprecation("tests.fake-default.old-key",
|
||||||
|
new String[]{ "tests.fake-default.new-key" });
|
||||||
|
assertEquals("hello", conf.get("tests.fake-default.new-key"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
29
src/test/test-fake-default.xml
Normal file
29
src/test/test-fake-default.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
|
||||||
|
|
||||||
|
<!-- This file is a fake version of a "default" file like
|
||||||
|
core-default or mapred-default, used for some of the unit tests.
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
<property>
|
||||||
|
<name>tests.fake-default.new-key</name>
|
||||||
|
<value>tests.fake-default.value</value>
|
||||||
|
<description>a default value for the "new" key of a deprecated pair.</description>
|
||||||
|
</property>
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue
Block a user