Search code examples
javahadoophdfs

Hadoop setting fsPermission recursively to dir using Java


I have test program which loads files into hdfs at this path user/user1/data/app/type/file.gz Now this test program runs multiple times by multiple users. So I want to set file permission to rwx so that anyone can delete this file. I have the following code

fs.setPermission(new Path("user/user1/data"),new FsPermission(FsAction.ALL,FsAction.ALL,FsAction.ALL)) 

Above line gives drwxrwxrwx to all dirs but for the file.gz it gives permission as -rw-r--r-- why so? Because of this reason another user apart from me not able to delete this file through test program. I can delete file through test program because I have full permission.

I am new to Hadoop.


Solution

  • Using FsShell APIs solved my dir permission problem. It may be not be optimal way but since I am solving it for test code it should be fine.

          FsShell shell=new FsShell(conf);
          try {
            shell.run(new String[]{"-chmod","-R","777","user/usr1/data"});
          }
         catch (  Exception e) {
            LOG.error("Couldnt change the file permissions ",e);
            throw new IOException(e);
          }