Skip to content

Commit 8e3822a

Browse files
zzvaraAndrew Or
authored andcommitted
[SPARK-7504] [YARN] NullPointerException when initializing SparkContext in YARN-cluster mode
Added a simple checking for SparkContext. Also added two rational checking against null at AM object. Author: ehnalis <[email protected]> Closes #6083 from ehnalis/cluster and squashes the following commits: 926bd96 [ehnalis] Moved check to SparkContext. 7c89b6e [ehnalis] Remove false line. ea2a5fe [ehnalis] [SPARK-7504] [YARN] NullPointerException when initializing SparkContext in YARN-cluster mode 4924e01 [ehnalis] [SPARK-7504] [YARN] NullPointerException when initializing SparkContext in YARN-cluster mode 39e4fa3 [ehnalis] SPARK-7504 [YARN] NullPointerException when initializing SparkContext in YARN-cluster mode 9f287c5 [ehnalis] [SPARK-7504] [YARN] NullPointerException when initializing SparkContext in YARN-cluster mode
1 parent ad92af9 commit 8e3822a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
371371
throw new SparkException("An application name must be set in your configuration")
372372
}
373373

374+
// System property spark.yarn.app.id must be set if user code ran by AM on a YARN cluster
375+
// yarn-standalone is deprecated, but still supported
376+
if ((master == "yarn-cluster" || master == "yarn-standalone") &&
377+
!_conf.contains("spark.yarn.app.id")) {
378+
throw new SparkException("Detected yarn-cluster mode, but isn't running on a cluster. " +
379+
"Deployment to YARN is not supported directly by SparkContext. Please use spark-submit.")
380+
}
381+
374382
if (_conf.getBoolean("spark.logConf", false)) {
375383
logInfo("Spark configuration:\n" + _conf.toDebugString)
376384
}

0 commit comments

Comments
 (0)