|
@@ -54,6 +54,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptS
|
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
|
import org.apache.zookeeper.KeeperException;
|
|
import org.apache.zookeeper.KeeperException;
|
|
|
|
+import org.apache.zookeeper.ZooDefs.Perms;
|
|
|
|
+import org.apache.zookeeper.data.ACL;
|
|
import org.junit.After;
|
|
import org.junit.After;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
@@ -65,6 +67,8 @@ import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
import javax.crypto.SecretKey;
|
|
import javax.crypto.SecretKey;
|
|
|
|
|
|
public class TestZKRMStateStore extends RMStateStoreTestBase {
|
|
public class TestZKRMStateStore extends RMStateStoreTestBase {
|
|
@@ -248,6 +252,70 @@ public class TestZKRMStateStore extends RMStateStoreTestBase {
|
|
return conf;
|
|
return conf;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static boolean verifyZKACL(String id, String scheme, int perm,
|
|
|
|
+ List<ACL> acls) {
|
|
|
|
+ for (ACL acl : acls) {
|
|
|
|
+ if (acl.getId().getScheme().equals(scheme) &&
|
|
|
|
+ acl.getId().getId().startsWith(id) &&
|
|
|
|
+ acl.getPerms() == perm) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test if RM can successfully start in HA disabled mode if it was previously
|
|
|
|
+ * running in HA enabled mode. And then start it in HA mode after running it
|
|
|
|
+ * with HA disabled. NoAuth Exception should not be sent by zookeeper and RM
|
|
|
|
+ * should start successfully.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testZKRootPathAcls() throws Exception {
|
|
|
|
+ StateChangeRequestInfo req = new StateChangeRequestInfo(
|
|
|
|
+ HAServiceProtocol.RequestSource.REQUEST_BY_USER);
|
|
|
|
+ String rootPath =
|
|
|
|
+ YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH + "/" +
|
|
|
|
+ ZKRMStateStore.ROOT_ZNODE_NAME;
|
|
|
|
+
|
|
|
|
+ // Start RM with HA enabled
|
|
|
|
+ Configuration conf = createHARMConf("rm1,rm2", "rm1", 1234);
|
|
|
|
+ conf.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
|
|
|
|
+ ResourceManager rm = new MockRM(conf);
|
|
|
|
+ rm.start();
|
|
|
|
+ rm.getRMContext().getRMAdminService().transitionToActive(req);
|
|
|
|
+ List<ACL> acls =
|
|
|
|
+ ((ZKRMStateStore)rm.getRMContext().getStateStore()).getACL(rootPath);
|
|
|
|
+ assertEquals(acls.size(), 2);
|
|
|
|
+ // CREATE and DELETE permissions for root node based on RM ID
|
|
|
|
+ verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls);
|
|
|
|
+ verifyZKACL(
|
|
|
|
+ "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls);
|
|
|
|
+ rm.close();
|
|
|
|
+
|
|
|
|
+ // Now start RM with HA disabled. NoAuth Exception should not be thrown.
|
|
|
|
+ conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, false);
|
|
|
|
+ rm = new MockRM(conf);
|
|
|
|
+ rm.start();
|
|
|
|
+ rm.getRMContext().getRMAdminService().transitionToActive(req);
|
|
|
|
+ acls = ((ZKRMStateStore)rm.getRMContext().getStateStore()).getACL(rootPath);
|
|
|
|
+ assertEquals(acls.size(), 1);
|
|
|
|
+ verifyZKACL("world", "anyone", Perms.ALL, acls);
|
|
|
|
+ rm.close();
|
|
|
|
+
|
|
|
|
+ // Start RM with HA enabled.
|
|
|
|
+ conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
|
|
|
|
+ rm = new MockRM(conf);
|
|
|
|
+ rm.start();
|
|
|
|
+ rm.getRMContext().getRMAdminService().transitionToActive(req);
|
|
|
|
+ acls = ((ZKRMStateStore)rm.getRMContext().getStateStore()).getACL(rootPath);
|
|
|
|
+ assertEquals(acls.size(), 2);
|
|
|
|
+ verifyZKACL("digest", "localhost", Perms.CREATE | Perms.DELETE, acls);
|
|
|
|
+ verifyZKACL(
|
|
|
|
+ "world", "anyone", Perms.ALL ^ (Perms.CREATE | Perms.DELETE), acls);
|
|
|
|
+ rm.close();
|
|
|
|
+ }
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
@Test
|
|
@Test
|
|
public void testFencing() throws Exception {
|
|
public void testFencing() throws Exception {
|