Skip to content

Commit

Permalink
SPARK-5425: Modified Utils.getSystemProperties to return a map of all…
Browse files Browse the repository at this point in the history
… system properties - explicit + defaults
  • Loading branch information
jacek-lewandowski committed Feb 2, 2015
1 parent 74b4489 commit 6c48a1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions core/src/main/scala/org/apache/spark/SparkConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

package org.apache.spark

import scala.collection.JavaConverters._
import scala.collection.mutable.HashMap

import org.apache.spark.util.Utils

/**
* Configuration for a Spark application. Used to set various Spark parameters as key-value pairs.
*
Expand Down Expand Up @@ -49,9 +50,8 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {

if (loadDefaults) {
// Load any spark.* system properties
val propNames = System.getProperties.stringPropertyNames().asScala
for (k <- propNames if k.startsWith("spark.")) {
settings(k) = System.getProperty(k)
for ((key, value) <- Utils.getSystemProperties if key.startsWith("spark.")) {
settings(key) = value
}
}

Expand Down
11 changes: 8 additions & 3 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,14 @@ private[spark] object Utils extends Logging {
hashAbs
}

/** Returns a copy of the system properties that is thread-safe to iterator over. */
def getSystemProperties(): Map[String, String] = {
System.getProperties.clone().asInstanceOf[java.util.Properties].toMap[String, String]
/** Returns the system properties map that is thread-safe to iterator over. It gets the
* properties which have been set explicitly, as well as those for which only a default value
* has been defined. */
def getSystemProperties: Map[String, String] = {
val sysProps = for (key <- System.getProperties.stringPropertyNames()) yield
(key, System.getProperty(key))

sysProps.toMap
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.apache.spark.examples

import scala.collection.JavaConversions._

import org.apache.spark.util.Utils

/** Prints out environmental information, sleeps, and then exits. Made to
* test driver submission in the standalone scheduler. */
object DriverSubmissionTest {
Expand All @@ -30,7 +32,7 @@ object DriverSubmissionTest {
val numSecondsToSleep = args(0).toInt

val env = System.getenv()
val properties = System.getProperties()
val properties = Utils.getSystemProperties

println("Environment variables containing SPARK_TEST:")
env.filter{case (k, v) => k.contains("SPARK_TEST")}.foreach(println)
Expand Down

0 comments on commit 6c48a1f

Please sign in to comment.