Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,27 @@ class HistoryServer(
return
}

val appKey =
if (parts.length == 3) {
s"${parts(1)}/${parts(2)}"
} else {
parts(1)
val appId = parts(1)
val attemptId = if (parts.length >= 3) Some(parts(2)) else None

// Since we may have applications with multiple attempts mixed with applications with a
// single attempt, we need to try both. Try the single-attempt route first, and if an
// error is raised, then try the multiple attempt route.
if (!loadAppUi(appId, None) && (!attemptId.isDefined || !loadAppUi(appId, attemptId))) {
val msg = <div class="row-fluid">Application {appId} not found.</div>
res.setStatus(HttpServletResponse.SC_NOT_FOUND)
UIUtils.basicSparkPage(msg, "Not Found").foreach { n =>
res.getWriter().write(n.toString)
}
return
}

// Note we don't use the UI retrieved from the cache; the cache loader above will register
// the app's UI, and all we need to do is redirect the user to the same URI that was
// requested, and the proper data should be served at that point.
try {
appCache.get(appKey)
res.sendRedirect(res.encodeRedirectURL(req.getRequestURI()))
} catch {
case e: Exception => e.getCause() match {
case nsee: NoSuchElementException =>
val msg = <div class="row-fluid">Application {appKey} not found.</div>
res.setStatus(HttpServletResponse.SC_NOT_FOUND)
UIUtils.basicSparkPage(msg, "Not Found").foreach(
n => res.getWriter().write(n.toString))

case cause: Exception => throw cause
}
}
res.sendRedirect(res.encodeRedirectURL(req.getRequestURI()))
}

// SPARK-5983 ensure TRACE is not supported
protected override def doTrace(req: HttpServletRequest, res: HttpServletResponse): Unit = {
res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED)
Expand Down Expand Up @@ -169,6 +165,20 @@ class HistoryServer(
*/
def getProviderConfig(): Map[String, String] = provider.getConfig()

private def loadAppUi(appId: String, attemptId: Option[String]): Boolean = {
try {
appCache.get(appId + attemptId.map { id => s"/$id" }.getOrElse(""))
true
} catch {
case e: Exception => e.getCause() match {
case nsee: NoSuchElementException =>
false

case cause: Exception => throw cause
}
}
}

}

/**
Expand Down