Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2379#discussion_r18548720
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1387,6 +1387,54 @@ private[spark] object Utils extends Logging {
         }
       }
     
    +  /**
    +   * Load default Spark properties from the given file. If no file is 
provided,
    +   * use the common defaults file. This mutates state in the given 
SparkConf and
    +   * in this JVM's system properties if the config specified in the file 
is not
    +   * already set. Return the path of the properties file used.
    +   */
    +  def loadDefaultSparkProperties(conf: SparkConf, filePath: String = 
null): String = {
    +    val path = Option(filePath).getOrElse(getDefaultPropertiesFile)
    +    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 path of the default Spark properties file. */
    +  def getDefaultPropertiesFile(): String = {
    +    sys.env.get("SPARK_CONF_DIR")
    +      .orElse(sys.env.get("SPARK_HOME").map { t => 
s"$t${File.separator}conf"})
    +      .map { t => new File(s"$t${File.separator}spark-defaults.conf")}
    --- End diff --
    
    nit: space before `}`


---
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

Reply via email to