-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-2058: Overriding SPARK_HOME/conf with SPARK_CONF_DIR #2481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,9 @@ import org.apache.spark.util.Utils | |
|
|
||
| /** | ||
| * Parses and encapsulates arguments from the spark-submit script. | ||
| * The env argument is used for testing. | ||
| */ | ||
| private[spark] class SparkSubmitArguments(args: Seq[String]) { | ||
| private[spark] class SparkSubmitArguments(args: Seq[String], env: Map[String, String] = sys.env) { | ||
| var master: String = null | ||
| var deployMode: String = null | ||
| var executorMemory: String = null | ||
|
|
@@ -86,20 +87,12 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) { | |
| private def mergeSparkProperties(): Unit = { | ||
| // Use common defaults file, if not specified by user | ||
| if (propertiesFile == null) { | ||
| sys.env.get("SPARK_CONF_DIR").foreach { sparkConfDir => | ||
| val sep = File.separator | ||
| val defaultPath = s"${sparkConfDir}${sep}spark-defaults.conf" | ||
| val file = new File(defaultPath) | ||
| if (file.exists()) { | ||
| propertiesFile = file.getAbsolutePath | ||
| } | ||
| } | ||
| } | ||
| val sep = File.separator | ||
| val sparkHomeConfig = env.get("SPARK_HOME").map(sparkHome => s"${sparkHome}${sep}conf") | ||
| val confDir = env.get("SPARK_CONF_DIR").orElse(sparkHomeConfig) | ||
|
|
||
| if (propertiesFile == null) { | ||
| sys.env.get("SPARK_HOME").foreach { sparkHome => | ||
| val sep = File.separator | ||
| val defaultPath = s"${sparkHome}${sep}conf${sep}spark-defaults.conf" | ||
| confDir.foreach { sparkConfDir => | ||
| val defaultPath = s"${sparkConfDir}${sep}spark-defaults.conf" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for this change. The previous code is duplicated. |
||
| val file = new File(defaultPath) | ||
| if (file.exists()) { | ||
| propertiesFile = file.getAbsolutePath | ||
|
|
@@ -113,19 +106,18 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) { | |
|
|
||
| // Use properties file as fallback for values which have a direct analog to | ||
| // arguments in this script. | ||
| master = Option(master).getOrElse(properties.get("spark.master").orNull) | ||
| executorMemory = Option(executorMemory) | ||
| .getOrElse(properties.get("spark.executor.memory").orNull) | ||
| executorCores = Option(executorCores) | ||
| .getOrElse(properties.get("spark.executor.cores").orNull) | ||
| master = Option(master).orElse(properties.get("spark.master")).orNull | ||
| executorMemory = Option(executorMemory).orElse(properties.get("spark.executor.memory")).orNull | ||
| executorCores = Option(executorCores).orElse(properties.get("spark.executor.cores")).orNull | ||
| totalExecutorCores = Option(totalExecutorCores) | ||
| .getOrElse(properties.get("spark.cores.max").orNull) | ||
| name = Option(name).getOrElse(properties.get("spark.app.name").orNull) | ||
| jars = Option(jars).getOrElse(properties.get("spark.jars").orNull) | ||
| .orElse(properties.get("spark.cores.max")) | ||
| .orNull | ||
| name = Option(name).orElse(properties.get("spark.app.name")).orNull | ||
| jars = Option(jars).orElse(properties.get("spark.jars")).orNull | ||
|
|
||
| // This supports env vars in older versions of Spark | ||
| master = Option(master).getOrElse(System.getenv("MASTER")) | ||
| deployMode = Option(deployMode).getOrElse(System.getenv("DEPLOY_MODE")) | ||
| master = Option(master).orElse(env.get("MASTER")).orNull | ||
| deployMode = Option(deployMode).orElse(env.get("DEPLOY_MODE")).orNull | ||
|
|
||
| // Try to set main class from JAR if no --class argument is given | ||
| if (mainClass == null && !isPython && primaryResource != null) { | ||
|
|
@@ -178,7 +170,7 @@ private[spark] class SparkSubmitArguments(args: Seq[String]) { | |
| } | ||
|
|
||
| if (master.startsWith("yarn")) { | ||
| val hasHadoopEnv = sys.env.contains("HADOOP_CONF_DIR") || sys.env.contains("YARN_CONF_DIR") | ||
| val hasHadoopEnv = env.contains("HADOOP_CONF_DIR") || env.contains("YARN_CONF_DIR") | ||
| if (!hasHadoopEnv && !Utils.isTesting) { | ||
| throw new Exception(s"When running with master '$master' " + | ||
| "either HADOOP_CONF_DIR or YARN_CONF_DIR must be set in the environment.") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this back down to where the comment is, but this is trivial I can fix it myself when I merge it.