From 9bbccb25d00d9e7a0fa21aed5607ec186014e93e Mon Sep 17 00:00:00 2001 From: zwangsheng <2213335496@qq.com> Date: Fri, 2 Dec 2022 16:09:24 +0800 Subject: [PATCH] [KYUUBI #3888] [HA] Add more info to log when zk auth keytab not found ### _Why are the changes needed?_ Add more info to log, when zookeeper auth keytab not fount. ### _How was this patch tested?_ - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #3888 from zwangsheng/improve/zk_keytab_not_found. Closes #3888 e12f4cf1 [zwangsheng] add more info in log Authored-by: zwangsheng <2213335496@qq.com> Signed-off-by: Cheng Pan --- .../ha/client/zookeeper/ZookeeperClientProvider.scala | 9 +++++---- .../client/zookeeper/ZookeeperDiscoveryClientSuite.scala | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperClientProvider.scala b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperClientProvider.scala index 0cfc3af4a..8dd32d6b6 100644 --- a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperClientProvider.scala +++ b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperClientProvider.scala @@ -22,6 +22,7 @@ import javax.security.auth.login.Configuration import scala.util.Random +import com.google.common.annotations.VisibleForTesting import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory} import org.apache.curator.retry._ import org.apache.hadoop.security.UserGroupInformation @@ -30,8 +31,7 @@ import org.apache.hadoop.security.token.delegation.ZKDelegationTokenSecretManage import org.apache.kyuubi.Logging import org.apache.kyuubi.config.KyuubiConf import org.apache.kyuubi.ha.HighAvailabilityConf._ -import org.apache.kyuubi.ha.client.AuthTypes -import org.apache.kyuubi.ha.client.RetryPolicies +import org.apache.kyuubi.ha.client.{AuthTypes, RetryPolicies} import org.apache.kyuubi.ha.client.RetryPolicies._ import org.apache.kyuubi.util.KyuubiHadoopUtils @@ -109,7 +109,7 @@ object ZookeeperClientProvider extends Logging { val kerberized = maybePrincipal.isDefined && keyTabFile.isDefined if (UserGroupInformation.isSecurityEnabled && kerberized) { if (!new File(keyTabFile.get).exists()) { - throw new IOException(s"${HA_ZK_AUTH_KEYTAB.key} does not exists") + throw new IOException(s"${HA_ZK_AUTH_KEYTAB.key}: $keyTabFile does not exists") } System.setProperty("zookeeper.sasl.clientconfig", "KyuubiZooKeeperClient") var principal = maybePrincipal.get @@ -129,7 +129,8 @@ object ZookeeperClientProvider extends Logging { } - private def getKeyTabFile(conf: KyuubiConf): Option[String] = { + @VisibleForTesting + def getKeyTabFile(conf: KyuubiConf): Option[String] = { val zkAuthKeytab = conf.get(HA_ZK_AUTH_KEYTAB) if (zkAuthKeytab.isDefined) { val zkAuthKeytabPath = zkAuthKeytab.get diff --git a/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperDiscoveryClientSuite.scala b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperDiscoveryClientSuite.scala index 72d5935b4..bbd8b94ac 100644 --- a/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperDiscoveryClientSuite.scala +++ b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/zookeeper/ZookeeperDiscoveryClientSuite.scala @@ -130,7 +130,8 @@ abstract class ZookeeperDiscoveryClientSuite extends DiscoveryClientTests conf.set(HA_ZK_AUTH_KEYTAB.key, s"${keytab.getName}") val e = intercept[IOException](ZookeeperClientProvider.setUpZooKeeperAuth(conf)) - assert(e.getMessage === s"${HA_ZK_AUTH_KEYTAB.key} does not exists") + assert(e.getMessage === + s"${HA_ZK_AUTH_KEYTAB.key}: ${ZookeeperClientProvider.getKeyTabFile(conf)} does not exists") } }