Skip to content

Commit ea95683

Browse files
gerashegalovMarcelo Vanzin
authored andcommitted
[SPARK-22914][DEPLOY] Register history.ui.port
## What changes were proposed in this pull request? Register spark.history.ui.port as a known spark conf to be used in substitution expressions even if it's not set explicitly. ## How was this patch tested? Added unit test to demonstrate the issue Author: Gera Shegalov <gera@apache.org> Author: Gera Shegalov <gshegalov@salesforce.com> Closes #20098 from gerashegalov/gera/register-SHS-port-conf.
1 parent 930b90a commit ea95683

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
2828

2929
import org.apache.spark.{SecurityManager, SparkConf}
3030
import org.apache.spark.deploy.SparkHadoopUtil
31+
import org.apache.spark.deploy.history.config.HISTORY_SERVER_UI_PORT
3132
import org.apache.spark.internal.Logging
3233
import org.apache.spark.internal.config._
3334
import org.apache.spark.status.api.v1.{ApiRootResource, ApplicationInfo, UIRoot}
@@ -276,7 +277,7 @@ object HistoryServer extends Logging {
276277
.newInstance(conf)
277278
.asInstanceOf[ApplicationHistoryProvider]
278279

279-
val port = conf.getInt("spark.history.ui.port", 18080)
280+
val port = conf.get(HISTORY_SERVER_UI_PORT)
280281

281282
val server = new HistoryServer(conf, provider, securityManager, port)
282283
server.bind()

core/src/main/scala/org/apache/spark/deploy/history/config.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ private[spark] object config {
4444
.bytesConf(ByteUnit.BYTE)
4545
.createWithDefaultString("10g")
4646

47+
val HISTORY_SERVER_UI_PORT = ConfigBuilder("spark.history.ui.port")
48+
.doc("Web UI port to bind Spark History Server")
49+
.intConf
50+
.createWithDefault(18080)
51+
4752
}

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,8 @@ private[spark] class ApplicationMaster(args: ApplicationMasterArguments) extends
427427
uiAddress: Option[String]) = {
428428
val appId = client.getAttemptId().getApplicationId().toString()
429429
val attemptId = client.getAttemptId().getAttemptId().toString()
430-
val historyAddress =
431-
_sparkConf.get(HISTORY_SERVER_ADDRESS)
432-
.map { text => SparkHadoopUtil.get.substituteHadoopVariables(text, yarnConf) }
433-
.map { address => s"${address}${HistoryServer.UI_PATH_PREFIX}/${appId}/${attemptId}" }
434-
.getOrElse("")
430+
val historyAddress = ApplicationMaster
431+
.getHistoryServerAddress(_sparkConf, yarnConf, appId, attemptId)
435432

436433
val driverUrl = RpcEndpointAddress(
437434
_sparkConf.get("spark.driver.host"),
@@ -834,6 +831,16 @@ object ApplicationMaster extends Logging {
834831
master.getAttemptId
835832
}
836833

834+
private[spark] def getHistoryServerAddress(
835+
sparkConf: SparkConf,
836+
yarnConf: YarnConfiguration,
837+
appId: String,
838+
attemptId: String): String = {
839+
sparkConf.get(HISTORY_SERVER_ADDRESS)
840+
.map { text => SparkHadoopUtil.get.substituteHadoopVariables(text, yarnConf) }
841+
.map { address => s"${address}${HistoryServer.UI_PATH_PREFIX}/${appId}/${attemptId}" }
842+
.getOrElse("")
843+
}
837844
}
838845

839846
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.deploy.yarn
19+
20+
import org.apache.hadoop.yarn.conf.YarnConfiguration
21+
22+
import org.apache.spark.{SparkConf, SparkFunSuite}
23+
24+
class ApplicationMasterSuite extends SparkFunSuite {
25+
26+
test("history url with hadoop and spark substitutions") {
27+
val host = "rm.host.com"
28+
val port = 18080
29+
val sparkConf = new SparkConf()
30+
31+
sparkConf.set("spark.yarn.historyServer.address",
32+
"http://${hadoopconf-yarn.resourcemanager.hostname}:${spark.history.ui.port}")
33+
val yarnConf = new YarnConfiguration()
34+
yarnConf.set("yarn.resourcemanager.hostname", host)
35+
val appId = "application_123_1"
36+
val attemptId = appId + "_1"
37+
38+
val shsAddr = ApplicationMaster
39+
.getHistoryServerAddress(sparkConf, yarnConf, appId, attemptId)
40+
41+
assert(shsAddr === s"http://${host}:${port}/history/${appId}/${attemptId}")
42+
}
43+
}

0 commit comments

Comments
 (0)