Yikf commented on code in PR #5868:
URL: https://github.com/apache/kyuubi/pull/5868#discussion_r1436445682


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/hive/HiveYarnModeProcessBuilder.scala:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.engine.hive
+
+import java.io.File
+import java.nio.file.{Files, Paths}
+import java.util
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
+
+import org.apache.kyuubi.{KyuubiException, Logging, SCALA_COMPILE_VERSION}
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.{ENGINE_HIVE_EXTRA_CLASSPATH, 
ENGINE_HIVE_MEMORY}
+import org.apache.kyuubi.config.KyuubiReservedKeys.{KYUUBI_ENGINE_ID, 
KYUUBI_SESSION_USER_KEY}
+import org.apache.kyuubi.engine.KyuubiApplicationManager
+import org.apache.kyuubi.engine.deploy.EngineYarnModeSubmitter._
+import 
org.apache.kyuubi.engine.hive.HiveProcessBuilder.HIVE_HADOOP_CLASSPATH_KEY
+import org.apache.kyuubi.operation.log.OperationLog
+import org.apache.kyuubi.util.command.CommandLineUtils.{confKeyValue, 
confKeyValues}
+
+/**
+ * A process builder for Hive on Yarn.
+ *
+ * It will new a process on kyuubi server side to submit hive engine to yarn.
+ */
+class HiveYarnModeProcessBuilder(
+    override val proxyUser: String,
+    override val conf: KyuubiConf,
+    override val engineRefId: String,
+    override val extraEngineLog: Option[OperationLog] = None)
+  extends HiveProcessBuilder(proxyUser, conf, engineRefId, extraEngineLog) 
with Logging {
+
+  override protected def mainClass: String =
+    "org.apache.kyuubi.engine.hive.deploy.HiveYarnModeSubmitter"
+
+  override def isClusterMode(): Boolean = true
+
+  override def clusterManager(): Option[String] = Some("yarn")
+
+  override protected val commands: Iterable[String] = {
+    KyuubiApplicationManager.tagApplication(engineRefId, shortName, 
clusterManager(), conf)
+    val buffer = new ArrayBuffer[String]()
+    buffer += executable
+
+    val memory = conf.get(ENGINE_HIVE_MEMORY)
+    buffer += s"-Xmx$memory"
+    buffer += "-cp"
+
+    val classpathEntries = new util.LinkedHashSet[String]
+    classpathEntries.addAll(confFiles(true))
+    classpathEntries.addAll(jarFiles(true))
+
+    buffer += classpathEntries.asScala.mkString(File.pathSeparator)
+    buffer += mainClass
+
+    buffer ++= confKeyValue(KYUUBI_SESSION_USER_KEY, proxyUser)
+    buffer ++= confKeyValue(KYUUBI_ENGINE_ID, engineRefId)
+
+    buffer ++= confKeyValue(
+      KYUUBI_ENGINE_DEPLOY_YARN_MODE_JARS_KEY,
+      
jarFiles(false).asScala.mkString(KYUUBI_ENGINE_DEPLOY_YARN_MODE_ARCHIVE_SEPARATOR))
+    buffer ++= confKeyValue(
+      KYUUBI_ENGINE_DEPLOY_YARN_MODE_CONF_KEY,
+      
confFiles(false).asScala.mkString(KYUUBI_ENGINE_DEPLOY_YARN_MODE_ARCHIVE_SEPARATOR))
+
+    buffer ++= confKeyValues(conf.getAll)
+
+    buffer
+  }
+
+  private def jarFiles(isClasspath: Boolean): util.LinkedHashSet[String] = {
+    val jarEntries = new util.LinkedHashSet[String]
+
+    mainResource.foreach(jarEntries.add)
+
+    
jarEntries.add(s"$hiveHome${File.separator}lib${appendClasspathSuffix(isClasspath)}")
+
+    val hadoopCp = env.get(HIVE_HADOOP_CLASSPATH_KEY)
+    hadoopCp.foreach(jarEntries.add)
+
+    val extraCp = conf.get(ENGINE_HIVE_EXTRA_CLASSPATH)
+    extraCp.foreach(jarEntries.add)
+
+    if (hadoopCp.isEmpty && extraCp.isEmpty) {
+      mainResource.foreach { path =>
+        val devHadoopJars = Paths.get(path).getParent
+          .resolve(s"scala-$SCALA_COMPILE_VERSION")
+          .resolve("jars")
+        if (!Files.exists(devHadoopJars)) {
+          throw new KyuubiException(s"The path $devHadoopJars does not exists. 
" +
+            s"Please set ${HIVE_HADOOP_CLASSPATH_KEY} or 
${ENGINE_HIVE_EXTRA_CLASSPATH.key} for " +
+            s"configuring location of hadoop client jars, etc")
+        }
+        jarEntries.add(s"$devHadoopJars${appendClasspathSuffix(isClasspath)}")
+      }
+    }
+
+    jarEntries
+  }
+
+  private def confFiles(isClasspath: Boolean): util.LinkedHashSet[String] = {
+    val confEntries = new util.LinkedHashSet[String]
+    confEntries.add(env.getOrElse(
+      "HIVE_CONF_DIR",
+      s"$hiveHome${File.separator}conf${appendClasspathSuffix(isClasspath)}"))
+    env.get("HADOOP_CONF_DIR").foreach(confEntries.add)
+    env.get("YARN_CONF_DIR").foreach(confEntries.add)

Review Comment:
   Basically similar



-- 
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