HDFS-11502. Datanode UI should display hostname based on JMX bean instead of window.location.hostname. Contributed by Jeffrey E Rodriguez and Yuanbo Liu.

This commit is contained in:
Xiaoyu Yao 2017-07-12 16:26:09 -07:00
parent 9845bea59c
commit e15e2713e1
4 changed files with 20 additions and 1 deletions

View File

@ -3063,6 +3063,14 @@ public class DataNode extends ReconfigurableBase
return JSON.toString(info); 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, * Returned information is a JSON representation of an array,
* each element of the array is a map contains the information * each element of the array is a map contains the information

View File

@ -74,6 +74,13 @@ public interface DataNodeMXBean {
*/ */
public String getNamenodeAddresses(); 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. * Gets information of the block pool service actors.
* *

View File

@ -25,7 +25,7 @@
function load() { function load() {
$.get('/jmx?qry=Hadoop:service=DataNode,name=DataNodeInfo', function(resp) { $.get('/jmx?qry=Hadoop:service=DataNode,name=DataNodeInfo', function(resp) {
data.dn = workaround(resp.beans[0]); data.dn = workaround(resp.beans[0]);
data.dn.HostName=window.location.hostname; data.dn.HostName = resp.beans[0]['DatanodeHostname'];
render(); render();
}).fail(show_err_msg); }).fail(show_err_msg);
} }

View File

@ -88,6 +88,10 @@ public class TestDataNodeMXBean {
String namenodeAddresses = (String)mbs.getAttribute(mxbeanName, String namenodeAddresses = (String)mbs.getAttribute(mxbeanName,
"NamenodeAddresses"); "NamenodeAddresses");
Assert.assertEquals(datanode.getNamenodeAddresses(),namenodeAddresses); Assert.assertEquals(datanode.getNamenodeAddresses(),namenodeAddresses);
// get attribute "getDatanodeHostname"
String datanodeHostname = (String)mbs.getAttribute(mxbeanName,
"DatanodeHostname");
Assert.assertEquals(datanode.getDatanodeHostname(),datanodeHostname);
// get attribute "getVolumeInfo" // get attribute "getVolumeInfo"
String volumeInfo = (String)mbs.getAttribute(mxbeanName, "VolumeInfo"); String volumeInfo = (String)mbs.getAttribute(mxbeanName, "VolumeInfo");
Assert.assertEquals(replaceDigits(datanode.getVolumeInfo()), Assert.assertEquals(replaceDigits(datanode.getVolumeInfo()),