Skip to content

Commit 8b78412

Browse files
andrewor14pwendell
authored andcommitted
[SPARK-1755] Respect SparkSubmit --name on YARN
Right now, SparkSubmit ignores the `--name` flag for both yarn-client and yarn-cluster. This is a bug. In client mode, SparkSubmit treats `--name` as a [cluster config](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala#L170) and does not propagate this to SparkContext. In cluster mode, SparkSubmit passes this flag to `org.apache.spark.deploy.yarn.Client`, which only uses it for the [YARN ResourceManager](https://github.com/apache/spark/blob/master/yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/Client.scala#L80), but does not propagate this to SparkContext. This PR ensures that `spark.app.name` is always set if SparkSubmit receives the `--name` flag, which is what the usage promises. This makes it possible for applications to start a SparkContext with an empty conf `val sc = new SparkContext(new SparkConf)`, and inherit the app name from SparkSubmit. Tested both modes on a YARN cluster. Author: Andrew Or <[email protected]> Closes #699 from andrewor14/yarn-app-name and squashes the following commits: 98f6a79 [Andrew Or] Fix tests dea932f [Andrew Or] Merge branch 'master' of github.com:apache/spark into yarn-app-name c86d9ca [Andrew Or] Respect SparkSubmit --name on YARN
1 parent 2fd2752 commit 8b78412

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,15 @@ object SparkSubmit {
160160
// each deploy mode; we iterate through these below
161161
val options = List[OptionAssigner](
162162
OptionAssigner(args.master, ALL_CLUSTER_MGRS, false, sysProp = "spark.master"),
163+
OptionAssigner(args.name, ALL_CLUSTER_MGRS, false, sysProp = "spark.app.name"),
163164
OptionAssigner(args.driverExtraClassPath, STANDALONE | YARN, true,
164165
sysProp = "spark.driver.extraClassPath"),
165166
OptionAssigner(args.driverExtraJavaOptions, STANDALONE | YARN, true,
166167
sysProp = "spark.driver.extraJavaOptions"),
167168
OptionAssigner(args.driverExtraLibraryPath, STANDALONE | YARN, true,
168169
sysProp = "spark.driver.extraLibraryPath"),
169170
OptionAssigner(args.driverMemory, YARN, true, clOption = "--driver-memory"),
170-
OptionAssigner(args.name, YARN, true, clOption = "--name"),
171+
OptionAssigner(args.name, YARN, true, clOption = "--name", sysProp = "spark.app.name"),
171172
OptionAssigner(args.queue, YARN, true, clOption = "--queue"),
172173
OptionAssigner(args.queue, YARN, false, sysProp = "spark.yarn.queue"),
173174
OptionAssigner(args.numExecutors, YARN, true, clOption = "--num-executors"),
@@ -188,8 +189,7 @@ object SparkSubmit {
188189
OptionAssigner(args.jars, YARN, true, clOption = "--addJars"),
189190
OptionAssigner(args.files, LOCAL | STANDALONE | MESOS, false, sysProp = "spark.files"),
190191
OptionAssigner(args.files, LOCAL | STANDALONE | MESOS, true, sysProp = "spark.files"),
191-
OptionAssigner(args.jars, LOCAL | STANDALONE | MESOS, false, sysProp = "spark.jars"),
192-
OptionAssigner(args.name, LOCAL | STANDALONE | MESOS, false, sysProp = "spark.app.name")
192+
OptionAssigner(args.jars, LOCAL | STANDALONE | MESOS, false, sysProp = "spark.jars")
193193
)
194194

195195
// For client mode make any added jars immediately visible on the classpath
@@ -205,7 +205,8 @@ object SparkSubmit {
205205
(clusterManager & opt.clusterManager) != 0) {
206206
if (opt.clOption != null) {
207207
childArgs += (opt.clOption, opt.value)
208-
} else if (opt.sysProp != null) {
208+
}
209+
if (opt.sysProp != null) {
209210
sysProps.put(opt.sysProp, opt.value)
210211
}
211212
}

core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class SparkSubmitSuite extends FunSuite with ShouldMatchers {
104104
"--master", "yarn", "--executor-memory", "5g", "--executor-cores", "5",
105105
"--class", "org.SomeClass", "--jars", "one.jar,two.jar,three.jar",
106106
"--driver-memory", "4g", "--queue", "thequeue", "--files", "file1.txt,file2.txt",
107-
"--archives", "archive1.txt,archive2.txt", "--num-executors", "6",
107+
"--archives", "archive1.txt,archive2.txt", "--num-executors", "6", "--name", "beauty",
108108
"thejar.jar", "arg1", "arg2")
109109
val appArgs = new SparkSubmitArguments(clArgs)
110110
val (childArgs, classpath, sysProps, mainClass) = createLaunchEnv(appArgs)
@@ -122,16 +122,17 @@ class SparkSubmitSuite extends FunSuite with ShouldMatchers {
122122
childArgsStr should include ("--num-executors 6")
123123
mainClass should be ("org.apache.spark.deploy.yarn.Client")
124124
classpath should have length (0)
125-
sysProps should have size (1)
125+
sysProps("spark.app.name") should be ("beauty")
126+
sysProps("SPARK_SUBMIT") should be ("true")
126127
}
127128

128129
test("handles YARN client mode") {
129130
val clArgs = Seq("--deploy-mode", "client",
130131
"--master", "yarn", "--executor-memory", "5g", "--executor-cores", "5",
131132
"--class", "org.SomeClass", "--jars", "one.jar,two.jar,three.jar",
132133
"--driver-memory", "4g", "--queue", "thequeue", "--files", "file1.txt,file2.txt",
133-
"--archives", "archive1.txt,archive2.txt", "--num-executors", "6", "thejar.jar",
134-
"arg1", "arg2")
134+
"--archives", "archive1.txt,archive2.txt", "--num-executors", "6", "--name", "trill",
135+
"thejar.jar", "arg1", "arg2")
135136
val appArgs = new SparkSubmitArguments(clArgs)
136137
val (childArgs, classpath, sysProps, mainClass) = createLaunchEnv(appArgs)
137138
childArgs.mkString(" ") should be ("arg1 arg2")
@@ -140,6 +141,7 @@ class SparkSubmitSuite extends FunSuite with ShouldMatchers {
140141
classpath should contain ("one.jar")
141142
classpath should contain ("two.jar")
142143
classpath should contain ("three.jar")
144+
sysProps("spark.app.name") should be ("trill")
143145
sysProps("spark.executor.memory") should be ("5g")
144146
sysProps("spark.executor.cores") should be ("5")
145147
sysProps("spark.yarn.queue") should be ("thequeue")

0 commit comments

Comments
 (0)