@@ -35,6 +35,7 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration
3535
3636import org .apache .spark .{Logging , SecurityManager , SparkConf , SparkContext , SparkEnv }
3737import org .apache .spark .deploy .SparkHadoopUtil
38+ import org .apache .spark .deploy .history .HistoryServer
3839import org .apache .spark .scheduler .cluster .CoarseGrainedSchedulerBackend
3940import org .apache .spark .scheduler .cluster .CoarseGrainedClusterMessages .AddWebUIFilter
4041import org .apache .spark .util .{AkkaUtils , SignalLogger , Utils }
@@ -70,16 +71,21 @@ private[spark] class ApplicationMaster(args: ApplicationMasterArguments,
7071 private val sparkContextRef = new AtomicReference [SparkContext ](null )
7172
7273 final def run (): Int = {
74+ val appAttemptId = client.getAttemptId()
75+
7376 if (isDriver) {
7477 // Set the web ui port to be ephemeral for yarn so we don't conflict with
7578 // other spark processes running on the same box
7679 System .setProperty(" spark.ui.port" , " 0" )
7780
7881 // Set the master property to match the requested mode.
7982 System .setProperty(" spark.master" , " yarn-cluster" )
83+
84+ // Propagate the application ID so that YarnClusterSchedulerBackend can pick it up.
85+ System .setProperty(" spark.yarn.app.id" , appAttemptId.getApplicationId().toString())
8086 }
8187
82- logInfo(" ApplicationAttemptId: " + client.getAttemptId() )
88+ logInfo(" ApplicationAttemptId: " + appAttemptId )
8389
8490 val cleanupHook = new Runnable {
8591 override def run () {
@@ -153,8 +159,12 @@ private[spark] class ApplicationMaster(args: ApplicationMasterArguments,
153159
154160 private def registerAM (uiAddress : String ) = {
155161 val sc = sparkContextRef.get()
156- val historyAddress = YarnSparkHadoopUtil .getUIHistoryAddress(sparkConf,
157- client.getAttemptId().getApplicationId().toString())
162+
163+ val appId = client.getAttemptId().getApplicationId().toString()
164+ val historyAddress =
165+ sparkConf.getOption(" spark.yarn.historyServer.address" )
166+ .map { address => s " ${address}${HistoryServer .UI_PATH_PREFIX }/ ${appId}" }
167+ .getOrElse(" " )
158168
159169 allocator = client.register(yarnConf,
160170 if (sc != null ) sc.getConf else sparkConf,
0 commit comments