[SPARK-7378] [CORE] Handle deep links to unloaded apps.

The code was treating deep links as if they were attempt IDs, so
for example if you tried to load "/history/app1/jobs" directly,
that would fail because the code would treat "jobs" as an attempt id.

This change modifies the code to try both cases - first without an
attempt id, then with it, so that deep links are handled correctly.
This assumes that the links in the Spark UI do not clash with the
attempt id namespace, though, which is the case for YARN at least,
which is the only backend that currently publishes attempt IDs.

Author: Marcelo Vanzin <vanzin@cloudera.com>

Closes #5922 from vanzin/SPARK-7378 and squashes the following commits:

96f648b [Marcelo Vanzin] Fix comparison.
ed3bcd4 [Marcelo Vanzin] Merge branch 'master' into SPARK-7378
23483e4 [Marcelo Vanzin] Fat fingers.
b728f08 [Marcelo Vanzin] [SPARK-7378] [core] Handle deep links to unloaded apps.

(cherry picked from commit 5467c34c3d)
Signed-off-by: Andrew Or <andrew@databricks.com>
This commit is contained in:
Marcelo Vanzin 2015-05-08 14:12:58 -07:00 committed by Andrew Or
parent 3da5f8b71a
commit 3024f6b01d

View file

@ -83,31 +83,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)
@ -183,6 +179,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
}
}
}
}
/**