HDFS-13886. HttpFSFileSystem.getFileStatus() doesn't return "snapshot enabled" bit. Contributed by Siyao Meng.

This commit is contained in:
Wei-Chiu Chuang 2018-09-18 15:33:02 -07:00
parent 8382b860d4
commit 44857476fa
3 changed files with 38 additions and 2 deletions

View File

@ -199,7 +199,7 @@ public class HttpFSFileSystem extends FileSystem
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";

View File

@ -120,6 +120,9 @@ public class FSOperations {
if (fileStatus.getPermission().getErasureCodedBit()) {
json.put(HttpFSFileSystem.EC_BIT_JSON, true);
}
if (fileStatus.isSnapshotEnabled()) {
json.put(HttpFSFileSystem.SNAPSHOT_BIT_JSON, true);
}
return json;
}

View File

@ -376,6 +376,35 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
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 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
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 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
case DELETE_SNAPSHOT:
testDeleteSnapshot();
break;
case FILE_STATUS_ATTR:
testFileStatusAttr();
break;
}
}