You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by GitBox <gi...@apache.org> on 2021/08/06 02:46:20 UTC

[GitHub] [incubator-kyuubi] pan3793 commented on a change in pull request #898: [KYUUBI-897] Support stop Spark engine through web ui

pan3793 commented on a change in pull request #898:
URL: https://github.com/apache/incubator-kyuubi/pull/898#discussion_r683194040



##########
File path: externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/ui/EngineTab.scala
##########
@@ -17,22 +17,49 @@
 
 package org.apache.spark.kyuubi.ui
 
+import javax.servlet.http.HttpServletRequest
+
 import org.apache.spark.ui.SparkUITab
+import scala.util.control.NonFatal
 
-import org.apache.kyuubi.Utils
+import org.apache.kyuubi.{Logging, Utils}
+import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.engine.spark.SparkSQLEngine
+import org.apache.kyuubi.service.ServiceState
 
 /**
  * Note that [[SparkUITab]] is private for Spark
  */
 case class EngineTab(engine: SparkSQLEngine)
-  extends SparkUITab(engine.spark.sparkContext.ui.orNull, "kyuubi") {
+  extends SparkUITab(engine.spark.sparkContext.ui.orNull, "kyuubi") with Logging {
 
   override val name: String = "Kyuubi Query Engine"
+  val killEnabled = engine.getConf.get(KyuubiConf.ENGINE_UI_STOP_ENABLED)
 
   engine.spark.sparkContext.ui.foreach { ui =>
     this.attachPage(EnginePage(this))
     ui.attachTab(this)
     Utils.addShutdownHook(() => ui.detachTab(this))
   }
+
+  engine.spark.sparkContext.ui.foreach { ui =>
+    try {
+      // Spark shade the jetty package so here we use reflect
+      Class.forName("org.apache.spark.ui.SparkUI")

Review comment:
       It's package access level, can we avoid using refection?
   `private[spark] class SparkUI`

##########
File path: externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/ui/KyuubiUIUtils.scala
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.spark.kyuubi.ui
+
+import java.net.URL
+import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
+
+import org.sparkproject.jetty.servlet.{ServletContextHandler, ServletHolder}
+
+// the code forked from `org.apache.spark.ui.JettyUtils`
+object KyuubiUIUtils {
+  def createServletHandler(
+      path: String,
+      servlet: HttpServlet,
+      basePath: String): ServletContextHandler = {
+    val prefixedPath = if (basePath == "" && path == "/") {
+      path
+    } else {
+      (basePath + path).stripSuffix("/")
+    }
+    val contextHandler = new ServletContextHandler
+    val holder = new ServletHolder(servlet)
+    contextHandler.setContextPath(prefixedPath)
+    contextHandler.addServlet(holder, "/")
+    contextHandler
+  }
+
+  def createRedirectHandler(

Review comment:
       It's a pretty stable API, no changes since Spark 3.0.0.
   ![image](https://user-images.githubusercontent.com/26535726/128315173-f9e44ef6-3d9f-4a41-be1b-6d498f35cf39.png)
   

##########
File path: externals/kyuubi-spark-sql-engine/pom.xml
##########
@@ -50,6 +50,19 @@
             <version>${project.version}</version>
         </dependency>
 
+        <!--  for kyuubi spark ui -->
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.spark</groupId>
+            <artifactId>spark-core_${scala.binary.version}</artifactId>
+            <scope>provided</scope>
+        </dependency>

Review comment:
       Updated
   `jakarta.servlet:jakarta.servlet-api` or `javax.servlet:javax.servlet-api` should be already pulled by `spark-sql`, please try remove changes in this `pom.xml` and see if works.

##########
File path: externals/kyuubi-spark-sql-engine/pom.xml
##########
@@ -50,6 +50,19 @@
             <version>${project.version}</version>
         </dependency>
 
+        <!--  for kyuubi spark ui -->
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.spark</groupId>
+            <artifactId>spark-core_${scala.binary.version}</artifactId>
+            <scope>provided</scope>
+        </dependency>

Review comment:
       Maybe the only required dependency here is `jakarta.servlet-api`? We already pulled `spark-core` from `spark-sql`
   ```
               <dependency>
                   <groupId>jakarta.servlet</groupId>
                   <artifactId>jakarta.servlet-api</artifactId>
                   <scope>provided</scope>
               </dependency>
   ```
   




-- 
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: commits-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org