aboutsummaryrefslogtreecommitdiff
path: root/common/network-common
diff options
context:
space:
mode:
authorMarcelo Vanzin <vanzin@cloudera.com>2016-03-07 14:13:44 -0800
committerMarcelo Vanzin <vanzin@cloudera.com>2016-03-07 14:13:44 -0800
commite1fb857992074164dcaa02498c5a9604fac6f57e (patch)
tree5f2a9de0230df4ebd0ca7317c879472eb8d3fbbc /common/network-common
parente9e67b39abb23a88d8be2d0fea5b5fd93184a25b (diff)
downloadspark-e1fb857992074164dcaa02498c5a9604fac6f57e.tar.gz
spark-e1fb857992074164dcaa02498c5a9604fac6f57e.tar.bz2
spark-e1fb857992074164dcaa02498c5a9604fac6f57e.zip
[SPARK-529][CORE][YARN] Add type-safe config keys to SparkConf.
This is, in a way, the basics to enable SPARK-529 (which was closed as won't fix but I think is still valuable). In fact, Spark SQL created something for that, and this change basically factors out that code and inserts it into SparkConf, with some extra bells and whistles. To showcase the usage of this pattern, I modified the YARN backend to use the new config keys (defined in the new `config` package object under `o.a.s.deploy.yarn`). Most of the changes are mechanic, although logic had to be slightly modified in a handful of places. Author: Marcelo Vanzin <vanzin@cloudera.com> Closes #10205 from vanzin/conf-opts.
Diffstat (limited to 'common/network-common')
-rw-r--r--common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java b/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
index b3d8e0cd7c..ccc527306d 100644
--- a/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
+++ b/common/network-common/src/main/java/org/apache/spark/network/util/JavaUtils.java
@@ -159,10 +159,10 @@ public class JavaUtils {
.build();
/**
- * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a time count for
- * internal use. If no suffix is provided a direct conversion is attempted.
+ * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a time count in the given unit.
+ * The unit is also considered the default if the given string does not specify a unit.
*/
- private static long parseTimeString(String str, TimeUnit unit) {
+ public static long timeStringAs(String str, TimeUnit unit) {
String lower = str.toLowerCase().trim();
try {
@@ -195,7 +195,7 @@ public class JavaUtils {
* no suffix is provided, the passed number is assumed to be in ms.
*/
public static long timeStringAsMs(String str) {
- return parseTimeString(str, TimeUnit.MILLISECONDS);
+ return timeStringAs(str, TimeUnit.MILLISECONDS);
}
/**
@@ -203,15 +203,14 @@ public class JavaUtils {
* no suffix is provided, the passed number is assumed to be in seconds.
*/
public static long timeStringAsSec(String str) {
- return parseTimeString(str, TimeUnit.SECONDS);
+ return timeStringAs(str, TimeUnit.SECONDS);
}
/**
- * Convert a passed byte string (e.g. 50b, 100kb, or 250mb) to a ByteUnit for
- * internal use. If no suffix is provided a direct conversion of the provided default is
- * attempted.
+ * Convert a passed byte string (e.g. 50b, 100kb, or 250mb) to the given. If no suffix is
+ * provided, a direct conversion to the provided unit is attempted.
*/
- private static long parseByteString(String str, ByteUnit unit) {
+ public static long byteStringAs(String str, ByteUnit unit) {
String lower = str.toLowerCase().trim();
try {
@@ -252,7 +251,7 @@ public class JavaUtils {
* If no suffix is provided, the passed number is assumed to be in bytes.
*/
public static long byteStringAsBytes(String str) {
- return parseByteString(str, ByteUnit.BYTE);
+ return byteStringAs(str, ByteUnit.BYTE);
}
/**
@@ -262,7 +261,7 @@ public class JavaUtils {
* If no suffix is provided, the passed number is assumed to be in kibibytes.
*/
public static long byteStringAsKb(String str) {
- return parseByteString(str, ByteUnit.KiB);
+ return byteStringAs(str, ByteUnit.KiB);
}
/**
@@ -272,7 +271,7 @@ public class JavaUtils {
* If no suffix is provided, the passed number is assumed to be in mebibytes.
*/
public static long byteStringAsMb(String str) {
- return parseByteString(str, ByteUnit.MiB);
+ return byteStringAs(str, ByteUnit.MiB);
}
/**
@@ -282,7 +281,7 @@ public class JavaUtils {
* If no suffix is provided, the passed number is assumed to be in gibibytes.
*/
public static long byteStringAsGb(String str) {
- return parseByteString(str, ByteUnit.GiB);
+ return byteStringAs(str, ByteUnit.GiB);
}
/**