From 76755a937419eefcc7242fde5d495941dce4427a Mon Sep 17 00:00:00 2001 From: Alejandro Abdelnur Date: Thu, 23 Aug 2012 23:28:50 +0000 Subject: [PATCH] HADOOP-8031. Configuration class fails to find embedded .jar resources; should use URL.openStream() (genman via tucu) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1376775 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 24 +++++--- .../org/apache/hadoop/conf/Configuration.java | 58 ++++++++++--------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 6e47ae412d4..7f70570ce73 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -224,6 +224,22 @@ Release 2.0.1-alpha - UNRELEASED HADOOP-4572. Can not access user logs - Jetty is not configured by default to serve aliases/symlinks (ahmed via tucu) + HADOOP-8660. TestPseudoAuthenticator failing with NPE. (tucu) + + HADOOP-8699. some common testcases create core-site.xml in test-classes + making other testcases to fail. (tucu) + + HADOOP-8660. TestPseudoAuthenticator failing with NPE. (tucu) + + HADOOP-7703. Improved excpetion handling of shutting down web server. + (Devaraj K via Eric Yang) + + HADOOP-8699. some common testcases create core-site.xml in test-classes + making other testcases to fail. (tucu) + + HADOOP-8031. Configuration class fails to find embedded .jar resources; + should use URL.openStream() (genman via tucu) + BREAKDOWN OF HDFS-3042 SUBTASKS HADOOP-8220. ZKFailoverController doesn't handle failure to become active @@ -256,14 +272,6 @@ Release 2.0.1-alpha - UNRELEASED HADOOP-8405. ZKFC tests leak ZK instances. (todd) - HADOOP-8660. TestPseudoAuthenticator failing with NPE. (tucu) - - HADOOP-7703. Improved excpetion handling of shutting down web server. - (Devaraj K via Eric Yang) - - HADOOP-8699. some common testcases create core-site.xml in test-classes - making other testcases to fail. (tucu) - Release 2.0.0-alpha - 05-23-2012 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 319e537abe5..516ca1c8e12 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 @@ -1824,6 +1824,32 @@ public class Configuration implements Iterable>, return result.entrySet().iterator(); } + private Document parse(DocumentBuilder builder, URL url) + throws IOException, SAXException { + if (!quietmode) { + LOG.info("parsing URL " + url); + } + if (url == null) { + return null; + } + return parse(builder, url.openStream()); + } + + private Document parse(DocumentBuilder builder, InputStream is) + throws IOException, SAXException { + if (!quietmode) { + LOG.info("parsing input stream " + is); + } + if (is == null) { + return null; + } + try { + return builder.parse(is); + } finally { + is.close(); + } + } + private void loadResources(Properties properties, ArrayList resources, boolean quiet) { @@ -1873,21 +1899,10 @@ public class Configuration implements Iterable>, boolean returnCachedProperties = false; if (resource instanceof URL) { // an URL resource - URL url = (URL)resource; - if (url != null) { - if (!quiet) { - LOG.info("parsing " + url); - } - doc = builder.parse(url.toString()); - } + doc = parse(builder, (URL)resource); } else if (resource instanceof String) { // a CLASSPATH resource URL url = getResource((String)resource); - if (url != null) { - if (!quiet) { - LOG.info("parsing " + url); - } - doc = builder.parse(url.toString()); - } + doc = parse(builder, url); } else if (resource instanceof Path) { // a file resource // Can't use FileSystem API or we get an infinite loop // since FileSystem uses Configuration API. Use java.io.File instead. @@ -1895,22 +1910,13 @@ public class Configuration implements Iterable>, .getAbsoluteFile(); if (file.exists()) { if (!quiet) { - LOG.info("parsing " + file); - } - InputStream in = new BufferedInputStream(new FileInputStream(file)); - try { - doc = builder.parse(in); - } finally { - in.close(); + LOG.info("parsing File " + file); } + doc = parse(builder, new BufferedInputStream(new FileInputStream(file))); } } else if (resource instanceof InputStream) { - try { - doc = builder.parse((InputStream)resource); - returnCachedProperties = true; - } finally { - ((InputStream)resource).close(); - } + doc = parse(builder, (InputStream) resource); + returnCachedProperties = true; } else if (resource instanceof Properties) { overlay(properties, (Properties)resource); } else if (resource instanceof Element) {