HADOOP - get nodename inside mapper

790 Views Asked by At

I'm writing a mapper and would like to know if it is possible to get the nodename, where the mapper is running.

2

There are 2 best solutions below

0
On

The configuration value fs.default.name will most probably give you a URL to the namenode, and if you get an instance of the FileSystem (Filesystem.get(conf)) you should be able to call the getUri() method to get the same information.

0
On

Hadoop automatically moves your MapReduce program to where your data is so I think you can just do getHostName() (if you're using Java that is) and it should return the name of the node on which your program is running.

java.net.InetAddress.getLocalHost().getHostName();

If you're using other languages such as Python, Ruby, etc. (i.e. using HadoopStreaming), the same idea holds true so you should be able to use the appropriate function/method available in those languages to get the host name.