/** * 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); } }
@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); } }