You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by su...@apache.org on 2019/02/21 15:20:05 UTC

[hadoop] branch branch-3.2 updated: HDFS-14216. NullPointerException happens in NamenodeWebHdfs. Contributed by lujie.

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/branch-3.2 by this push:
     new 2e93951  HDFS-14216. NullPointerException happens in NamenodeWebHdfs. Contributed by lujie.
2e93951 is described below

commit 2e939515dfbaf26ca466c8a755cedde0ce4e9c1a
Author: Surendra Singh Lilhore <su...@apache.org>
AuthorDate: Thu Feb 21 20:36:34 2019 +0530

    HDFS-14216. NullPointerException happens in NamenodeWebHdfs. Contributed by lujie.
    
    (cherry picked from commit 92b53c40f070bbfe65c736f6f3eca721b9d227f5)
---
 .../web/resources/NamenodeWebHdfsMethods.java      | 16 +++++++++++----
 .../web/resources/TestWebHdfsDataLocality.java     | 23 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java
index e42b632..defab72 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java
@@ -273,11 +273,19 @@ public class NamenodeWebHdfsMethods {
       for (String host : StringUtils
           .getTrimmedStringCollection(excludeDatanodes)) {
         int idx = host.indexOf(":");
-        if (idx != -1) {          
-          excludes.add(bm.getDatanodeManager().getDatanodeByXferAddr(
-              host.substring(0, idx), Integer.parseInt(host.substring(idx + 1))));
+        Node excludeNode = null;
+        if (idx != -1) {
+          excludeNode = bm.getDatanodeManager().getDatanodeByXferAddr(
+             host.substring(0, idx), Integer.parseInt(host.substring(idx + 1)));
         } else {
-          excludes.add(bm.getDatanodeManager().getDatanodeByHost(host));
+          excludeNode = bm.getDatanodeManager().getDatanodeByHost(host);
+        }
+
+        if (excludeNode != null) {
+          excludes.add(excludeNode);
+        } else {
+          LOG.debug("DataNode {} was requested to be excluded, "
+                + "but it was not found.", host);
         }
       }
     }
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/web/resources/TestWebHdfsDataLocality.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/web/resources/TestWebHdfsDataLocality.java
index 028e18c..e009bc6 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/web/resources/TestWebHdfsDataLocality.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/web/resources/TestWebHdfsDataLocality.java
@@ -240,6 +240,29 @@ public class TestWebHdfsDataLocality {
   }
 
   @Test
+  public void testExcludeWrongDataNode() throws Exception {
+    final Configuration conf = WebHdfsTestUtil.createConf();
+    final String[] racks = {RACK0};
+    final String[] hosts = {"DataNode1"};
+    final int nDataNodes = hosts.length;
+
+    final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
+        .hosts(hosts).numDataNodes(nDataNodes).racks(racks).build();
+    try {
+      cluster.waitActive();
+      final NameNode namenode = cluster.getNameNode();
+      NamenodeWebHdfsMethods.chooseDatanode(
+          namenode, "/path", PutOpParam.Op.CREATE, 0,
+          DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT,
+          "DataNode2", LOCALHOST, null);
+    } catch (Exception e) {
+      Assert.fail("Failed to exclude DataNode2" + e.getMessage());
+    } finally {
+      cluster.shutdown();
+    }
+  }
+
+  @Test
   public void testChooseDatanodeBeforeNamesystemInit() throws Exception {
     NameNode nn = mock(NameNode.class);
     when(nn.getNamesystem()).thenReturn(null);


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