Skip to content

Commit 1fbb925

Browse files
committed
add addAmIpFilter to yarn alpha
1 parent 210299c commit 1fbb925

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import akka.actor.Terminated
3232
import org.apache.spark.{Logging, SecurityManager, SparkConf}
3333
import org.apache.spark.util.{Utils, AkkaUtils}
3434
import org.apache.spark.scheduler.cluster.CoarseGrainedSchedulerBackend
35+
import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages.AddWebUIFilter
3536
import org.apache.spark.scheduler.SplitInfo
3637
import org.apache.spark.deploy.SparkHadoopUtil
3738

@@ -81,6 +82,9 @@ class ExecutorLauncher(args: ApplicationMasterArguments, conf: Configuration, sp
8182
case x: DisassociatedEvent =>
8283
logInfo(s"Driver terminated or disconnected! Shutting down. $x")
8384
driverClosed = true
85+
case x: AddWebUIFilter =>
86+
logInfo(s"Add WebUI Filter. $x")
87+
driver ! x
8488
}
8589
}
8690

@@ -111,7 +115,7 @@ class ExecutorLauncher(args: ApplicationMasterArguments, conf: Configuration, sp
111115
}
112116

113117
waitForSparkMaster()
114-
118+
addAmIpFilter()
115119
// Allocate all containers
116120
allocateExecutors()
117121

@@ -171,7 +175,8 @@ class ExecutorLauncher(args: ApplicationMasterArguments, conf: Configuration, sp
171175
}
172176

173177
private def registerApplicationMaster(): RegisterApplicationMasterResponse = {
174-
logInfo("Registering the ApplicationMaster")
178+
val appUIAddress = sparkConf.get("spark.driver.appUIAddress", "")
179+
logInfo(s"Registering the ApplicationMaster with appUIAddress: $appUIAddress")
175180
val appMasterRequest = Records.newRecord(classOf[RegisterApplicationMasterRequest])
176181
.asInstanceOf[RegisterApplicationMasterRequest]
177182
appMasterRequest.setApplicationAttemptId(appAttemptId)
@@ -180,10 +185,21 @@ class ExecutorLauncher(args: ApplicationMasterArguments, conf: Configuration, sp
180185
appMasterRequest.setHost(Utils.localHostName())
181186
appMasterRequest.setRpcPort(0)
182187
// What do we provide here ? Might make sense to expose something sensible later ?
183-
appMasterRequest.setTrackingUrl("")
188+
appMasterRequest.setTrackingUrl(appUIAddress)
184189
resourceManager.registerApplicationMaster(appMasterRequest)
185190
}
186191

192+
// add the yarn amIpFilter that Yarn requires for properly securing the UI
193+
private def addAmIpFilter() {
194+
val proxy = YarnConfiguration.getProxyHostAndPort(conf)
195+
val parts: Array[String] = proxy.split(":")
196+
val proxyBase = System.getenv(ApplicationConstants.APPLICATION_WEB_PROXY_BASE_ENV)
197+
val uriBase = "http://" + proxy + proxyBase
198+
val amFilter = "PROXY_HOST=" + parts(0) + "," + "PROXY_URI_BASE=" + uriBase
199+
val amFilterName = "org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter"
200+
actor ! AddWebUIFilter(amFilterName, amFilter, proxyBase)
201+
}
202+
187203
private def waitForSparkMaster() {
188204
logInfo("Waiting for spark driver to be reachable.")
189205
var driverUp = false

0 commit comments

Comments
 (0)