From e15e2713e1e344b14d63726639d1c83451921515 Mon Sep 17 00:00:00 2001 From: Xiaoyu Yao Date: Wed, 12 Jul 2017 16:26:09 -0700 Subject: [PATCH] HDFS-11502. Datanode UI should display hostname based on JMX bean instead of window.location.hostname. Contributed by Jeffrey E Rodriguez and Yuanbo Liu. --- .../org/apache/hadoop/hdfs/server/datanode/DataNode.java | 8 ++++++++ .../hadoop/hdfs/server/datanode/DataNodeMXBean.java | 7 +++++++ .../hadoop-hdfs/src/main/webapps/datanode/dn.js | 2 +- .../hadoop/hdfs/server/datanode/TestDataNodeMXBean.java | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index a95fdea54ec..35fbb9c5ef6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -3063,6 +3063,14 @@ public class DataNode extends ReconfigurableBase return JSON.toString(info); } + /** + * Return hostname of the datanode. + */ + @Override // DataNodeMXBean + public String getDatanodeHostname() { + return this.hostName; + } + /** * Returned information is a JSON representation of an array, * each element of the array is a map contains the information diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java index c86fe449131..b5f0cd0a5d3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java @@ -74,6 +74,13 @@ public interface DataNodeMXBean { */ public String getNamenodeAddresses(); + /** + * Gets the datanode hostname. + * + * @return the datanode hostname for the datanode. + */ + public String getDatanodeHostname(); + /** * Gets information of the block pool service actors. * diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/dn.js b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/dn.js index ea963cc37aa..9e2732ca5de 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/dn.js +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/dn.js @@ -25,7 +25,7 @@ function load() { $.get('/jmx?qry=Hadoop:service=DataNode,name=DataNodeInfo', function(resp) { data.dn = workaround(resp.beans[0]); - data.dn.HostName=window.location.hostname; + data.dn.HostName = resp.beans[0]['DatanodeHostname']; render(); }).fail(show_err_msg); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java index faead188f58..9107aaef600 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java @@ -88,6 +88,10 @@ public class TestDataNodeMXBean { String namenodeAddresses = (String)mbs.getAttribute(mxbeanName, "NamenodeAddresses"); Assert.assertEquals(datanode.getNamenodeAddresses(),namenodeAddresses); + // get attribute "getDatanodeHostname" + String datanodeHostname = (String)mbs.getAttribute(mxbeanName, + "DatanodeHostname"); + Assert.assertEquals(datanode.getDatanodeHostname(),datanodeHostname); // get attribute "getVolumeInfo" String volumeInfo = (String)mbs.getAttribute(mxbeanName, "VolumeInfo"); Assert.assertEquals(replaceDigits(datanode.getVolumeInfo()),