From 0caafb63effeb12e7dd559e1eefd7d1f3b65302a Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Thu, 7 Feb 2013 03:06:15 +0000 Subject: [PATCH] svn merge -c 1443297 from trunk for HDFS-4458. In DFSUtil.getNameServiceUris(..), convert default fs URI using NetUtils.createSocketAddr(..) for being consistent with other addresses. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1443300 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 4 ++++ .../src/main/java/org/apache/hadoop/hdfs/DFSUtil.java | 7 +++++++ .../test/java/org/apache/hadoop/hdfs/TestDFSUtil.java | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index c79f3fbc878..88bb5e6cc64 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -12,6 +12,10 @@ Release 2.0.4-beta - UNRELEASED BUG FIXES + HDFS-4458. In DFSUtil.getNameServiceUris(..), convert default fs URI using + NetUtils.createSocketAddr(..) for being consistent with other addresses. + (Binglin Chang via szetszwo) + Release 2.0.3-alpha - 2013-02-06 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java index 613f8defd17..773b1ad1996 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java @@ -764,6 +764,13 @@ public class DFSUtil { // Add the default URI if it is an HDFS URI. URI defaultUri = FileSystem.getDefaultUri(conf); + // checks if defaultUri is ip:port format + // and convert it to hostname:port format + if (defaultUri != null && (defaultUri.getPort() != -1)) { + defaultUri = createUri(defaultUri.getScheme(), + NetUtils.createSocketAddr(defaultUri.getHost(), + defaultUri.getPort())); + } if (defaultUri != null && HdfsConstants.HDFS_URI_SCHEME.equals(defaultUri.getScheme()) && !nonPreferredUris.contains(defaultUri)) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java index 06b4ed0cb8a..75596cbaeb4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java @@ -619,6 +619,16 @@ public class TestDFSUtil { assertEquals(1, uris.size()); assertTrue(uris.contains(new URI("hdfs://" + NN1_SRVC_ADDR))); + + // Make sure when config FS_DEFAULT_NAME_KEY using IP address, + // it will automatically convert it to hostname + conf = new HdfsConfiguration(); + conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, "hdfs://127.0.0.1:8020"); + uris = DFSUtil.getNameServiceUris(conf); + assertEquals(1, uris.size()); + for (URI uri : uris) { + assertFalse(uri.getHost().equals("127.0.0.1")); + } } @Test