获取HDFS集群上所有节点名称信息

来源:互联网 发布:美国校园暴力事件数据 编辑:程序博客网 时间:2024/05/17 00:10
通过"DatanodeInfo.getHostName()"可获取HDFS集群上的所有节点名称。具体实现如下:

packagecom.hebut.file;

importorg.apache.hadoop.conf.Configuration;

importorg.apache.hadoop.fs.FileSystem;

importorg.apache.hadoop.hdfs.DistributedFileSystem;

importorg.apache.hadoop.hdfs.protocol.DatanodeInfo;

publicclassGetList {

publicstaticvoidmain(String[] args) throwsException {

Configuration conf=newConfiguration();

FileSystem fs=FileSystem.get(conf);

DistributedFileSystem hdfs = (DistributedFileSystem)fs;

DatanodeInfo[] dataNodeStats = hdfs.getDataNodeStats();

for(inti=0;ilength;i++){

System.out.println("DataNode_"+i+"_Name:"+dataNodeStats[i].getHostName());

}

}

}

原创粉丝点击