userprivilegedexception,同时通过java在hdfs中作为特定用户创建目录

rnmwe5a2  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(211)

我用的是CDH4.7。我正在尝试在/user/cloudera的hdfs中创建一个文件夹。但是会抛出userprivilegedexception。以下是我的代码(复制)
public static void main(字符串参数[]){

try {

        UserGroupInformation ugi = 
                UserGroupInformation.createProxyUser("cloudera", UserGroupInformation.getLoginUser());

        System.out.println(ugi.getUserName());
        ugi.doAs(new PrivilegedExceptionAction<Void>() {

            public Void run() throws Exception {
                System.out.println("aaa");
                Configuration conf = new Configuration();
                conf.set("fs.defaultFS", "hdfs://localhost.localdomain:8020/user/cloudera");
                conf.set("hadoop.job.ugi", "cloudera");

                FileSystem fs = FileSystem.get(conf);

                fs.createNewFile(new Path("/user/cloudera/test"));
                Path path = new Path("/user/cloudera/Hbasesyntax.txt");

                FileStatus[] status = fs.listStatus(path);
                for(int i=0;i<status.length;i++){
                    System.out.println(status[i].getPath());
                }
                return null;
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

然后,我甚至尝试访问我通过终端输入的文件(hbasesyntax.txt)。但是,也无法从中获取文件信息。我遗漏了什么吗。
下面是引发的异常:

Feb 23, 2015 1:18:27 AM org.apache.hadoop.security.UserGroupInformation doAs
SEVERE:**PriviledgedActionException as:cloudera via cloudera        cause:java.io.IOException: Mkdirs failed to create /user/cloudera
java.io.IOException: Mkdirs failed to create /user/cloudera
at** org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:378)
    at   org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:364)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:564)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:545)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:507)
    at org.apache.hadoop.fs.FileSystem.createNewFile(FileSystem.java:647)
    at HDFSFileOperations.GetIntoFS$1.run(GetIntoFS.java:32)
    at HDFSFileOperations.GetIntoFS$1.run(GetIntoFS.java:1)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:396)
    at     org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1    190)
    at HDFSFileOperations.GetIntoFS.main(GetIntoFS.java:21)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题