Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3916#discussion_r25314811
  
    --- Diff: 
launcher/src/main/java/org/apache/spark/launcher/SparkLauncher.java ---
    @@ -0,0 +1,270 @@
    +/*
    + * 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.spark.launcher;
    +
    +import java.io.File;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +
    +import static org.apache.spark.launcher.CommandBuilderUtils.*;
    +
    +/**
    + * Launcher for Spark applications.
    + * <p/>
    + * Use this class to start Spark applications programmatically. The class 
uses a builder pattern
    + * to allow clients to configure the Spark application and launch it as a 
child process.
    + * <p/>
    + * Note that launching Spark applications using this class will not 
automatically load environment
    + * variables from the "spark-env.sh" or "spark-env.cmd" scripts in the 
configuration directory.
    + */
    +public class SparkLauncher {
    +
    +  /** The Spark master. */
    +  public static final String SPARK_MASTER = "spark.master";
    +
    +  /** Configuration key for the driver memory. */
    +  public static final String DRIVER_MEMORY = "spark.driver.memory";
    +  /** Configuration key for the driver class path. */
    +  public static final String DRIVER_EXTRA_CLASSPATH = 
"spark.driver.extraClassPath";
    +  /** Configuration key for the driver VM options. */
    +  public static final String DRIVER_EXTRA_JAVA_OPTIONS = 
"spark.driver.extraJavaOptions";
    +  /** Configuration key for the driver native library path. */
    +  public static final String DRIVER_EXTRA_LIBRARY_PATH = 
"spark.driver.extraLibraryPath";
    +
    +  /** Configuration key for the executor memory. */
    +  public static final String EXECUTOR_MEMORY = "spark.executor.memory";
    +  /** Configuration key for the executor class path. */
    +  public static final String EXECUTOR_EXTRA_CLASSPATH = 
"spark.executor.extraClassPath";
    +  /** Configuration key for the executor VM options. */
    +  public static final String EXECUTOR_EXTRA_JAVA_OPTIONS = 
"spark.executor.extraJavaOptions";
    +  /** Configuration key for the executor native library path. */
    +  public static final String EXECUTOR_EXTRA_LIBRARY_PATH = 
"spark.executor.extraLibraryOptions";
    +  /** Configuration key for the number of executor CPU cores. */
    +  public static final String EXECUTOR_CORES = "spark.executor.cores";
    +
    +  private final SparkSubmitCommandBuilder builder;
    +
    +  public SparkLauncher() {
    +    this(null);
    +  }
    +
    +  /**
    +   * Creates a launcher that will set the given environment variables in 
the child.
    +   *
    +   * @param env Environment variables to set.
    +   */
    +  public SparkLauncher(Map<String, String> env) {
    +    this.builder = new SparkSubmitCommandBuilder();
    +    if (env != null) {
    +      this.builder.childEnv.putAll(env);
    +    }
    +  }
    +
    +  /**
    +   * Set a custom JAVA_HOME for launching the Spark application.
    +   *
    +   * @param javaHome Path to the JAVA_HOME to use.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setJavaHome(String javaHome) {
    +    checkNotNull(javaHome, "javaHome");
    +    builder.javaHome = javaHome;
    +    return this;
    +  }
    +
    +  /**
    +   * Set a custom Spark installation location for the application.
    +   *
    +   * @param sparkHome Path to the Spark installation to use.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setSparkHome(String sparkHome) {
    +    checkNotNull(sparkHome, "sparkHome");
    +    builder.childEnv.put(ENV_SPARK_HOME, sparkHome);
    +    return this;
    +  }
    +
    +  /**
    +   * Set a custom properties file with Spark configuration for the 
application.
    +   *
    +   * @param path Path to custom properties file to use.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setPropertiesFile(String path) {
    +    checkNotNull(path, "path");
    +    builder.propertiesFile = path;
    +    return this;
    +  }
    +
    +  /**
    +   * Set a single configuration value for the application.
    +   *
    +   * @param key Configuration key.
    +   * @param value The value to use.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setConf(String key, String value) {
    +    checkNotNull(key, "key");
    +    checkNotNull(value, "value");
    +    checkArgument(key.startsWith("spark."), "'key' must start with 
'spark.'");
    +    builder.conf.put(key, value);
    +    return this;
    +  }
    +
    +  /**
    +   * Set the application name.
    +   *
    +   * @param appName Application name.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setAppName(String appName) {
    +    checkNotNull(appName, "appName");
    +    builder.appName = appName;
    +    return this;
    +  }
    +
    +  /**
    +   * Set the Spark master for the application.
    +   *
    +   * @param master Spark master.
    +   * @return This launcher.
    +   */
    +  public SparkLauncher setMaster(String master) {
    +    checkNotNull(master, "master");
    +    builder.master = master;
    +    return this;
    +  }
    +
    +  /**
    +   * Set the deploy mode for the application.
    +   *
    +   * @param mode Deploy mode.
    +   * @return This launcher.
    --- End diff --
    
    Public class needs nice javadoc documentation, so unless there's a strong 
argument for making it non-public (which would mean removing it), the extra 
verbosity is actually good.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to