HDFS-15418. CHeckstyle and test fixes
This commit is contained in:
parent
2d156bcbdd
commit
2c55c9a5cf
|
@ -213,8 +213,6 @@ public class ViewFileSystem extends FileSystem {
|
||||||
InodeTree<FileSystem> fsState; // the fs state; ie the mount table
|
InodeTree<FileSystem> fsState; // the fs state; ie the mount table
|
||||||
Path homeDir = null;
|
Path homeDir = null;
|
||||||
private boolean enableInnerCache = false;
|
private boolean enableInnerCache = false;
|
||||||
private static boolean showMountLinksAsSymlinks = true;
|
|
||||||
|
|
||||||
private InnerCache cache;
|
private InnerCache cache;
|
||||||
// Default to rename within same mountpoint
|
// Default to rename within same mountpoint
|
||||||
private RenameStrategy renameStrategy = RenameStrategy.SAME_MOUNTPOINT;
|
private RenameStrategy renameStrategy = RenameStrategy.SAME_MOUNTPOINT;
|
||||||
|
@ -271,9 +269,6 @@ public class ViewFileSystem extends FileSystem {
|
||||||
config = conf;
|
config = conf;
|
||||||
enableInnerCache = config.getBoolean(CONFIG_VIEWFS_ENABLE_INNER_CACHE,
|
enableInnerCache = config.getBoolean(CONFIG_VIEWFS_ENABLE_INNER_CACHE,
|
||||||
CONFIG_VIEWFS_ENABLE_INNER_CACHE_DEFAULT);
|
CONFIG_VIEWFS_ENABLE_INNER_CACHE_DEFAULT);
|
||||||
showMountLinksAsSymlinks = config
|
|
||||||
.getBoolean(CONFIG_VIEWFS_MOUNT_LINKS_AS_SYMLINKS,
|
|
||||||
CONFIG_VIEWFS_MOUNT_LINKS_AS_SYMLINKS_DEFAULT);
|
|
||||||
FsGetter fsGetter = fsGetter();
|
FsGetter fsGetter = fsGetter();
|
||||||
final InnerCache innerCache = new InnerCache(fsGetter);
|
final InnerCache innerCache = new InnerCache(fsGetter);
|
||||||
// Now build client side view (i.e. client side mount table) from config.
|
// Now build client side view (i.e. client side mount table) from config.
|
||||||
|
@ -1121,6 +1116,7 @@ public class ViewFileSystem extends FileSystem {
|
||||||
final long creationTime; // of the the mount table
|
final long creationTime; // of the the mount table
|
||||||
final UserGroupInformation ugi; // the user/group of user who created mtable
|
final UserGroupInformation ugi; // the user/group of user who created mtable
|
||||||
final URI myUri;
|
final URI myUri;
|
||||||
|
final boolean showMountLinksAsSymlinks;
|
||||||
|
|
||||||
public InternalDirOfViewFs(final InodeTree.INodeDir<FileSystem> dir,
|
public InternalDirOfViewFs(final InodeTree.INodeDir<FileSystem> dir,
|
||||||
final long cTime, final UserGroupInformation ugi, URI uri,
|
final long cTime, final UserGroupInformation ugi, URI uri,
|
||||||
|
@ -1134,6 +1130,9 @@ public class ViewFileSystem extends FileSystem {
|
||||||
theInternalDir = dir;
|
theInternalDir = dir;
|
||||||
creationTime = cTime;
|
creationTime = cTime;
|
||||||
this.ugi = ugi;
|
this.ugi = ugi;
|
||||||
|
showMountLinksAsSymlinks = config
|
||||||
|
.getBoolean(CONFIG_VIEWFS_MOUNT_LINKS_AS_SYMLINKS,
|
||||||
|
CONFIG_VIEWFS_MOUNT_LINKS_AS_SYMLINKS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static private void checkPathIsSlash(final Path f) throws IOException {
|
static private void checkPathIsSlash(final Path f) throws IOException {
|
||||||
|
@ -1240,9 +1239,9 @@ public class ViewFileSystem extends FileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We will represent as non-symlinks. Here it will show target
|
// We will represent as non-symlinks. Here it will show target
|
||||||
// directories properties like permissions, isDirectory etc on mount
|
// directory/file properties like permissions, isDirectory etc on
|
||||||
// path. The path will be a mount link path and isDirectory is true
|
// mount path. The path will be a mount link path and isDirectory is
|
||||||
// if target is dir, otherwise false.
|
// true if target is dir, otherwise false.
|
||||||
String linkedPath = link.getTargetFileSystem().getUri().getPath();
|
String linkedPath = link.getTargetFileSystem().getUri().getPath();
|
||||||
if ("".equals(linkedPath)) {
|
if ("".equals(linkedPath)) {
|
||||||
linkedPath = "/";
|
linkedPath = "/";
|
||||||
|
@ -1257,9 +1256,8 @@ public class ViewFileSystem extends FileSystem {
|
||||||
status.getPermission(), status.getOwner(), status.getGroup(),
|
status.getPermission(), status.getOwner(), status.getGroup(),
|
||||||
null, path);
|
null, path);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
LOG.warn(
|
LOG.warn("Cannot get one of the children's(" + path
|
||||||
"Cannot get one of the children's(" + path + ") target path("
|
+ ") target path(" + link.getTargetFileSystem().getUri()
|
||||||
+ link.getTargetFileSystem().getUri() + linkedPath
|
|
||||||
+ ") file status.", ex);
|
+ ") file status.", ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1007,8 +1007,7 @@ public class ViewFs extends AbstractFileSystem {
|
||||||
* will be listed in the returned result.
|
* will be listed in the returned result.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FileStatus[] listStatus(final Path f) throws AccessControlException,
|
public FileStatus[] listStatus(final Path f) throws IOException {
|
||||||
IOException {
|
|
||||||
checkPathIsSlash(f);
|
checkPathIsSlash(f);
|
||||||
FileStatus[] fallbackStatuses = listStatusForFallbackLink();
|
FileStatus[] fallbackStatuses = listStatusForFallbackLink();
|
||||||
FileStatus[] result = new FileStatus[theInternalDir.getChildren().size()];
|
FileStatus[] result = new FileStatus[theInternalDir.getChildren().size()];
|
||||||
|
@ -1034,9 +1033,9 @@ public class ViewFs extends AbstractFileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We will represent as non-symlinks. Here it will show target
|
// We will represent as non-symlinks. Here it will show target
|
||||||
// directories properties like permissions, isDirectory etc on mount
|
// directory/file properties like permissions, isDirectory etc on
|
||||||
// path. The path will be a mount link path and isDirectory is true
|
// mount path. The path will be a mount link path and isDirectory is
|
||||||
// if target is dir, otherwise false.
|
// true if target is dir, otherwise false.
|
||||||
String linkedPath = link.getTargetFileSystem().getUri().getPath();
|
String linkedPath = link.getTargetFileSystem().getUri().getPath();
|
||||||
if ("".equals(linkedPath)) {
|
if ("".equals(linkedPath)) {
|
||||||
linkedPath = "/";
|
linkedPath = "/";
|
||||||
|
@ -1051,9 +1050,8 @@ public class ViewFs extends AbstractFileSystem {
|
||||||
status.getPermission(), status.getOwner(), status.getGroup(),
|
status.getPermission(), status.getOwner(), status.getGroup(),
|
||||||
null, path);
|
null, path);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
LOG.warn(
|
LOG.warn("Cannot get one of the children's(" + path
|
||||||
"Cannot get one of the children's(" + path + ") target path("
|
+ ") target path(" + link.getTargetFileSystem().getUri()
|
||||||
+ link.getTargetFileSystem().getUri() + linkedPath
|
|
||||||
+ ") file status.", ex);
|
+ ") file status.", ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,21 +30,17 @@ import org.apache.hadoop.fs.FileUtil;
|
||||||
import org.apache.hadoop.fs.FsConstants;
|
import org.apache.hadoop.fs.FsConstants;
|
||||||
import org.apache.hadoop.fs.LocalFileSystem;
|
import org.apache.hadoop.fs.LocalFileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.contract.ContractTestUtils;
|
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.io.DataInputBuffer;
|
|
||||||
import org.apache.hadoop.io.DataOutputBuffer;
|
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ViewFsOverloadScheme ListStatus
|
* ViewFsOverloadScheme ListStatus.
|
||||||
*/
|
*/
|
||||||
public class TestViewFsOverloadSchemeListStatus {
|
public class TestViewFsOverloadSchemeListStatus {
|
||||||
|
|
||||||
|
@ -64,7 +60,8 @@ public class TestViewFsOverloadSchemeListStatus {
|
||||||
* Tests the ACL and isDirectory returned from listStatus for directories and
|
* Tests the ACL and isDirectory returned from listStatus for directories and
|
||||||
* files.
|
* files.
|
||||||
*/
|
*/
|
||||||
@Test public void testListStatusACL() throws IOException, URISyntaxException {
|
@Test
|
||||||
|
public void testListStatusACL() throws IOException, URISyntaxException {
|
||||||
String testfilename = "testFileACL";
|
String testfilename = "testFileACL";
|
||||||
String childDirectoryName = "testDirectoryACL";
|
String childDirectoryName = "testDirectoryACL";
|
||||||
TEST_DIR.mkdirs();
|
TEST_DIR.mkdirs();
|
||||||
|
@ -81,24 +78,24 @@ public class TestViewFsOverloadSchemeListStatus {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
ConfigUtil.addLink(conf, "/file", infile.toURI());
|
ConfigUtil.addLink(conf, "/file", infile.toURI());
|
||||||
ConfigUtil.addLink(conf, "/dir", childDir.toURI());
|
ConfigUtil.addLink(conf, "/dir", childDir.toURI());
|
||||||
String FILE_SCHEME = "file";
|
String fileScheme = "file";
|
||||||
conf.set(String.format("fs.%s.impl", FILE_SCHEME),
|
conf.set(String.format("fs.%s.impl", fileScheme),
|
||||||
ViewFileSystemOverloadScheme.class.getName());
|
ViewFileSystemOverloadScheme.class.getName());
|
||||||
conf.set(String
|
conf.set(String
|
||||||
.format(FsConstants.FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN,
|
.format(FsConstants.FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN,
|
||||||
FILE_SCHEME), LocalFileSystem.class.getName());
|
fileScheme), LocalFileSystem.class.getName());
|
||||||
String FILE_URI_STR = "file:///";
|
String fileUriStr = "file:///";
|
||||||
try (FileSystem vfs = FileSystem.get(new URI(FILE_URI_STR), conf)) {
|
try (FileSystem vfs = FileSystem.get(new URI(fileUriStr), conf)) {
|
||||||
assertEquals(ViewFileSystemOverloadScheme.class, vfs.getClass());
|
assertEquals(ViewFileSystemOverloadScheme.class, vfs.getClass());
|
||||||
FileStatus[] statuses = vfs.listStatus(new Path("/"));
|
FileStatus[] statuses = vfs.listStatus(new Path("/"));
|
||||||
|
|
||||||
FileSystem localFs = ((ViewFileSystemOverloadScheme) vfs)
|
FileSystem localFs = ((ViewFileSystemOverloadScheme) vfs)
|
||||||
.getRawFileSystem(new Path(FILE_URI_STR), conf);
|
.getRawFileSystem(new Path(fileUriStr), conf);
|
||||||
FileStatus fileStat = localFs.getFileStatus(new Path(infile.getPath()));
|
FileStatus fileStat = localFs.getFileStatus(new Path(infile.getPath()));
|
||||||
FileStatus dirStat = localFs.getFileStatus(new Path(childDir.getPath()));
|
FileStatus dirStat = localFs.getFileStatus(new Path(childDir.getPath()));
|
||||||
|
|
||||||
for (FileStatus status : statuses) {
|
for (FileStatus status : statuses) {
|
||||||
if (status.getPath().getName().equals(FILE_SCHEME)) {
|
if (status.getPath().getName().equals(fileScheme)) {
|
||||||
assertEquals(fileStat.getPermission(), status.getPermission());
|
assertEquals(fileStat.getPermission(), status.getPermission());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(dirStat.getPermission(), status.getPermission());
|
assertEquals(dirStat.getPermission(), status.getPermission());
|
||||||
|
@ -112,7 +109,7 @@ public class TestViewFsOverloadSchemeListStatus {
|
||||||
|
|
||||||
statuses = vfs.listStatus(new Path("/"));
|
statuses = vfs.listStatus(new Path("/"));
|
||||||
for (FileStatus status : statuses) {
|
for (FileStatus status : statuses) {
|
||||||
if (status.getPath().getName().equals(FILE_SCHEME)) {
|
if (status.getPath().getName().equals(fileScheme)) {
|
||||||
assertEquals(FsPermission.valueOf("-rwxr--r--"),
|
assertEquals(FsPermission.valueOf("-rwxr--r--"),
|
||||||
status.getPermission());
|
status.getPermission());
|
||||||
assertEquals(false, status.isDirectory());
|
assertEquals(false, status.isDirectory());
|
||||||
|
@ -125,7 +122,8 @@ public class TestViewFsOverloadSchemeListStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass public static void cleanup() throws IOException {
|
@AfterClass
|
||||||
|
public static void cleanup() throws IOException {
|
||||||
FileUtil.fullyDelete(TEST_DIR);
|
FileUtil.fullyDelete(TEST_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,11 @@ public class TestViewFileSystemOverloadSchemeHdfsFileSystemContract
|
||||||
assumeTrue(rootDirTestEnabled());
|
assumeTrue(rootDirTestEnabled());
|
||||||
Path dir = path("/");
|
Path dir = path("/");
|
||||||
Path child = path("/FileSystemContractBaseTest");
|
Path child = path("/FileSystemContractBaseTest");
|
||||||
|
try (FileSystem dfs = ((ViewFileSystemOverloadScheme) fs).getRawFileSystem(
|
||||||
|
new Path(conf.get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY), "/"),
|
||||||
|
conf)) {
|
||||||
|
dfs.mkdirs(child);
|
||||||
|
}
|
||||||
assertListStatusFinds(dir, child);
|
assertListStatusFinds(dir, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,17 @@ public class TestViewFileSystemOverloadSchemeWithHdfsScheme {
|
||||||
new String[] {hdfsTargetPath.toUri().toString(),
|
new String[] {hdfsTargetPath.toUri().toString(),
|
||||||
localTargetDir.toURI().toString() },
|
localTargetDir.toURI().toString() },
|
||||||
conf);
|
conf);
|
||||||
|
try (DistributedFileSystem dfs = new DistributedFileSystem()) {
|
||||||
|
dfs.initialize(defaultFSURI, conf);
|
||||||
|
dfs.mkdirs(hdfsTargetPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (RawLocalFileSystem lfs = new RawLocalFileSystem()) {
|
||||||
|
lfs.initialize(localTargetDir.toURI(), conf);
|
||||||
|
lfs.mkdirs(new Path(localTargetDir.toURI()));
|
||||||
|
}
|
||||||
try (FileSystem fs = FileSystem.get(conf)) {
|
try (FileSystem fs = FileSystem.get(conf)) {
|
||||||
|
fs.mkdirs(hdfsTargetPath);
|
||||||
FileStatus[] ls = fs.listStatus(new Path("/"));
|
FileStatus[] ls = fs.listStatus(new Path("/"));
|
||||||
Assert.assertEquals(2, ls.length);
|
Assert.assertEquals(2, ls.length);
|
||||||
String lsPath1 =
|
String lsPath1 =
|
||||||
|
|
Loading…
Reference in New Issue