SLIDER-29 add JavaCommandLineBuilder subclass to clean up AM launch
git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1592973 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index 4d1fa57..b26d035 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -78,6 +78,7 @@
import org.apache.slider.core.launch.AppMasterLauncher;
import org.apache.slider.core.launch.ClasspathConstructor;
import org.apache.slider.core.launch.CommandLineBuilder;
+import org.apache.slider.core.launch.JavaCommandLineBuilder;
import org.apache.slider.core.launch.LaunchedApplication;
import org.apache.slider.core.launch.RunningApplication;
import org.apache.slider.core.main.RunService;
@@ -673,12 +674,12 @@
MapOperations sliderAMResourceComponent =
resourceOperations.getOrAddComponent(SliderKeys.COMPONENT_AM);
AppMasterLauncher amLauncher = new AppMasterLauncher(clustername,
- SliderKeys.APP_TYPE,
- config,
+ SliderKeys.APP_TYPE,
+ config,
sliderFileSystem,
- yarnClient,
- clusterSecure,
- sliderAMResourceComponent);
+ yarnClient,
+ clusterSecure,
+ sliderAMResourceComponent);
ApplicationId appId = amLauncher.getApplicationId();
// set the application name;
@@ -811,8 +812,7 @@
libdir,
getConfig(),
usingMiniMRCluster);
- amLauncher.setEnv("CLASSPATH",
- classpath.buildClasspath());
+ amLauncher.setClasspath(classpath);
if (log.isDebugEnabled()) {
log.debug("AM classpath={}", classpath);
log.debug("Environment Map:\n{}",
@@ -835,8 +835,7 @@
}
String rmAddr = NetUtils.getHostPortString(rmSchedulerAddress);
- CommandLineBuilder commandLine = new CommandLineBuilder();
- commandLine.addJavaBinary();
+ JavaCommandLineBuilder commandLine = new JavaCommandLineBuilder();
// insert any JVM options);
sliderAM.addJVMOptions(instanceDefinition, commandLine);
// enable asserts if the text option is set
@@ -879,7 +878,7 @@
commandLine.addOutAndErrFiles(STDOUT_AM, STDERR_AM);
String cmdStr = commandLine.build();
- log.info("Completed setting up app master command {}", cmdStr);
+ log.debug("Completed setting up app master command {}", cmdStr);
amLauncher.addCommandLine(commandLine);
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java b/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
index c4692d9..fa37219 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
@@ -230,6 +230,13 @@
}
+ /**
+ * Utility method to set up the classpath
+ * @param classpath classpath to use
+ */
+ public void setClasspath(ClasspathConstructor classpath) {
+ setEnv("CLASSPATH", classpath.buildClasspath());
+ }
public void setEnv(String var, String value) {
env.put(var, value);
}
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java b/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
index 60d9b7c..013bff6 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
@@ -32,11 +32,6 @@
public class CommandLineBuilder {
protected final List<String> argumentList = new ArrayList<String>(20);
- public void addJavaBinary() {
- add(
- ApplicationConstants.Environment.JAVA_HOME.$() + "/bin/java");
- }
-
/**
* Add an entry to the command list
@@ -106,23 +101,4 @@
return argumentList;
}
- /**
- * Set the size of the heap if a non-empty heap is passed in.
- * @param heap empty string or something like "128M" ,"1G" etc. The value is
- * trimmed.
- */
- public void setJVMHeap(String heap) {
- if (SliderUtils.isSet(heap)) {
- add("-Xmx" + heap.trim());
- }
- }
-
- public void enableJavaAssertions() {
- add("-ea");
- add("-esa");
- }
-
- public void sysprop(String property, String value) {
- add("-D" + property + "=" + value);
- }
}
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
new file mode 100644
index 0000000..8d90225
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.core.launch;
+
+
+import org.apache.hadoop.yarn.api.ApplicationConstants;
+import org.apache.slider.common.tools.SliderUtils;
+
+/**
+ * Command line builder purely for the Java CLI
+ */
+public class JavaCommandLineBuilder extends CommandLineBuilder {
+
+ public JavaCommandLineBuilder() {
+ add(getJavaBinary());
+ }
+
+
+ /**
+ * Get the java binary. This is called in the constructor so don't try and
+ * do anything other than return a constant.
+ * @return the path to the Java binary
+ */
+ protected String getJavaBinary() {
+ return ApplicationConstants.Environment.JAVA_HOME.$() + "/bin/java";
+ }
+
+ /**
+ * Set the size of the heap if a non-empty heap is passed in.
+ * @param heap empty string or something like "128M" ,"1G" etc. The value is
+ * trimmed.
+ */
+ public void setJVMHeap(String heap) {
+ if (SliderUtils.isSet(heap)) {
+ add("-Xmx" + heap.trim());
+ }
+ }
+
+ public void enableJavaAssertions() {
+ add("-ea");
+ add("-esa");
+ }
+
+ /**
+ * Add a system property definition -must be used before setting the main entry point
+ * @param property
+ * @param value
+ */
+ public void sysprop(String property, String value) {
+ add("-D" + property + "=" + value);
+ }
+}
diff --git a/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java b/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java
index 9b3b9ef..66cfeba 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java
@@ -40,6 +40,7 @@
import org.apache.slider.core.exceptions.SliderException;
import org.apache.slider.core.launch.AbstractLauncher;
import org.apache.slider.core.launch.CommandLineBuilder;
+import org.apache.slider.core.launch.JavaCommandLineBuilder;
import org.apache.slider.providers.AbstractClientProvider;
import org.apache.slider.providers.PlacementPolicy;
import org.apache.slider.providers.ProviderRole;
@@ -221,8 +222,9 @@
* add them to the command line
*/
public void addJVMOptions(AggregateConf aggregateConf,
- CommandLineBuilder cmdLine) throws
+ JavaCommandLineBuilder cmdLine) throws
BadConfigException {
+
MapOperations sliderAM =
aggregateConf.getAppConfOperations().getMandatoryComponent(
SliderKeys.COMPONENT_AM);