[KYUUBI #7017] Using mutable JettyServer uri to prevent batch kyuubi instance mismatch
### Why are the changes needed? To fix the batch kyuubi instance port is negative issue. <img width="697" alt="image" src="https://github.com/user-attachments/assets/ef992390-8d20-44b3-8640-35496caff85d" /> It happen after I stop the kyuubi service. We should use variable instead of function for jetty server serverUri. After the server connector stopped, the localPort would be `-2`.  ### How was this patch tested? Existing UT. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #7017 from turboFei/server_port_negative. Closes #7017 3d34c4031 [Wang, Fei] warn e58298646 [Wang, Fei] mutable server uri 2cbaf772a [Wang, Fei] Revert "hard code the server uri" b64d91b32 [Wang, Fei] hard code the server uri Authored-by: Wang, Fei <fwang12@ebay.com> Signed-off-by: Wang, Fei <fwang12@ebay.com>
This commit is contained in:
parent
d6f07a6b64
commit
0cc52d035c
@ -22,18 +22,22 @@ import org.eclipse.jetty.server.handler.{ContextHandlerCollection, ErrorHandler}
|
||||
import org.eclipse.jetty.util.component.LifeCycle
|
||||
import org.eclipse.jetty.util.thread.{QueuedThreadPool, ScheduledExecutorScheduler}
|
||||
|
||||
import org.apache.kyuubi.Logging
|
||||
import org.apache.kyuubi.util.JavaUtils
|
||||
|
||||
private[kyuubi] class JettyServer(
|
||||
server: Server,
|
||||
connector: ServerConnector,
|
||||
rootHandler: ContextHandlerCollection) {
|
||||
rootHandler: ContextHandlerCollection) extends Logging {
|
||||
|
||||
def start(): Unit = synchronized {
|
||||
try {
|
||||
server.start()
|
||||
connector.start()
|
||||
server.addConnector(connector)
|
||||
val localPort = connector.getLocalPort
|
||||
require(localPort > 0, "Jetty server port should be positive, but got " + localPort)
|
||||
_serverUri = connector.getHost + ":" + localPort
|
||||
} catch {
|
||||
case e: Exception =>
|
||||
stop()
|
||||
@ -49,7 +53,13 @@ private[kyuubi] class JettyServer(
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
def getServerUri: String = connector.getHost + ":" + connector.getLocalPort
|
||||
|
||||
@volatile private var _serverUri: String = _
|
||||
def getServerUri: String = Option(_serverUri).getOrElse {
|
||||
val uri = connector.getHost + ":" + connector.getLocalPort
|
||||
warn("Jetty server is not started yet, returning " + uri)
|
||||
uri
|
||||
}
|
||||
|
||||
def addHandler(handler: Handler): Unit = synchronized {
|
||||
rootHandler.addHandler(handler)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user