hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1134088 - in /hadoop/common/branches/yahoo-merge: 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
Date Thu, 09 Jun 2011 21:24:14 GMT
Author: mahadev
Date: Thu Jun  9 21:24:14 2011
New Revision: 1134088

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

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

Modified: hadoop/common/branches/yahoo-merge/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/CHANGES.txt?rev=1134088&r1=1134087&r2=1134088&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/CHANGES.txt (original)
+++ hadoop/common/branches/yahoo-merge/CHANGES.txt Thu Jun  9 21:24:14 2011
@@ -132,6 +132,9 @@ Trunk (unreleased changes)
 
     HADOOP-7284 Trash and shell's rm does not work for viewfs (Sanjay Radia)
 
+    HADOOP-7287. Configuration deprecation mechanism doesn't work properly for
+    GenericOptionsParser and Tools. (Aaron T. Myers via todd)
+
 Release 0.22.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/conf/Configuration.java?rev=1134088&r1=1134087&r2=1134088&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/conf/Configuration.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/conf/Configuration.java
Thu Jun  9 21:24:14 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/branches/yahoo-merge/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java?rev=1134088&r1=1134087&r2=1134088&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
Thu Jun  9 21:24:14 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/branches/yahoo-merge/src/test/test-fake-default.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/test-fake-default.xml?rev=1134088&view=auto
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/test-fake-default.xml (added)
+++ hadoop/common/branches/yahoo-merge/src/test/test-fake-default.xml Thu Jun  9 21:24:14
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>



Mime
View raw message