This is an automated email from the ASF dual-hosted git repository.
inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0db3ee5b4b9 HADOOP-18427. Improve
ZKDelegationTokenSecretManager#startThead With recommended methods. (#4812)
0db3ee5b4b9 is described below
commit 0db3ee5b4b93723d7c8584de458f3e4c6aa0d9e8
Author: slfan1989 <[email protected]>
AuthorDate: Fri Sep 9 02:41:21 2022 +0800
HADOOP-18427. Improve ZKDelegationTokenSecretManager#startThead With
recommended methods. (#4812)
---
.../delegation/ZKDelegationTokenSecretManager.java | 10 +++++---
.../TestZKDelegationTokenSecretManager.java | 29 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
index d0630e38b4d..909f1afbffa 100644
---
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
+++
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java
@@ -42,7 +42,6 @@ import
org.apache.curator.framework.recipes.cache.CuratorCacheListener;
import org.apache.curator.framework.recipes.shared.SharedCount;
import org.apache.curator.framework.recipes.shared.VersionedValue;
import org.apache.curator.retry.RetryNTimes;
-import org.apache.curator.utils.EnsurePath;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
@@ -134,6 +133,11 @@ public abstract class
ZKDelegationTokenSecretManager<TokenIdent extends Abstract
CURATOR_TL.set(curator);
}
+ @VisibleForTesting
+ protected static CuratorFramework getCurator() {
+ return CURATOR_TL.get();
+ }
+
private final boolean isExternalClient;
protected final CuratorFramework zkClient;
private SharedCount delTokSeqCounter;
@@ -260,10 +264,8 @@ public abstract class
ZKDelegationTokenSecretManager<TokenIdent extends Abstract
// If namespace parents are implicitly created, they won't have ACLs.
// So, let's explicitly create them.
CuratorFramework nullNsFw = zkClient.usingNamespace(null);
- EnsurePath ensureNs =
- nullNsFw.newNamespaceAwareEnsurePath("/" + zkClient.getNamespace());
try {
- ensureNs.ensure(nullNsFw.getZookeeperClient());
+ nullNsFw.create().creatingParentContainersIfNeeded().forPath("/" +
zkClient.getNamespace());
} catch (Exception e) {
throw new IOException("Could not create namespace", e);
}
diff --git
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
index 63d01ccab9e..84899e519b3 100644
---
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
+++
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java
@@ -41,6 +41,7 @@ import org.apache.hadoop.test.GenericTestUtils;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
+import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
import org.junit.After;
import org.junit.Assert;
@@ -507,4 +508,32 @@ public class TestZKDelegationTokenSecretManager {
}
}, 1000, 5000);
}
+
+ @Test
+ public void testCreatingParentContainersIfNeeded() throws Exception {
+
+ String connectString = zkServer.getConnectString();
+ RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
+ Configuration conf = getSecretConf(connectString);
+ CuratorFramework curatorFramework =
+ CuratorFrameworkFactory.builder()
+ .connectString(connectString)
+ .retryPolicy(retryPolicy)
+ .build();
+ curatorFramework.start();
+ ZKDelegationTokenSecretManager.setCurator(curatorFramework);
+ DelegationTokenManager tm1 = new DelegationTokenManager(conf, new
Text("foo"));
+
+ // When the init method is called,
+ // the ZKDelegationTokenSecretManager#startThread method will be called,
+ // and the creatingParentContainersIfNeeded will be called to create the
nameSpace.
+ tm1.init();
+
+ String workingPath = "/" +
conf.get(ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH,
+ ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT) +
"/ZKDTSMRoot";
+
+ // Check if the created NameSpace exists.
+ Stat stat = curatorFramework.checkExists().forPath(workingPath);
+ Assert.assertNotNull(stat);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]