Skip to content

Commit af0adf7

Browse files
committed
Automatically add user jar
1 parent a56b125 commit af0adf7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ object SparkSubmit {
116116
val file = new File(filename)
117117
getDefaultProperties(file).foreach { case (k, v) =>
118118
if (k.startsWith("spark")) {
119+
if (k == "spark.master")
120+
throw new Exception("Setting spark.master in spark-defaults.properties is not " +
121+
"supported. Use MASTER environment variable or --master.")
119122
sysProps(k) = v
120123
if (appArgs.verbose) printStream.println(s"Adding default property: $k=$v")
121124
}
@@ -165,10 +168,11 @@ object SparkSubmit {
165168
new OptionAssigner(appArgs.files, YARN, true, clOption = "--files"),
166169
new OptionAssigner(appArgs.archives, YARN, false, sysProp = "spark.yarn.dist.archives"),
167170
new OptionAssigner(appArgs.archives, YARN, true, clOption = "--archives"),
168-
new OptionAssigner(appArgs.jars, YARN, true, clOption = "--addJars")
171+
new OptionAssigner(appArgs.jars, YARN, true, clOption = "--addJars"),
172+
new OptionAssigner(appArgs.jars, STANDALONE | YARN | MESOS, true, sysProp = "spark.jars")
169173
)
170174

171-
// more jars
175+
// For client mode make any added jars immediately visible on the classpath
172176
if (appArgs.jars != null && !deployOnCluster) {
173177
for (jar <- appArgs.jars.split(",")) {
174178
childClasspath += jar
@@ -186,6 +190,14 @@ object SparkSubmit {
186190
}
187191
}
188192

193+
// For standalone mode, add the application jar automatically so the user doesn't have to
194+
// call sc.addJar. TODO: Standalone mode in the cluster
195+
if (clusterManager == STANDALONE) {
196+
val existingJars = sysProps.get("spark.jars").map(x => x.split(",").toSeq).getOrElse(Seq())
197+
sysProps.put("spark.jars", (existingJars ++ Seq(appArgs.primaryResource)).mkString(","))
198+
println("SPARK JARS" + sysProps.get("spark.jars"))
199+
}
200+
189201
if (deployOnCluster && clusterManager == STANDALONE) {
190202
if (appArgs.supervise) {
191203
childArgs += "--supervise"
@@ -196,7 +208,7 @@ object SparkSubmit {
196208
childArgs += (appArgs.master, appArgs.primaryResource, appArgs.mainClass)
197209
}
198210

199-
// args
211+
// Arguments to be passed to user program
200212
if (appArgs.childArgs != null) {
201213
if (!deployOnCluster || clusterManager == STANDALONE) {
202214
childArgs ++= appArgs.childArgs

0 commit comments

Comments
 (0)