File tree Expand file tree Collapse file tree 3 files changed +10
-13
lines changed
core/src/main/scala/org/apache/spark
yarn/src/main/scala/org/apache/spark/deploy/yarn Expand file tree Collapse file tree 3 files changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -448,6 +448,15 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
448448 }
449449 }
450450 }
451+
452+ // System property spark.yarn.app.id must be set if user code ran by AM on a YARN cluster
453+ // yarn-standalone is deprecated, but still supported
454+ if ((get(" spark.master" ) == " yarn-cluster" || get(" spark.master" ) == " yarn-standalone" ) &&
455+ get(" spark.yarn.app.id" , null ) == null ) {
456+ throw new SparkException (" Detected yarn-cluster mode, but isn't running on a cluster. " +
457+ " Deployment to YARN is not supported directly by SparkContext. Please use spark-submit." )
458+ }
459+
451460 }
452461
453462 /**
Original file line number Diff line number Diff line change @@ -371,13 +371,6 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
371371 throw new SparkException (" An application name must be set in your configuration" )
372372 }
373373
374- // Thread name has been set to "Driver" if user code ran by AM on a YARN cluster
375- if (master == " yarn-cluster" &&
376- Thread .currentThread().getName != " Driver" ) {
377- throw new SparkException (" Detected yarn-cluster mode, but isn't running on a cluster. " +
378- " Deployment to YARN is not supported directly by SparkContext. Please use spark-submit." )
379- }
380-
381374 if (_conf.getBoolean(" spark.logConf" , false )) {
382375 logInfo(" Spark configuration:\n " + _conf.toDebugString)
383376 }
@@ -1477,6 +1470,7 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
14771470 def addJar (path : String ) {
14781471 if (path == null ) {
14791472 logWarning(" null specified as parameter to addJar" )
1473+ // yarn-standalone is deprecated, but still supported
14801474 } else {
14811475 var key = " "
14821476 if (path.contains(" \\ " )) {
Original file line number Diff line number Diff line change @@ -573,16 +573,10 @@ object ApplicationMaster extends Logging {
573573 }
574574
575575 private [spark] def sparkContextInitialized (sc : SparkContext ): Unit = {
576- if (master == null ){
577- throw new SparkException (" ApplicationMaster is not initialized!" )
578- }
579576 master.sparkContextInitialized(sc)
580577 }
581578
582579 private [spark] def sparkContextStopped (sc : SparkContext ): Boolean = {
583- if (master == null ){
584- throw new SparkException (" ApplicationMaster is not initialized!" )
585- }
586580 master.sparkContextStopped(sc)
587581 }
588582
You can’t perform that action at this time.
0 commit comments