diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala index 9a6a43914bca3..5ca624a8d66cb 100644 --- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala +++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala @@ -211,9 +211,13 @@ private[spark] class ApplicationMaster( final def run(): Int = { try { val attemptID = if (isClusterMode) { - // Set the web ui port to be ephemeral for yarn so we don't conflict with - // other spark processes running on the same box - System.setProperty(UI_PORT.key, "0") + // Set the web ui port to be ephemeral for yarn if not set explicitly + // so we don't conflict with other spark processes running on the same box + // If set explicitly, Web UI will attempt to run on UI_PORT and try + // incrementally until UI_PORT + `spark.port.maxRetries` + if (System.getProperty(UI_PORT.key) == null) { + System.setProperty(UI_PORT.key, "0") + } // Set the master and deploy mode property to match the requested mode. System.setProperty("spark.master", "yarn")