|
@@ -18,6 +18,7 @@
|
|
package org.apache.hadoop.hdfs.server.federation.router;
|
|
package org.apache.hadoop.hdfs.server.federation.router;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
@@ -46,10 +47,16 @@ public class TestRouterRetryCache {
|
|
|
|
|
|
@Before
|
|
@Before
|
|
public void setup() throws Exception {
|
|
public void setup() throws Exception {
|
|
- Configuration namenodeConf = new Configuration();
|
|
|
|
- namenodeConf.set(DFS_NAMENODE_IP_PROXY_USERS, "fake_joe");
|
|
|
|
- cluster = new MiniRouterDFSCluster(true, 1);
|
|
|
|
- cluster.addNamenodeOverrides(namenodeConf);
|
|
|
|
|
|
+ UserGroupInformation routerUser = UserGroupInformation.getLoginUser();
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ String adminUser = routerUser.getUserName();
|
|
|
|
+ conf.set("hadoop.proxyuser." + adminUser + ".hosts", "*");
|
|
|
|
+ conf.set("hadoop.proxyuser." + adminUser + ".groups", "*");
|
|
|
|
+ conf.set("hadoop.proxyuser.fake_joe.hosts", "*");
|
|
|
|
+ conf.set("hadoop.proxyuser.fake_joe.groups", "*");
|
|
|
|
+ conf.set(DFS_NAMENODE_IP_PROXY_USERS, routerUser.getShortUserName());
|
|
|
|
+ cluster = new MiniRouterDFSCluster(true, 1, conf);
|
|
|
|
+ cluster.addNamenodeOverrides(conf);
|
|
|
|
|
|
// Start NNs and DNs and wait until ready
|
|
// Start NNs and DNs and wait until ready
|
|
cluster.startCluster();
|
|
cluster.startCluster();
|
|
@@ -83,7 +90,28 @@ public class TestRouterRetryCache {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testRetryCache() throws Exception {
|
|
|
|
|
|
+ public void testRetryCacheWithOneLevelProxyUser() throws Exception {
|
|
|
|
+ internalTestRetryCache(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testRetryCacheWithTwoLevelProxyUser() throws Exception {
|
|
|
|
+ internalTestRetryCache(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test RetryCache through RBF with proxyUser and non-ProxyUser respectively.
|
|
|
|
+ *
|
|
|
|
+ * 1. Start cluster with current user.
|
|
|
|
+ * 2. Create one test directory by the admin user.
|
|
|
|
+ * 3. Create one Router FileSystem with one mocked user, one proxyUser or non-ProxyUser.
|
|
|
|
+ * 4. Try to create one test directory by the router fileSystem.
|
|
|
|
+ * 5. Try to rename the new test directory to one test destination directory
|
|
|
|
+ * 6. Then failover the active to the standby
|
|
|
|
+ * 7. Try to rename the source directory to the destination directory again with the same callId
|
|
|
|
+ * 8. Try to
|
|
|
|
+ */
|
|
|
|
+ private void internalTestRetryCache(boolean twoLevelProxyUGI) throws Exception {
|
|
RetryInvocationHandler.SET_CALL_ID_FOR_TEST.set(false);
|
|
RetryInvocationHandler.SET_CALL_ID_FOR_TEST.set(false);
|
|
FileSystem routerFS = cluster.getRandomRouter().getFileSystem();
|
|
FileSystem routerFS = cluster.getRandomRouter().getFileSystem();
|
|
Path testDir = new Path("/target-ns0/testdir");
|
|
Path testDir = new Path("/target-ns0/testdir");
|
|
@@ -91,12 +119,13 @@ public class TestRouterRetryCache {
|
|
routerFS.setPermission(testDir, FsPermission.getDefault());
|
|
routerFS.setPermission(testDir, FsPermission.getDefault());
|
|
|
|
|
|
// Run as fake joe to authorize the test
|
|
// Run as fake joe to authorize the test
|
|
- UserGroupInformation joe =
|
|
|
|
- UserGroupInformation.createUserForTesting("fake_joe",
|
|
|
|
- new String[]{"fake_group"});
|
|
|
|
- FileSystem joeFS = joe.doAs(
|
|
|
|
- (PrivilegedExceptionAction<FileSystem>) () ->
|
|
|
|
- FileSystem.newInstance(routerFS.getUri(), routerFS.getConf()));
|
|
|
|
|
|
+ UserGroupInformation joe = UserGroupInformation.createUserForTesting("fake_joe",
|
|
|
|
+ new String[] {"fake_group"});
|
|
|
|
+ if (twoLevelProxyUGI) {
|
|
|
|
+ joe = UserGroupInformation.createProxyUser("fake_proxy_joe", joe);
|
|
|
|
+ }
|
|
|
|
+ FileSystem joeFS = joe.doAs((PrivilegedExceptionAction<FileSystem>) () ->
|
|
|
|
+ FileSystem.newInstance(routerFS.getUri(), routerFS.getConf()));
|
|
|
|
|
|
Path renameSrc = new Path(testDir, "renameSrc");
|
|
Path renameSrc = new Path(testDir, "renameSrc");
|
|
Path renameDst = new Path(testDir, "renameDst");
|
|
Path renameDst = new Path(testDir, "renameDst");
|
|
@@ -121,6 +150,15 @@ public class TestRouterRetryCache {
|
|
|
|
|
|
Client.setCallIdAndRetryCount(callId, 0, null);
|
|
Client.setCallIdAndRetryCount(callId, 0, null);
|
|
assertTrue(joeFS.rename(renameSrc, renameDst));
|
|
assertTrue(joeFS.rename(renameSrc, renameDst));
|
|
|
|
+
|
|
|
|
+ FileStatus fileStatus = joeFS.getFileStatus(renameDst);
|
|
|
|
+ if (twoLevelProxyUGI) {
|
|
|
|
+ assertEquals("fake_proxy_joe", fileStatus.getOwner());
|
|
|
|
+ } else {
|
|
|
|
+ assertEquals("fake_joe", fileStatus.getOwner());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ joeFS.delete(renameDst, true);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|