Repository: spark
Updated Branches:
  refs/heads/master 643c49c75 -> dc7e399fc


[SPARK-11338] [WEBUI] Prepend app links on HistoryPage with uiRoot path

[SPARK-11338: HistoryPage not multi-tenancy enabled 
...](https://issues.apache.org/jira/browse/SPARK-11338)
- `HistoryPage.scala` ...prepending all page links with the web proxy 
(`uiRoot`) path
- `HistoryServerSuite.scala` ...adding a test case to verify all site-relative 
links are prefixed when the environment variable `APPLICATION_WEB_PROXY_BASE` 
(or System property `spark.ui.proxyBase`) is set

Author: Christian Kadner <ckad...@us.ibm.com>

Closes #9291 from ckadner/SPARK-11338 and squashes the following commits:

01d2f35 [Christian Kadner] [SPARK-11338][WebUI] nit fixes
d054bd7 [Christian Kadner] [SPARK-11338][WebUI] prependBaseUri in method 
makePageLink
8bcb3dc [Christian Kadner] [SPARK-11338][WebUI] Prepend application links on 
HistoryPage with uiRoot path


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/dc7e399f
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/dc7e399f
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/dc7e399f

Branch: refs/heads/master
Commit: dc7e399fc01e74f2ba28ebd945785cc0f7759ccd
Parents: 643c49c
Author: Christian Kadner <ckad...@us.ibm.com>
Authored: Sun Nov 1 13:09:42 2015 -0800
Committer: Marcelo Vanzin <van...@cloudera.com>
Committed: Sun Nov 1 13:09:42 2015 -0800

----------------------------------------------------------------------
 .../spark/deploy/history/HistoryPage.scala      |  9 ++++-----
 .../deploy/history/HistoryServerSuite.scala     | 21 ++++++++++++++++++--
 2 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/dc7e399f/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
----------------------------------------------------------------------
diff --git 
a/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala 
b/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
index b347cb3..642d71b 100644
--- a/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
+++ b/core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala
@@ -161,7 +161,7 @@ private[history] class HistoryPage(parent: HistoryServer) 
extends WebUIPage("")
       info: ApplicationHistoryInfo,
       attempt: ApplicationAttemptInfo,
       isFirst: Boolean): Seq[Node] = {
-    val uiAddress = HistoryServer.getAttemptURI(info.id, attempt.attemptId)
+    val uiAddress = 
UIUtils.prependBaseUri(HistoryServer.getAttemptURI(info.id, attempt.attemptId))
     val startTime = UIUtils.formatDate(attempt.startTime)
     val endTime = if (attempt.endTime > 0) UIUtils.formatDate(attempt.endTime) 
else "-"
     val duration =
@@ -190,8 +190,7 @@ private[history] class HistoryPage(parent: HistoryServer) 
extends WebUIPage("")
       {
         if (renderAttemptIdColumn) {
           if (info.attempts.size > 1 && attempt.attemptId.isDefined) {
-            <td><a href={HistoryServer.getAttemptURI(info.id, 
attempt.attemptId)}>
-              {attempt.attemptId.get}</a></td>
+            <td><a href={uiAddress}>{attempt.attemptId.get}</a></td>
           } else {
             <td>&nbsp;</td>
           }
@@ -218,9 +217,9 @@ private[history] class HistoryPage(parent: HistoryServer) 
extends WebUIPage("")
   }
 
   private def makePageLink(linkPage: Int, showIncomplete: Boolean): String = {
-    "/?" + Array(
+    UIUtils.prependBaseUri("/?" + Array(
       "page=" + linkPage,
       "showIncomplete=" + showIncomplete
-    ).mkString("&")
+      ).mkString("&"))
   }
 }

http://git-wip-us.apache.org/repos/asf/spark/blob/dc7e399f/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
----------------------------------------------------------------------
diff --git 
a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala 
b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
index e5b5e1b..4b7fd4f 100644
--- 
a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
+++ 
b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala
@@ -29,7 +29,7 @@ import org.scalatest.{BeforeAndAfter, Matchers}
 import org.scalatest.mock.MockitoSugar
 
 import org.apache.spark.{JsonTestUtils, SecurityManager, SparkConf, 
SparkFunSuite}
-import org.apache.spark.ui.SparkUI
+import org.apache.spark.ui.{SparkUI, UIUtils}
 
 /**
  * A collection of tests against the historyserver, including comparing 
responses from the json
@@ -261,7 +261,24 @@ class HistoryServerSuite extends SparkFunSuite with 
BeforeAndAfter with Matchers
       l <- links
       attrs <- l.attribute("href")
     } yield (attrs.toString)
-    justHrefs should contain(link)
+    justHrefs should contain (UIUtils.prependBaseUri(resource = link))
+  }
+
+  test("relative links are prefixed with uiRoot (spark.ui.proxyBase)") {
+    val proxyBaseBeforeTest = System.getProperty("spark.ui.proxyBase")
+    val uiRoot = 
Option(System.getenv("APPLICATION_WEB_PROXY_BASE")).getOrElse("/testwebproxybase")
+    val page = new HistoryPage(server)
+    val request = mock[HttpServletRequest]
+
+    // when
+    System.setProperty("spark.ui.proxyBase", uiRoot)
+    val response = page.render(request)
+    System.setProperty("spark.ui.proxyBase", 
Option(proxyBaseBeforeTest).getOrElse(""))
+
+    // then
+    val urls = response \\ "@href" map (_.toString)
+    val siteRelativeLinks = urls filter (_.startsWith("/"))
+    all (siteRelativeLinks) should startWith (uiRoot)
   }
 
   def getContentAndCode(path: String, port: Int = port): (Int, Option[String], 
Option[String]) = {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to