From 44857476fa993fbf9c97f979b91e19d27632c10a Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Tue, 18 Sep 2018 15:33:02 -0700 Subject: [PATCH] HDFS-13886. HttpFSFileSystem.getFileStatus() doesn't return "snapshot enabled" bit. Contributed by Siyao Meng. --- .../fs/http/client/HttpFSFileSystem.java | 2 +- .../hadoop/fs/http/server/FSOperations.java | 3 ++ .../fs/http/client/BaseTestHttpFSWith.java | 35 ++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java index ce76f05fb8..dd285d4dfc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java @@ -199,7 +199,7 @@ public static FILE_TYPE getType(FileStatus fileStatus) { public static final String ENC_BIT_JSON = "encBit"; public static final String EC_BIT_JSON = "ecBit"; - public static final String SNAPSHOT_BIT_JSON = "seBit"; + public static final String SNAPSHOT_BIT_JSON = "snapshotEnabled"; public static final String DIRECTORY_LISTING_JSON = "DirectoryListing"; public static final String PARTIAL_LISTING_JSON = "partialListing"; diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java index 1d47a61af5..a3c45c7982 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java @@ -120,6 +120,9 @@ private static Map toJsonInner(FileStatus fileStatus, if (fileStatus.getPermission().getErasureCodedBit()) { json.put(HttpFSFileSystem.EC_BIT_JSON, true); } + if (fileStatus.isSnapshotEnabled()) { + json.put(HttpFSFileSystem.SNAPSHOT_BIT_JSON, true); + } return json; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java index a6dce4da10..8dabdeaa6d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java @@ -376,6 +376,35 @@ private void testListStatus() throws Exception { Assert.assertEquals(stati[0].getPath(), statl[0].getPath()); } + private void testFileStatusAttr() throws Exception { + if (!this.isLocalFS()) { + // Create a directory + Path path = new Path("/tmp/tmp-snap-test"); + DistributedFileSystem distributedFs = (DistributedFileSystem) FileSystem + .get(path.toUri(), this.getProxiedFSConf()); + distributedFs.mkdirs(path); + // Get the FileSystem instance that's being tested + FileSystem fs = this.getHttpFSFileSystem(); + // Check FileStatus + assertFalse("Snapshot should be disallowed by default", + fs.getFileStatus(path).isSnapshotEnabled()); + // Allow snapshot + distributedFs.allowSnapshot(path); + // Check FileStatus + assertTrue("Snapshot enabled bit is not set in FileStatus", + fs.getFileStatus(path).isSnapshotEnabled()); + // Disallow snapshot + distributedFs.disallowSnapshot(path); + // Check FileStatus + assertFalse("Snapshot enabled bit is not cleared in FileStatus", + fs.getFileStatus(path).isSnapshotEnabled()); + // Cleanup + fs.delete(path, true); + fs.close(); + distributedFs.close(); + } + } + private static void assertSameListing(FileSystem expected, FileSystem actual, Path p) throws IOException { // Consume all the entries from both iterators @@ -1041,7 +1070,8 @@ protected enum Operation { SET_REPLICATION, CHECKSUM, CONTENT_SUMMARY, FILEACLS, DIRACLS, SET_XATTR, GET_XATTRS, REMOVE_XATTR, LIST_XATTRS, ENCRYPTION, LIST_STATUS_BATCH, GETTRASHROOT, STORAGEPOLICY, ERASURE_CODING, - CREATE_SNAPSHOT, RENAME_SNAPSHOT, DELETE_SNAPSHOT + CREATE_SNAPSHOT, RENAME_SNAPSHOT, DELETE_SNAPSHOT, + FILE_STATUS_ATTR } private void operation(Operation op) throws Exception { @@ -1139,6 +1169,9 @@ private void operation(Operation op) throws Exception { case DELETE_SNAPSHOT: testDeleteSnapshot(); break; + case FILE_STATUS_ATTR: + testFileStatusAttr(); + break; } }