target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testToProtobuFileStatusWithDefault() throws IOException { FileStatus status = new FileStatus(); DFS.FileStatus result = RemoteNodeFileSystem.toProtoFileStatus(status); assertFalse(result.hasPath()); assertEquals(0, result.getLength()); assertFalse(result.getIsDirectory()); assertEquals(0, result.getBlockReplication()); assertEquals(0, result.getBlockSize()); assertEquals(0, result.getAccessTime()); assertEquals(0, result.getModificationTime()); assertEquals(FsPermission.getFileDefault().toExtendedShort(), result.getPermission()); assertEquals("", result.getOwner()); assertEquals("", result.getGroup()); assertFalse(result.hasSymlink()); } | static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testToProtobuFileStatusWithDirectory() throws IOException { FileStatus status = new FileStatus(0, true, 0, 0, 1, 2, null, null, null, TEST_PATH); DFS.FileStatus result = RemoteNodeFileSystem.toProtoFileStatus(status); assertEquals(TEST_PATH_STRING, result.getPath()); assertEquals(0, result.getLength()); assertTrue(result.getIsDirectory()); assertEquals(0, result.getBlockReplication()); assertEquals(0, result.getBlockSize()); assertEquals(2, result.getAccessTime()); assertEquals(1, result.getModificationTime()); assertEquals(FsPermission.getDirDefault().toExtendedShort(), result.getPermission()); assertEquals("", result.getOwner()); assertEquals("", result.getGroup()); assertFalse(result.hasSymlink()); } | static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testGetFileStatusRoot() throws Exception { { DFS.FileStatus status = newFileStatus(1024L, true, 0, 4096L, 37L, 42L, 0755, "root", "wheel", "/"); setupRPC( DFS.RpcType.GET_FILE_STATUS_REQUEST, DFS.GetFileStatusRequest.newBuilder().setPath("/").build(), DFS.RpcType.GET_FILE_STATUS_RESPONSE, DFS.GetFileStatusResponse.newBuilder().setStatus(status).build()); } FileSystem fs = newRemoteNodeFileSystem(); Path root = new Path("/"); FileStatus status = fs.getFileStatus(root); assertEquals(new Path("sabot: assertTrue(status.isDirectory()); assertEquals(0755, status.getPermission().toExtendedShort()); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test(expected = FileNotFoundException.class) public void testGetFileStatusWithInvalidPath() throws Exception { { setupRPC( DFS.RpcType.GET_FILE_STATUS_REQUEST, DFS.GetFileStatusRequest.newBuilder().setPath("/foo/bar").build(), DFS.GetFileStatusResponse.class, newRPCException(LOCAL_ENDPOINT, new FileNotFoundException("File not found"))); } FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); fs.getFileStatus(path); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testGetFileStatusWithValidPath() throws Exception { { DFS.FileStatus status = newFileStatus(1024, false, 1, 4096, 42, 37, 0644 , "root", "wheel", "/foo/bar"); setupRPC( DFS.RpcType.GET_FILE_STATUS_REQUEST, DFS.GetFileStatusRequest.newBuilder().setPath("/foo/bar").build(), DFS.RpcType.GET_FILE_STATUS_RESPONSE, DFS.GetFileStatusResponse.newBuilder().setStatus(status).build()); } FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("sabot: assertFalse(status.isDirectory()); assertEquals(1024, status.getLen()); assertEquals(1, status.getReplication()); assertEquals(4096, status.getBlockSize()); assertEquals(42, status.getAccessTime()); assertEquals(37, status.getModificationTime()); assertEquals("root", status.getOwner()); assertEquals("wheel", status.getGroup()); assertEquals(0644, status.getPermission().toExtendedShort()); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void splitListCardGen() throws Exception { File dataFile = temp.newFile("splitExact.json"); try (PrintWriter writer = new PrintWriter(dataFile)) { writer.append("{ \"col\" : \"aBa\" }"); writer.append("{ \"col\" : \"abaBa\" }"); writer.append("{ \"col\" : null }"); writer.append("{ \"col\" : \"abababa\" }"); writer.append("{ \"col\" : \"aaa\" }"); } { SplitRule rule = new SplitRule("b", MatchType.exact, true); TransformRuleWrapper<SplitRule> wrapper = recommender.wrapRule(rule); assertEquals("regexp_matches(\"tbl name\".col, '(?i)(?u).*\\Qb\\E.*')", wrapper.getMatchFunctionExpr("\"tbl name\".col")); assertEquals("regexp_split(tbl.col, '(?i)(?u)\\Qb\\E', 'ALL', 10)", wrapper.getFunctionExpr("tbl.col", SplitPositionType.ALL, 10)); assertEquals("regexp_split_positions(tbl.\"col name\", '(?i)(?u)\\Qb\\E')", wrapper.getExampleFunctionExpr("tbl.\"col name\"")); assertEquals("Exactly matches \"b\" ignore case", wrapper.describe()); List<List<CardExamplePosition>> highlights = asList( asList(new CardExamplePosition(1, 1)), asList(new CardExamplePosition(1, 1), new CardExamplePosition(3, 1)), null, asList(new CardExamplePosition(1, 1), new CardExamplePosition(3, 1), new CardExamplePosition(5, 1)), null ); validate(dataFile.getAbsolutePath(), wrapper, new Object[] { SplitPositionType.INDEX, 1}, list((Object)list("aBa"), list("aba", "a"), null, list("aba", "aba"), list("aaa")), asList(true, true, false, true, false), highlights ); } { SplitRule rule = new SplitRule("b", MatchType.exact, false); TransformRuleWrapper<SplitRule> wrapper = recommender.wrapRule(rule); assertEquals("regexp_matches(tbl.col, '.*\\Qb\\E.*')", wrapper.getMatchFunctionExpr("tbl.col")); assertEquals("regexp_split(tbl.col, '\\Qb\\E', 'ALL', 10)", wrapper.getFunctionExpr("tbl.col", SplitPositionType.ALL, 10)); assertEquals("regexp_split_positions(tbl.col, '\\Qb\\E')", wrapper.getExampleFunctionExpr("tbl.col")); assertEquals("Exactly matches \"b\"", wrapper.describe()); List<List<CardExamplePosition>> highlights = asList( null, asList(new CardExamplePosition(1, 1)), null, asList(new CardExamplePosition(1, 1), new CardExamplePosition(3, 1), new CardExamplePosition(5, 1)), null ); validate(dataFile.getAbsolutePath(), wrapper, new Object[] {SplitPositionType.LAST, -1 }, list((Object)list("aBa"), list("a", "aBa"), null, list("ababa", "a"), list("aaa")), asList(false, true, false, true, false), highlights ); } } | public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } |
@Test public void testListStatusRoot() throws Exception { { DFS.ListStatusResponse listStatusResponse = DFS.ListStatusResponse.newBuilder() .addStatuses(newFileStatus(42, true, 0, 0, 456, 879, 0755, "root", "wheel", "/foo")) .addStatuses(newFileStatus(1024, false, 1, 4096, 354, 435, 0644, "admin", "admin", "/bar")) .build(); setupRPC( DFS.RpcType.LIST_STATUS_REQUEST, DFS.ListStatusRequest.newBuilder().setPath("/").setLimit(RemoteNodeFileSystem.LIST_STATUS_BATCH_SIZE_DEFAULT).build(), DFS.RpcType.LIST_STATUS_RESPONSE, listStatusResponse); } FileSystem fs = newRemoteNodeFileSystem(); Path root = new Path("/"); FileStatus[] statuses = fs.listStatus(root); assertEquals(ENDPOINTS_LIST.size(), statuses.length); assertEquals(new Path("sabot: assertTrue(statuses[0].isDirectory()); assertEquals(0755, statuses[0].getPermission().toExtendedShort()); assertEquals(new Path("sabot: assertFalse(statuses[1].isDirectory()); assertEquals(0644, statuses[1].getPermission().toExtendedShort()); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testListStatusRootOneByOne() throws Exception { { DFS.ListStatusContinuationHandle handle = DFS.ListStatusContinuationHandle.newBuilder().setId("test-handle").build(); DFS.ListStatusResponse listStatusInitialResponse = DFS.ListStatusResponse.newBuilder() .addStatuses(newFileStatus(42, true, 0, 0, 456, 879, 0755, "root", "wheel", "/foo")) .setHandle(handle) .build(); DFS.ListStatusResponse listStatusLastResponse = DFS.ListStatusResponse.newBuilder() .addStatuses(newFileStatus(1024, false, 1, 4096, 354, 435, 0644, "admin", "admin", "/bar")) .build(); setupRPC( DFS.RpcType.LIST_STATUS_REQUEST, Arrays.asList( DFS.ListStatusRequest.newBuilder().setPath("/").setLimit(1).build(), DFS.ListStatusRequest.newBuilder().setPath("/").setHandle(handle).setLimit(1).build()), DFS.RpcType.LIST_STATUS_RESPONSE, Arrays.asList(listStatusInitialResponse, listStatusLastResponse), Arrays.asList((ByteBuf) null, null) ); } final Configuration configuration = new Configuration(false); configuration.setTimeDuration(RemoteNodeFileSystem.RPC_TIMEOUT_KEY, TEST_RPC_TIMEOUT_MS, TimeUnit.MILLISECONDS); configuration.setInt(RemoteNodeFileSystem.LIST_STATUS_BATCH_SIZE_KEY, 1); FileSystem fs = newRemoteNodeFileSystem(configuration); Path root = new Path("/"); FileStatus[] statuses = fs.listStatus(root); assertEquals(ENDPOINTS_LIST.size(), statuses.length); assertEquals(new Path("sabot: assertTrue(statuses[0].isDirectory()); assertEquals(0755, statuses[0].getPermission().toExtendedShort()); assertEquals(new Path("sabot: assertFalse(statuses[1].isDirectory()); assertEquals(0644, statuses[1].getPermission().toExtendedShort()); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testListStatusWithValidPath() throws Exception { { DFS.ListStatusResponse listStatusResponse = DFS.ListStatusResponse.newBuilder() .addStatuses(newFileStatus(42, true, 0, 0, 456, 879, 0755, "root", "wheel", "/foo/bar/dir")) .addStatuses(newFileStatus(1024, false, 1, 4096, 354, 435, 0644, "admin", "admin", "/foo/bar/file")) .build(); setupRPC( DFS.RpcType.LIST_STATUS_REQUEST, DFS.ListStatusRequest.newBuilder().setPath("/foo/bar").setLimit(RemoteNodeFileSystem.LIST_STATUS_BATCH_SIZE_DEFAULT).build(), DFS.RpcType.LIST_STATUS_RESPONSE, listStatusResponse); } FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); FileStatus[] statuses = fs.listStatus(path); assertEquals(ENDPOINTS_LIST.size(), statuses.length); assertEquals(new Path("sabot: assertTrue(statuses[0].isDirectory()); assertEquals(0755, statuses[0].getPermission().toExtendedShort()); assertEquals(new Path("sabot: assertFalse(statuses[1].isDirectory()); assertEquals(0644, statuses[1].getPermission().toExtendedShort()); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test(expected = FileNotFoundException.class) public void testListStatusWithInvalidPath() throws Exception { setupRPC( DFS.RpcType.LIST_STATUS_REQUEST, DFS.ListStatusRequest.newBuilder().setPath("/foo/bar").setLimit(RemoteNodeFileSystem.LIST_STATUS_BATCH_SIZE_DEFAULT).build(), DFS.ListStatusResponse.class, newRPCException(LOCAL_ENDPOINT, new FileNotFoundException("File not found"))); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); fs.listStatus(path); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); List<FileStatus> statuses = new ArrayList<>(); while(remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testDeleteWithValidPath() throws Exception { setupRPC( DFS.RpcType.DELETE_REQUEST, DFS.DeleteRequest.newBuilder().setPath("/foo/bar").setRecursive(true).build(), DFS.RpcType.DELETE_RESPONSE, DFS.DeleteResponse.newBuilder().setValue(true).build()); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); boolean result = fs.delete(path, true); assertTrue(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testDeleteWithValidPathButNotDeleted() throws Exception { setupRPC( DFS.RpcType.DELETE_REQUEST, DFS.DeleteRequest.newBuilder().setPath("/foo/bar").setRecursive(true).build(), DFS.RpcType.DELETE_RESPONSE, DFS.DeleteResponse.newBuilder().setValue(false).build()); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); boolean result = fs.delete(path, true); assertFalse(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testDeleteWithInvalidPath() throws Exception { setupRPC( DFS.RpcType.DELETE_REQUEST, DFS.DeleteRequest.newBuilder().setPath("/foo/bar").setRecursive(true).build(), DFS.DeleteResponse.class, newRPCException(LOCAL_ENDPOINT, new FileNotFoundException("File not found"))); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); try { fs.delete(path, true); fail("Expected fs.delete() to throw FileNotFoundException"); } catch(FileNotFoundException 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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch (RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testMkdirsWithValidPath() throws Exception { setupRPC( DFS.RpcType.MKDIRS_REQUEST, DFS.MkdirsRequest.newBuilder().setPath("/foo/bar").setPermission(0755).build(), DFS.RpcType.MKDIRS_RESPONSE, DFS.MkdirsResponse.newBuilder().setValue(true).build()); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); boolean result = fs.mkdirs(path, FsPermission.createImmutable((short) 0755)); assertTrue(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testMkdirsWithValidPathButNotCreated() throws Exception { setupRPC( DFS.RpcType.MKDIRS_REQUEST, DFS.MkdirsRequest.newBuilder().setPath("/foo/bar").setPermission(0755).build(), DFS.RpcType.MKDIRS_RESPONSE, DFS.MkdirsResponse.newBuilder().setValue(false).build()); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); boolean result = fs.mkdirs(path, FsPermission.createImmutable((short) 0755)); assertFalse(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testMkdirsWithInvalidPath() throws Exception { setupRPC( DFS.RpcType.MKDIRS_REQUEST, DFS.MkdirsRequest.newBuilder().setPath("/foo/bar").setPermission(0755).build(), DFS.MkdirsResponse.class, newRPCException(LOCAL_ENDPOINT, new FileNotFoundException("File not found"))); FileSystem fs = newRemoteNodeFileSystem(); Path path = new Path("/foo/bar"); try { fs.mkdirs(path, FsPermission.createImmutable((short) 0755)); fail("Expected fs.mkdirs() to throw FileNotFoundException"); } catch(FileNotFoundException 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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void splitRegex() throws Exception { File dataFile = temp.newFile("splitRegex.json"); try (PrintWriter writer = new PrintWriter(dataFile)) { writer.append("{ \"col\" : \"aaa111BBB222cc33d\" }"); writer.append("{ \"col\" : \"a1b2c3\" }"); writer.append("{ \"col\" : null }"); writer.append("{ \"col\" : \"abababa\" }"); writer.append("{ \"col\" : \"111\" }"); } { SplitRule rule = new SplitRule("\\d+", MatchType.regex, false); TransformRuleWrapper<SplitRule> wrapper = recommender.wrapRule(rule); assertEquals("regexp_matches(\"tbl name\".col, '.*\\d+.*')", wrapper.getMatchFunctionExpr("\"tbl name\".col")); assertEquals("regexp_split(tbl.col, '\\d+', 'ALL', 10)", wrapper.getFunctionExpr("tbl.col", SplitPositionType.ALL, 10)); assertEquals("regexp_split_positions(tbl.\"col name\", '\\d+')", wrapper.getExampleFunctionExpr("tbl.\"col name\"")); assertEquals("Matches regex \"\\d+\"", wrapper.describe()); List<List<CardExamplePosition>> highlights = asList( asList(new CardExamplePosition(3, 3), new CardExamplePosition(9, 3), new CardExamplePosition(14, 2)), asList(new CardExamplePosition(1, 1), new CardExamplePosition(3, 1), new CardExamplePosition(5, 1)), null, null, asList(new CardExamplePosition(0, 3)) ); validate(dataFile.getAbsolutePath(), wrapper, new Object[] { SplitPositionType.FIRST, -1 }, list((Object)list("aaa", "BBB222cc33d"), list("a", "b2c3"), null, list("abababa"), list("", "")), asList(true, true, false, false, true), highlights ); } { SplitRule rule = new SplitRule("[a-z]+", MatchType.regex, true); TransformRuleWrapper<SplitRule> wrapper = recommender.wrapRule(rule); assertEquals("regexp_matches(tbl.col, '(?i)(?u).*[a-z]+.*')", wrapper.getMatchFunctionExpr("tbl.col")); assertEquals("regexp_split(tbl.col, '(?i)(?u)[a-z]+', 'ALL', 10)", wrapper.getFunctionExpr("tbl.col", SplitPositionType.ALL, 10)); assertEquals("regexp_split_positions(tbl.col, '(?i)(?u)[a-z]+')", wrapper.getExampleFunctionExpr("tbl.col")); assertEquals("Matches regex \"[a-z]+\" ignore case", wrapper.describe()); List<List<CardExamplePosition>> highlights = asList( asList(new CardExamplePosition(0, 3), new CardExamplePosition(6, 3), new CardExamplePosition(12, 2), new CardExamplePosition(16, 1)), asList(new CardExamplePosition(0, 1), new CardExamplePosition(2, 1), new CardExamplePosition(4, 1)), null, asList(new CardExamplePosition(0, 7)), null ); validate(dataFile.getAbsolutePath(), wrapper, new Object[] { SplitPositionType.ALL, 2}, list((Object)list("", "111"), list("", "1"), null, list("", ""), list("111")), asList(true, true, false, true, false), highlights ); } } | public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { public TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule) { return new SplitTransformRuleWrapper(rule); } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } |
@Test public void testRenameWithValidPath() throws Exception { setupRPC( DFS.RpcType.RENAME_REQUEST, DFS.RenameRequest.newBuilder().setOldpath("/foo/bar").setNewpath("/foo/bar2").build(), DFS.RpcType.RENAME_RESPONSE, DFS.RenameResponse.newBuilder().setValue(true).build()); FileSystem fs = newRemoteNodeFileSystem(); Path oldPath = new Path("/foo/bar"); Path newPath = new Path("/foo/bar2"); boolean result = fs.rename(oldPath, newPath); assertTrue(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testRenameWithButNotRenamed() throws Exception { setupRPC( DFS.RpcType.RENAME_REQUEST, DFS.RenameRequest.newBuilder().setOldpath("/foo/bar").setNewpath("/foo/bar2").build(), DFS.RpcType.RENAME_RESPONSE, DFS.RenameResponse.newBuilder().setValue(false).build()); FileSystem fs = newRemoteNodeFileSystem(); Path oldPath = new Path("/foo/bar"); Path newPath = new Path("/foo/bar2"); boolean result = fs.rename(oldPath, newPath); assertFalse(result); } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testRenameWithInvalidPath() throws Exception { setupRPC( DFS.RpcType.RENAME_REQUEST, DFS.RenameRequest.newBuilder().setOldpath("/foo/bar").setNewpath("/foo/bar2").build(), DFS.RenameResponse.class, newRPCException(LOCAL_ENDPOINT, new FileNotFoundException("File not found"))); FileSystem fs = newRemoteNodeFileSystem(); Path oldPath = new Path("/foo/bar"); Path newPath = new Path("/foo/bar2"); try { fs.rename(oldPath, newPath); fail("Expected fs.mkdirs() to throw FileNotFoundException"); } catch(FileNotFoundException e) { } } | @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @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 = DremioFutures.getChecked( future, RpcException.class, rpcTimeoutMs, TimeUnit.MILLISECONDS, RpcException::mapException ); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occurred during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testInputStream() throws Exception { Path filePath = new Path("/foo/bar"); byte[] data = new byte[100]; for (int i = 0; i < 100; ++i) { data[i] = (byte)i; } byte [] readBuf = new byte[1000]; ByteBuf byteBuf = Unpooled.wrappedBuffer(data, 0, 100); setupRPC( DFS.RpcType.GET_FILE_DATA_REQUEST, DFS.GetFileDataRequest.newBuilder().setPath(filePath.toString()).setStart(0).setLength(100).build(), DFS.RpcType.GET_FILE_DATA_RESPONSE, DFS.GetFileDataResponse.newBuilder().setRead(100).build(), byteBuf); FileSystem fs = newRemoteNodeFileSystem(); FSDataInputStream inputStream = fs.open(filePath, 100); int read = inputStream.read(readBuf, 0, 50); assertEquals(50, read); setupRPC( DFS.RpcType.GET_FILE_DATA_REQUEST, DFS.GetFileDataRequest.newBuilder().setPath(filePath.toString()).setStart(100).setLength(100).build(), DFS.RpcType.GET_FILE_DATA_RESPONSE, DFS.GetFileDataResponse.newBuilder().setRead(-1).build()); read = inputStream.read(readBuf, 50, 1000); assertEquals(50, read); for (int i = 0; i < 100; ++i) { assertEquals((byte)i, readBuf[i]); } } | @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final String path = absolutePath.toUri().getPath(); return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); } | RemoteNodeFileSystem extends FileSystem { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final String path = absolutePath.toUri().getPath(); return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); } } | RemoteNodeFileSystem extends FileSystem { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final String path = absolutePath.toUri().getPath(); return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final String path = absolutePath.toUri().getPath(); return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final String path = absolutePath.toUri().getPath(); return new FSDataInputStream(new RemoteNodeInputStream(path, bufferSize)); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
@Test public void testGetFileStatusRoot() throws IOException { Path root = new Path("/"); FileStatus status = fs.getFileStatus(root); assertEquals(new Path("pdfs:/"), status.getPath()); assertTrue(status.isDirectory()); assertEquals(0555, status.getPermission().toExtendedShort()); } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusForInvalidPath() throws IOException { Path path = new Path("/foo/baz"); try { fs.getFileStatus(path); fail("Expected getFileStatus to throw FileNotFoundException"); } catch (FileNotFoundException e) { } } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusForValidDirectory() throws IOException { Path path = new Path("/foo/bar"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("pdfs:/foo/bar"), status.getPath()); assertTrue(status.isDirectory()); assertEquals(69, status.getModificationTime()); assertEquals(90, status.getAccessTime()); } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusForUnaccessibleDirectory() throws IOException { doThrow(new AccessControlException()).when(mockRemoteFS).getFileStatus(new Path("/foo/baz")); Path path = new Path("/foo/baz"); try { fs.getFileStatus(path); fail("Expected some IOException"); } catch(AccessControlException e) { } } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusWithValidRemotePath() throws IOException { doReturn(new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot: .when(mockRemoteFS).getFileStatus(new Path("/tmp/file")); Path path = new Path("/tmp/10.0.0.2@file"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("pdfs:/tmp/10.0.0.2@file"), status.getPath()); assertFalse(status.isDirectory()); assertEquals(1024, status.getLen()); assertEquals(1, status.getReplication()); assertEquals(4096, status.getBlockSize()); assertEquals(42, status.getAccessTime()); assertEquals(37, status.getModificationTime()); assertEquals("root", status.getOwner()); assertEquals("wheel", status.getGroup()); assertEquals(0644, status.getPermission().toExtendedShort()); } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusWithValidLocalPath() throws IOException { Path tmpPath = new Path("/tmp/file"); doReturn(new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", tmpPath)).when(mockLocalFS).getFileStatus(tmpPath); Path path = new Path("/tmp/10.0.0.1@file"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("pdfs:/tmp/10.0.0.1@file"), status.getPath()); assertFalse(status.isDirectory()); assertEquals(1024, status.getLen()); assertEquals(1, status.getReplication()); assertEquals(4096, status.getBlockSize()); assertEquals(42, status.getAccessTime()); assertEquals(37, status.getModificationTime()); assertEquals("root", status.getOwner()); assertEquals("wheel", status.getGroup()); assertEquals(0644, status.getPermission().toExtendedShort()); } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testBrokenHistory() throws Exception { DatasetPath datasetPath = new DatasetPath(Arrays.asList("space", "dataset")); DatasetVersion current = new DatasetVersion("123"); DatasetVersion tip = new DatasetVersion("456"); DatasetVersion broken = new DatasetVersion("001"); VirtualDatasetUI tipDataset = new VirtualDatasetUI(); tipDataset.setCreatedAt(0L); tipDataset.setFullPathList(datasetPath.toPathList()); tipDataset.setVersion(tip); tipDataset.setPreviousVersion(new NameDatasetRef() .setDatasetVersion(broken.getVersion()) .setDatasetPath(datasetPath.toString())); Transform transform = new Transform(TransformType.updateSQL); transform.setUpdateSQL(new TransformUpdateSQL("sql")); tipDataset.setLastTransform(transform); DatasetVersionMutator datasetVersionMutator = mock(DatasetVersionMutator.class); when(datasetVersionMutator.getVersion(datasetPath, tip)).thenReturn(tipDataset); when(datasetVersionMutator.get(any())).thenReturn(tipDataset); when(datasetVersionMutator.getVersion(datasetPath, broken)).thenThrow(DatasetNotFoundException.class); JobsService jobsService = mock(JobsService.class); when(jobsService.searchJobs(any())).thenReturn(Collections.emptyList()); QueryExecutor executor = mock(QueryExecutor.class); SecurityContext securityContext = new SecurityContext() { @Override public Principal getUserPrincipal() { return new Principal() { @Override public String getName() { return "user"; } }; } @Override public boolean isUserInRole(String role) { return false; } @Override public boolean isSecure() { return false; } @Override public String getAuthenticationScheme() { return null; } }; final DatasetTool tool = new DatasetTool(datasetVersionMutator, jobsService, executor, securityContext); History history = tool.getHistory(datasetPath, current, tip); Assert.assertEquals(1, history.getItems().size()); } | History getHistory(final DatasetPath datasetPath, DatasetVersion currentDataset) throws DatasetVersionNotFoundException { return getHistory(datasetPath, currentDataset, currentDataset); } | DatasetTool { History getHistory(final DatasetPath datasetPath, DatasetVersion currentDataset) throws DatasetVersionNotFoundException { return getHistory(datasetPath, currentDataset, currentDataset); } } | DatasetTool { History getHistory(final DatasetPath datasetPath, DatasetVersion currentDataset) throws DatasetVersionNotFoundException { return getHistory(datasetPath, currentDataset, currentDataset); } DatasetTool(
DatasetVersionMutator datasetService,
JobsService jobsService,
QueryExecutor executor,
SecurityContext context); } | DatasetTool { History getHistory(final DatasetPath datasetPath, DatasetVersion currentDataset) throws DatasetVersionNotFoundException { return getHistory(datasetPath, currentDataset, currentDataset); } DatasetTool(
DatasetVersionMutator datasetService,
JobsService jobsService,
QueryExecutor executor,
SecurityContext context); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
Integer limit); static UserException toInvalidQueryException(UserException e, String sql, List<String> context); static UserException toInvalidQueryException(UserException e, String sql, List<String> context,
DatasetSummary datasetSummary); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
DatasetSummary parentSummary,
boolean prepare,
Integer limit); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
DatasetSummary parentSummary,
boolean prepare,
Integer limit,
boolean runInSameThread); static VirtualDatasetUI newDatasetBeforeQueryMetadata(
DatasetPath datasetPath,
DatasetVersion version,
From from,
List<String> sqlContext,
String owner); static void applyQueryMetadata(VirtualDatasetUI dataset, JobInfo jobInfo, QueryMetadata metadata); static void applyQueryMetadata(VirtualDatasetUI dataset, Optional<List<ParentDatasetInfo>> parents,
Optional<BatchSchema> batchSchema, Optional<List<FieldOrigin>> fieldOrigins, Optional<List<ParentDataset>> grandParents,
QueryMetadata metadata); } | DatasetTool { History getHistory(final DatasetPath datasetPath, DatasetVersion currentDataset) throws DatasetVersionNotFoundException { return getHistory(datasetPath, currentDataset, currentDataset); } DatasetTool(
DatasetVersionMutator datasetService,
JobsService jobsService,
QueryExecutor executor,
SecurityContext context); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
Integer limit); static UserException toInvalidQueryException(UserException e, String sql, List<String> context); static UserException toInvalidQueryException(UserException e, String sql, List<String> context,
DatasetSummary datasetSummary); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
DatasetSummary parentSummary,
boolean prepare,
Integer limit); InitialPreviewResponse newUntitled(
BufferAllocator allocator,
FromBase from,
DatasetVersion version,
List<String> context,
DatasetSummary parentSummary,
boolean prepare,
Integer limit,
boolean runInSameThread); static VirtualDatasetUI newDatasetBeforeQueryMetadata(
DatasetPath datasetPath,
DatasetVersion version,
From from,
List<String> sqlContext,
String owner); static void applyQueryMetadata(VirtualDatasetUI dataset, JobInfo jobInfo, QueryMetadata metadata); static void applyQueryMetadata(VirtualDatasetUI dataset, Optional<List<ParentDatasetInfo>> parents,
Optional<BatchSchema> batchSchema, Optional<List<FieldOrigin>> fieldOrigins, Optional<List<ParentDataset>> grandParents,
QueryMetadata metadata); static final DatasetPath TMP_DATASET_PATH; } |
@Test public void testGetFileStatusWithLocalPath() throws IOException { try { Path path = new Path("/tmp/file"); @SuppressWarnings("unused") FileStatus status = fs.getFileStatus(path); fail("Expected getFileStatus call to throw an exception"); } catch (IOException e) { } } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileStatusWithUnknownRemotePath() throws IOException { Path path = new Path("/tmp/10.0.0.3@file"); try { fs.getFileStatus(path); fail("Expected getFileStatus to throw FileNotFoundException"); } catch (FileNotFoundException e) { } } | @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (!isRemoteFile(absolutePath)) { return new GetFileStatusTask(absolutePath).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); FileStatus status = delegate.getFileStatus(remotePath.path); return fixFileStatus(remotePath.address, status); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testListStatusRoot() throws IOException { Path root = new Path("/"); FileStatus[] statuses = fs.listStatus(root); assertEquals(1, statuses.length); assertEquals(new Path("pdfs:/foo"), statuses[0].getPath()); assertTrue(statuses[0].isDirectory()); assertEquals(0755, statuses[0].getPermission().toExtendedShort()); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testListStatusWithValidPath() throws IOException { Path path = new Path("/foo/bar"); FileStatus[] statuses = fs.listStatus(path); assertEquals(5, statuses.length); Arrays.sort(statuses); final FileStatus searchKeyStatus = new FileStatus(); searchKeyStatus.setPath(new Path("pdfs:/foo/bar/10.0.0.1@file1")); int testIndex = Arrays.binarySearch(statuses, searchKeyStatus); assertTrue("Status for path " + searchKeyStatus.getPath().toString() + " not found", testIndex >= 0); assertEquals(new Path("pdfs:/foo/bar/10.0.0.1@file1"), statuses[testIndex].getPath()); assertFalse(statuses[testIndex].isDirectory()); assertEquals(1024, statuses[testIndex].getLen()); assertEquals(1, statuses[testIndex].getReplication()); assertEquals(4096, statuses[testIndex].getBlockSize()); assertEquals(42, statuses[testIndex].getAccessTime()); assertEquals(37, statuses[testIndex].getModificationTime()); assertEquals("root", statuses[testIndex].getOwner()); assertEquals("wheel", statuses[testIndex].getGroup()); assertEquals(0644, statuses[testIndex].getPermission().toExtendedShort()); searchKeyStatus.setPath(new Path("pdfs:/foo/bar/10.0.0.1@file2")); testIndex = Arrays.binarySearch(statuses, searchKeyStatus); assertTrue("Status for path " + searchKeyStatus.getPath().toString() + " not found", testIndex >= 0); assertEquals(new Path("pdfs:/foo/bar/10.0.0.1@file2"), statuses[testIndex].getPath()); assertFalse(statuses[1].isDirectory()); assertEquals(2048, statuses[testIndex].getLen()); assertEquals(1, statuses[testIndex].getReplication()); assertEquals(4096, statuses[testIndex].getBlockSize()); assertEquals(42, statuses[testIndex].getAccessTime()); assertEquals(37, statuses[testIndex].getModificationTime()); assertEquals("root", statuses[testIndex].getOwner()); assertEquals("wheel", statuses[testIndex].getGroup()); assertEquals(0644, statuses[testIndex].getPermission().toExtendedShort()); searchKeyStatus.setPath(new Path("pdfs:/foo/bar/10.0.0.2@file1")); testIndex = Arrays.binarySearch(statuses, searchKeyStatus); assertTrue("Status for path " + searchKeyStatus.getPath().toString() + " not found", testIndex >= 0); assertEquals(new Path("pdfs:/foo/bar/10.0.0.2@file1"), statuses[testIndex].getPath()); assertFalse(statuses[testIndex].isDirectory()); assertEquals(1027, statuses[testIndex].getLen()); assertEquals(1, statuses[testIndex].getReplication()); assertEquals(4096, statuses[testIndex].getBlockSize()); assertEquals(42, statuses[testIndex].getAccessTime()); assertEquals(37, statuses[testIndex].getModificationTime()); assertEquals("root", statuses[testIndex].getOwner()); assertEquals("wheel", statuses[testIndex].getGroup()); assertEquals(0644, statuses[testIndex].getPermission().toExtendedShort()); searchKeyStatus.setPath(new Path("pdfs:/foo/bar/10.0.0.2@file3")); testIndex = Arrays.binarySearch(statuses, searchKeyStatus); assertTrue("Status for path " + searchKeyStatus.getPath().toString() + " not found", testIndex >= 0); assertEquals(new Path("pdfs:/foo/bar/10.0.0.2@file3"), statuses[testIndex].getPath()); assertFalse(statuses[testIndex].isDirectory()); assertEquals(2049, statuses[testIndex].getLen()); assertEquals(1, statuses[testIndex].getReplication()); assertEquals(4096, statuses[testIndex].getBlockSize()); assertEquals(42, statuses[testIndex].getAccessTime()); assertEquals(37, statuses[testIndex].getModificationTime()); assertEquals("root", statuses[testIndex].getOwner()); assertEquals("wheel", statuses[testIndex].getGroup()); assertEquals(0644, statuses[testIndex].getPermission().toExtendedShort()); searchKeyStatus.setPath(new Path("pdfs:/foo/bar/dir")); testIndex = Arrays.binarySearch(statuses, searchKeyStatus); assertTrue("Status for path " + searchKeyStatus.getPath().toString() + " not found", testIndex >= 0); assertEquals(new Path("pdfs:/foo/bar/dir"), statuses[testIndex].getPath()); assertTrue(statuses[testIndex].isDirectory()); assertEquals(47, statuses[testIndex].getLen()); assertEquals(0, statuses[testIndex].getReplication()); assertEquals(0, statuses[testIndex].getBlockSize()); assertEquals(3645, statuses[testIndex].getAccessTime()); assertEquals(1234, statuses[testIndex].getModificationTime()); assertEquals("admin", statuses[testIndex].getOwner()); assertEquals("admin", statuses[testIndex].getGroup()); assertEquals(0755, statuses[testIndex].getPermission().toExtendedShort()); } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testListStatusWithUnknownRemotePath() throws IOException { Path path = new Path("/foo/10.0.0.3@bar"); try { fs.listStatus(path); fail("Expected getFileStatus to throw FileNotFoundException"); } catch (FileNotFoundException e) { } } | @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FileStatus[] listStatus(Path f) throws FileNotFoundException, IOException { final RemoteIterator<FileStatus> remoteIterator = listStatusIterator(f); final List<FileStatus> statuses = Lists.newArrayList(); while (remoteIterator.hasNext()) { statuses.add(remoteIterator.next()); } return statuses.toArray(new FileStatus[0]); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testListStatusIteratorPastLastElement() throws IOException { final Path root = new Path("/"); final RemoteIterator<FileStatus> statusIter = fs.listStatusIterator(root); while (statusIter.hasNext()) { statusIter.next(); } try { statusIter.next(); fail("NoSuchElementException should be throw when next() is called when there are no elements remaining."); } catch (NoSuchElementException ex) { } } | @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testListStatusIteratorRoot() throws IOException { final Path root = new Path("/"); final RemoteIterator<FileStatus> statusIterator = fs.listStatusIterator(root); assertTrue(statusIterator.hasNext()); final FileStatus onlyStatus = statusIterator.next(); assertEquals(new Path("pdfs:/foo"), onlyStatus.getPath()); assertTrue(onlyStatus.isDirectory()); assertEquals(0755, onlyStatus.getPermission().toExtendedShort()); assertTrue(!statusIterator.hasNext()); } | @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public RemoteIterator<FileStatus> listStatusIterator(Path f) throws FileNotFoundException, IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return new RemoteIterator<FileStatus>() { private boolean hasNext = true; @Override public boolean hasNext() throws IOException { return hasNext; } @Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } }; } return new ListStatusIteratorTask(absolutePath).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testOpenRoot() throws IOException { Path root = new Path("/"); try { fs.open(root); fail("Expected open call to throw an exception"); } catch (AccessControlException e) { } } | @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testOpenFile() throws IOException { FSDataInputStream mockFDIS = mock(FSDataInputStream.class); doReturn(mockFDIS).when(mockLocalFS).open(new Path("/foo/bar/file"), 32768); Path root = new Path("/foo/bar/10.0.0.1@file"); FSDataInputStream fdis = fs.open(root, 32768); assertNotNull(fdis); } | @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testOpenLocalFile() throws IOException { try { Path path = new Path("/tmp/file"); @SuppressWarnings("unused") FSDataInputStream fdis = fs.open(path, 32768); fail("Expected open call to throw an exception"); } catch (IOException e) { } } | @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataInputStream open(Path f, int bufferSize) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.open(remotePath.path, bufferSize); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testTransformWithExtract() throws Exception { setSpace(); DatasetPath myDatasetPath = new DatasetPath("spacefoo.folderbar.folderbaz.datasetbuzz"); createDatasetFromParentAndSave(myDatasetPath, "cp.\"tpch/supplier.parquet\""); DatasetUI dataset = getDataset(myDatasetPath); Transformer testTransformer = new Transformer(l(SabotContext.class), l(JobsService.class), newNamespaceService(), newDatasetVersionMutator(), null, l(SecurityContext.class)); VirtualDatasetUI vdsui = DatasetsUtil.getHeadVersion(myDatasetPath, newNamespaceService(), newDatasetVersionMutator()); List<ViewFieldType> sqlFields = vdsui.getSqlFieldsList(); boolean isContainOriginal = false; boolean isContainConverted = false; for (ViewFieldType sqlType : sqlFields) { if (sqlType.getName().equalsIgnoreCase("s_address")) { isContainOriginal = true; break; } } assertTrue(isContainOriginal); isContainOriginal = false; VirtualDatasetUI vdsuiTransformed = testTransformer.transformWithExtract(dataset.getDatasetVersion(), myDatasetPath, vdsui, new TransformRename("s_address", "s_addr")); List<ViewFieldType> sqlFieldsTransformed = vdsuiTransformed.getSqlFieldsList(); for (ViewFieldType sqlType : sqlFieldsTransformed) { if (sqlType.getName().equalsIgnoreCase("s_addr")) { isContainConverted = true; } if (sqlType.getName().equalsIgnoreCase("s_address")) { isContainOriginal = true; } } assertTrue(isContainConverted); assertTrue(!isContainOriginal); } | public VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform) throws DatasetNotFoundException, NamespaceException{ final ExtractTransformActor actor = new ExtractTransformActor(baseDataset.getState(), false, username(), executor); final TransformResult result = transform.accept(actor); if (!actor.hasMetadata()) { VirtualDatasetState vss = protectAgainstNull(result, transform); actor.getMetadata(new SqlQuery(SQLGenerator.generateSQL(vss), vss.getContextList(), securityContext)); } VirtualDatasetUI dataset = asDataset(newVersion, path, baseDataset, transform, result, actor); datasetService.putVersion(dataset); return dataset; } | Transformer { public VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform) throws DatasetNotFoundException, NamespaceException{ final ExtractTransformActor actor = new ExtractTransformActor(baseDataset.getState(), false, username(), executor); final TransformResult result = transform.accept(actor); if (!actor.hasMetadata()) { VirtualDatasetState vss = protectAgainstNull(result, transform); actor.getMetadata(new SqlQuery(SQLGenerator.generateSQL(vss), vss.getContextList(), securityContext)); } VirtualDatasetUI dataset = asDataset(newVersion, path, baseDataset, transform, result, actor); datasetService.putVersion(dataset); return dataset; } } | Transformer { public VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform) throws DatasetNotFoundException, NamespaceException{ final ExtractTransformActor actor = new ExtractTransformActor(baseDataset.getState(), false, username(), executor); final TransformResult result = transform.accept(actor); if (!actor.hasMetadata()) { VirtualDatasetState vss = protectAgainstNull(result, transform); actor.getMetadata(new SqlQuery(SQLGenerator.generateSQL(vss), vss.getContextList(), securityContext)); } VirtualDatasetUI dataset = asDataset(newVersion, path, baseDataset, transform, result, actor); datasetService.putVersion(dataset); return dataset; } Transformer(SabotContext context, JobsService jobsService, NamespaceService namespace, DatasetVersionMutator datasetService,
QueryExecutor executor, SecurityContext securityContext); } | Transformer { public VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform) throws DatasetNotFoundException, NamespaceException{ final ExtractTransformActor actor = new ExtractTransformActor(baseDataset.getState(), false, username(), executor); final TransformResult result = transform.accept(actor); if (!actor.hasMetadata()) { VirtualDatasetState vss = protectAgainstNull(result, transform); actor.getMetadata(new SqlQuery(SQLGenerator.generateSQL(vss), vss.getContextList(), securityContext)); } VirtualDatasetUI dataset = asDataset(newVersion, path, baseDataset, transform, result, actor); datasetService.putVersion(dataset); return dataset; } Transformer(SabotContext context, JobsService jobsService, NamespaceService namespace, DatasetVersionMutator datasetService,
QueryExecutor executor, SecurityContext securityContext); static String describe(TransformBase transform); DatasetAndData editOriginalSql(DatasetVersion newVersion, List<Transform> operations, QueryType queryType,
JobStatusListener listener); VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform); DatasetAndData transformWithExecute(
DatasetVersion newVersion,
DatasetPath path,
VirtualDatasetUI original,
TransformBase transform,
QueryType queryType); InitialPendingTransformResponse transformPreviewWithExecute(
DatasetVersion newVersion,
DatasetPath path,
VirtualDatasetUI original,
TransformBase transform,
BufferAllocator allocator,
int limit); } | Transformer { public VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform) throws DatasetNotFoundException, NamespaceException{ final ExtractTransformActor actor = new ExtractTransformActor(baseDataset.getState(), false, username(), executor); final TransformResult result = transform.accept(actor); if (!actor.hasMetadata()) { VirtualDatasetState vss = protectAgainstNull(result, transform); actor.getMetadata(new SqlQuery(SQLGenerator.generateSQL(vss), vss.getContextList(), securityContext)); } VirtualDatasetUI dataset = asDataset(newVersion, path, baseDataset, transform, result, actor); datasetService.putVersion(dataset); return dataset; } Transformer(SabotContext context, JobsService jobsService, NamespaceService namespace, DatasetVersionMutator datasetService,
QueryExecutor executor, SecurityContext securityContext); static String describe(TransformBase transform); DatasetAndData editOriginalSql(DatasetVersion newVersion, List<Transform> operations, QueryType queryType,
JobStatusListener listener); VirtualDatasetUI transformWithExtract(DatasetVersion newVersion, DatasetPath path, VirtualDatasetUI baseDataset, TransformBase transform); DatasetAndData transformWithExecute(
DatasetVersion newVersion,
DatasetPath path,
VirtualDatasetUI original,
TransformBase transform,
QueryType queryType); InitialPendingTransformResponse transformPreviewWithExecute(
DatasetVersion newVersion,
DatasetPath path,
VirtualDatasetUI original,
TransformBase transform,
BufferAllocator allocator,
int limit); static final String VALUE_PLACEHOLDER; } |
@Test public void testCreateRoot() throws IOException { Path root = new Path("/"); try { fs.create(root, FsPermission.getFileDefault(), true, 0, (short) 1, 4096, null); fail("Expected create call to throw an exception"); } catch (AccessControlException e) { } } | @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCreateFile() throws IOException { FSDataOutputStream mockFDOS = mock(FSDataOutputStream.class); doReturn(mockFDOS).when(mockLocalFS).create( new Path("/foo/bar/file"), FsPermission.getFileDefault(), true, 0, (short) 1, 4096L,null); Path path = new Path("/foo/bar/10.0.0.1@file"); FSDataOutputStream fdos = fs.create(path, FsPermission.getFileDefault(), true, 0, (short) 1, 4096, null); assertNotNull(fdos); } | @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCreateLocalFile() throws IOException { try { Path path = new Path("foo/bar/file"); @SuppressWarnings("unused") FSDataOutputStream fdos = fs.create(path, FsPermission.getFileDefault(), true, 0, (short) 1, 4096, null); fail("Expected create call to throw an exception"); } catch (IOException e) { } } | @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testAppendRoot() throws IOException { Path root = new Path("/"); try { fs.append(root, 4096, null); fail("Expected append call to throw an exception"); } catch (AccessControlException e) { } } | @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testAppendFile() throws IOException { FSDataOutputStream mockFDOS = mock(FSDataOutputStream.class); doReturn(mockFDOS).when(mockRemoteFS).append( new Path("/foo/bar/file"), 4096, null); Path path = new Path("/foo/bar/10.0.0.2@file"); FSDataOutputStream fdos = fs.append(path, 4096, null); assertNotNull(fdos); } | @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testAppendLocalFile() throws IOException { try { Path path = new Path("/foo/bar/file"); @SuppressWarnings("unused") FSDataOutputStream fdos = fs.append(path, 4096, null); fail("Expected append call to throw an exception"); } catch (IOException e) { } } | @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testDeleteRoot() throws IOException { Path root = new Path("/"); try { fs.delete(root, false); fail("Expected delete call to throw an exception"); } catch (AccessControlException e) { } } | @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testDeleteLocalFile() throws IOException { try { Path path = new Path("/foo/bar/file"); fs.delete(path, false); fail("Expected delete call to throw an exception"); } catch (IOException e) { } } | @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testDeleteFile() throws IOException { doReturn(true).when(mockRemoteFS).delete( new Path("/foo/bar"), false); Path path = new Path("/foo/10.0.0.2@bar"); assertTrue(fs.delete(path, false)); } | @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testDeleteUnknownLocalFile() throws IOException { doThrow(FileNotFoundException.class).when(mockLocalFS).delete( new Path("/foo/unknown"), false); Path path = new Path("/foo/10.0.0.1@unknown"); try{ fs.delete(path, false); fail("Expecting FileNotFoundException"); } catch(FileNotFoundException e) { } } | @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testReplaceInvalidReplacedValues() { boolean exThrown = false; try { VirtualDatasetState state = new VirtualDatasetState() .setFrom(nameDSRef); Expression exp0 = new ExpColumnReference("bar").wrap(); FieldTransformationBase transf1 = new FieldReplaceValue() .setReplacedValuesList(Collections.<String>emptyList()) .setReplacementType(DATE) .setReplaceType(ReplaceType.VALUE) .setReplacementValue("2016-11-05"); Expression exp = new ExpFieldTransformation(transf1.wrap(), exp0).wrap(); SQLGenerator.generateSQL(state.setColumnsList(asList(new Column("foo", exp)))); fail("not expected to reach here"); } catch (UserException e) { exThrown = true; assertEquals("select at least one value to replace", e.getMessage()); } assertTrue("expected a UserException", exThrown); } | public static String generateSQL(VirtualDatasetState vss){ return new SQLGenerator().innerGenerateSQL(vss); } | SQLGenerator { public static String generateSQL(VirtualDatasetState vss){ return new SQLGenerator().innerGenerateSQL(vss); } } | SQLGenerator { public static String generateSQL(VirtualDatasetState vss){ return new SQLGenerator().innerGenerateSQL(vss); } SQLGenerator(); } | SQLGenerator { public static String generateSQL(VirtualDatasetState vss){ return new SQLGenerator().innerGenerateSQL(vss); } SQLGenerator(); static String generateSQL(VirtualDatasetState vss); static String getTableAlias(From from); } | SQLGenerator { public static String generateSQL(VirtualDatasetState vss){ return new SQLGenerator().innerGenerateSQL(vss); } SQLGenerator(); static String generateSQL(VirtualDatasetState vss); static String getTableAlias(From from); } |
@Test public void testDeleteUnknownRemoteFile() throws IOException { doThrow(FileNotFoundException.class).when(mockRemoteFS).delete( new Path("/foo/unknown"), false); Path path = new Path("/foo/10.0.0.2@unknown"); try{ fs.delete(path, false); fail("Expecting FileNotFoundException"); } catch(FileNotFoundException e) { } } | @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { throw new AccessControlException("Cannot delete " + f); } if (!isRemoteFile(f)) { return new DeleteTask(absolutePath, recursive).get(); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.delete(remotePath.path, recursive); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testMkdirsRoot() throws IOException { Path root = new Path("/"); assertTrue(fs.mkdirs(root, FsPermission.getDirDefault())); } | @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testMkdirsRemoteFile() throws IOException { doReturn(true).when(mockLocalFS).mkdirs( new Path("/foo/bar/dir2"), FsPermission.getFileDefault()); doReturn(true).when(mockRemoteFS).mkdirs( new Path("/foo/bar/dir2"), FsPermission.getFileDefault()); Path path = new Path("/foo/bar/dir2"); assertTrue(fs.mkdirs(path, FsPermission.getFileDefault())); } | @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); if (absolutePath.isRoot()) { return true; } if (isRemoteFile(absolutePath)) { throw new IOException("Cannot create a directory under file " + f); } return new MkdirsTask(absolutePath, permission).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testRenameFromRoot() throws IOException { Path root = new Path("/"); Path dst = new Path("/foo/baz"); try { fs.rename(root, dst); fail("Expected rename to throw an exception"); } catch(IOException e) { } } | @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testRenameToRoot() throws IOException { Path root = new Path("/"); Path src = new Path("/foo/bar"); try { fs.rename(src, root); fail("Expected rename to throw an exception"); } catch(IOException e) { } } | @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testRenameFileSameEndpoint() throws IOException { doReturn(true).when(mockLocalFS).rename( new Path("/foo/bar/file1"), new Path("/foo/bar/file3")); Path src = new Path("/foo/bar/10.0.0.1@file1"); Path dst = new Path("/foo/bar/10.0.0.1@file3"); assertTrue(fs.rename(src, dst)); } | @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testRenameRemoteFileDifferentEndpoints() throws IOException { Path src = new Path("/foo/bar/10.0.0.1@file1"); Path dst = new Path("/foo/bar/10.0.0.2@file3"); try { fs.rename(src, dst); fail("Expected rename across endpoints to fail"); } catch(IOException e) { } } | @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testRenameDirectories() throws IOException { doReturn(true).when(mockLocalFS).rename( new Path("/foo/bar"), new Path("/foo/baz")); doReturn(true).when(mockRemoteFS).rename( new Path("/foo/bar"), new Path("/foo/baz")); Path src = new Path("/foo/bar"); Path dst = new Path("/foo/baz"); assertTrue(fs.rename(src, dst)); } | @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); if (absoluteSrc.isRoot()) { throw new IOException("Cannot rename " + absoluteSrc); } if (absoluteDst.isRoot()) { throw new IOException("Cannot rename into" + absoluteDst); } boolean isSrcRemote = isRemoteFile(absoluteSrc); boolean isDstRemote = isRemoteFile(absoluteDst); if (isSrcRemote) { RemotePath srcRemotePath = getRemotePath(absoluteSrc); final String srcAddress = srcRemotePath.address; final Path srcPath = srcRemotePath.path; if (isDstRemote) { RemotePath dstRemotePath = getRemotePath(absoluteDst); final String dstAddress = dstRemotePath.address; final Path dstPath = dstRemotePath.path; if (!Objects.equal(srcAddress, dstAddress)) { throw new IOException("Cannot rename across endpoints: from " + absoluteSrc + " to " + absoluteDst); } FileSystem delegateFS = getDelegateFileSystem(dstAddress); return delegateFS.rename(srcPath, dstPath); } boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); } FileSystem delegateFS = getDelegateFileSystem(srcAddress); try { FileStatus status = delegateFS.getFileStatus(absoluteDst); if (!status.isDirectory()) { throw new IOException("A remote file for path " + absoluteDst + " already exists on endpoint " + srcAddress); } } catch(FileNotFoundException e) { delegateFS.mkdirs(absoluteDst); } return delegateFS.rename(srcPath, absoluteDst); } if (isDstRemote) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst); if (!(isSrcDirectory || isDstDirectory)) { throw new IOException("Cannot rename " + absoluteSrc + " to " + absoluteDst); } return new RenameTask(absoluteSrc, absoluteDst).get(); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileBlockLocations() throws IOException { Path path = new Path("/foo/10.0.0.1@bar"); BlockLocation[] locations = fs.getFileBlockLocations(new FileStatus(1027, false, 1, 4096, 123456, path), 7, 1024); assertEquals(1, locations.length); BlockLocation location = locations[0]; assertArrayEquals(new String[] { "10.0.0.1:1234", "10.0.0.1:9012" }, location.getNames()); assertArrayEquals(new String[] { "10.0.0.1" }, location.getHosts()); assertEquals(0, location.getOffset()); assertEquals(1027, location.getLength()); } | @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileBlockLocationsStartGreaterThanLen() throws IOException { Path path = new Path("/foo/10.0.0.1@bar"); assertArrayEquals(new BlockLocation[]{}, fs.getFileBlockLocations(new FileStatus(1024, false, 1,4096, 123456, path), 4096, 8192)); } | @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testTimeIntervals() throws Exception { HistogramGenerator hg = new HistogramGenerator(null); String myTimeStr = "2016-02-29 13:59:01"; DateTimeFormatter dtf = DateFunctionsUtils.getISOFormatterForFormatString("YYYY-MM-DD HH24:MI:SS"); LocalDateTime myTime = dtf.parseLocalDateTime(myTimeStr); System.out.println("Exact time: " + myTime + ", Month: " + myTime.getMonthOfYear()); for (HistogramGenerator.TruncEvalEnum value : HistogramGenerator.TruncEvalEnum.getSortedAscValues()) { LocalDateTime roundedDown = hg.roundTime(myTime, value, true); LocalDateTime roundedUp = hg.roundTime(myTime, value, false); switch(value) { case SECOND: assertEquals(myTime, roundedDown); assertEquals(myTime, roundedUp); break; case MINUTE: assertEquals(dtf.parseLocalDateTime("2016-02-29 13:59:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-02-29 14:00:00"), roundedUp); break; case HOUR: assertEquals(dtf.parseLocalDateTime("2016-02-29 13:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-02-29 14:00:00"), roundedUp); break; case DAY: assertEquals(dtf.parseLocalDateTime("2016-02-29 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-03-01 00:00:00"), roundedUp); break; case WEEK: assertEquals(dtf.parseLocalDateTime("2016-02-29 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-03-07 00:00:00"), roundedUp); break; case MONTH: assertEquals(dtf.parseLocalDateTime("2016-02-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-03-01 00:00:00"), roundedUp); break; case QUARTER: assertEquals(dtf.parseLocalDateTime("2016-01-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2016-04-01 00:00:00"), roundedUp); break; case YEAR: assertEquals(dtf.parseLocalDateTime("2016-01-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2017-01-01 00:00:00"), roundedUp); break; case DECADE: assertEquals(dtf.parseLocalDateTime("2010-01-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2020-01-01 00:00:00"), roundedUp); break; case CENTURY: assertEquals(dtf.parseLocalDateTime("2000-01-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("2100-01-01 00:00:00"), roundedUp); break; case MILLENNIUM: assertEquals(dtf.parseLocalDateTime("2000-01-01 00:00:00"), roundedDown); assertEquals(dtf.parseLocalDateTime("3000-01-01 00:00:00"), roundedUp); break; default: fail(); } } } | @VisibleForTesting protected static LocalDateTime roundTime(LocalDateTime tmpValue, TruncEvalEnum trucateTo, boolean isRoundDown) { switch (trucateTo) { case SECOND: if (isRoundDown) { return tmpValue.secondOfMinute().roundFloorCopy(); } else { return tmpValue.secondOfMinute().roundCeilingCopy(); } case MINUTE: if (isRoundDown) { return tmpValue.minuteOfHour().roundFloorCopy(); } else { return tmpValue.minuteOfHour().roundCeilingCopy(); } case HOUR: if (isRoundDown) { return tmpValue.hourOfDay().roundFloorCopy(); } else { return tmpValue.hourOfDay().roundCeilingCopy(); } case DAY: if (isRoundDown) { return tmpValue.dayOfMonth().roundFloorCopy(); } else { return tmpValue.dayOfMonth().roundCeilingCopy(); } case WEEK: if (isRoundDown) { return tmpValue.weekOfWeekyear().roundFloorCopy(); } else { return tmpValue.weekOfWeekyear().roundCeilingCopy(); } case MONTH: if (isRoundDown) { return tmpValue.monthOfYear().roundFloorCopy(); } else { return tmpValue.monthOfYear().roundCeilingCopy(); } case QUARTER: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.monthOfYear().roundFloorCopy(); int month = roundeddown.getMonthOfYear(); int quarter = (month - 1) % 3; return roundeddown.minusMonths(quarter); } else { LocalDateTime roundedUp = tmpValue.monthOfYear().roundCeilingCopy(); int month = roundedUp.getMonthOfYear(); int quarter = 3 - (month - 1) % 3; return roundedUp.plusMonths(quarter); } case YEAR: if (isRoundDown) { return tmpValue.year().roundFloorCopy(); } else { return tmpValue.year().roundCeilingCopy(); } case DECADE: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 10; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 10 - year % 10; return roundedUp.plusYears(roundedUpYear); } case CENTURY: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 100; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 100 - year % 100; return roundedUp.plusYears(roundedUpYear); } case MILLENNIUM: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 1000; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 1000 - year % 1000; return roundedUp.plusYears(roundedUpYear); } default: return tmpValue; } } | HistogramGenerator { @VisibleForTesting protected static LocalDateTime roundTime(LocalDateTime tmpValue, TruncEvalEnum trucateTo, boolean isRoundDown) { switch (trucateTo) { case SECOND: if (isRoundDown) { return tmpValue.secondOfMinute().roundFloorCopy(); } else { return tmpValue.secondOfMinute().roundCeilingCopy(); } case MINUTE: if (isRoundDown) { return tmpValue.minuteOfHour().roundFloorCopy(); } else { return tmpValue.minuteOfHour().roundCeilingCopy(); } case HOUR: if (isRoundDown) { return tmpValue.hourOfDay().roundFloorCopy(); } else { return tmpValue.hourOfDay().roundCeilingCopy(); } case DAY: if (isRoundDown) { return tmpValue.dayOfMonth().roundFloorCopy(); } else { return tmpValue.dayOfMonth().roundCeilingCopy(); } case WEEK: if (isRoundDown) { return tmpValue.weekOfWeekyear().roundFloorCopy(); } else { return tmpValue.weekOfWeekyear().roundCeilingCopy(); } case MONTH: if (isRoundDown) { return tmpValue.monthOfYear().roundFloorCopy(); } else { return tmpValue.monthOfYear().roundCeilingCopy(); } case QUARTER: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.monthOfYear().roundFloorCopy(); int month = roundeddown.getMonthOfYear(); int quarter = (month - 1) % 3; return roundeddown.minusMonths(quarter); } else { LocalDateTime roundedUp = tmpValue.monthOfYear().roundCeilingCopy(); int month = roundedUp.getMonthOfYear(); int quarter = 3 - (month - 1) % 3; return roundedUp.plusMonths(quarter); } case YEAR: if (isRoundDown) { return tmpValue.year().roundFloorCopy(); } else { return tmpValue.year().roundCeilingCopy(); } case DECADE: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 10; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 10 - year % 10; return roundedUp.plusYears(roundedUpYear); } case CENTURY: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 100; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 100 - year % 100; return roundedUp.plusYears(roundedUpYear); } case MILLENNIUM: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 1000; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 1000 - year % 1000; return roundedUp.plusYears(roundedUpYear); } default: return tmpValue; } } } | HistogramGenerator { @VisibleForTesting protected static LocalDateTime roundTime(LocalDateTime tmpValue, TruncEvalEnum trucateTo, boolean isRoundDown) { switch (trucateTo) { case SECOND: if (isRoundDown) { return tmpValue.secondOfMinute().roundFloorCopy(); } else { return tmpValue.secondOfMinute().roundCeilingCopy(); } case MINUTE: if (isRoundDown) { return tmpValue.minuteOfHour().roundFloorCopy(); } else { return tmpValue.minuteOfHour().roundCeilingCopy(); } case HOUR: if (isRoundDown) { return tmpValue.hourOfDay().roundFloorCopy(); } else { return tmpValue.hourOfDay().roundCeilingCopy(); } case DAY: if (isRoundDown) { return tmpValue.dayOfMonth().roundFloorCopy(); } else { return tmpValue.dayOfMonth().roundCeilingCopy(); } case WEEK: if (isRoundDown) { return tmpValue.weekOfWeekyear().roundFloorCopy(); } else { return tmpValue.weekOfWeekyear().roundCeilingCopy(); } case MONTH: if (isRoundDown) { return tmpValue.monthOfYear().roundFloorCopy(); } else { return tmpValue.monthOfYear().roundCeilingCopy(); } case QUARTER: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.monthOfYear().roundFloorCopy(); int month = roundeddown.getMonthOfYear(); int quarter = (month - 1) % 3; return roundeddown.minusMonths(quarter); } else { LocalDateTime roundedUp = tmpValue.monthOfYear().roundCeilingCopy(); int month = roundedUp.getMonthOfYear(); int quarter = 3 - (month - 1) % 3; return roundedUp.plusMonths(quarter); } case YEAR: if (isRoundDown) { return tmpValue.year().roundFloorCopy(); } else { return tmpValue.year().roundCeilingCopy(); } case DECADE: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 10; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 10 - year % 10; return roundedUp.plusYears(roundedUpYear); } case CENTURY: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 100; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 100 - year % 100; return roundedUp.plusYears(roundedUpYear); } case MILLENNIUM: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 1000; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 1000 - year % 1000; return roundedUp.plusYears(roundedUpYear); } default: return tmpValue; } } HistogramGenerator(QueryExecutor executor); } | HistogramGenerator { @VisibleForTesting protected static LocalDateTime roundTime(LocalDateTime tmpValue, TruncEvalEnum trucateTo, boolean isRoundDown) { switch (trucateTo) { case SECOND: if (isRoundDown) { return tmpValue.secondOfMinute().roundFloorCopy(); } else { return tmpValue.secondOfMinute().roundCeilingCopy(); } case MINUTE: if (isRoundDown) { return tmpValue.minuteOfHour().roundFloorCopy(); } else { return tmpValue.minuteOfHour().roundCeilingCopy(); } case HOUR: if (isRoundDown) { return tmpValue.hourOfDay().roundFloorCopy(); } else { return tmpValue.hourOfDay().roundCeilingCopy(); } case DAY: if (isRoundDown) { return tmpValue.dayOfMonth().roundFloorCopy(); } else { return tmpValue.dayOfMonth().roundCeilingCopy(); } case WEEK: if (isRoundDown) { return tmpValue.weekOfWeekyear().roundFloorCopy(); } else { return tmpValue.weekOfWeekyear().roundCeilingCopy(); } case MONTH: if (isRoundDown) { return tmpValue.monthOfYear().roundFloorCopy(); } else { return tmpValue.monthOfYear().roundCeilingCopy(); } case QUARTER: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.monthOfYear().roundFloorCopy(); int month = roundeddown.getMonthOfYear(); int quarter = (month - 1) % 3; return roundeddown.minusMonths(quarter); } else { LocalDateTime roundedUp = tmpValue.monthOfYear().roundCeilingCopy(); int month = roundedUp.getMonthOfYear(); int quarter = 3 - (month - 1) % 3; return roundedUp.plusMonths(quarter); } case YEAR: if (isRoundDown) { return tmpValue.year().roundFloorCopy(); } else { return tmpValue.year().roundCeilingCopy(); } case DECADE: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 10; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 10 - year % 10; return roundedUp.plusYears(roundedUpYear); } case CENTURY: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 100; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 100 - year % 100; return roundedUp.plusYears(roundedUpYear); } case MILLENNIUM: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 1000; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 1000 - year % 1000; return roundedUp.plusYears(roundedUpYear); } default: return tmpValue; } } HistogramGenerator(QueryExecutor executor); Histogram<HistogramValue> getHistogram(final DatasetPath datasetPath, DatasetVersion version, Selection selection,
DataType colType, SqlQuery datasetQuery, BufferAllocator allocator); Histogram<CleanDataHistogramValue> getCleanDataHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); Map<DataType, Long> getTypeHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); long getSelectionCount(final DatasetPath datasetPath, final DatasetVersion version,
final SqlQuery datasetQuery, final DataType dataType, final String colName, Set<String> selectedValues, BufferAllocator allocator); } | HistogramGenerator { @VisibleForTesting protected static LocalDateTime roundTime(LocalDateTime tmpValue, TruncEvalEnum trucateTo, boolean isRoundDown) { switch (trucateTo) { case SECOND: if (isRoundDown) { return tmpValue.secondOfMinute().roundFloorCopy(); } else { return tmpValue.secondOfMinute().roundCeilingCopy(); } case MINUTE: if (isRoundDown) { return tmpValue.minuteOfHour().roundFloorCopy(); } else { return tmpValue.minuteOfHour().roundCeilingCopy(); } case HOUR: if (isRoundDown) { return tmpValue.hourOfDay().roundFloorCopy(); } else { return tmpValue.hourOfDay().roundCeilingCopy(); } case DAY: if (isRoundDown) { return tmpValue.dayOfMonth().roundFloorCopy(); } else { return tmpValue.dayOfMonth().roundCeilingCopy(); } case WEEK: if (isRoundDown) { return tmpValue.weekOfWeekyear().roundFloorCopy(); } else { return tmpValue.weekOfWeekyear().roundCeilingCopy(); } case MONTH: if (isRoundDown) { return tmpValue.monthOfYear().roundFloorCopy(); } else { return tmpValue.monthOfYear().roundCeilingCopy(); } case QUARTER: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.monthOfYear().roundFloorCopy(); int month = roundeddown.getMonthOfYear(); int quarter = (month - 1) % 3; return roundeddown.minusMonths(quarter); } else { LocalDateTime roundedUp = tmpValue.monthOfYear().roundCeilingCopy(); int month = roundedUp.getMonthOfYear(); int quarter = 3 - (month - 1) % 3; return roundedUp.plusMonths(quarter); } case YEAR: if (isRoundDown) { return tmpValue.year().roundFloorCopy(); } else { return tmpValue.year().roundCeilingCopy(); } case DECADE: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 10; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 10 - year % 10; return roundedUp.plusYears(roundedUpYear); } case CENTURY: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 100; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 100 - year % 100; return roundedUp.plusYears(roundedUpYear); } case MILLENNIUM: if (isRoundDown) { LocalDateTime roundeddown = tmpValue.year().roundFloorCopy(); int year = roundeddown.getYear(); int roundedDownYear = year % 1000; return roundeddown.minusYears(roundedDownYear); } else { LocalDateTime roundedUp = tmpValue.year().roundCeilingCopy(); int year = roundedUp.getYear(); int roundedUpYear = 1000 - year % 1000; return roundedUp.plusYears(roundedUpYear); } default: return tmpValue; } } HistogramGenerator(QueryExecutor executor); Histogram<HistogramValue> getHistogram(final DatasetPath datasetPath, DatasetVersion version, Selection selection,
DataType colType, SqlQuery datasetQuery, BufferAllocator allocator); Histogram<CleanDataHistogramValue> getCleanDataHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); Map<DataType, Long> getTypeHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); long getSelectionCount(final DatasetPath datasetPath, final DatasetVersion version,
final SqlQuery datasetQuery, final DataType dataType, final String colName, Set<String> selectedValues, BufferAllocator allocator); } |
@Test public void testGetFileBlockLocationsNegativeStart() throws IOException { Path path = new Path("/foo/10.0.0.1@bar"); try { fs.getFileBlockLocations(new FileStatus(1024, false, 1,4096, 123456, path), -22, 8192); fail("Expected getFileBlockLocation to throw an exception"); } catch (IllegalArgumentException e) { } } | @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testGetFileBlockLocationsNegativeLen() throws IOException { Path path = new Path("/foo/10.0.0.1@bar"); try { fs.getFileBlockLocations(new FileStatus(1024, false, 1,4096, 123456, path), 18, -2); fail("Expected getFileBlockLocation to throw an exception"); } catch (IllegalArgumentException e) { } } | @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { Preconditions.checkArgument(start >= 0, "start should be positive"); Preconditions.checkArgument(len >= 0, "len should be positive"); if (start >= file.getLen()) { return new BlockLocation[] {}; } try { final RemotePath remotePath = getRemotePath(file.getPath()); final List<NodeEndpoint> endpoints = getEndpoints(remotePath.address); if (endpoints.isEmpty()) { if (localAccessAllowed && localIdentity.getAddress().equals(remotePath.address)) { return new BlockLocation[]{ new BlockLocation( new String[]{format("%s:%d", localIdentity.getAddress(), localIdentity.getFabricPort())}, new String[]{localIdentity.getAddress()}, 0, file.getLen()) }; } return new BlockLocation[]{}; } String address = endpoints.get(0).getAddress(); String[] hosts = new String[] { address }; String[] names = new String[endpoints.size()]; int i = 0; for (NodeEndpoint endpoint : endpoints) { names[i++] = format("%s:%d", address, endpoint.getFabricPort()); } return new BlockLocation[] { new BlockLocation(names, hosts, 0, file.getLen()) }; } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + file.getPath()).initCause(e)); } } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCanonicalizeRemoteFile() throws IOException { Path path = new Path("/foo/bar/10.0.0.2@file"); Path resolvedPath = fs.canonicalizePath(path); assertEquals(new Path("/foo/bar/10.0.0.2@file"), resolvedPath); } | @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCanonicalizeDirectoryFile() throws IOException { Path path = new Path("/foo/bar"); Path resolvedPath = fs.canonicalizePath(path); assertEquals(new Path("/foo/bar"), resolvedPath); } | @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCanonicalizeLocalFile() throws IOException { Path path = new Path("/foo/bar/file"); Path resolvedPath = fs.canonicalizePath(path); assertEquals(new Path("/foo/bar/10.0.0.1@file"), resolvedPath); } | @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void testCanonicalizeLocalFileIfNoLocalAccess() throws IOException { Provider<Iterable<NodeEndpoint>> endpointsProvider = DirectProvider.<Iterable<NodeEndpoint>>wrap((Arrays.asList(REMOTE_ENDPOINT_1, REMOTE_ENDPOINT_2))); PDFSConfig pdfsConfig = new PDFSConfig(MoreExecutors.newDirectExecutorService(), null, null, endpointsProvider, LOCAL_ENDPOINT, false); PseudoDistributedFileSystem pdfs = newPseudoDistributedFileSystem(pdfsConfig); Path path = new Path("/foo/bar/file"); Path resolvedPath = pdfs.canonicalizePath(path); assertEquals(new Path("/foo/bar/10.0.0.2@file"), resolvedPath); } | @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); } | PseudoDistributedFileSystem extends FileSystem implements PathCanonicalizer { @Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localIdentity.getAddress(), absolutePath); } final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); } PseudoDistributedFileSystem(); @VisibleForTesting PseudoDistributedFileSystem(PDFSConfig config); static synchronized void configure(PDFSConfig config); static String getRemoteFileName(String basename); static RemotePath getRemotePath(Path path); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override String getScheme(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override Path canonicalizePath(Path p); static final String NAME; } |
@Test public void impersonationDisabledShouldReturnSystemUser() { final HiveConf hiveConf = new HiveConf(); hiveConf.setBoolVar(HIVE_SERVER2_ENABLE_DOAS, false); final SabotContext context = mock(SabotContext.class); final Hive3StoragePlugin plugin = createHiveStoragePlugin(hiveConf, context); final String userName = plugin.getUsername(TEST_USER_NAME); assertEquals(SystemUser.SYSTEM_USERNAME, userName); } | public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(DatasetHandle datasetHandle, DatasetMetadata oldDatasetMetadata,
Map<String, AttributeValue> attributes, AlterMetadataOption... options); T getPF4JStoragePlugin(); } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(DatasetHandle datasetHandle, DatasetMetadata oldDatasetMetadata,
Map<String, AttributeValue> attributes, AlterMetadataOption... options); T getPF4JStoragePlugin(); } |
@Test public void impersonationEnabledShouldReturnUser() { final HiveConf hiveConf = new HiveConf(); hiveConf.setBoolVar(HIVE_SERVER2_ENABLE_DOAS, true); final SabotContext context = mock(SabotContext.class); final Hive3StoragePlugin plugin = new Hive3StoragePlugin(hiveConf, context, "foo"); final String userName = plugin.getUsername(TEST_USER_NAME); assertEquals(TEST_USER_NAME, userName); } | public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(DatasetHandle datasetHandle, DatasetMetadata oldDatasetMetadata,
Map<String, AttributeValue> attributes, AlterMetadataOption... options); T getPF4JStoragePlugin(); } | Hive3StoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting Hive3StoragePlugin(HiveConf hiveConf, SabotContext context, String name); Hive3StoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(DatasetHandle datasetHandle, DatasetMetadata oldDatasetMetadata,
Map<String, AttributeValue> attributes, AlterMetadataOption... options); T getPF4JStoragePlugin(); } |
@Test public void ensureStoragePluginIsUsedForUsername() throws Exception { final String originalName = "Test"; final String finalName = "Replaced"; final HiveScanBatchCreator creator = new HiveScanBatchCreator(); final Hive3StoragePlugin plugin = mock(Hive3StoragePlugin.class); when(plugin.getUsername(originalName)).thenReturn(finalName); final FragmentExecutionContext fragmentExecutionContext = mock(FragmentExecutionContext.class); when(fragmentExecutionContext.getStoragePlugin(any())).thenReturn(plugin); final OpProps props = mock(OpProps.class); final HiveProxyingSubScan hiveSubScan = mock(HiveProxyingSubScan.class); when(hiveSubScan.getProps()).thenReturn(props); when(hiveSubScan.getProps().getUserName()).thenReturn(originalName); final UserGroupInformation ugi = creator.getUGI(plugin, hiveSubScan); verify(plugin).getUsername(originalName); assertEquals(finalName, ugi.getUserName()); } | @VisibleForTesting public UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config); } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(Hive3StoragePlugin storagePlugin, HiveProxyingSubScan config); } |
@Test public void testShouldReturnPluginRoot() { properties.set(DremioConfig.PLUGINS_ROOT_PATH_PROPERTY, "/tmp/plugins"); Path expectedPath = Paths.get("/tmp/plugins/connectors"); Path actualPath = nativeLibPluginManager.createPluginsRoot(); Assert.assertEquals(expectedPath, actualPath); } | @Override protected Path createPluginsRoot() { final Path pluginsPath = this.isDevelopment() ? Paths.get(PLUGINS_PATH_DEV_MODE) : DremioConfig.getPluginsRootPath().resolve("connectors"); return pluginsPath; } | NativeLibPluginManager extends DefaultPluginManager { @Override protected Path createPluginsRoot() { final Path pluginsPath = this.isDevelopment() ? Paths.get(PLUGINS_PATH_DEV_MODE) : DremioConfig.getPluginsRootPath().resolve("connectors"); return pluginsPath; } } | NativeLibPluginManager extends DefaultPluginManager { @Override protected Path createPluginsRoot() { final Path pluginsPath = this.isDevelopment() ? Paths.get(PLUGINS_PATH_DEV_MODE) : DremioConfig.getPluginsRootPath().resolve("connectors"); return pluginsPath; } } | NativeLibPluginManager extends DefaultPluginManager { @Override protected Path createPluginsRoot() { final Path pluginsPath = this.isDevelopment() ? Paths.get(PLUGINS_PATH_DEV_MODE) : DremioConfig.getPluginsRootPath().resolve("connectors"); return pluginsPath; } } | NativeLibPluginManager extends DefaultPluginManager { @Override protected Path createPluginsRoot() { final Path pluginsPath = this.isDevelopment() ? Paths.get(PLUGINS_PATH_DEV_MODE) : DremioConfig.getPluginsRootPath().resolve("connectors"); return pluginsPath; } } |
@Test public void testProduceRanges() { List<Number> ranges = new ArrayList<>(); HistogramGenerator.produceRanges(ranges , new LocalDateTime(1970, 1, 1, 1, 0, 0), new LocalDateTime(1970, 1, 1, 11, 59, 0), TruncEvalEnum.HOUR); List<Number> expected = new ArrayList<>(); for (int i = 0; i < 13; i++) { expected.add((i + 1 ) * 3600_000L); } Assert.assertEquals(expected.size(), ranges.size()); Assert.assertEquals(expected, ranges); } | @VisibleForTesting static void produceRanges(List<Number> ranges, LocalDateTime min, LocalDateTime max, TruncEvalEnum truncateTo) { long timeValue = toMillis(roundTime(min, truncateTo, true)); long maxTimeValue = toMillis(roundTime(max, truncateTo, false)); ranges.add(timeValue); while ( timeValue <= maxTimeValue) { LocalDateTime tmpValue = new LocalDateTime(timeValue, DateTimeZone.UTC); switch (truncateTo) { case SECOND: timeValue = toMillis(tmpValue.plusSeconds(1)); break; case MINUTE: timeValue = toMillis(tmpValue.plusMinutes(1)); break; case HOUR: timeValue = toMillis(tmpValue.plusHours(1)); break; case DAY: timeValue = toMillis(tmpValue.plusDays(1)); break; case WEEK: timeValue = toMillis(tmpValue.plusWeeks(1)); break; case MONTH: timeValue = toMillis(tmpValue.plusMonths(1)); break; case QUARTER: timeValue = toMillis(tmpValue.plusMonths(3)); break; case YEAR: timeValue = toMillis(tmpValue.plusYears(1)); break; case DECADE: timeValue = toMillis(tmpValue.plusYears(10)); break; case CENTURY: timeValue = toMillis(tmpValue.plusYears(100)); break; case MILLENNIUM: timeValue = toMillis(tmpValue.plusYears(1000)); default: break; } ranges.add(timeValue); if (ranges.size() > 100_000) { throw new AssertionError(String.format("the ranges size should not grow that big: min: %s, max: %s, t: %s", min, max, truncateTo)); } } } | HistogramGenerator { @VisibleForTesting static void produceRanges(List<Number> ranges, LocalDateTime min, LocalDateTime max, TruncEvalEnum truncateTo) { long timeValue = toMillis(roundTime(min, truncateTo, true)); long maxTimeValue = toMillis(roundTime(max, truncateTo, false)); ranges.add(timeValue); while ( timeValue <= maxTimeValue) { LocalDateTime tmpValue = new LocalDateTime(timeValue, DateTimeZone.UTC); switch (truncateTo) { case SECOND: timeValue = toMillis(tmpValue.plusSeconds(1)); break; case MINUTE: timeValue = toMillis(tmpValue.plusMinutes(1)); break; case HOUR: timeValue = toMillis(tmpValue.plusHours(1)); break; case DAY: timeValue = toMillis(tmpValue.plusDays(1)); break; case WEEK: timeValue = toMillis(tmpValue.plusWeeks(1)); break; case MONTH: timeValue = toMillis(tmpValue.plusMonths(1)); break; case QUARTER: timeValue = toMillis(tmpValue.plusMonths(3)); break; case YEAR: timeValue = toMillis(tmpValue.plusYears(1)); break; case DECADE: timeValue = toMillis(tmpValue.plusYears(10)); break; case CENTURY: timeValue = toMillis(tmpValue.plusYears(100)); break; case MILLENNIUM: timeValue = toMillis(tmpValue.plusYears(1000)); default: break; } ranges.add(timeValue); if (ranges.size() > 100_000) { throw new AssertionError(String.format("the ranges size should not grow that big: min: %s, max: %s, t: %s", min, max, truncateTo)); } } } } | HistogramGenerator { @VisibleForTesting static void produceRanges(List<Number> ranges, LocalDateTime min, LocalDateTime max, TruncEvalEnum truncateTo) { long timeValue = toMillis(roundTime(min, truncateTo, true)); long maxTimeValue = toMillis(roundTime(max, truncateTo, false)); ranges.add(timeValue); while ( timeValue <= maxTimeValue) { LocalDateTime tmpValue = new LocalDateTime(timeValue, DateTimeZone.UTC); switch (truncateTo) { case SECOND: timeValue = toMillis(tmpValue.plusSeconds(1)); break; case MINUTE: timeValue = toMillis(tmpValue.plusMinutes(1)); break; case HOUR: timeValue = toMillis(tmpValue.plusHours(1)); break; case DAY: timeValue = toMillis(tmpValue.plusDays(1)); break; case WEEK: timeValue = toMillis(tmpValue.plusWeeks(1)); break; case MONTH: timeValue = toMillis(tmpValue.plusMonths(1)); break; case QUARTER: timeValue = toMillis(tmpValue.plusMonths(3)); break; case YEAR: timeValue = toMillis(tmpValue.plusYears(1)); break; case DECADE: timeValue = toMillis(tmpValue.plusYears(10)); break; case CENTURY: timeValue = toMillis(tmpValue.plusYears(100)); break; case MILLENNIUM: timeValue = toMillis(tmpValue.plusYears(1000)); default: break; } ranges.add(timeValue); if (ranges.size() > 100_000) { throw new AssertionError(String.format("the ranges size should not grow that big: min: %s, max: %s, t: %s", min, max, truncateTo)); } } } HistogramGenerator(QueryExecutor executor); } | HistogramGenerator { @VisibleForTesting static void produceRanges(List<Number> ranges, LocalDateTime min, LocalDateTime max, TruncEvalEnum truncateTo) { long timeValue = toMillis(roundTime(min, truncateTo, true)); long maxTimeValue = toMillis(roundTime(max, truncateTo, false)); ranges.add(timeValue); while ( timeValue <= maxTimeValue) { LocalDateTime tmpValue = new LocalDateTime(timeValue, DateTimeZone.UTC); switch (truncateTo) { case SECOND: timeValue = toMillis(tmpValue.plusSeconds(1)); break; case MINUTE: timeValue = toMillis(tmpValue.plusMinutes(1)); break; case HOUR: timeValue = toMillis(tmpValue.plusHours(1)); break; case DAY: timeValue = toMillis(tmpValue.plusDays(1)); break; case WEEK: timeValue = toMillis(tmpValue.plusWeeks(1)); break; case MONTH: timeValue = toMillis(tmpValue.plusMonths(1)); break; case QUARTER: timeValue = toMillis(tmpValue.plusMonths(3)); break; case YEAR: timeValue = toMillis(tmpValue.plusYears(1)); break; case DECADE: timeValue = toMillis(tmpValue.plusYears(10)); break; case CENTURY: timeValue = toMillis(tmpValue.plusYears(100)); break; case MILLENNIUM: timeValue = toMillis(tmpValue.plusYears(1000)); default: break; } ranges.add(timeValue); if (ranges.size() > 100_000) { throw new AssertionError(String.format("the ranges size should not grow that big: min: %s, max: %s, t: %s", min, max, truncateTo)); } } } HistogramGenerator(QueryExecutor executor); Histogram<HistogramValue> getHistogram(final DatasetPath datasetPath, DatasetVersion version, Selection selection,
DataType colType, SqlQuery datasetQuery, BufferAllocator allocator); Histogram<CleanDataHistogramValue> getCleanDataHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); Map<DataType, Long> getTypeHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); long getSelectionCount(final DatasetPath datasetPath, final DatasetVersion version,
final SqlQuery datasetQuery, final DataType dataType, final String colName, Set<String> selectedValues, BufferAllocator allocator); } | HistogramGenerator { @VisibleForTesting static void produceRanges(List<Number> ranges, LocalDateTime min, LocalDateTime max, TruncEvalEnum truncateTo) { long timeValue = toMillis(roundTime(min, truncateTo, true)); long maxTimeValue = toMillis(roundTime(max, truncateTo, false)); ranges.add(timeValue); while ( timeValue <= maxTimeValue) { LocalDateTime tmpValue = new LocalDateTime(timeValue, DateTimeZone.UTC); switch (truncateTo) { case SECOND: timeValue = toMillis(tmpValue.plusSeconds(1)); break; case MINUTE: timeValue = toMillis(tmpValue.plusMinutes(1)); break; case HOUR: timeValue = toMillis(tmpValue.plusHours(1)); break; case DAY: timeValue = toMillis(tmpValue.plusDays(1)); break; case WEEK: timeValue = toMillis(tmpValue.plusWeeks(1)); break; case MONTH: timeValue = toMillis(tmpValue.plusMonths(1)); break; case QUARTER: timeValue = toMillis(tmpValue.plusMonths(3)); break; case YEAR: timeValue = toMillis(tmpValue.plusYears(1)); break; case DECADE: timeValue = toMillis(tmpValue.plusYears(10)); break; case CENTURY: timeValue = toMillis(tmpValue.plusYears(100)); break; case MILLENNIUM: timeValue = toMillis(tmpValue.plusYears(1000)); default: break; } ranges.add(timeValue); if (ranges.size() > 100_000) { throw new AssertionError(String.format("the ranges size should not grow that big: min: %s, max: %s, t: %s", min, max, truncateTo)); } } } HistogramGenerator(QueryExecutor executor); Histogram<HistogramValue> getHistogram(final DatasetPath datasetPath, DatasetVersion version, Selection selection,
DataType colType, SqlQuery datasetQuery, BufferAllocator allocator); Histogram<CleanDataHistogramValue> getCleanDataHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); Map<DataType, Long> getTypeHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery, BufferAllocator allocator); long getSelectionCount(final DatasetPath datasetPath, final DatasetVersion version,
final SqlQuery datasetQuery, final DataType dataType, final String colName, Set<String> selectedValues, BufferAllocator allocator); } |
@Test public void testLegalUpgrade() throws Exception { final ByteString prevEdition = ByteString.copyFrom("OSS".getBytes()); final ConfigurationEntry configurationEntry = new ConfigurationEntry(); configurationEntry.setValue(prevEdition); final LegacyKVStoreProvider kvStoreProvider = LegacyKVStoreProviderAdapter.inMemory(CLASSPATH_SCAN_RESULT); kvStoreProvider.start(); final ConfigurationStore configurationStore = new ConfigurationStore(kvStoreProvider); new Upgrade(DACConfig.newConfig(), CLASSPATH_SCAN_RESULT, false).validateUpgrade(kvStoreProvider, "OSS"); configurationStore.put(SupportService.DREMIO_EDITION, configurationEntry); new Upgrade(DACConfig.newConfig(), CLASSPATH_SCAN_RESULT, false).validateUpgrade(kvStoreProvider, "OSS"); } | @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); static final Comparator<Version> UPGRADE_VERSION_ORDERING; } |
@Test public void validateZipDirectoryValidNatural() throws IOException { ZipEntry entry = new ZipEntry("somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirWithTrailingSlash, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirInPrivateMappedDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirInPrivateMappedDirWithTrailingSlash, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryValidSelfref() throws IOException { ZipEntry entry = new ZipEntry("./somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirWithTrailingSlash, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirInPrivateMappedDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirInPrivateMappedDirWithTrailingSlash, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryValidUpdirThenCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../tmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirWithTrailingSlash, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryValidUpdirMoreTheCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../../../../../tmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); NativeLibPluginClassLoader.validateZipDirectory(mockTempDirWithTrailingSlash, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryValidNestedUpdirThenCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../nestedTmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryValidUpdirMoreThanNestedCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../../../../baseTmpDir/nestedTmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryZipSlipTestUpdirMoreThanNestedCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../../../../../baseTmpDir/nestedTmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryZipSlipTestUpdirMoreThanNestedCorrectDir2() throws IOException { ZipEntry entry = new ZipEntry("../../../../../../../../../../../baseTmpDir/nestedTmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test(expected = IOException.class) public void validateZipDirectoryZipSlipTestUpdirMoreThanNestedCorrectDirFinalDirDifferent() throws IOException { ZipEntry entry = new ZipEntry("../../../../../baseTmpDir/nestedTmpDir2/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test(expected = IOException.class) public void validateZipDirectoryZipSlipTestNested() throws IOException { ZipEntry entry = new ZipEntry("../tmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void testExtractMapRules() throws Exception { List<ExtractMapRule> rules = recommender.getRules(new MapSelection("foo", ImmutableList.of("a")), DataType.MAP); assertEquals(1, rules.size()); assertEquals("a", rules.get(0).getPath()); } | @Override public List<ExtractMapRule> getRules(MapSelection selection, DataType selColType) { checkArgument(selColType == DataType.MAP, "Extract map entries is supported only on MAP type columns"); return Collections.singletonList(new ExtractMapRule(Joiner.on(".").join(selection.getMapPathList()))); } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public List<ExtractMapRule> getRules(MapSelection selection, DataType selColType) { checkArgument(selColType == DataType.MAP, "Extract map entries is supported only on MAP type columns"); return Collections.singletonList(new ExtractMapRule(Joiner.on(".").join(selection.getMapPathList()))); } } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public List<ExtractMapRule> getRules(MapSelection selection, DataType selColType) { checkArgument(selColType == DataType.MAP, "Extract map entries is supported only on MAP type columns"); return Collections.singletonList(new ExtractMapRule(Joiner.on(".").join(selection.getMapPathList()))); } } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public List<ExtractMapRule> getRules(MapSelection selection, DataType selColType) { checkArgument(selColType == DataType.MAP, "Extract map entries is supported only on MAP type columns"); return Collections.singletonList(new ExtractMapRule(Joiner.on(".").join(selection.getMapPathList()))); } @Override List<ExtractMapRule> getRules(MapSelection selection, DataType selColType); @Override TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule); } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public List<ExtractMapRule> getRules(MapSelection selection, DataType selColType) { checkArgument(selColType == DataType.MAP, "Extract map entries is supported only on MAP type columns"); return Collections.singletonList(new ExtractMapRule(Joiner.on(".").join(selection.getMapPathList()))); } @Override List<ExtractMapRule> getRules(MapSelection selection, DataType selColType); @Override TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule); } |
@Test(expected = IOException.class) public void validateZipDirectoryZipSlipTestNestedUpdirMore() throws IOException { ZipEntry entry = new ZipEntry("../../../../../tmpDir/somedir/somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockNestedTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test(expected = IOException.class) public void validateZipDirectoryZipSlipTest() throws IOException { ZipEntry entry = new ZipEntry("../somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test(expected = IOException.class) public void validateZipDirectoryZipSlipTestUpMoreDirs() throws IOException { ZipEntry entry = new ZipEntry("../../../../../somefile"); NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void validateZipDirectoryZipSlipTestUpDirsMispelledCorrectDir() throws IOException { ZipEntry entry = new ZipEntry("../../../.. NativeLibPluginClassLoader.validateZipDirectory(mockTempDir, entry); } | @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } | NativeLibPluginClassLoader extends PluginClassLoader { @VisibleForTesting static void validateZipDirectory(Path tempDirectory, final ZipEntry entry) throws IOException { final Path destinationPath = tempDirectory.resolve(entry.getName()).normalize(); if (!destinationPath.startsWith(tempDirectory)) { throw new IOException(String.format("JAR entry %s is outside of the target directory %s. ", entry.getName(), tempDirectory)); } } NativeLibPluginClassLoader(Path pluginPath, PluginManager pluginManager,
PluginDescriptor pluginDescriptor, ClassLoader parent); @Override void close(); } |
@Test public void testYarnController() throws Exception { assumeNonMaprProfile(); YarnController yarnController = new YarnController(); YarnConfiguration yarnConfiguration = createYarnConfig("resource-manager", "hdfs: String jvmOptions = yarnController.prepareCommandOptions(yarnConfiguration, getProperties()); logger.info("JVMOptions: {}", jvmOptions); assertTrue(jvmOptions.contains(" -Dpaths.dist=pdfs: assertTrue(jvmOptions.contains(" -Xmx4096")); assertTrue(jvmOptions.contains(" -XX:MaxDirectMemorySize=5120m")); assertTrue(jvmOptions.contains(" -Xms4096m")); assertTrue(jvmOptions.contains(" -XX:ThreadStackSize=512")); assertTrue(jvmOptions.contains(" -Dzookeeper.saslprovider=com.mapr.security.maprsasl.MaprSaslProvider")); assertTrue(jvmOptions.contains(" -Dzookeeper.client.sasl=false")); assertTrue(jvmOptions.contains(" -Dzookeeper.sasl.clientconfig=Client")); assertTrue(jvmOptions.contains(" -Djava.security.auth.login.config=/opt/mapr/conf/mapr.login.conf")); assertTrue(jvmOptions.contains(" -Dpaths.spilling=[maprfs: assertFalse(jvmOptions.contains("JAVA_HOME")); assertTrue(jvmOptions.contains(" -DMAPR_IMPALA_RA_THROTTLE")); assertTrue(jvmOptions.contains(" -DMAPR_MAX_RA_STREAMS")); assertTrue(jvmOptions.contains(" -D" + DremioConfig.NETTY_REFLECTIONS_ACCESSIBLE + "=true")); assertTrue(jvmOptions.contains(" -D"+VM.DREMIO_CPU_AVAILABLE_PROPERTY + "=2")); DacDaemonYarnApplication.Environment myEnv = new DacDaemonYarnApplication.Environment() { @Override public String getEnv(String name) { return tempDir.getRoot().toString(); } }; DacDaemonYarnApplication dacDaemonApp = new DacDaemonYarnApplication(yarnController.dremioConfig, yarnConfiguration, myEnv); TwillSpecification twillSpec = dacDaemonApp.configure(); assertEquals(DacDaemonYarnApplication.YARN_APPLICATION_NAME_DEFAULT, twillSpec.getName()); Map<String, RuntimeSpecification> runnables = twillSpec.getRunnables(); assertNotNull(runnables); assertEquals(1, runnables.size()); RuntimeSpecification runnable = runnables.get(DacDaemonYarnApplication.YARN_RUNNABLE_NAME); assertNotNull(runnable); assertEquals(DacDaemonYarnApplication.YARN_RUNNABLE_NAME, runnable.getName()); assertEquals(9216, runnable.getResourceSpecification().getMemorySize()); assertEquals(2, runnable.getResourceSpecification().getVirtualCores()); assertEquals(3, runnable.getResourceSpecification().getInstances()); } | public YarnController() { this(DremioConfig.create()); } | YarnController { public YarnController() { this(DremioConfig.create()); } } | YarnController { public YarnController() { this(DremioConfig.create()); } YarnController(); YarnController(DremioConfig config); } | YarnController { public YarnController() { this(DremioConfig.create()); } YarnController(); YarnController(DremioConfig config); TwillRunnerService getTwillService(ClusterId key); void invalidateTwillService(final ClusterId key); TwillRunnerService startTwillRunner(YarnConfiguration yarnConfiguration); TwillController startCluster(YarnConfiguration yarnConfiguration, List<Property> propertyList); } | YarnController { public YarnController() { this(DremioConfig.create()); } YarnController(); YarnController(DremioConfig config); TwillRunnerService getTwillService(ClusterId key); void invalidateTwillService(final ClusterId key); TwillRunnerService startTwillRunner(YarnConfiguration yarnConfiguration); TwillController startCluster(YarnConfiguration yarnConfiguration, List<Property> propertyList); } |
@Test public void testStartCluster() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); Cluster cluster = new Cluster(); cluster.setState(ClusterState.CREATED); cluster.setStateChangeTime(System.currentTimeMillis()); cluster.setId(new ClusterId(UUID.randomUUID().toString())); ClusterConfig clusterConfig = new ClusterConfig(); clusterConfig.setClusterSpec(new ClusterSpec().setContainerCount(2).setMemoryMBOffHeap(4096).setMemoryMBOnHeap(4096).setVirtualCoreCount(2)); List<Property> propertyList = new ArrayList<>(); propertyList.add(new Property(FS_DEFAULT_NAME_KEY, "hdfs: propertyList.add(new Property(RM_HOSTNAME, "resource-manager")); propertyList.add(new Property(DremioConfig.DIST_WRITE_PATH_STRING, "pdfs: clusterConfig.setSubPropertyList(propertyList); cluster.setClusterConfig(clusterConfig); YarnConfiguration yarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(cluster, yarnConfig); assertNotNull(yarnConfig.get(FS_DEFAULT_NAME_KEY)); assertNotNull(yarnConfig.get(RM_HOSTNAME)); assertNotNull(yarnConfig.get(DremioConfig.DIST_WRITE_PATH_STRING)); assertEquals("hdfs: assertEquals("resource-manager", yarnConfig.get(RM_HOSTNAME)); assertEquals("pdfs: TwillController twillController = Mockito.mock(TwillController.class); RunId runId = RunIds.generate(); ResourceReport resourceReport = Mockito.mock(ResourceReport.class); when(controller.startCluster(any(YarnConfiguration.class), any(List.class))) .thenReturn(twillController); when(twillController.getRunId()).thenReturn(runId); when(twillController.getResourceReport()).thenReturn(resourceReport); ClusterEnriched clusterEnriched = yarnService.startCluster(cluster); assertNull(null,clusterEnriched.getRunTimeInfo()); assertEquals(ClusterState.STARTING, cluster.getState()); assertNotNull(cluster.getRunId()); assertEquals(runId.getId(), cluster.getRunId().getId()); } | @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testDistroDefaults() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); Cluster cluster = new Cluster(); cluster.setState(ClusterState.CREATED); cluster.setStateChangeTime(System.currentTimeMillis()); cluster.setId(new ClusterId(UUID.randomUUID().toString())); ClusterConfig clusterConfig = new ClusterConfig(); clusterConfig.setClusterSpec(new ClusterSpec().setContainerCount(2).setMemoryMBOffHeap(4096).setMemoryMBOnHeap(4096).setVirtualCoreCount(2)); clusterConfig.setIsSecure(false); clusterConfig.setDistroType(DistroType.MAPR); List<Property> propertyList = new ArrayList<>(); propertyList.add(new Property(FS_DEFAULT_NAME_KEY, "hdfs: propertyList.add(new Property(RM_HOSTNAME, "resource-manager")); propertyList.add(new Property(DremioConfig.DIST_WRITE_PATH_STRING, "pdfs: clusterConfig.setSubPropertyList(propertyList); cluster.setClusterConfig(clusterConfig); YarnConfiguration yarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(cluster, yarnConfig); assertNotNull(yarnConfig.get(FS_DEFAULT_NAME_KEY)); assertNotNull(yarnConfig.get(RM_HOSTNAME)); assertNotNull(yarnConfig.get(DremioConfig.DIST_WRITE_PATH_STRING)); assertEquals("hdfs: assertEquals("resource-manager", yarnConfig.get(RM_HOSTNAME)); assertEquals("pdfs: assertEquals("/opt/mapr/conf/mapr.login.conf", yarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", yarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client_simple", yarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.simplesasl.SimpleSaslProvider", yarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); Cluster myCluster = createCluster(); myCluster.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(true); YarnConfiguration myYarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(myCluster, myYarnConfig); assertEquals("/opt/mapr/conf/mapr.login.conf", myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.maprsasl.MaprSaslProvider", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); } | @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testDistroMapRDefaults() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); properties.clear(MAPR_IMPALA_RA_THROTTLE); properties.clear(MAPR_MAX_RA_STREAMS); Cluster myCluster = createCluster(); myCluster.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(true); YarnConfiguration myYarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(myCluster, myYarnConfig); assertEquals("/opt/mapr/conf/mapr.login.conf", myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.maprsasl.MaprSaslProvider", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); assertEquals("0", myYarnConfig.get(NETTY_MAX_DIRECT_MEMORY)); assertNull(myYarnConfig.get(MAPR_IMPALA_RA_THROTTLE)); assertNull(myYarnConfig.get(MAPR_MAX_RA_STREAMS)); Cluster myClusterOff = createCluster(); myClusterOff.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(false); YarnConfiguration myYarnConfigOff = new YarnConfiguration(); yarnService.updateYarnConfiguration(myClusterOff, myYarnConfigOff); assertEquals("/opt/mapr/conf/mapr.login.conf", myYarnConfigOff.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client_simple", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.simplesasl.SimpleSaslProvider", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); assertEquals("0", myYarnConfigOff.get(NETTY_MAX_DIRECT_MEMORY)); assertNull(myYarnConfigOff.get(MAPR_IMPALA_RA_THROTTLE)); assertNull(myYarnConfigOff.get(MAPR_MAX_RA_STREAMS)); } | @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testDistroMapRDefaultsWithMaprRAStreams() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); properties.set("MAPR_IMPALA_RA_THROTTLE", ""); properties.set("MAPR_MAX_RA_STREAMS", "123"); Cluster myCluster = createCluster(); myCluster.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(true); YarnConfiguration myYarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(myCluster, myYarnConfig); assertEquals("/opt/mapr/conf/mapr.login.conf", myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.maprsasl.MaprSaslProvider", myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); assertEquals("0", myYarnConfig.get(NETTY_MAX_DIRECT_MEMORY)); assertEquals("", myYarnConfig.get(MAPR_IMPALA_RA_THROTTLE)); assertEquals("123", myYarnConfig.get(MAPR_MAX_RA_STREAMS)); Cluster myClusterOff = createCluster(); myClusterOff.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(false); YarnConfiguration myYarnConfigOff = new YarnConfiguration(); yarnService.updateYarnConfiguration(myClusterOff, myYarnConfigOff); assertEquals("/opt/mapr/conf/mapr.login.conf", myYarnConfigOff.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertEquals("false", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertEquals("Client_simple", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertEquals("com.mapr.security.simplesasl.SimpleSaslProvider", myYarnConfigOff.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"maprfs: .SPILL_PATH)); assertEquals("0", myYarnConfigOff.get(NETTY_MAX_DIRECT_MEMORY)); assertEquals("", myYarnConfigOff.get(MAPR_IMPALA_RA_THROTTLE)); assertEquals("123", myYarnConfigOff.get(MAPR_MAX_RA_STREAMS)); } | @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testDistroHDPDefaults() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); Cluster myCluster = createCluster(); myCluster.getClusterConfig().setDistroType(DistroType.HDP).setIsSecure(true); YarnConfiguration myYarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(myCluster, myYarnConfig); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"file: assertEquals("0", myYarnConfig.get(NETTY_MAX_DIRECT_MEMORY)); Cluster myClusterOff = createCluster(); myClusterOff.getClusterConfig().setDistroType(DistroType.MAPR).setIsSecure(false); YarnConfiguration myYarnConfigOff = new YarnConfiguration(); yarnService.updateYarnConfiguration(myClusterOff, myYarnConfigOff); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("[\"file: assertEquals("0", myYarnConfigOff.get(NETTY_MAX_DIRECT_MEMORY)); } | @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testGenExtractMapRuleWrapper() throws Exception { TransformRuleWrapper<ExtractMapRule> wrapper = recommender.wrapRule(new ExtractMapRule("a")); assertEquals("a", wrapper.getRule().getPath()); assertEquals("extract from map a", wrapper.describe()); assertEquals("tbl.foo.a IS NOT NULL", wrapper.getMatchFunctionExpr("tbl.foo")); assertEquals("tbl.foo.a", wrapper.getFunctionExpr("tbl.foo")); TransformRuleWrapper<ExtractMapRule> wrapper2 = recommender.wrapRule(new ExtractMapRule("c[0].b")); assertEquals("extract from map c[0].b", wrapper2.describe()); assertEquals("tbl.foo.c[0].b IS NOT NULL", wrapper2.getMatchFunctionExpr("tbl.foo")); assertEquals("tbl.foo.c[0].b", wrapper2.getFunctionExpr("tbl.foo")); } | @Override public TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule) { return new ExtractMapTransformRuleWrapper(rule); } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule) { return new ExtractMapTransformRuleWrapper(rule); } } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule) { return new ExtractMapTransformRuleWrapper(rule); } } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule) { return new ExtractMapTransformRuleWrapper(rule); } @Override List<ExtractMapRule> getRules(MapSelection selection, DataType selColType); @Override TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule); } | ExtractMapRecommender extends Recommender<ExtractMapRule, MapSelection> { @Override public TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule) { return new ExtractMapTransformRuleWrapper(rule); } @Override List<ExtractMapRule> getRules(MapSelection selection, DataType selColType); @Override TransformRuleWrapper<ExtractMapRule> wrapRule(ExtractMapRule rule); } |
@Test public void testDistroDefaultsOverwrite() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); Cluster myCluster = createCluster(); List<Property> props = myCluster.getClusterConfig().getSubPropertyList(); props.add(new Property(YarnDefaultsConfigurator.SPILL_PATH, "/abc/bcd")); props.add(new Property(YarnDefaultsConfigurator.JAVA_LOGIN, "/abc/bcd/login.conf")); myCluster.getClusterConfig().setDistroType(DistroType.HDP).setIsSecure(true); YarnConfiguration myYarnConfig = new YarnConfiguration(); yarnService.updateYarnConfiguration(myCluster, myYarnConfig); assertEquals("/abc/bcd/login.conf", myYarnConfig.get(YarnDefaultsConfigurator.JAVA_LOGIN)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_CLIENT_CONFIG)); assertNull(myYarnConfig.get(YarnDefaultsConfigurator.ZK_SASL_PROVIDER)); assertEquals("/abc/bcd", myYarnConfig.get(YarnDefaultsConfigurator.SPILL_PATH)); } | @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @VisibleForTesting protected String updateYarnConfiguration(Cluster cluster, YarnConfiguration yarnConfiguration) { String rmAddress = null; setYarnDefaults(cluster, yarnConfiguration); List<Property> keyValues = cluster.getClusterConfig().getSubPropertyList(); if ( keyValues != null && !keyValues.isEmpty()) { for (Property property : keyValues) { yarnConfiguration.set(property.getKey(), property.getValue()); if (RM_HOSTNAME.equalsIgnoreCase(property.getKey())) { rmAddress = property.getValue(); } } } String queue = cluster.getClusterConfig().getClusterSpec().getQueue(); if (queue != null && !queue.isEmpty()) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_QUEUE_NAME, queue); } Integer memoryOnHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); Integer memoryOffHeap = cluster.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); Preconditions.checkNotNull(memoryOnHeap, "Heap Memory is not specified"); Preconditions.checkNotNull(memoryOffHeap, "Direct Memory is not specified"); final int totalMemory = memoryOnHeap.intValue() + memoryOffHeap.intValue(); final double heapToDirectMemRatio = (double) (memoryOnHeap.intValue()) / totalMemory; yarnConfiguration.setDouble(HEAP_RESERVED_MIN_RATIO, Math.min(heapToDirectMemRatio, 0.1D)); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_ON_HEAP, memoryOnHeap.intValue()); yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_MEMORY_OFF_HEAP, memoryOffHeap.intValue()); yarnConfiguration.setInt(JAVA_RESERVED_MEMORY_MB, memoryOffHeap.intValue()); Integer cpu = cluster.getClusterConfig().getClusterSpec().getVirtualCoreCount(); if (cpu != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CPU, cpu.intValue()); } Integer containerCount = cluster.getClusterConfig().getClusterSpec().getContainerCount(); if (containerCount != null) { yarnConfiguration.setInt(DacDaemonYarnApplication.YARN_CONTAINER_COUNT, containerCount.intValue()); } String clusterName = cluster.getClusterConfig().getName(); if (clusterName != null) { yarnConfiguration.set(DacDaemonYarnApplication.YARN_APP_NAME, clusterName); } yarnConfiguration.set(YARN_CLUSTER_ID, cluster.getId().getId()); return rmAddress; } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testMemorySplit() throws Exception { assumeNonMaprProfile(); try ( final LegacyKVStoreProvider kvstore = LegacyKVStoreProviderAdapter.inMemory(DremioTest.CLASSPATH_SCAN_RESULT)) { SingletonRegistry registry = new SingletonRegistry(); registry.bind(LegacyKVStoreProvider.class, kvstore); registry.start(); ProvisioningService service = Mockito.spy(new ProvisioningServiceImpl( DremioConfig.create(), registry.provider(LegacyKVStoreProvider.class), Mockito.mock(NodeProvider.class), DremioTest.CLASSPATH_SCAN_RESULT, DirectProvider.wrap(null), DirectProvider.wrap(null))); service.start(); ProvisioningResource resource = new ProvisioningResource(service); List<Property> props = new ArrayList<>(); props.add(new Property(ProvisioningService.YARN_HEAP_SIZE_MB_PROPERTY, "2048")); props.add(new Property(FS_DEFAULT_NAME_KEY, "hdfs: props.add(new Property("yarn.resourcemanager.hostname", "resource-manager")); ClusterCreateRequest createRequest = ClusterCreateRequest.builder() .setClusterType(ClusterType.YARN) .setDynamicConfig(DynamicConfig.builder().setContainerCount(2).build()) .setYarnProps(YarnPropsApi.builder() .setVirtualCoreCount(2) .setMemoryMB(8192) .setSubPropertyList(props) .build()) .build(); doReturn(new ClusterEnriched()).when(service).startCluster(any(ClusterId.class)); try { resource.createCluster(createRequest); } catch (NullPointerException e) { } LegacyKVStore<ClusterId, Cluster> store = registry.provider(LegacyKVStoreProvider.class).get().getStore(ProvisioningServiceImpl.ProvisioningStoreCreator.class); Iterable<Map.Entry<ClusterId, Cluster>> entries = store.find(); assertTrue(entries.iterator().hasNext()); int count = 0; for (Map.Entry<ClusterId, Cluster> entry : entries) { Cluster clusterEntry = entry.getValue(); int offHeap = clusterEntry.getClusterConfig().getClusterSpec().getMemoryMBOffHeap(); assertEquals(8192-2048, offHeap); int onHeap = clusterEntry.getClusterConfig().getClusterSpec().getMemoryMBOnHeap(); assertEquals(2048, onHeap); count++; } assertEquals(1, count); } } | @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testUpdater() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); final TestListener listener = new TestListener(); YarnService yarnService = new YarnService(listener, controller, Mockito.mock(NodeProvider.class)); final Cluster cluster = createCluster(); final TwillController twillController = Mockito.mock(TwillController.class); RunId runId = RunIds.generate(); ResourceReport resourceReport = Mockito.mock(ResourceReport.class); when(controller.startCluster(any(YarnConfiguration.class), any(List.class))) .thenReturn(twillController); when(twillController.getRunId()).thenReturn(runId); when(twillController.getResourceReport()).thenReturn(resourceReport); final Future<? extends ServiceController> futureController1 = Executors.newSingleThreadExecutor() .submit(new Runnable() { @Override public void run() { } }, twillController ); doAnswer(new Answer<Future<? extends ServiceController>>() { @Override public Future<? extends ServiceController> answer(InvocationOnMock invocationOnMock) throws Throwable { return futureController1; } }).when(twillController).terminate(); final YarnService.OnRunningRunnable onRunning = yarnService.new OnRunningRunnable(cluster); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { try { Thread.sleep(100); onRunning.run(); System.out.println("run"); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }).when(twillController).onRunning(any(Runnable.class), any(Executor.class)); final YarnService.OnTerminatingRunnable onTerminating = yarnService.new OnTerminatingRunnable(cluster, twillController); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { try { Thread.sleep(1000); onTerminating.run(); System.out.println("terminate"); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }).when(twillController).onTerminated(any(Runnable.class), any(Executor.class)); cluster.setState(ClusterState.CREATED); cluster.setStateChangeTime(System.currentTimeMillis()); ClusterEnriched clusterEnriched = yarnService.startCluster(cluster); assertEquals(ClusterState.STOPPED, clusterEnriched.getCluster().getState()); assertNull(cluster.getRunId()); assertTrue(yarnService.terminatingThreads.isEmpty()); } | @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testFailedUpdater() throws Exception { assumeNonMaprProfile(); YarnController controller = Mockito.mock(YarnController.class); final TestListener listener = new TestListener(); YarnService yarnService = new YarnService(listener, controller, Mockito.mock(NodeProvider.class)); final Cluster cluster = createCluster(); cluster.setDesiredState(ClusterState.RUNNING); final TwillController twillController = Mockito.mock(TwillController.class); RunId runId = RunIds.generate(); ResourceReport resourceReport = Mockito.mock(ResourceReport.class); when(controller.startCluster(any(YarnConfiguration.class), any(List.class))) .thenReturn(twillController); when(twillController.getRunId()).thenReturn(runId); when(twillController.getResourceReport()).thenReturn(resourceReport); final Future<? extends ServiceController> futureController1 = Executors.newSingleThreadExecutor() .submit(new Runnable() { @Override public void run() { } }, twillController ); doAnswer(new Answer<Future<? extends ServiceController>>() { @Override public Future<? extends ServiceController> answer(InvocationOnMock invocationOnMock) throws Throwable { return futureController1; } }).when(twillController).terminate(); final YarnService.OnRunningRunnable onRunning = yarnService.new OnRunningRunnable(cluster); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { try { Thread.sleep(100); onRunning.run(); System.out.println("run"); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }).when(twillController).onRunning(any(Runnable.class), any(Executor.class)); final YarnService.OnTerminatingRunnable onTerminatingNoOP = yarnService.new OnTerminatingRunnable(cluster, twillController); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { try { Thread.sleep(1000); cluster.setState(ClusterState.FAILED); cluster.setStateChangeTime(System.currentTimeMillis()); cluster.setError("My error"); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }).when(twillController).onTerminated(any(Runnable.class), any(Executor.class)); ClusterEnriched clusterEnriched = yarnService.startCluster(cluster); assertEquals(ClusterState.FAILED, clusterEnriched.getCluster().getState()); assertEquals("My error", clusterEnriched.getCluster().getError()); assertEquals(ClusterState.RUNNING, clusterEnriched.getCluster().getDesiredState()); } | @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public ClusterEnriched startCluster(Cluster cluster) throws YarnProvisioningHandlingException { Preconditions.checkArgument(cluster.getState() != ClusterState.RUNNING); return startClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
@Test public void testStopCluster() throws Exception { assumeNonMaprProfile(); Cluster myCluster = createCluster(); myCluster.setState(ClusterState.RUNNING); myCluster.setStateChangeTime(System.currentTimeMillis()); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); TwillController twillController = Mockito.mock(TwillController.class); RunId runId = RunIds.generate(); when(controller.startCluster(any(YarnConfiguration.class), eq(myCluster.getClusterConfig().getSubPropertyList()))) .thenReturn(twillController); when(twillController.getRunId()).thenReturn(runId); myCluster.setRunId(new com.dremio.provision.RunId(runId.getId())); yarnService.stopCluster(myCluster); assertEquals(ClusterState.STOPPED, myCluster.getState()); } | @Override public void stopCluster(Cluster cluster) throws YarnProvisioningHandlingException { stopClusterAsync(cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public void stopCluster(Cluster cluster) throws YarnProvisioningHandlingException { stopClusterAsync(cluster); } } | YarnService implements ProvisioningServiceDelegate { @Override public void stopCluster(Cluster cluster) throws YarnProvisioningHandlingException { stopClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); } | YarnService implements ProvisioningServiceDelegate { @Override public void stopCluster(Cluster cluster) throws YarnProvisioningHandlingException { stopClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } | YarnService implements ProvisioningServiceDelegate { @Override public void stopCluster(Cluster cluster) throws YarnProvisioningHandlingException { stopClusterAsync(cluster); } YarnService(DremioConfig config, ProvisioningStateListener stateListener, NodeProvider executionNodeProvider,
OptionManager options, EditionProvider editionProvider); @VisibleForTesting YarnService(ProvisioningStateListener stateListener, YarnController controller, NodeProvider executionNodeProvider); @Override ClusterType getType(); @Override ClusterEnriched startCluster(Cluster cluster); @Override void stopCluster(Cluster cluster); @Override ClusterEnriched resizeCluster(Cluster cluster); @Override ClusterEnriched getClusterInfo(final Cluster cluster); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.