From 743837b25942d2f4c90e7d0020d80c882cd3c374 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Fri, 1 Aug 2014 21:54:18 +0000 Subject: [PATCH] HDFS-6793. Missing changes in HftpFileSystem when Reintroduce dfs.http.port / dfs.https.port in branch-2. Contributed by Juan Yu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1615243 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hadoop/hdfs/web/HftpFileSystem.java | 3 +- .../hadoop/hdfs/web/HsftpFileSystem.java | 3 +- .../hadoop/hdfs/web/TestHftpFileSystem.java | 41 +++++++++++++++++-- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index ffe3101adf5..fba94c9b979 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -735,6 +735,9 @@ Release 2.5.0 - UNRELEASED HDFS-6768. Fix a few unit tests that use hard-coded port numbers. (Arpit Agarwal) + HDFS-6793. Missing changes in HftpFileSystem when Reintroduce + dfs.http.port / dfs.https.port in branch-2. (Juan Yu via wang). + BREAKDOWN OF HDFS-2006 SUBTASKS AND RELATED JIRAS HDFS-6299. Protobuf for XAttr and client-side implementation. (Yi Liu via umamahesh) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HftpFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HftpFileSystem.java index 63a6aecab5b..581f0888aaf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HftpFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HftpFileSystem.java @@ -123,7 +123,8 @@ public class HftpFileSystem extends FileSystem @Override protected int getDefaultPort() { - return DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT; + return getConf().getInt(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_KEY, + DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HsftpFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HsftpFileSystem.java index 3029e2a3982..b232f5b831e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HsftpFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/HsftpFileSystem.java @@ -64,6 +64,7 @@ public class HsftpFileSystem extends HftpFileSystem { @Override protected int getDefaultPort() { - return DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_DEFAULT; + return getConf().getInt(DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_KEY, + DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_DEFAULT); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHftpFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHftpFileSystem.java index ce63ee60750..19c54efd287 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHftpFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHftpFileSystem.java @@ -310,6 +310,23 @@ public class TestHftpFileSystem { fs.getCanonicalServiceName()); } + @Test + public void testHftpCustomDefaultPorts() throws IOException { + Configuration conf = new Configuration(); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_KEY, 123); + + URI uri = URI.create("hftp://localhost"); + HftpFileSystem fs = (HftpFileSystem) FileSystem.get(uri, conf); + + assertEquals(123, fs.getDefaultPort()); + + assertEquals(uri, fs.getUri()); + + // HFTP uses http to get the token so canonical service name should + // return the http port. + assertEquals("127.0.0.1:123", fs.getCanonicalServiceName()); + } + @Test public void testHftpCustomUriPortWithDefaultPorts() throws IOException { Configuration conf = new Configuration(); @@ -326,11 +343,12 @@ public class TestHftpFileSystem { @Test public void testHftpCustomUriPortWithCustomDefaultPorts() throws IOException { Configuration conf = new Configuration(); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_KEY, 123); + URI uri = URI.create("hftp://localhost:789"); HftpFileSystem fs = (HftpFileSystem) FileSystem.get(uri, conf); - assertEquals(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT, - fs.getDefaultPort()); + assertEquals(123, fs.getDefaultPort()); assertEquals(uri, fs.getUri()); assertEquals("127.0.0.1:789", fs.getCanonicalServiceName()); @@ -365,6 +383,20 @@ public class TestHftpFileSystem { fs.getCanonicalServiceName()); } + @Test + public void testHsftpCustomDefaultPorts() throws IOException { + Configuration conf = new Configuration(); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_KEY, 123); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_KEY, 456); + + URI uri = URI.create("hsftp://localhost"); + HsftpFileSystem fs = (HsftpFileSystem) FileSystem.get(uri, conf); + + assertEquals(456, fs.getDefaultPort()); + + assertEquals(uri, fs.getUri()); + assertEquals("127.0.0.1:456", fs.getCanonicalServiceName()); + } @Test public void testHsftpCustomUriPortWithDefaultPorts() throws IOException { @@ -382,12 +414,13 @@ public class TestHftpFileSystem { @Test public void testHsftpCustomUriPortWithCustomDefaultPorts() throws IOException { Configuration conf = new Configuration(); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_KEY, 123); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_KEY, 456); URI uri = URI.create("hsftp://localhost:789"); HsftpFileSystem fs = (HsftpFileSystem) FileSystem.get(uri, conf); - assertEquals(DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_DEFAULT, - fs.getDefaultPort()); + assertEquals(456, fs.getDefaultPort()); assertEquals(uri, fs.getUri()); assertEquals("127.0.0.1:789", fs.getCanonicalServiceName());