You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by to...@apache.org on 2011/05/23 22:30:49 UTC

svn commit: r1126719 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java src/test/test-fake-default.xml

Author: todd
Date: Mon May 23 20:30:48 2011
New Revision: 1126719

URL: http://svn.apache.org/viewvc?rev=1126719&view=rev
Log:
HADOOP-7287. Configuration deprecation mechanism doesn't work properly for GenericOptionsParser and Tools. Contributed by Aaron T. Myers.

Added:
    hadoop/common/trunk/src/test/test-fake-default.xml
Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1126719&r1=1126718&r2=1126719&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Mon May 23 20:30:48 2011
@@ -720,6 +720,9 @@ Release 0.22.0 - Unreleased
     HADOOP-7318. MD5Hash factory should reset the digester it returns.
     (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
 
   IMPROVEMENTS

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=1126719&r1=1126718&r2=1126719&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java Mon May 23 20:30:48 2011
@@ -247,9 +247,15 @@ public class Configuration implements It
    * and custom message(if any provided).
    */
   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.
    * It does not override any existing entries in the deprecation map.
    * This is to be used only by the developers in order to add deprecation of
@@ -269,6 +275,9 @@ public class Configuration implements It
       DeprecatedKeyInfo newKeyInfo;
       newKeyInfo = new DeprecatedKeyInfo(newKeys, customMessage);
       deprecatedKeyMap.put(key, newKeyInfo);
+      for (String newKey : newKeys) {
+        reverseDeprecatedKeyMap.put(newKey, key);
+      }
     }
   }
 
@@ -301,7 +310,11 @@ public class Configuration implements It
   /**
    * 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
-   * 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
    * @return the first property in the list of properties mapping
    *         the <code>name</code> or the <code>name</code> itself.
@@ -319,6 +332,17 @@ public class Configuration implements It
         }
       }
     }
+    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;
   }
   

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java?rev=1126719&r1=1126718&r2=1126719&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java Mon May 23 20:30:48 2011
@@ -42,6 +42,10 @@ public class TestConfigurationDeprecatio
   final static String CONFIG3 = 
     new File("./test-config3.xml").getAbsolutePath();
   BufferedWriter out;
+  
+  static {
+    Configuration.addDefaultResource("test-fake-default.xml");
+  }
 
   @Before
   public void setUp() throws Exception {
@@ -249,4 +253,21 @@ public class TestConfigurationDeprecatio
     assertNull(conf.get("I"));
     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"));
+  }
 }

Added: hadoop/common/trunk/src/test/test-fake-default.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/test-fake-default.xml?rev=1126719&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/test-fake-default.xml (added)
+++ hadoop/common/trunk/src/test/test-fake-default.xml Mon May 23 20:30:48 2011
@@ -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>