SLIDER-1020 Slider client to copy slider.* to AM config -not the feature. merely the propagation logic
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/c14eb35b Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/c14eb35b Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/c14eb35b Branch: refs/heads/develop Commit: c14eb35b3723fe3097c86ec687f3ed2e561b19a2 Parents: 3f8bfbd Author: Steve Loughran <ste...@apache.org> Authored: Mon Dec 14 17:38:33 2015 +0000 Committer: Steve Loughran <ste...@apache.org> Committed: Mon Dec 14 17:40:42 2015 +0000 ---------------------------------------------------------------------- .../core/launch/JavaCommandLineBuilder.java | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c14eb35b/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java b/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java index dcb322e..b8aa4c6 100644 --- a/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java +++ b/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java @@ -25,6 +25,9 @@ import org.apache.hadoop.yarn.api.ApplicationConstants; import org.apache.slider.common.tools.SliderUtils; import org.apache.slider.core.exceptions.BadConfigException; +import java.util.Iterator; +import java.util.Map; + /** * Command line builder purely for the Java CLI. * Some of the <code>define</code> methods are designed to work with Hadoop tool and @@ -94,15 +97,42 @@ public class JavaCommandLineBuilder extends CommandLineBuilder { * @param conf configuration source * @param keys keys */ - public void addConfOptions(Configuration conf, String...keys) { + public void addConfOptions(Configuration conf, String... keys) { for (String key : keys) { addConfOption(conf, key); } } + /** + * Add all configuration options which match the prefix + * @param conf configuration + * @param prefix prefix, e.g {@code "slider."} + * @return the number of entries copied + */ + public int addPrefixedConfOptions(Configuration conf, String prefix) { + int copied = 0; + for (Map.Entry<String, String> entry : conf) { + if (entry.getKey().startsWith(prefix)) { + define(entry.getKey(), entry.getValue()); + copied++; + } + } + return copied; + } + + /** + * Ass a configuration option to the command line of the application + * @param conf configuration + * @param key key + * @param defVal default value + * @return the resolved configuration option + * @throws IllegalArgumentException if key is null or the looked up value + * is null (that is: the argument is missing and devVal was null. + */ public String addConfOptionToCLI(Configuration conf, String key, String defVal) { + Preconditions.checkArgument(key != null, "null key"); String val = conf.get(key, defVal); define(key, val); return val; @@ -112,6 +142,7 @@ public class JavaCommandLineBuilder extends CommandLineBuilder { * Add a <code>-D key=val</code> command to the CLI. This is very Hadoop API * @param key key * @param val value + * @throws IllegalArgumentException if either argument is null */ public void define(String key, String val) { Preconditions.checkArgument(key != null, "null key");