diff --git a/core/src/main/resources/org/apache/spark/ui/static/utils.js b/core/src/main/resources/org/apache/spark/ui/static/utils.js index 1bec1c174df5..78ff9b6ea8ad 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/utils.js +++ b/core/src/main/resources/org/apache/spark/ui/static/utils.js @@ -96,19 +96,24 @@ function formatLogsCells(execLogs, type) { } function getStandAloneAppId(cb) { - var words = getBaseURI().split('/'); - var ind = words.indexOf("proxy"); - var appId; - if (ind > 0) { - appId = words[ind + 1]; - cb(appId); - return; - } - ind = words.indexOf("history"); - if (ind > 0) { - appId = words[ind + 1]; - cb(appId); - return; + let proxyWords = reverseProxyURL.split('/'); + // If the configured proxy base URL doesn't contain "proxy" or "history", we can get the APP id + // from the current base URI. + if (proxyWords.indexOf("proxy") < 0 && proxyWords.indexOf("history") < 0) { + var words = getBaseURI().split('/'); + var ind = words.indexOf("proxy"); + var appId; + if (ind > 0) { + appId = words[ind + 1]; + cb(appId); + return; + } + ind = words.indexOf("history"); + if (ind > 0) { + appId = words[ind + 1]; + cb(appId); + return; + } } // Looks like Web UI is running in standalone mode // Let's get application-id using REST End Point @@ -149,13 +154,7 @@ function ConvertDurationString(data) { function createTemplateURI(appId, templateName) { var words = getBaseURI().split('/'); - var ind = words.indexOf("proxy"); - var baseURI; - if (ind > 0) { - baseURI = words.slice(0, ind + 1).join('/') + '/' + appId + '/static/' + templateName + '-template.html'; - return baseURI; - } - ind = words.indexOf("history"); + ind = words.lastIndexOf("history"); if(ind > 0) { baseURI = words.slice(0, ind).join('/') + '/static/' + templateName + '-template.html'; return baseURI; @@ -184,14 +183,7 @@ function formatDate(date) { function createRESTEndPointForExecutorsPage(appId) { var words = getBaseURI().split('/'); - var ind = words.indexOf("proxy"); - var newBaseURI; - if (ind > 0) { - appId = words[ind + 1]; - newBaseURI = words.slice(0, ind + 2).join('/'); - return newBaseURI + "/api/v1/applications/" + appId + "/allexecutors"; - } - ind = words.indexOf("history"); + ind = words.lastIndexOf("history"); if (ind > 0) { appId = words[ind + 1]; var attemptId = words[ind + 2]; @@ -231,4 +223,4 @@ function createRESTEndPointForMiscellaneousProcess(appId) { function getBaseURI() { return document.baseURI || document.URL; } -/* eslint-enable no-unused-vars */ \ No newline at end of file +/* eslint-enable no-unused-vars */ diff --git a/core/src/main/resources/org/apache/spark/ui/static/webui.js b/core/src/main/resources/org/apache/spark/ui/static/webui.js index c149f2d84337..00144f37bfa8 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/webui.js +++ b/core/src/main/resources/org/apache/spark/ui/static/webui.js @@ -19,6 +19,7 @@ /* eslint-disable no-unused-vars */ var uiRoot = ""; var appBasePath = ""; +var reverseProxyURL = ""; function setUIRoot(val) { uiRoot = val; @@ -27,6 +28,11 @@ function setUIRoot(val) { function setAppBasePath(path) { appBasePath = path; } + +function setReverseProxyURL(base) { + reverseProxyURL = base; +} + /* eslint-enable no-unused-vars */ function collapseTablePageLoad(name, table){ diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala index 7257371256d9..32dc6bc70513 100644 --- a/core/src/main/scala/org/apache/spark/SparkContext.scala +++ b/core/src/main/scala/org/apache/spark/SparkContext.scala @@ -592,9 +592,10 @@ class SparkContext(config: SparkConf) extends Logging { _env.blockManager.blockStoreClient.setAppAttemptId(attemptId) } if (_conf.get(UI_REVERSE_PROXY)) { - val proxyUrl = _conf.get(UI_REVERSE_PROXY_URL.key, "").stripSuffix("/") + - "/proxy/" + _applicationId + val reverseProxyURL = _conf.get(UI_REVERSE_PROXY_URL.key, "").stripSuffix("/") + val proxyUrl = reverseProxyURL + "/proxy/" + _applicationId System.setProperty("spark.ui.proxyBase", proxyUrl) + System.setProperty("spark.ui.reverseProxyURL", reverseProxyURL) } _ui.foreach(_.setAppId(_applicationId)) _env.blockManager.initialize(_applicationId) diff --git a/core/src/main/scala/org/apache/spark/ui/UIUtils.scala b/core/src/main/scala/org/apache/spark/ui/UIUtils.scala index 60db87c18a97..34243070eded 100644 --- a/core/src/main/scala/org/apache/spark/ui/UIUtils.scala +++ b/core/src/main/scala/org/apache/spark/ui/UIUtils.scala @@ -240,6 +240,7 @@ private[spark] object UIUtils extends Logging { + } def vizHeaderNodes(request: HttpServletRequest): Seq[Node] = {