hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weic...@apache.org
Subject [hadoop] branch branch-3.1 updated: HDFS-14460. DFSUtil#getNamenodeWebAddr should return HTTPS address based on policy configured. Contributed by CR Hota.
Date Tue, 01 Oct 2019 18:05:07 GMT
This is an automated email from the ASF dual-hosted git repository.

weichiu pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 528dc81  HDFS-14460. DFSUtil#getNamenodeWebAddr should return HTTPS address based
on policy configured. Contributed by CR Hota.
528dc81 is described below

commit 528dc8199be5163cff09f8d36e7e8257aa5eb75a
Author: Inigo Goiri <inigoiri@apache.org>
AuthorDate: Thu May 2 10:09:21 2019 -0700

    HDFS-14460. DFSUtil#getNamenodeWebAddr should return HTTPS address based on policy configured.
Contributed by CR Hota.
    
    (cherry picked from commit 865c3289308327788f3bed355864c510deb40956)
---
 .../main/java/org/apache/hadoop/hdfs/DFSUtil.java  | 12 ++++++---
 .../java/org/apache/hadoop/hdfs/TestDFSUtil.java   | 31 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

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 4c94e38..e28fa12 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
@@ -1307,11 +1307,15 @@ public class DFSUtil {
       nsId = getOnlyNameServiceIdOrNull(conf);
     }
 
+    String webAddrBaseKey = DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY;
+    String webAddrDefault = DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_DEFAULT;
+    if (getHttpPolicy(conf) == HttpConfig.Policy.HTTPS_ONLY) {
+      webAddrBaseKey = DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY;
+      webAddrDefault = DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_DEFAULT;
+    }
     String webAddrKey = DFSUtilClient.concatSuffixes(
-        DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, nsId, nnId);
-
-    String webAddr =
-        conf.get(webAddrKey, DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_DEFAULT);
+        webAddrBaseKey, nsId, nnId);
+    String webAddr = conf.get(webAddrKey, webAddrDefault);
     return webAddr;
   }
 
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 afe34ad..358edb8 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
@@ -22,6 +22,8 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_INTERNAL_NAMESERVICES_KEY;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HTTP_POLICY_KEY;
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_DEFAULT;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY;
 import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT;
@@ -70,6 +72,7 @@ import org.apache.hadoop.hdfs.protocol.LocatedBlock;
 import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider;
+import org.apache.hadoop.http.HttpConfig;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.alias.CredentialProvider;
@@ -87,6 +90,8 @@ public class TestDFSUtil {
   static final String NS1_NN_ADDR    = "ns1-nn.example.com:8020";
   static final String NS1_NN1_ADDR   = "ns1-nn1.example.com:8020";
   static final String NS1_NN2_ADDR   = "ns1-nn2.example.com:8020";
+  static final String NS1_NN1_HTTPS_ADDR   = "ns1-nn1.example.com:50740";
+  static final String NS1_NN1_HTTP_ADDR    = "ns1-nn1.example.com:50070";
 
   /**
    * Reset to default UGI settings since some tests change them.
@@ -466,6 +471,32 @@ public class TestDFSUtil {
   }
 
   @Test
+  public void testGetNamenodeWebAddr() {
+    HdfsConfiguration conf = new HdfsConfiguration();
+
+    conf.set(DFSUtil.addKeySuffixes(
+        DFS_NAMENODE_HTTPS_ADDRESS_KEY, "ns1", "nn1"), NS1_NN1_HTTPS_ADDR);
+    conf.set(DFSUtil.addKeySuffixes(
+        DFS_NAMENODE_HTTP_ADDRESS_KEY, "ns1", "nn1"), NS1_NN1_HTTP_ADDR);
+
+    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTPS_ONLY.name());
+    String httpsOnlyWebAddr = DFSUtil.getNamenodeWebAddr(
+        conf, "ns1", "nn1");
+    assertEquals(NS1_NN1_HTTPS_ADDR, httpsOnlyWebAddr);
+
+    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTP_ONLY.name());
+    String httpOnlyWebAddr = DFSUtil.getNamenodeWebAddr(
+        conf, "ns1", "nn1");
+    assertEquals(NS1_NN1_HTTP_ADDR, httpOnlyWebAddr);
+
+    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTP_AND_HTTPS.name());
+    String httpAndHttpsWebAddr = DFSUtil.getNamenodeWebAddr(
+        conf, "ns1", "nn1");
+    assertEquals(NS1_NN1_HTTP_ADDR, httpAndHttpsWebAddr);
+
+  }
+
+  @Test
   public void testGetInfoServer() throws IOException, URISyntaxException {
     HdfsConfiguration conf = new HdfsConfiguration();
     


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message