G
G
gingerose2021-02-16 14:57:28
Java
gingerose, 2021-02-16 14:57:28

How to connect to hdfs via java?

There is an ambari cluster on which hdfs is installed. Ambari cluster installed via VirtualBox.
I try to connect to hdfs like this, but it gives a connection error.

Configuration configuration = new Configuration();
 Path p=new Path("hdfs://127.0.0.1:8080/file.txt");
 FileSystem fs = FileSystem.get(new URI("hdfs://127.0.0.1:8080"), configuration);
 System.out.println(p.getName() + " exists: " + fs.exists(p));


[2021-02-16 13:55:19,044] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 0 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:20,053] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 1 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:21,054] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 2 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:22,055] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 3 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:23,057] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 4 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:24,059] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 5 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:25,061] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 6 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:26,063] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 7 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:27,065] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 8 time(s). (org.apache.hadoop.ipc.Client:666)
[2021-02-16 13:55:28,068] INFO Retrying connect to server: localhost/127.0.0.1:8080. Already tried 9 time(s). (org.apache.hadoop.ipc.Client:666)
Exception in thread "main" java.net.ConnectException: Call to localhost/127.0.0.1:8080 failed on connection exception: java.net.ConnectException: Connection refused

How to read file from hdfs to java on local machine?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gingerose, 2021-02-17
@gingerose

This bug has been resolved. The hostname must be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question