Skip to content
Snippets Groups Projects
Commit 0d1d146c authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Marcelo Vanzin
Browse files

[SPARK-9724] [WEB UI] Avoid unnecessary redirects in the Spark Web UI.

Author: Rohit Agarwal <rohita@qubole.com>

Closes #8014 from mindprince/SPARK-9724 and squashes the following commits:

a7af5ff [Rohit Agarwal] [SPARK-9724] [WEB UI] Inline attachPrefix and attachPrefixForRedirect. Fix logic of attachPrefix
8a977cd [Rohit Agarwal] [SPARK-9724] [WEB UI] Address review comments: Remove unneeded code, update scaladoc.
b257844 [Rohit Agarwal] [SPARK-9724] [WEB UI] Avoid unnecessary redirects in the Spark Web UI.
parent 8ce60963
No related branches found
No related tags found
No related merge requests found
...@@ -106,7 +106,11 @@ private[spark] object JettyUtils extends Logging { ...@@ -106,7 +106,11 @@ private[spark] object JettyUtils extends Logging {
path: String, path: String,
servlet: HttpServlet, servlet: HttpServlet,
basePath: String): ServletContextHandler = { basePath: String): ServletContextHandler = {
val prefixedPath = attachPrefix(basePath, path) val prefixedPath = if (basePath == "" && path == "/") {
path
} else {
(basePath + path).stripSuffix("/")
}
val contextHandler = new ServletContextHandler val contextHandler = new ServletContextHandler
val holder = new ServletHolder(servlet) val holder = new ServletHolder(servlet)
contextHandler.setContextPath(prefixedPath) contextHandler.setContextPath(prefixedPath)
...@@ -121,7 +125,7 @@ private[spark] object JettyUtils extends Logging { ...@@ -121,7 +125,7 @@ private[spark] object JettyUtils extends Logging {
beforeRedirect: HttpServletRequest => Unit = x => (), beforeRedirect: HttpServletRequest => Unit = x => (),
basePath: String = "", basePath: String = "",
httpMethods: Set[String] = Set("GET")): ServletContextHandler = { httpMethods: Set[String] = Set("GET")): ServletContextHandler = {
val prefixedDestPath = attachPrefix(basePath, destPath) val prefixedDestPath = basePath + destPath
val servlet = new HttpServlet { val servlet = new HttpServlet {
override def doGet(request: HttpServletRequest, response: HttpServletResponse): Unit = { override def doGet(request: HttpServletRequest, response: HttpServletResponse): Unit = {
if (httpMethods.contains("GET")) { if (httpMethods.contains("GET")) {
...@@ -246,11 +250,6 @@ private[spark] object JettyUtils extends Logging { ...@@ -246,11 +250,6 @@ private[spark] object JettyUtils extends Logging {
val (server, boundPort) = Utils.startServiceOnPort[Server](port, connect, conf, serverName) val (server, boundPort) = Utils.startServiceOnPort[Server](port, connect, conf, serverName)
ServerInfo(server, boundPort, collection) ServerInfo(server, boundPort, collection)
} }
/** Attach a prefix to the given path, but avoid returning an empty path */
private def attachPrefix(basePath: String, relativePath: String): String = {
if (basePath == "") relativePath else (basePath + relativePath).stripSuffix("/")
}
} }
private[spark] case class ServerInfo( private[spark] case class ServerInfo(
......
...@@ -64,11 +64,11 @@ private[spark] class SparkUI private ( ...@@ -64,11 +64,11 @@ private[spark] class SparkUI private (
attachTab(new EnvironmentTab(this)) attachTab(new EnvironmentTab(this))
attachTab(new ExecutorsTab(this)) attachTab(new ExecutorsTab(this))
attachHandler(createStaticHandler(SparkUI.STATIC_RESOURCE_DIR, "/static")) attachHandler(createStaticHandler(SparkUI.STATIC_RESOURCE_DIR, "/static"))
attachHandler(createRedirectHandler("/", "/jobs", basePath = basePath)) attachHandler(createRedirectHandler("/", "/jobs/", basePath = basePath))
attachHandler(ApiRootResource.getServletHandler(this)) attachHandler(ApiRootResource.getServletHandler(this))
// This should be POST only, but, the YARN AM proxy won't proxy POSTs // This should be POST only, but, the YARN AM proxy won't proxy POSTs
attachHandler(createRedirectHandler( attachHandler(createRedirectHandler(
"/stages/stage/kill", "/stages", stagesTab.handleKillRequest, "/stages/stage/kill", "/stages/", stagesTab.handleKillRequest,
httpMethods = Set("GET", "POST"))) httpMethods = Set("GET", "POST")))
} }
initialize() initialize()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment