Skip to content

Commit c8c1d74

Browse files
yanghuaulysses-you
authored andcommitted
[KYUUBI #1872] Make ProcBuilder decouple with YARN
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> ### _How was this patch tested?_ - [ ] 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 #1874 from yanghua/KYUUBI-1872. Closes #1872 e0b1264 [yanghua] [KYUUBI #1872] Make ProcBuilder decouple with YARN Authored-by: yanghua <yanghua1127@gmail.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 08fc087 commit c8c1d74

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
package org.apache.kyuubi.engine
1919

2020
import java.io.{File, IOException}
21-
import java.lang.ProcessBuilder.Redirect
2221
import java.nio.charset.StandardCharsets
2322
import java.nio.file.{Files, Path, Paths}
2423

2524
import scala.collection.JavaConverters._
26-
import scala.util.matching.Regex
2725

2826
import com.google.common.collect.EvictingQueue
2927
import org.apache.commons.lang3.StringUtils.containsIgnoreCase
@@ -98,7 +96,7 @@ trait ProcBuilder {
9896
@volatile private var error: Throwable = UNCAUGHT_ERROR
9997

10098
private val engineLogMaxLines = conf.get(KyuubiConf.SESSION_ENGINE_STARTUP_MAX_LOG_LINES)
101-
private val lastRowsOfLog: EvictingQueue[String] = EvictingQueue.create(engineLogMaxLines)
99+
protected val lastRowsOfLog: EvictingQueue[String] = EvictingQueue.create(engineLogMaxLines)
102100
// Visible for test
103101
@volatile private[kyuubi] var logCaptureThreadReleased: Boolean = true
104102
private var logCaptureThread: Thread = _
@@ -186,28 +184,7 @@ trait ProcBuilder {
186184
proc
187185
}
188186

189-
val YARN_APP_NAME_REGEX: Regex = "application_\\d+_\\d+".r
190-
191-
def killApplication(line: String = lastRowsOfLog.toArray.mkString("\n")): String =
192-
YARN_APP_NAME_REGEX.findFirstIn(line) match {
193-
case Some(appId) =>
194-
env.get(KyuubiConf.KYUUBI_HOME) match {
195-
case Some(kyuubiHome) =>
196-
val pb = new ProcessBuilder("/bin/sh", s"$kyuubiHome/bin/stop-application.sh", appId)
197-
pb.environment()
198-
.putAll(childProcEnv.asJava)
199-
pb.redirectError(Redirect.appendTo(engineLog))
200-
pb.redirectOutput(Redirect.appendTo(engineLog))
201-
val process = pb.start()
202-
process.waitFor() match {
203-
case id if id != 0 => s"Failed to kill Application $appId, please kill it manually. "
204-
case _ => s"Killed Application $appId successfully. "
205-
}
206-
case None =>
207-
s"KYUUBI_HOME is not set! Failed to kill Application $appId, please kill it manually."
208-
}
209-
case None => ""
210-
}
187+
def killApplication(line: String = lastRowsOfLog.toArray.mkString("\n")): String = ""
211188

212189
def close(): Unit = {
213190
if (logCaptureThread != null) {

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
package org.apache.kyuubi.engine.spark
1919

2020
import java.io.{File, FilenameFilter, IOException}
21+
import java.lang.ProcessBuilder.Redirect
2122
import java.net.URI
2223
import java.nio.file.{Files, Paths}
2324

25+
import scala.collection.JavaConverters._
2426
import scala.collection.mutable.ArrayBuffer
27+
import scala.util.matching.Regex
2528

2629
import org.apache.hadoop.security.UserGroupInformation
2730

@@ -163,6 +166,8 @@ class SparkProcessBuilder(
163166

164167
override protected def module: String = "kyuubi-spark-sql-engine"
165168

169+
val YARN_APP_NAME_REGEX: Regex = "application_\\d+_\\d+".r
170+
166171
private def useKeytab(): Boolean = {
167172
val principal = conf.getOption(PRINCIPAL)
168173
val keytab = conf.getOption(KEYTAB)
@@ -201,6 +206,27 @@ class SparkProcessBuilder(
201206
}
202207
}
203208

209+
override def killApplication(line: String = lastRowsOfLog.toArray.mkString("\n")): String =
210+
YARN_APP_NAME_REGEX.findFirstIn(line) match {
211+
case Some(appId) =>
212+
env.get(KyuubiConf.KYUUBI_HOME) match {
213+
case Some(kyuubiHome) =>
214+
val pb = new ProcessBuilder("/bin/sh", s"$kyuubiHome/bin/stop-application.sh", appId)
215+
pb.environment()
216+
.putAll(childProcEnv.asJava)
217+
pb.redirectError(Redirect.appendTo(engineLog))
218+
pb.redirectOutput(Redirect.appendTo(engineLog))
219+
val process = pb.start()
220+
process.waitFor() match {
221+
case id if id != 0 => s"Failed to kill Application $appId, please kill it manually. "
222+
case _ => s"Killed Application $appId successfully. "
223+
}
224+
case None =>
225+
s"KYUUBI_HOME is not set! Failed to kill Application $appId, please kill it manually."
226+
}
227+
case None => ""
228+
}
229+
204230
}
205231

206232
object SparkProcessBuilder {

0 commit comments

Comments
 (0)