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");
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://10.236.173.95:8020/user/hbase");
conf.set("hadoop.job.ugi", "hbase");
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 program. I have downloaded my jar from this site. I can see UserGroupInformation class is there. I checked createRemoteUser method is a member of this class.
I compile this program using
javac -classpath hadoop-0.20.1-dev-core.jar -d Write/ Write.java
My directory structure contains
jarfile WriteDirectory Write.java
I am getting the following error
Write.java:16: error: cannot find symbol
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hbase");
^
symbol: method createRemoteUser(String)
location: class UserGroupInformation
Write.java:18: error: cannot find symbol
ugi.doAs(new PrivilegedExceptionAction<Void>() {
^
symbol: method doAs(<anonymous PrivilegedExceptionAction<Void>>)
location: variable ugi of type UserGroupInformation
2 errors
What could be the reason?
The problem is the version of Hadoop you're compiling against. You're compiling against hadoop-0.20.1-dev-core.jar. I've just downloaded that, and javap
shows the following for the UserGroupInformation class:
public abstract class org.apache.hadoop.security.UserGroupInformation implements org.apache.hadoop.io.Writable,java.security.Principal {
public static final org.apache.commons.logging.Log LOG;
public org.apache.hadoop.security.UserGroupInformation();
public static org.apache.hadoop.security.UserGroupInformation getCurrentUGI();
public static void setCurrentUGI(org.apache.hadoop.security.UserGroupInformation);
static javax.security.auth.Subject getCurrentUser();
public static void setCurrentUser(org.apache.hadoop.security.UserGroupInformation);
public abstract java.lang.String getUserName();
public abstract java.lang.String[] getGroupNames();
public static org.apache.hadoop.security.UserGroupInformation login(org.apache.hadoop.conf.Configuration) throws javax.security.auth.login.LoginException;
public static org.apache.hadoop.security.UserGroupInformation readFrom(org.apache.hadoop.conf.Configuration) throws java.io.IOException;
static {};
}
There's no sign of the method you're trying to call.
Looks like you should download a more recent version of Hadoop. (I suggest you replace the whole of Hadoop, not just a single jar file. I haven't done any Hadoop development, so I don't know how many jar files are involved.)
See more on this question at Stackoverflow