コード例 #1
0
 public static UserGroupInformation getCurrentUserGroup() {
   if (g_CurrentUserGroup == null) {
     //            throw new UnsupportedOperationException("Uncomment when using version 1.0.*");
     String user = RemoteUtilities.getUser();
     //     user = "******";
     g_CurrentUserGroup = UserGroupInformation.createRemoteUser(user);
   }
   return g_CurrentUserGroup;
 }
コード例 #2
0
 /**
  * there are issues with hdfs and running as a remote user InputFormats should be running in the
  * cluster and should alerday be the right user
  *
  * @return true is you are running on the cluster
  */
 @Override
 public boolean isRunningAsUser() {
   Configuration cong = new Configuration();
   try {
     //            if(true)    throw new UnsupportedOperationException("Uncomment when using
     // version 1.0.*");
     UserGroupInformation uig = UserGroupInformation.getCurrentUser();
     String userName = uig.getShortUserName();
     String user = RemoteUtilities.getUser();
     return user.equals(userName);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   //        return false;
 }
コード例 #3
0
  protected FileSystem getNewDFS() {
    final FileSystem[] returned = new FileSystem[1];
    IHDFSFileSystem access = null;
    final String host = RemoteUtilities.getHost();
    final int port = RemoteUtilities.getPort();
    //     RemoteUtilities.getPassword()
    final String user = RemoteUtilities.getUser();
    String connStr = host + ":" + port + ":" + user + ":" + RemoteUtilities.getPassword();

    final String userDir = "/user/" + user;
    //   final String userDir = "/user" ;

    try {
      UserGroupInformation ugi = getCurrentUserGroup();
      //           if(true)    throw new UnsupportedOperationException("Uncomment when using version
      // 1.0.*");
      ugi.doAs(
          new PrivilegedExceptionAction<Void>() {

            public Void run() throws Exception {

              Configuration conf = new Configuration();
              conf.set("fs.default.name", "hdfs://" + host + ":" + port);
              conf.set("fs.defaultFS", "hdfs://" + host + ":" + port + userDir);
              //       conf.set("fs.defaultFS", "hdfs://" + host + ":" + port + userDir);
              //              conf.set("hadoop.job.ugi", user);
              conf.set("hadoop.job.ugi", user);
              //             conf.set("hadoop.job.ugi", "hdfs");

              returned[0] = FileSystem.get(conf);

              return null;
            }
          });
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    if (returned[0] == null) throw new IllegalStateException("cannot get file system");
    return returned[0];
  }
コード例 #4
0
  public static boolean isHDFSAccessible() {

    IHDFSFileSystem access = null;
    final String host = RemoteUtilities.getHost();
    final int port = RemoteUtilities.getPort();
    //     RemoteUtilities.getPassword()
    final String user = RemoteUtilities.getUser();
    String connStr = host + ":" + port + ":" + user + ":" + RemoteUtilities.getPassword();

    final String userDir = "/user/" + user;
    //   final String userDir = "/user" ;

    try {
      UserGroupInformation ugi = getCurrentUserGroup();
      //          throw new UnsupportedOperationException("Uncomment when using version 1.0.*");
      ugi.doAs(
          new PrivilegedExceptionAction<Void>() {

            public Void run() throws Exception {

              Configuration conf = new Configuration();
              conf.set("fs.default.name", "hdfs://" + host + ":" + port);
              conf.set("fs.defaultFS", "hdfs://" + host + ":" + port + userDir);
              //       conf.set("fs.defaultFS", "hdfs://" + host + ":" + port + userDir);
              //              conf.set("hadoop.job.ugi", user);
              conf.set("hadoop.job.ugi", user);
              //             conf.set("hadoop.job.ugi", "hdfs");

              FileSystem fs = FileSystem.get(conf);

              Path udir = new Path(userDir);

              FileStatus fileStatus = fs.getFileStatus(udir);
              FsPermission permission = fileStatus.getPermission();

              //           fs.setPermission(udir, ALL_ACCESS);

              fileStatus = fs.getFileStatus(udir);
              permission = fileStatus.getPermission();

              //         fs.mkdirs(new Path(userDir + "/ebi/" ),IHDFSFileSystem.FULL_ACCESS);
              //         fs.mkdirs(new Path(userDir + "/ebi/Sample2/"
              // ),IHDFSFileSystem.FULL_ACCESS);

              FileStatus[] fileStatuses = fs.listStatus(udir);
              for (int i = 0; i < fileStatuses.length; i++) {
                FileStatus fileStatuse = fileStatuses[i];
                System.err.println(fileStatuse.getPath());
              }

              //                    fs.createNewFile(new Path(userDir + "/test"));
              //
              //                    FileStatus[] status = fs.listStatus(new Path("/user/" + user));
              //                    for (int i = 0; i < status.length; i++) {
              //                        System.out.println(status[i].getPath());
              //                    }
              return null;
            }
          });
    } catch (Exception e) {
      return false;
    }

    //        if (true)
    //            return true;
    return true;
  }
コード例 #5
0
 protected HDFWithNameAccessor(final String host, final int port) {
   this(host, port, RemoteUtilities.getUser());
 }
コード例 #6
0
 protected HDFWithNameAccessor() {
   this(RemoteUtilities.getHost(), RemoteUtilities.getPort(), RemoteUtilities.getUser());
 }