cxzl25 commented on code in PR #6275:
URL: https://github.com/apache/kyuubi/pull/6275#discussion_r1561069860


##########
integration-tests/kyuubi-jdbc-it/src/test/scala/org/apache/kyuubi/it/jdbc/mysql/WithKyuubiServerAndMySQLContainerYarnMode.scala:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kyuubi.it.jdbc.mysql
+
+import java.nio.file.{Files, Path, Paths}
+
+import org.apache.kyuubi.WithKyuubiServerAndHadoopMiniCluster
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.{ENGINE_IDLE_TIMEOUT, 
ENGINE_JDBC_EXTRA_CLASSPATH, ENGINE_TYPE, KYUUBI_ENGINE_ENV_PREFIX, KYUUBI_HOME}
+import org.apache.kyuubi.engine.deploy.DeployMode
+import org.apache.kyuubi.engine.jdbc.mysql.MySQLOperationSuite
+
+class WithKyuubiServerAndMySQLContainerYarnMode extends MySQLOperationSuite
+  with WithKyuubiServerAndHadoopMiniCluster {
+
+  private val mysqlJdbcConnectorPath: String = {
+    val keyword = "mysql-connector"
+
+    val jarsDir = Paths.get(kyuubiHome)
+      .resolve("integration-tests")
+      .resolve("kyuubi-jdbc-it")
+      .resolve("target")
+
+    Files.list(jarsDir)
+      .filter { p: Path => p.getFileName.toString contains keyword }
+      .findFirst
+      .orElseThrow { () => new IllegalStateException(s"Can not find $keyword 
in $jarsDir.") }
+      .toAbsolutePath
+      .toString
+  }
+
+  override protected val conf: KyuubiConf = {
+    KyuubiConf()
+      .set(s"$KYUUBI_ENGINE_ENV_PREFIX.$KYUUBI_HOME", kyuubiHome)
+      .set(ENGINE_JDBC_EXTRA_CLASSPATH, mysqlJdbcConnectorPath)
+      .set(ENGINE_TYPE, "JDBC")
+      .set(KyuubiConf.ENGINE_HIVE_DEPLOY_MODE, DeployMode.YARN.toString)

Review Comment:
   ```suggestion
         .set(KyuubiConf.ENGINE_JDBC_DEPLOY_MODE, DeployMode.YARN.toString)
   ```



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/jdbc/JdbcProcessBuilder.scala:
##########
@@ -113,3 +116,55 @@ class JdbcProcessBuilder(
     }
   }
 }
+
+object JdbcProcessBuilder extends Logging {
+
+  final val JDBC_ENGINE_NAME = "jdbc.engine.name"
+
+  def apply(
+      proxyUser: String,
+      doAsEnabled: Boolean,
+      conf: KyuubiConf,
+      engineRefId: String,
+      extraEngineLog: Option[OperationLog],
+      defaultEngineName: String): JdbcProcessBuilder = {
+    checkKeytab(proxyUser, conf)
+    DeployMode.withName(conf.get(ENGINE_JDBC_DEPLOY_MODE)) match {
+      case LOCAL =>
+        new JdbcProcessBuilder(proxyUser, doAsEnabled, conf, engineRefId, 
extraEngineLog)
+      case YARN =>
+        warn(s"JDBC on YARN model is experimental.")
+        conf.setIfMissing(ENGINE_DEPLOY_YARN_MODE_APP_NAME, 
Some(defaultEngineName))
+        new JdbcYarnModeProcessBuilder(proxyUser, doAsEnabled, conf, 
engineRefId, extraEngineLog)
+      case other => throw new KyuubiException(s"Unsupported deploy mode: 
$other")
+    }
+  }
+
+  private def checkKeytab(proxyUser: String, conf: KyuubiConf): Unit = {
+    val principal = conf.get(ENGINE_PRINCIPAL)
+    val keytab = conf.get(ENGINE_KEYTAB)
+    if (!UserGroupInformation.isSecurityEnabled) {
+      if (principal.isDefined || keytab.isDefined) {
+        warn("Principal and keytab takes no effect when hadoop security is not 
enabled.")
+      }
+      return
+    }
+
+    require(
+      principal.isDefined == keytab.isDefined,
+      s"Both principal and keytab must be defined, or neither.")
+    if (principal.isDefined && keytab.isDefined) {
+      val ugi = UserGroupInformation
+        .loginUserFromKeytabAndReturnUGI(principal.get, keytab.get)
+      require(
+        ugi.getShortUserName == proxyUser,
+        s"Proxy user: $proxyUser is not same with " +
+          s"engine principal: ${ugi.getShortUserName}.")
+    }
+
+    val deployMode = DeployMode.withName(conf.get(ENGINE_JDBC_DEPLOY_MODE))
+    if (principal.isEmpty && keytab.isEmpty && deployMode == YARN) {
+      warn("Hive on YARN can not work properly without principal and keytab.")

Review Comment:
   ```suggestion
         warn("Jdbc on YARN can not work properly without principal and 
keytab.")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to