Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0C9DD91B0 for ; Thu, 21 Jun 2012 21:12:57 +0000 (UTC) Received: (qmail 57398 invoked by uid 500); 21 Jun 2012 21:12:56 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 57359 invoked by uid 500); 21 Jun 2012 21:12:56 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 57352 invoked by uid 99); 21 Jun 2012 21:12:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2012 21:12:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2012 21:12:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 896912388865; Thu, 21 Jun 2012 21:12:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1352689 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/conf/Configuration.java src/test/java/org/apache/hadoop/conf/TestConfiguration.java Date: Thu, 21 Jun 2012 21:12:32 -0000 To: common-commits@hadoop.apache.org From: harsh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120621211232.896912388865@eris.apache.org> Author: harsh Date: Thu Jun 21 21:12:31 2012 New Revision: 1352689 URL: http://svn.apache.org/viewvc?rev=1352689&view=rev Log: HADOOP-8524. Allow users to get source of a Configuration parameter. (harsh) Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1352689&r1=1352688&r2=1352689&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Thu Jun 21 21:12:31 2012 @@ -209,6 +209,9 @@ Branch-2 ( Unreleased changes ) HADOOP-8368. Use CMake rather than autotools to build native code (ccccabe via tucu) + HADOOP-8524. Allow users to get source of a Configuration + parameter (harsh) + BUG FIXES HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java?rev=1352689&r1=1352688&r2=1352689&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java Thu Jun 21 21:12:31 2012 @@ -1071,6 +1071,38 @@ public class Configuration implements It } /** + * Gets the absolute path to the resource object (file, URL, etc.), for a given + * property name. + * + * @param name - The property name to get the source of. + * @return null - If the property or its source wasn't found or if the property + * was defined in code (i.e. in a Configuration instance, not from a physical + * resource). Otherwise, returns the absolute path of the resource that loaded + * the property name, as a String. + */ + @InterfaceStability.Unstable + public synchronized String getPropertySource(String name) { + if (properties == null) { + // If properties is null, it means a resource was newly added + // but the props were cleared so as to load it upon future + // requests. So lets force a load by asking a properties list. + getProps(); + } + // Return a null right away if our properties still + // haven't loaded or the resource mapping isn't defined + if (properties == null || updatingResource == null) { + return null; + } else { + String source = updatingResource.get(name); + if (source == null || source.equals(UNKNOWN_RESOURCE)) { + return null; + } else { + return source; + } + } + } + + /** * A class that represents a set of positive integer ranges. It parses * strings of the form: "2-3,5,7-" where ranges are separated by comma and * the lower/upper bounds are separated by dash. Either the lower or upper Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java?rev=1352689&r1=1352688&r2=1352689&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java (original) +++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java Thu Jun 21 21:12:31 2012 @@ -663,6 +663,26 @@ public class TestConfiguration extends T conf.getPattern("test.pattern3", defaultPattern).pattern()); } + public void testPropertySource() throws IOException { + out = new BufferedWriter(new FileWriter(CONFIG)); + startConfig(); + appendProperty("test.foo", "bar"); + endConfig(); + Path fileResource = new Path(CONFIG); + conf.addResource(fileResource); + conf.set("fs.defaultFS", "value"); + assertEquals( + "Resource string returned for a file-loaded property" + + " must be a proper absolute path", + fileResource, + new Path(conf.getPropertySource("test.foo"))); + assertEquals("Resource string returned for a set() property must be null", + null, + conf.getPropertySource("fs.defaultFS")); + assertEquals("Resource string returned for an unset property must be null", + null, conf.getPropertySource("fs.defaultFoo")); + } + public void testSocketAddress() throws IOException { Configuration conf = new Configuration(); final String defaultAddr = "host:1";