zhouyifan279 commented on a change in pull request #1119:
URL: https://github.com/apache/incubator-kyuubi/pull/1119#discussion_r713663109



##########
File path: 
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala
##########
@@ -148,6 +149,39 @@ trait ProcBuilder {
     proc
   }
 
+  def execCommand(command: String): Int = {
+    val pb = new ProcessBuilder("/bin/sh", "-c", command)
+    var exitValue: Option[Int] = None
+
+    try {
+      val process = pb.start()
+      exitValue = Some(process.waitFor())
+    } catch {
+      case e: Exception =>
+        throw KyuubiSQLException(s"Failed to kill yarn job. command : 
$command", e.getCause)
+    }
+    exitValue.get
+  }
+
+  def getCommand(appId: String): String = {
+    val hadoopHomeOpt = env.get("HADOOP_HOME").orElse {
+      throw KyuubiSQLException(s"Failed to kill yarn job. HADOOP_HOME is not 
set! " +
+        "For more detail information on installing and configuring Yarn, 
please visit " +
+        "https://kyuubi.apache.org/docs/stable/deployment/on_yarn.html";)
+    }.map { hadoopHome =>
+      Paths.get(hadoopHome, "bin", 
"yarn").toAbsolutePath.toFile.getCanonicalPath
+    }.get
+    hadoopHomeOpt + " application -kill " + appId
+  }
+
+  val YARN_APP_NAME_REGEX: Regex = "application_\\d+_\\d+".r
+
+  def killApplication(line: String = lastRowOfLog): Unit =
+    YARN_APP_NAME_REGEX.findFirstIn(line) match {
+      case Some(appId) if line.contains("state: ACCEPTED") => 
execCommand(getCommand(appId))

Review comment:
       It is possible, although rare, that the last row of log reports state to 
be NEW/NEW_SAVING/SUBMITTED when engine is submitted in YARN Cluster mode and 
`spark.yarn.submit.waitAppCompletion` is `false`.




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


Reply via email to