hdfs - Get hadoop configuration in Java util -


i'm writing java utility needs access dfs, need configuration object. when create 1 using

configuration conf = new configuration()

it doesn't seem find dfs, , uses local file system; printing

fs.gethomedirectory()

gives local home directory. i've tried adding core-site.xml,mapred-site.xml,yarn-site.xml,and hdfs-site.xml configuration resources, doesn't change anything. need pick hdfs settings?

thanks reading

the reason why it's pointing local file system core-site.xml , hdfs-site.xml not added properly. below code snippet you.

configuration conf = new configuration(); conf.addresource(new path("file:///etc/hadoop/conf/core-site.xml")); // replace actual path conf.addresource(new path("file:///etc/hadoop/conf/hdfs-site.xml")); // replace actual path  path pt = new path("."); // hdfs path filesystem fs = pt.getfilesystem(conf);  system.out.println("home directory :"+fs.gethomedirectory()); 

update :

above option should've worked, seems issues in configuration file or path. have option instead of adding configuration files using addresource method, use set method. open core-site.xml file , find value of fs.defaultfs. use set method instead of addresource method.

conf.set("fs.defaultfs","hdfs://<namenode-host>:<port>");  // refer core-site.xml file , replace <namenode-host> , <port> cluster namenode , port (default port number should `8020`).  

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -