turboFei commented on code in PR #6008:
URL: https://github.com/apache/kyuubi/pull/6008#discussion_r1533250250


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/AdminResource.scala:
##########
@@ -255,24 +259,47 @@ private[v1] class AdminResource extends ApiRequestContext 
with Logging {
     }
     val engine = normalizeEngineInfo(userName, engineType, shareLevel, 
subdomain, "default")
     val engineSpace = calculateEngineSpace(engine)
+    var msg = s"Engine $engineSpace is deleted successfully."
 
     withDiscoveryClient(fe.getConf) { discoveryClient =>
       val engineNodes = discoveryClient.getChildren(engineSpace)
       engineNodes.foreach { node =>
         val nodePath = s"$engineSpace/$node"
-        info(s"Deleting engine node:$nodePath")
-        try {
-          discoveryClient.delete(nodePath)
-        } catch {
-          case e: Exception =>
-            error(s"Failed to delete engine node:$nodePath", e)
-            throw new NotFoundException(s"Failed to delete engine 
node:$nodePath," +
-              s"${e.getMessage}")
+        if (forceKill) {
+          val refIds = node.split(";")
+            .flatMap(_.split("=", 2) match {
+              case Array("refId", value) if StringUtils.isNotBlank(value) => 
Some(value)
+              case _ => None
+            })
+
+          refIds.foreach(refId => {
+            val applicationManagerInfo = ApplicationManagerInfo(
+              Option(resourceManager),
+              Option(kubernetesContext),
+              Option(kubernetesNamespace))
+            val killMessage = 
fe.be.sessionManager.asInstanceOf[KyuubiSessionManager]
+              .applicationManager.killApplication(applicationManagerInfo, 
refId)
+            if (!killMessage._1) {
+              msg = s"Engine $engineSpace failed to get deleted forcibly," +
+                s"cause ${killMessage._2}"
+              error(msg)
+              throw new NotFoundException(msg)
+            }
+          })
+        } else {
+          info(s"Deleting engine node:$nodePath")
+          try {
+            discoveryClient.delete(nodePath)
+          } catch {
+            case e: Exception =>
+              error(s"Failed to delete engine node:$nodePath", e)
+              throw new NotFoundException(s"Failed to delete engine 
node:$nodePath," +
+                s"${e.getMessage}")

Review Comment:
   FYI:
   ```
   ....
       withDiscoveryClient(fe.getConf) { discoveryClient =>
         val engineNodes = discoveryClient.getServiceNodesInfo(engineSpace, 
silent = true)
         engineNodes.foreach { engineNode =>
           val nodePath = s"$engineSpace/${engineNode.nodeName}"
           info(s"Deleting engine node:$nodePath")
           try {
             discoveryClient.delete(nodePath)
           } catch {
             case e: Exception =>
               error(s"Failed to delete engine node:$nodePath", e)
               throw new NotFoundException(s"Failed to delete engine 
node:$nodePath," +
                 s"${e.getMessage}")
           }
   
           if (forceKill) {
             val applicationManagerInfo = ApplicationManagerInfo(
               Option(resourceManager),
               Option(kubernetesContext),
               Option(kubernetesNamespace))
             engineNode.engineRefId.foreach { engineRefId =>
               fe.be.sessionManager.asInstanceOf[KyuubiSessionManager]
                 .applicationManager.killApplication(applicationManagerInfo, 
engineRefId)
   .....
             }
           }
         }
       }
   ....
   ```



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