Github user witgo commented on a diff in the pull request: https://github.com/apache/spark/pull/2379#discussion_r18070980 --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala --- @@ -1357,6 +1357,58 @@ private[spark] object Utils extends Logging { } } + /** + * Load the default spark properties from the file + * Use common defaults file, if not specified by user. + */ + def loadDefaultSparkProperties(conf: SparkConf, + file: String = null): String = { + val path = Option(file).getOrElse(getDefaultConfigFile) + Option(path).foreach { confFile => + getPropertiesFromFile(confFile).filter { case (k, v) => + k.startsWith("spark.") + }.foreach { case (k, v) => + conf.setIfMissing(k, v) + sys.props.getOrElseUpdate(k, v) + } + } + path + } + + /** Load properties present in the given file. */ + def getPropertiesFromFile(filename: String): Map[String, String] = { + val file = new File(filename) + require(file.exists(), s"Properties file $file does not exist") + require(file.isFile(), s"Properties file $file is not a normal file") + + val inReader = new InputStreamReader(new FileInputStream(file), "UTF-8") + try { + val properties = new Properties() + properties.load(inReader) + properties.stringPropertyNames().map(k => (k, properties(k).trim)).toMap + } catch { + case e: IOException => + throw new SparkException(s"Failed when loading Spark properties from $filename", e) + } finally { + inReader.close() + } + } + + /** Return the default spark configuration file */ + def getDefaultConfigFile(): String = { + val s = File.separator + val configFile = sys.env.get("SPARK_CONF_DIR") + .map(t => new File(s"$t${s}spark-defaults.conf")) + .filter(_.isFile) + .map(_.getAbsolutePath) + + configFile.getOrElse(sys.env.get("SPARK_HOME") + .map(t => new File(s"${t}${s}conf${s}spark-defaults.conf")) + .filter(_.isFile) + .map(_.getAbsolutePath) --- End diff -- eg: ```shell export SPARK_CONF_DIR=/opt/spark/config export SPARK_HOME=/opt/spark/spark_1.10 ``` `/opt/spark/config/spark-defaults.conf` does not exist. `/opt/spark/spark_1.10/conf/spark-defaults.conf` exists. The above code can't load `/opt/spark/spark_1.10/conf/spark-defaults.conf`
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org