List Data nodes in hadoop cluster Java code:
Configuration conf = new Configuration();
try{
FileSystem fs = FileSystem.get(conf);
BufferedWriter buffWrite = new BufferedWriter(new FileWriter(file));
DistributedFileSystem hdfs = (DistributedFileSystem) fs;
DatanodeInfo[] dataNodeStats = hdfs.getDataNodeStats();
for (int i = 0; i < dataNodeStats.length; i++) {
System.out.println(dataNodeStats[i].getHost());
}
}catch(IOException e) {
logger.error("IOException when writing the node list to file \t" + e.toString());
}
No comments:
Post a Comment