forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spark-544, introducing SparkConf and related configuration overhaul.
- Loading branch information
1 parent
0bc57c5
commit 2573add
Showing
96 changed files
with
612 additions
and
478 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.apache.spark | ||
|
||
import scala.collection.JavaConversions._ | ||
import scala.collection.concurrent.TrieMap | ||
|
||
import com.typesafe.config.ConfigFactory | ||
|
||
private[spark] class SparkConf(loadClasspathRes: Boolean = true) extends Serializable { | ||
@transient lazy val config = ConfigFactory.systemProperties() | ||
.withFallback(ConfigFactory.parseResources("spark.conf")) | ||
// TODO this should actually be synchronized | ||
private val configMap = TrieMap[String, String]() | ||
|
||
if (loadClasspathRes && !config.entrySet().isEmpty) { | ||
for (e <- config.entrySet()) { | ||
configMap += ((e.getKey, e.getValue.unwrapped().toString)) | ||
} | ||
} | ||
|
||
def setMasterUrl(master: String) = { | ||
if (master != null) | ||
configMap += (("spark.master", master)) | ||
this | ||
} | ||
|
||
def setAppName(name: String) = { | ||
if (name != null) | ||
configMap += (("spark.appName", name)) | ||
this | ||
} | ||
|
||
def setJars(jars: Seq[String]) = { | ||
if (!jars.isEmpty) | ||
configMap += (("spark.jars", jars.mkString(","))) | ||
this | ||
} | ||
|
||
def set(k: String, value: String) = { | ||
configMap += ((k, value)) | ||
this | ||
} | ||
|
||
def setSparkHome(home: String) = { | ||
if (home != null) | ||
configMap += (("spark.home", home)) | ||
this | ||
} | ||
|
||
def set(map: Seq[(String, String)]) = { | ||
if (map != null && !map.isEmpty) | ||
configMap ++= map | ||
this | ||
} | ||
|
||
def get(k: String): String = { | ||
configMap(k) | ||
} | ||
|
||
def getAllConfiguration = configMap.clone.entrySet().iterator | ||
|
||
def getOrElse(k: String, defaultValue: String): String = { | ||
configMap.getOrElse(k, defaultValue) | ||
} | ||
|
||
override def clone: SparkConf = { | ||
val conf = new SparkConf(false) | ||
conf.set(configMap.toSeq) | ||
conf | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.