From c8bb6f59b8de48f533414fb92f8220ea60b701bc Mon Sep 17 00:00:00 2001 From: Mahadev Konar Date: Fri, 27 Jan 2012 03:42:36 +0000 Subject: [PATCH] HADOOP-7993. Hadoop ignores old-style config options for enabling compressed output. (Anupam Seth via mahadev) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1236506 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/conf/Configuration.java | 14 +++++++++++-- .../hadoop/conf/TestDeprecatedKeys.java | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index dc9ad36440f..fb7eb2a2e18 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -295,6 +295,9 @@ Release 0.23.1 - Unreleased HADOOP-7997. SequenceFile.createWriter(...createParent...) no longer works on existing file. (Gregory Chanan via eli) + HADOOP-7993. Hadoop ignores old-style config options for enabling compressed + output. (Anupam Seth via mahadev) + Release 0.23.0 - 2011-11-01 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 79e0793253c..84a31871195 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -345,7 +345,17 @@ public class Configuration implements Iterable>, } return name; } - + + private void handleDeprecation() { + LOG.debug("Handling deprecation for all properties in config..."); + Set keys = new HashSet(); + keys.addAll(getProps().keySet()); + for (Object item: keys) { + LOG.debug("Handling deprecation for " + (String)item); + handleDeprecation((String)item); + } + } + static{ //print deprecation warning if hadoop-site.xml is found in classpath ClassLoader cL = Thread.currentThread().getContextClassLoader(); @@ -1667,7 +1677,7 @@ public class Configuration implements Iterable>, Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); - getProps(); // ensure properties is set + handleDeprecation(); //ensure properties is set and deprecation is handled for (Enumeration e = properties.keys(); e.hasMoreElements();) { String name = (String)e.nextElement(); Object object = properties.get(name); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java index 7008544f7b8..8631771b9df 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestDeprecatedKeys.java @@ -18,6 +18,8 @@ package org.apache.hadoop.conf; +import java.io.ByteArrayOutputStream; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; @@ -32,4 +34,22 @@ public class TestDeprecatedKeys extends TestCase { String scriptFile = conf.get(CommonConfigurationKeys.NET_TOPOLOGY_SCRIPT_FILE_NAME_KEY); assertTrue(scriptFile.equals("xyz")) ; } + + //Tests reading / writing a conf file with deprecation after setting + public void testReadWriteWithDeprecatedKeys() throws Exception { + Configuration conf = new Configuration(); + conf.setBoolean("old.config.yet.to.be.deprecated", true); + Configuration.addDeprecation("old.config.yet.to.be.deprecated", + new String[]{"new.conf.to.replace.deprecated.conf"}); + ByteArrayOutputStream out=new ByteArrayOutputStream(); + String fileContents; + try { + conf.writeXml(out); + fileContents = out.toString(); + } finally { + out.close(); + } + assertTrue(fileContents.contains("old.config.yet.to.be.deprecated")); + assertTrue(fileContents.contains("new.conf.to.replace.deprecated.conf")); + } }