-
Notifications
You must be signed in to change notification settings - Fork 118
Use a list of environment variables for JVM options. #444
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,11 @@ ENV PYSPARK_DRIVER_PYTHON python | |
ENV PYTHONPATH ${SPARK_HOME}/python/:${SPARK_HOME}/python/lib/py4j-0.10.4-src.zip:${PYTHONPATH} | ||
|
||
CMD SPARK_CLASSPATH="${SPARK_HOME}/jars/*" && \ | ||
env | grep SPARK_JAVA_OPT_ | sed 's/[^=]*=\(.*\)/\1/g' > /tmp/java_opts.txt && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pretty strange and is fairly dependent on the shell being Bash instead of sh. It would be good to make this compatible with Separately, the usage of a temporary file is also sub-par. I found that when piping the result of I would appreciate any feedback or suggestions from those who are experienced at shell scripting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also appreciate thoughts on how to avoid bouncing this off a temp file. What's there now is ugly but works, so if someone knows how to do this where it's pretty and works, that'd be even better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @ifilonenko @erikerlandson @foxish for shell scripting suggestions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readarray can be at the end of the pipe, which avoids the temp file. That's at least slightly cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Piping to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird, I'd expect that to be equivalent to the code using the temp file. |
||
readarray -t SPARK_DRIVER_JAVA_OPTS < /tmp/java_opts.txt && \ | ||
if ! [ -z ${SPARK_MOUNTED_CLASSPATH+x} ]; then SPARK_CLASSPATH="$SPARK_MOUNTED_CLASSPATH:$SPARK_CLASSPATH"; fi && \ | ||
if ! [ -z ${SPARK_SUBMIT_EXTRA_CLASSPATH+x} ]; then SPARK_CLASSPATH="$SPARK_SUBMIT_EXTRA_CLASSPATH:$SPARK_CLASSPATH"; fi && \ | ||
if ! [ -z ${SPARK_EXTRA_CLASSPATH+x} ]; then SPARK_CLASSPATH="$SPARK_EXTRA_CLASSPATH:$SPARK_CLASSPATH"; fi && \ | ||
if ! [ -z ${SPARK_MOUNTED_FILES_DIR} ]; then cp -R "$SPARK_MOUNTED_FILES_DIR/." .; fi && \ | ||
if ! [ -z ${SPARK_MOUNTED_FILES_FROM_SECRET_DIR} ]; then cp -R "$SPARK_MOUNTED_FILES_FROM_SECRET_DIR/." .; fi && \ | ||
${JAVA_HOME}/bin/java $SPARK_DRIVER_JAVA_OPTS -cp $SPARK_CLASSPATH \ | ||
-Xms$SPARK_DRIVER_MEMORY -Xmx$SPARK_DRIVER_MEMORY \ | ||
$SPARK_DRIVER_CLASS $PYSPARK_PRIMARY $PYSPARK_FILES $SPARK_DRIVER_ARGS | ||
if ! [ -z ${SPARK_MOUNTED_FILES_DIR+x} ]; then cp -R "$SPARK_MOUNTED_FILES_DIR/." .; fi && \ | ||
if ! [ -z ${SPARK_MOUNTED_FILES_FROM_SECRET_DIR+x} ]; then cp -R "$SPARK_MOUNTED_FILES_FROM_SECRET_DIR/." .; fi && \ | ||
${JAVA_HOME}/bin/java "${SPARK_DRIVER_JAVA_OPTS[@]}" -cp $SPARK_CLASSPATH -Xms$SPARK_DRIVER_MEMORY -Xmx$SPARK_DRIVER_MEMORY $SPARK_DRIVER_CLASS $PYSPARK_PRIMARY $PYSPARK_FILES $SPARK_DRIVER_ARGS |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.spark.deploy.kubernetes.integrationtest.jobs | ||
|
||
import java.io.{File, FileInputStream} | ||
import java.util.Properties | ||
|
||
import com.google.common.collect.Maps | ||
import scala.collection.JavaConverters._ | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.util.Utils | ||
|
||
private[spark] object JavaOptionsTest { | ||
|
||
def main(args: Array[String]): Unit = { | ||
// scalastyle:off println | ||
if (args.length != 1) { | ||
println(s"Invalid arguments: ${args.mkString(",")}." + | ||
s"Usage: JavaOptionsTest <driver-java-options-list-file>") | ||
System.exit(1) | ||
} | ||
val expectedDriverJavaOptions = loadPropertiesFromFile(args(0)) | ||
val nonMatchingDriverOptions = expectedDriverJavaOptions.filter { | ||
case (optKey, optValue) => System.getProperty(optKey) != optValue | ||
} | ||
if (nonMatchingDriverOptions.nonEmpty) { | ||
println(s"The driver's JVM options did not match. Expected $expectedDriverJavaOptions." + | ||
s" But these options did not match: $nonMatchingDriverOptions.") | ||
val sysProps = Maps.fromProperties(System.getProperties).asScala | ||
println("System properties are:") | ||
for (prop <- sysProps) { | ||
println(s"Key: ${prop._1}, Value: ${prop._2}") | ||
} | ||
System.exit(1) | ||
} | ||
|
||
// TODO support spark.executor.extraJavaOptions and test here. | ||
println(s"All expected JVM options were present on the driver and executors.") | ||
// scalastyle:on println | ||
} | ||
|
||
private def loadPropertiesFromFile(filePath: String): Map[String, String] = { | ||
val file = new File(filePath) | ||
if (!file.isFile) { | ||
throw new IllegalArgumentException(s"File not found at $filePath or is not a file.") | ||
} | ||
val properties = new Properties() | ||
Utils.tryWithResource(new FileInputStream(file)) { is => | ||
properties.load(is) | ||
} | ||
Maps.fromProperties(properties).asScala.toMap | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
*/ | ||
package org.apache.spark.deploy.kubernetes.integrationtest | ||
|
||
import java.io.File | ||
import java.io.{File, FileOutputStream} | ||
import java.nio.file.Paths | ||
import java.util.UUID | ||
import java.util.{Properties, UUID} | ||
|
||
import com.google.common.base.Charsets | ||
import com.google.common.io.Files | ||
|
@@ -229,6 +229,26 @@ private[spark] class KubernetesSuite extends SparkFunSuite with BeforeAndAfter { | |
Seq.empty[String]) | ||
} | ||
|
||
test("Setting JVM options on the driver and executors with spaces.") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right now this PR only tests drivers -- the executors is coming in the followup PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with keeping the name as-is for now though given that the next PR is imminent. |
||
assume(testBackend.name == MINIKUBE_TEST_BACKEND) | ||
launchStagingServer(SSLOptions(), None) | ||
val driverJvmOptionsFile = storeJvmOptionsInTempFile( | ||
Map("simpleDriverConf" -> "simpleDriverConfValue", | ||
"driverconfwithspaces" -> "driver conf with spaces value"), | ||
"driver-jvm-options.properties", | ||
"JVM options that should be set on the driver.") | ||
sparkConf.set(SparkLauncher.DRIVER_EXTRA_JAVA_OPTIONS, | ||
"-DsimpleDriverConf=simpleDriverConfValue" + | ||
" -Ddriverconfwithspaces='driver conf with spaces value'") | ||
sparkConf.set("spark.files", driverJvmOptionsFile.getAbsolutePath) | ||
runSparkApplicationAndVerifyCompletion( | ||
JavaMainAppResource(SUBMITTER_LOCAL_MAIN_APP_RESOURCE), | ||
JAVA_OPTIONS_MAIN_CLASS, | ||
Seq(s"All expected JVM options were present on the driver and executors."), | ||
Array(driverJvmOptionsFile.getName), | ||
Seq.empty[String]) | ||
} | ||
|
||
test("Submit small local files without the resource staging server.") { | ||
assume(testBackend.name == MINIKUBE_TEST_BACKEND) | ||
sparkConf.setJars(Seq(CONTAINER_LOCAL_HELPER_JAR_PATH)) | ||
|
@@ -360,6 +380,20 @@ private[spark] class KubernetesSuite extends SparkFunSuite with BeforeAndAfter { | |
} | ||
} | ||
} | ||
|
||
private def storeJvmOptionsInTempFile( | ||
options: Map[String, String], | ||
propertiesFileName: String, | ||
comments: String): File = { | ||
val tempDir = Utils.createTempDir() | ||
val propertiesFile = new File(tempDir, propertiesFileName) | ||
val properties = new Properties() | ||
options.foreach { case (propKey, propValue) => properties.setProperty(propKey, propValue) } | ||
Utils.tryWithResource(new FileOutputStream(propertiesFile)) { os => | ||
properties.store(os, comments) | ||
} | ||
propertiesFile | ||
} | ||
} | ||
|
||
private[spark] object KubernetesSuite { | ||
|
@@ -389,6 +423,8 @@ private[spark] object KubernetesSuite { | |
".integrationtest.jobs.FileExistenceTest" | ||
val GROUP_BY_MAIN_CLASS = "org.apache.spark.deploy.kubernetes" + | ||
".integrationtest.jobs.GroupByTest" | ||
val JAVA_OPTIONS_MAIN_CLASS = "org.apache.spark.deploy.kubernetes" + | ||
".integrationtest.jobs.JavaOptionsTest" | ||
val TEST_EXISTENCE_FILE_CONTENTS = "contents" | ||
|
||
case object ShuffleNotReadyException extends Exception | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was this
+|-
for before? afaik that's not valid syntaxThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure - probably just a badly written unit test.