Skip to content

Commit 7f36999

Browse files
committed
Use env vars to detect if running in YARN container.
1 parent 399ac25 commit 7f36999

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,16 @@ private[spark] object Utils extends Logging {
464464
getOrCreateLocalRootDirs(conf)(0)
465465
}
466466

467+
private[spark] def isRunningInYarnContainer(conf: SparkConf): Boolean = {
468+
conf.getenv("NM_HOST") != null || conf.getenv("CONTAINER_ID") != null
469+
}
470+
467471
/**
468472
* Gets or creates the directories listed in spark.local.dir or SPARK_LOCAL_DIRS,
469473
* and returns only the directories that exist / could be created.
470474
*/
471475
private[spark] def getOrCreateLocalRootDirs(conf: SparkConf): Array[String] = {
472-
val isYarn = java.lang.Boolean.valueOf(
473-
System.getProperty("SPARK_YARN_MODE", conf.getenv("SPARK_YARN_MODE")))
474-
val confValue = if (isYarn) {
476+
val confValue = if (isRunningInYarnContainer(conf)) {
475477
// If we are in yarn mode, systems can have different disk layouts so we must set it
476478
// to what Yarn on this system said was available.
477479
getYarnLocalDirs(conf)

0 commit comments

Comments
 (0)