|
@@ -18,25 +18,37 @@
|
|
|
package org.apache.hadoop.fs.viewfs;
|
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.util.EnumSet;
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.crypto.key.JavaKeyStoreProvider;
|
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
|
import org.apache.hadoop.fs.FsConstants;
|
|
|
+import org.apache.hadoop.fs.FsShell;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
+import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
|
|
|
+import org.apache.hadoop.hdfs.client.CreateEncryptionZoneFlag;
|
|
|
+import org.apache.hadoop.hdfs.client.HdfsAdmin;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.junit.After;
|
|
|
import org.junit.AfterClass;
|
|
|
+import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.BeforeClass;
|
|
|
+import org.junit.Test;
|
|
|
|
|
|
|
|
|
public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
|
|
@@ -58,6 +70,19 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
|
|
|
@BeforeClass
|
|
|
public static void clusterSetupAtBegining() throws IOException,
|
|
|
LoginException, URISyntaxException {
|
|
|
+
|
|
|
+ // Encryption Zone settings
|
|
|
+ FileSystemTestHelper fsHelper = new FileSystemTestHelper();
|
|
|
+ String testRoot = fsHelper.getTestRootDir();
|
|
|
+ CONF.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH,
|
|
|
+ JavaKeyStoreProvider.SCHEME_NAME + "://file" +
|
|
|
+ new Path(new File(testRoot).getAbsoluteFile().toString(), "test" +
|
|
|
+ ".jks").toUri());
|
|
|
+ CONF.setBoolean(DFSConfigKeys
|
|
|
+ .DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true);
|
|
|
+ CONF.setInt(DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES,
|
|
|
+ 2);
|
|
|
+
|
|
|
SupportsBlocks = true;
|
|
|
CONF.setBoolean(
|
|
|
DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true);
|
|
@@ -137,4 +162,36 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
|
|
|
int getExpectedDelegationTokenCountWithCredentials() {
|
|
|
return 2;
|
|
|
}
|
|
|
+
|
|
|
+ @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);
|
|
|
+ Assert.assertTrue("ViewFileSystem trash roots should include EZ file trash",
|
|
|
+ (fsView.getTrashRoots(true).size() == 1));
|
|
|
+
|
|
|
+ //Verify deletion of EZ
|
|
|
+ DFSTestUtil.verifyDelete(shell, fsTarget, zone, true);
|
|
|
+ Assert.assertTrue("ViewFileSystem trash roots should include EZ zone trash",
|
|
|
+ (fsView.getTrashRoots(true).size() == 2));
|
|
|
+ }
|
|
|
}
|