@Override public void setWorkingDirectory(Path newDir) { Path absolutePath = toAbsolutePath(newDir); checkPath(absolutePath); this.workingDirectory = absolutePath; }
@Override public RemoteIterator<FileStatus> listStatusIterator(final Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath);
@Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); // Create a tunnel to connect remotely final String path = absolutePath.toUri().getPath(); //return new InputStream return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); }
@Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); final RenameCommand command = new RenameCommand(absoluteSrc.toUri().getPath(), absoluteDst.toUri().getPath()); runner.runCommand(command); RpcFuture<DFS.RenameResponse> future = command.getFuture(); try { DFS.RenameResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final DeleteCommand command = new DeleteCommand(absolutePath.toUri().getPath(), recursive); runner.runCommand(command); RpcFuture<DFS.DeleteResponse> future = command.getFuture(); try { DFS.DeleteResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final GetFileStatusCommand command = new GetFileStatusCommand(absolutePath.toUri().getPath()); runner.runCommand(command); RpcFuture<DFS.GetFileStatusResponse> future = command.getFuture(); try { DFS.GetFileStatusResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final MkdirsCommand command = new MkdirsCommand( absolutePath.toUri().getPath(), permission != null ? (int) permission.toExtendedShort() : null); runner.runCommand(command); RpcFuture<DFS.MkdirsResponse> future = command.getFuture(); try { DFS.MkdirsResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }