diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala index e2736267f..c099f2cb9 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala @@ -34,7 +34,7 @@ class KyuubiBatchService( private lazy val restFrontend = server.frontendServices .filter(_.isInstanceOf[KyuubiRestFrontendService]) - .head + .head.asInstanceOf[KyuubiRestFrontendService] private def kyuubiInstance: String = restFrontend.connectionUrl @@ -66,6 +66,7 @@ class KyuubiBatchService( override def start(): Unit = { assert(running.compareAndSet(false, true)) val submitTask: Runnable = () => { + restFrontend.waitForServerStarted() while (running.get) { metadataManager.pickBatchForSubmitting(kyuubiInstance) match { case None => Thread.sleep(1000) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala index 811f3d053..35ee0afff 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala @@ -193,19 +193,23 @@ class KyuubiRestFrontendService(override val serverable: Serverable) } } + def waitForServerStarted(): Unit = { + // block until the HTTP server is started, otherwise, we may get + // the wrong HTTP server port -1 + while (!server.isStarted) { + info(s"Waiting for $getName's HTTP server getting started") + Thread.sleep(1000) + } + } + override def start(): Unit = synchronized { if (!isStarted.get) { try { server.start() + startInternal() + waitForServerStarted() isStarted.set(true) startBatchChecker() - startInternal() - // block until the HTTP server is started, otherwise, we may get - // the wrong HTTP server port -1 - while (server.getState != "STARTED") { - info(s"Waiting for $getName's HTTP server getting started") - Thread.sleep(1000) - } recoverBatchSessions() } catch { case e: Exception => throw new KyuubiException(s"Cannot start $getName", e) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala index f0b752061..f88d46241 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala @@ -24,7 +24,7 @@ import org.eclipse.jetty.util.thread.{QueuedThreadPool, ScheduledExecutorSchedul import org.apache.kyuubi.util.JavaUtils -private[kyuubi] case class JettyServer( +private[kyuubi] class JettyServer( server: Server, connector: ServerConnector, rootHandler: ContextHandlerCollection) { @@ -68,7 +68,7 @@ private[kyuubi] case class JettyServer( addHandler(JettyUtils.createRedirectHandler(src, dest)) } - def getState: String = server.getState + def isStarted: Boolean = server.isStarted } object JettyServer {