ulysses-you commented on a change in pull request #1171:
URL: https://github.com/apache/incubator-kyuubi/pull/1171#discussion_r717275918



##########
File path: 
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/SparkSQLEngine.scala
##########
@@ -127,38 +111,64 @@ object SparkSQLEngine extends Logging {
   def startEngine(spark: SparkSession): Unit = {
     currentEngine = Some(new SparkSQLEngine(spark))
     currentEngine.foreach { engine =>
-      engine.initialize(kyuubiConf)
-      engine.start()
+      // start event logging ahead so that we can capture all statuses
+      val eventLogging = new EventLoggingService(spark.sparkContext)
+      try {
+        eventLogging.initialize(kyuubiConf)
+        eventLogging.start()
+      } catch {
+        case NonFatal(e) =>
+          // Don't block the main process if the `EventLoggingService` failed 
to start
+          warn(s"Failed to initialize EventLoggingService: ${e.getMessage}", e)
+      }
+
+      try {
+        engine.initialize(kyuubiConf)
+        EventLoggingService.onEvent(EngineEvent(engine))
+      } catch {
+        case t: Throwable =>
+          throw new KyuubiException(s"Failed to initialize SparkSQLEngine: 
${t.getMessage}", t)
+      }
+      try {
+        engine.start()
+        EngineTab(engine)
+        val event = EngineEvent(engine)
+        info(event)
+        EventLoggingService.onEvent(event)
+      } catch {
+        case t: Throwable =>
+          throw new KyuubiException(s"Failed to start SparkSQLEngine: 
${t.getMessage}", t)
+      }
       // Stop engine before SparkContext stopped to avoid calling a stopped 
SparkContext
-      addShutdownHook(() => engine.stop(), SPARK_CONTEXT_SHUTDOWN_PRIORITY + 1)
-      EngineTab(engine)
-      info(engine.engineStatus)
+      addShutdownHook(() => engine.stop(), SPARK_CONTEXT_SHUTDOWN_PRIORITY + 2)
+      addShutdownHook(() => eventLogging.stop(), 
SPARK_CONTEXT_SHUTDOWN_PRIORITY + 1)
     }
   }
 
   def main(args: Array[String]): Unit = {
     SignalRegister.registerLogger(logger)
     var spark: SparkSession = null
     try {
-      spark = createSpark()
-      startEngine(spark)
+      try {

Review comment:
       shall we combine this line `try` and line 151 `try` ?




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