コード例 #1
0
  /**
   * write text to a remote file system
   *
   * @param hdfsPath !null remote path
   * @param content !null test content
   */
  @Override
  public void writeToFileSystem(final String hdfsPath, final String content) {
    if (isRunningAsUser()) {
      super.writeToFileSystem(hdfsPath, content);
      return;
    }
    UserGroupInformation uig = getCurrentUserGroup();
    try {
      //          if(true)    throw new UnsupportedOperationException("Uncomment when using version
      // 1.0.*");
      uig.doAs(
          new PrivilegedExceptionAction<Void>() {

            public Void run() throws Exception {
              FileSystem fs = getDFS();
              Path src = new Path(hdfsPath);
              Path parent = src.getParent();
              guaranteeDirectory(parent);
              OutputStream os = FileSystem.create(fs, src, FULL_FILE_ACCESS);
              FileUtilities.writeFile(os, content);
              return null;
            }
          });
    } catch (Exception e) {
      throw new RuntimeException(
          "Failed to writeToFileSystem because "
              + e.getMessage()
              + " exception of class "
              + e.getClass(),
          e);
    }
  }
コード例 #2
0
  @Override
  public void writeToFileSystem(final String hdfsPath, final File localPath) {
    if (isRunningAsUser()) {
      super.writeToFileSystem(hdfsPath, localPath);
      return;
    }
    UserGroupInformation uig = getCurrentUserGroup();
    try {
      //           if(true)    throw new UnsupportedOperationException("Uncomment when using version
      // 1.0.*");
      uig.doAs(
          new PrivilegedExceptionAction<Void>() {

            public Void run() throws Exception {
              FileSystem fileSystem = getDFS();

              Path dst = new Path(hdfsPath);

              Path src = new Path(localPath.getAbsolutePath());

              fileSystem.copyFromLocalFile(src, dst);
              fileSystem.setPermission(dst, FULL_FILE_ACCESS);
              return null;
            }
          });
    } catch (Exception e) {
      throw new RuntimeException(
          "Failed to writeToFileSystem because "
              + e.getMessage()
              + " exception of class "
              + e.getClass(),
          e);
    }
  }
コード例 #3
0
 @Override
 protected void setDFS(FileSystem DFS) {
   if (DFS instanceof LocalFileSystem)
     throw new IllegalArgumentException(
         "This class must talk to a remote file system"); // ToDo change
   super.setDFS(DFS);
 }
コード例 #4
0
  /**
   * guarantee the existance of a directory on the remote system
   *
   * @param hdfsPath !null path - on the remote system
   */
  @Override
  public void guaranteeDirectory(String hdfsPath) {
    if (isRunningAsUser()) {
      super.guaranteeDirectory(hdfsPath);
      return;
    }
    Path src = new Path(hdfsPath);

    guaranteeDirectory(src);
  }
コード例 #5
0
  /**
   * guarantee the existance of a file on the remote system
   *
   * @param hdfsPath !null path - on the remote system
   * @param file !null exitsing file
   */
  @Override
  public void guaranteeFile(String hdfsPath, File file) {
    if (isRunningAsUser()) {
      super.guaranteeFile(hdfsPath, file);
      return;
    }
    final FileSystem fs = getDFS();
    Path src = new Path(hdfsPath);

    try {
      if (fs.exists(src)) return;
      this.writeToFileSystem(hdfsPath, file);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }