I am, in the included test program, attempting to copy a file from the local disk to HDFS. The code is as follows:
package foo.foo1.foo2.test;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class TestTestTest {
public static void main(String[] args) {
String srcLocation = "foo";
String destination = "hdfs:///tmp/";
FileSystem hdfs = null;
Configuration configuration = new Configuration();
configuration.set("fs.default.name", "hdfs://namenode:54310/");
try {
hdfs = FileSystem.get(configuration);
} catch (IOException e2) {
e2.printStackTrace();
return;
}
Path srcpath = new Path(srcLocation);
Path dstpath = new Path(destination);
try {
hdfs.copyFromLocalFile(srcpath, dstpath);
} catch (IOException e) {
e.printStackTrace();
}
}
}
This fails with the following exception:
java.io.IOException: Call to namenode/10.1.1.1:54310 failed on local exception: java.io.EOFException
at org.apache.hadoop.ipc.Client.wrapException(Client.java:775)
at org.apache.hadoop.ipc.Client.call(Client.java:743)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:220)
at $Proxy0.getProtocolVersion(Unknown Source)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:359)
at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:106)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:207)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:170)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:82)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1378)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:95)
at foo.foo1.foo2.test.TestTestTest.main(TestTestTest.java:22)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:501)
at org.apache.hadoop.ipc.Client$Connection.run(Client.java:446)
My question is deceptively simple: What is causing this, and how can I make this program work? From what little information I've been able to find, I gather that there is a problem connecting to HDFS, and that this has something to do with the fs.default.name property in the Configuration. Below is the relevant section of my core-site.xml file:
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://namenode:54310</value>
</property>
</configuration>
Perhaps of special interest is the fact that if I bundle all the jars in my classpath into one mega-jar, and run this program via the hadoop command, it works just fine. So what am I doing wrong?
Make sure you are compiling against the same Hadoop version that you are running on your cluster.
Make sure the proper exception with serializable interface and going with a proper version of hadoop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With