package org.myorg;
import java.security.PrivilegedExceptionAction;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
public class Write{
public static void main(String args[]) {
try {
// UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hbase");
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception
{
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://10.72.40.XX:8020/user/hbase");
//conf.set("hadoop.job.ugi", "hbase");
conf.set("hadoop.job.ugi", "root");
FileSystem fs = FileSystem.get(conf);
fs.createNewFile(new Path("/user/hbase/test"));
System.out.println("File Created");
return null;
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
This is my java file.
My ip is 10.72.40.XX
hostname -i
gives this ip to me.
jps
says
Jobtracker, namenode, datanode, tasktracker, secondarynamenode, jps
are running.
I compiled this java program using
javac -classpath hadoop-core-1.1.2.jar -d Write/ Write.java
Created jar using
jar -cvf Write.jar -C Write/ .
Run this program using
hadoop-1.2.1/bin/hadoop jar Write.jar org.myorg.Write
It says,
Retrying 0-9 [10] times
failed on connection exception: java.net.ConnectException: Connection refused
Then i checked if something is listening at port 8020
netstat -plten | grep java
tcp 0 0 ::ffff:127.0.0.1:8020 :::* LISTEN 0 55639 15717/java
returns service is listening at port 8020.
Then, for debugging purpose, i replaced ip with localhost, It is succeeded. What could be the problem?
How do i solve it?
Does ip and localhost are different for the same machine?