You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/05/07 13:26:16 UTC

svn commit: r1592973 - in /incubator/slider/trunk/slider-core/src/main/java/org/apache/slider: client/ core/launch/ providers/slideram/

Author: stevel
Date: Wed May  7 11:26:15 2014
New Revision: 1592973

URL: http://svn.apache.org/r1592973
Log:
SLIDER-29 add JavaCommandLineBuilder subclass to clean up AM launch

Added:
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java   (with props)
Modified:
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java?rev=1592973&r1=1592972&r2=1592973&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java Wed May  7 11:26:15 2014
@@ -78,6 +78,7 @@ import org.apache.slider.core.exceptions
 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 @@ public class SliderClient extends Abstra
     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 @@ public class SliderClient extends Abstra
         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 @@ public class SliderClient extends Abstra
     }
     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 @@ public class SliderClient extends Abstra
     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);
 

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java?rev=1592973&r1=1592972&r2=1592973&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java Wed May  7 11:26:15 2014
@@ -230,6 +230,13 @@ public abstract class AbstractLauncher e
   }
 
 
+  /**
+   * 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);
   }

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java?rev=1592973&r1=1592972&r2=1592973&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java Wed May  7 11:26:15 2014
@@ -32,11 +32,6 @@ import java.util.List;
 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 @@ public class CommandLineBuilder {
     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);
-  }
 }

Added: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java?rev=1592973&view=auto
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java (added)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java Wed May  7 11:26:15 2014
@@ -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);
+  }
+}

Propchange: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/launch/JavaCommandLineBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java?rev=1592973&r1=1592972&r2=1592973&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMClientProvider.java Wed May  7 11:26:15 2014
@@ -40,6 +40,7 @@ import org.apache.slider.core.exceptions
 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 @@ public class SliderAMClientProvider exte
    * 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);