|
@@ -57,6 +57,7 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERV
|
|
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
|
|
|
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
|
|
|
|
|
|
+import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
import org.junit.After;
|
|
|
import org.junit.AfterClass;
|
|
|
import org.junit.Before;
|
|
@@ -191,34 +192,38 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
|
|
|
|
|
|
@Test
|
|
|
public void testTrashRootsAfterEncryptionZoneDeletion() throws Exception {
|
|
|
- final Path zone = new Path("/EZ");
|
|
|
- fsTarget.mkdirs(zone);
|
|
|
- final Path zone1 = new Path("/EZ/zone1");
|
|
|
- fsTarget.mkdirs(zone1);
|
|
|
-
|
|
|
- DFSTestUtil.createKey("test_key", cluster, CONF);
|
|
|
- HdfsAdmin hdfsAdmin = new HdfsAdmin(cluster.getURI(0), CONF);
|
|
|
- final EnumSet<CreateEncryptionZoneFlag> provisionTrash =
|
|
|
- EnumSet.of(CreateEncryptionZoneFlag.PROVISION_TRASH);
|
|
|
- hdfsAdmin.createEncryptionZone(zone1, "test_key", provisionTrash);
|
|
|
-
|
|
|
- final Path encFile = new Path(zone1, "encFile");
|
|
|
- DFSTestUtil.createFile(fsTarget, encFile, 10240, (short) 1, 0xFEED);
|
|
|
-
|
|
|
- Configuration clientConf = new Configuration(CONF);
|
|
|
- clientConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
|
|
|
- clientConf.set("fs.default.name", fsTarget.getUri().toString());
|
|
|
- FsShell shell = new FsShell(clientConf);
|
|
|
-
|
|
|
- //Verify file deletion within EZ
|
|
|
- DFSTestUtil.verifyDelete(shell, fsTarget, encFile, true);
|
|
|
- assertTrue("ViewFileSystem trash roots should include EZ file trash",
|
|
|
- (fsView.getTrashRoots(true).size() == 1));
|
|
|
-
|
|
|
- //Verify deletion of EZ
|
|
|
- DFSTestUtil.verifyDelete(shell, fsTarget, zone, true);
|
|
|
- assertTrue("ViewFileSystem trash roots should include EZ zone trash",
|
|
|
- (fsView.getTrashRoots(true).size() == 2));
|
|
|
+ try {
|
|
|
+ final Path zone = new Path("/EZ");
|
|
|
+ fsTarget.mkdirs(zone);
|
|
|
+ final Path zone1 = new Path("/EZ/zone1");
|
|
|
+ fsTarget.mkdirs(zone1);
|
|
|
+
|
|
|
+ DFSTestUtil.createKey("test_key", cluster, CONF);
|
|
|
+ HdfsAdmin hdfsAdmin = new HdfsAdmin(cluster.getURI(0), CONF);
|
|
|
+ final EnumSet<CreateEncryptionZoneFlag> provisionTrash =
|
|
|
+ EnumSet.of(CreateEncryptionZoneFlag.PROVISION_TRASH);
|
|
|
+ hdfsAdmin.createEncryptionZone(zone1, "test_key", provisionTrash);
|
|
|
+
|
|
|
+ final Path encFile = new Path(zone1, "encFile");
|
|
|
+ DFSTestUtil.createFile(fsTarget, encFile, 10240, (short) 1, 0xFEED);
|
|
|
+
|
|
|
+ Configuration clientConf = new Configuration(CONF);
|
|
|
+ clientConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
|
|
|
+ clientConf.set("fs.default.name", fsTarget.getUri().toString());
|
|
|
+ FsShell shell = new FsShell(clientConf);
|
|
|
+
|
|
|
+ //Verify file deletion within EZ
|
|
|
+ DFSTestUtil.verifyDelete(shell, fsTarget, encFile, true);
|
|
|
+ assertTrue("ViewFileSystem trash roots should include EZ file trash",
|
|
|
+ (fsView.getTrashRoots(true).size() == 1));
|
|
|
+
|
|
|
+ //Verify deletion of EZ
|
|
|
+ DFSTestUtil.verifyDelete(shell, fsTarget, zone, true);
|
|
|
+ assertTrue("ViewFileSystem trash roots should include EZ zone trash",
|
|
|
+ (fsView.getTrashRoots(true).size() == 2));
|
|
|
+ } finally {
|
|
|
+ DFSTestUtil.deleteKey("test_key", cluster);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -506,4 +511,92 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
|
|
|
assertEquals(fs.getFileStatus(subDirOfInternalDir).getPermission(),
|
|
|
fs.getFileStatus(subDirOfRealDir).getPermission());
|
|
|
}
|
|
|
+
|
|
|
+ private Path getViewFsPath(Path path, FileSystem fs) {
|
|
|
+ return fs.makeQualified(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Path getViewFsPath(String path, FileSystem fs) {
|
|
|
+ return getViewFsPath(new Path(path), fs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEnclosingRootsBase() throws Exception {
|
|
|
+ try {
|
|
|
+ final Path zone = new Path("/data/EZ");
|
|
|
+ fsTarget.mkdirs(zone);
|
|
|
+ final Path zone1 = new Path("/data/EZ/zone1");
|
|
|
+ fsTarget.mkdirs(zone1);
|
|
|
+
|
|
|
+ DFSTestUtil.createKey("test_key", cluster, 0, CONF);
|
|
|
+ HdfsAdmin hdfsAdmin = new HdfsAdmin(cluster.getURI(0), CONF);
|
|
|
+ final EnumSet<CreateEncryptionZoneFlag> provisionTrash =
|
|
|
+ EnumSet.of(CreateEncryptionZoneFlag.PROVISION_TRASH);
|
|
|
+ hdfsAdmin.createEncryptionZone(zone1, "test_key", provisionTrash);
|
|
|
+ assertEquals(fsView.getEnclosingRoot(zone), getViewFsPath("/data", fsView));
|
|
|
+ assertEquals(fsView.getEnclosingRoot(zone1), getViewFsPath(zone1, fsView));
|
|
|
+
|
|
|
+ Path nn02Ez = new Path("/mountOnNn2/EZ");
|
|
|
+ fsTarget2.mkdirs(nn02Ez);
|
|
|
+ assertEquals(fsView.getEnclosingRoot((nn02Ez)), getViewFsPath("/mountOnNn2", fsView));
|
|
|
+ HdfsAdmin hdfsAdmin2 = new HdfsAdmin(cluster.getURI(1), CONF);
|
|
|
+ DFSTestUtil.createKey("test_key", cluster, 1, CONF);
|
|
|
+ hdfsAdmin2.createEncryptionZone(nn02Ez, "test_key", provisionTrash);
|
|
|
+ assertEquals(fsView.getEnclosingRoot((nn02Ez)), getViewFsPath(nn02Ez, fsView));
|
|
|
+ assertEquals(fsView.getEnclosingRoot(new Path(nn02Ez, "dir/dir2/file")),
|
|
|
+ getViewFsPath(nn02Ez, fsView));
|
|
|
+
|
|
|
+ // With viewfs:// scheme
|
|
|
+ assertEquals(fsView.getEnclosingRoot(fsView.getWorkingDirectory()),
|
|
|
+ getViewFsPath("/user", fsView));
|
|
|
+ } finally {
|
|
|
+ DFSTestUtil.deleteKey("test_key", cluster, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEnclosingRootFailure() throws Exception {
|
|
|
+ LambdaTestUtils.intercept(NotInMountpointException.class,
|
|
|
+ ()-> fsView.getEnclosingRoot(new Path("/does/not/exist")));
|
|
|
+
|
|
|
+ final Path zone = new Path("/data/EZ");
|
|
|
+ Path fs1 = fsTarget.makeQualified(zone);
|
|
|
+
|
|
|
+ LambdaTestUtils.intercept(IllegalArgumentException.class,
|
|
|
+ ()-> fsView.getEnclosingRoot(fs1));
|
|
|
+ LambdaTestUtils.intercept(IllegalArgumentException.class,
|
|
|
+ ()-> fsView.getEnclosingRoot(new Path("hdfs://fakeAuthority/")));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEnclosingRootWrapped() throws Exception {
|
|
|
+ try {
|
|
|
+ final Path zone = new Path("/data/EZ");
|
|
|
+ fsTarget.mkdirs(zone);
|
|
|
+ final Path zone1 = new Path("/data/EZ/testZone1");
|
|
|
+ fsTarget.mkdirs(zone1);
|
|
|
+
|
|
|
+ DFSTestUtil.createKey("test_key", cluster, 0, CONF);
|
|
|
+ HdfsAdmin hdfsAdmin = new HdfsAdmin(cluster.getURI(0), CONF);
|
|
|
+ final EnumSet<CreateEncryptionZoneFlag> provisionTrash =
|
|
|
+ EnumSet.of(CreateEncryptionZoneFlag.PROVISION_TRASH);
|
|
|
+ hdfsAdmin.createEncryptionZone(zone1, "test_key", provisionTrash);
|
|
|
+
|
|
|
+ UserGroupInformation ugi = UserGroupInformation.createRemoteUser("foo");
|
|
|
+ Path p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> {
|
|
|
+ FileSystem wFs = FileSystem.get(FsConstants.VIEWFS_URI, this.conf);
|
|
|
+ return wFs.getEnclosingRoot(zone);
|
|
|
+ });
|
|
|
+ assertEquals(p, getViewFsPath("/data", fsView));
|
|
|
+ p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> {
|
|
|
+ FileSystem wFs = FileSystem.get(FsConstants.VIEWFS_URI, this.conf);
|
|
|
+ return wFs.getEnclosingRoot(zone1);
|
|
|
+ });
|
|
|
+ assertEquals(p, getViewFsPath(zone1, fsView));
|
|
|
+
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ DFSTestUtil.deleteKey("test_key", cluster, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|