Skip to content

Commit a2ab1b0

Browse files
committed
Parse spark.driver.extra* in bash
1 parent 250cb95 commit a2ab1b0

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

bin/spark-submit

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ while (($#)); do
2525
DEPLOY_MODE=$2
2626
elif [ "$1" = "--driver-memory" ]; then
2727
DRIVER_MEMORY=$2
28+
elif [ "$1" = "--properties-file" ]; then
29+
PROPERTIES_FILE=$2
2830
elif [ "$1" = "--driver-library-path" ]; then
2931
export SPARK_SUBMIT_LIBRARY_PATH=$2
3032
elif [ "$1" = "--driver-class-path" ]; then
@@ -36,9 +38,35 @@ while (($#)); do
3638
done
3739

3840
DEPLOY_MODE=${DEPLOY_MODE:-"client"}
41+
PROPERTIES_FILE=${PROPERTIES_FILE:-"$SPARK_HOME/conf/spark-defaults.conf"}
3942

40-
if [ -n "$DRIVER_MEMORY" ] && [ $DEPLOY_MODE == "client" ]; then
41-
export SPARK_DRIVER_MEMORY=$DRIVER_MEMORY
43+
# For client mode, the driver will be launched in the JVM that launches
44+
# SparkSubmit, so we need to handle the class paths, java options, and
45+
# memory pre-emptively in bash. Otherwise, it will be too late by the
46+
# time the JVM has started.
47+
48+
if [ $DEPLOY_MODE == "client" ]; then
49+
if [ -n "$DRIVER_MEMORY" ]; then
50+
export SPARK_DRIVER_MEMORY=$DRIVER_MEMORY
51+
fi
52+
# We parse the default properties file here, assuming each line is
53+
# a key value pair delimited either by white space or "=" sign. All
54+
# spark.driver.* configs must be processed now before it's too late.
55+
if [ -f "$PROPERTIES_FILE" ]; then
56+
DRIVER_EXTRA_JAVA_OPTS="spark.driver.extraJavaOptions"
57+
DRIVER_EXTRA_CLASSPATH="spark.driver.extraClassPath"
58+
DRIVER_EXTRA_LIBRARY_PATH="spark.driver.extraLibraryPath"
59+
# Remove "=" sign and double quotes around the value, if any
60+
DRIVER_EXTRA_JAVA_OPTS=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_JAVA_OPTS" | \
61+
sed "s/$DRIVER_EXTRA_JAVA_OPTS//g" | sed "s/^=//g" | sed "s/^\"\(.*\)\"$/\1/g")
62+
DRIVER_EXTRA_CLASSPATH=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_CLASSPATH" | \
63+
sed "s/$DRIVER_EXTRA_CLASSPATH//g" | sed "s/^=//g" | sed "s/^\"\(.*\)\"$/\1/g")
64+
DRIVER_EXTRA_LIBRARY_PATH=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_LIBRARY_PATH" | \
65+
sed "s/$DRIVER_EXTRA_LIBRARY_PATH//g" | sed "s/^=//g" | sed "s/^\"\(.*\)\"$/\1/g")
66+
export SPARK_SUBMIT_OPTS="$SPARK_SUBMIT_OPTS $DRIVER_EXTRA_JAVA_OPTS"
67+
export SPARK_SUBMIT_CLASSPATH="$SPARK_SUBMIT_CLASSPATH:$DRIVER_EXTRA_CLASSPATH"
68+
export SPARK_SUBMIT_LIBRARY_PATH="$SPARK_SUBMIT_LIBRARY_PATH:$DRIVER_EXTRA_LIBRARY_PATH"
69+
fi
4270
fi
4371

4472
exec $SPARK_HOME/bin/spark-class org.apache.spark.deploy.SparkSubmit "${ORIG_ARGS[@]}"

bin/spark-submit.new

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership.
7+
# The ASF licenses this file to You under the Apache License, Version 2.0
8+
# (the "License"); you may not use this file except in compliance with
9+
# the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
SPARK_HOME="$(cd `dirname $0`/..; pwd)"
21+
ORIG_ARGS=("$@")
22+
23+
while (($#)); do
24+
if [ "$1" = "--deploy-mode" ]; then
25+
DEPLOY_MODE=$2
26+
elif [ "$1" = "--driver-memory" ]; then
27+
DRIVER_MEMORY=$2
28+
elif [ "$1" = "--driver-library-path" ]; then
29+
SPARK_SUBMIT_LIBRARY_PATH=$2
30+
elif [ "$1" = "--driver-class-path" ]; then
31+
SPARK_SUBMIT_CLASSPATH=$2
32+
elif [ "$1" = "--driver-java-options" ]; then
33+
SPARK_SUBMIT_OPTS=$2
34+
elif [ "$1" = "--properties-file" ]; then
35+
PROPERTIES_FILE=$2
36+
fi
37+
shift
38+
done
39+
40+
DEPLOY_MODE=${DEPLOY_MODE:-"client"}
41+
42+
if [ -n "$DRIVER_MEMORY" ] && [ $DEPLOY_MODE == "client" ]; then
43+
SPARK_DRIVER_MEMORY=$DRIVER_MEMORY
44+
fi
45+
46+
PROPERTIES_FILE=${PROPERTIES_FILE:-"$SPARK_HOME/conf/spark-defaults.conf"}
47+
if [ -f $PROPERTIES_FILE ]; then
48+
DRIVER_EXTRA_JAVA_OPTIONS="spark.driver.extraJavaOptions"
49+
DRIVER_EXTRA_CLASSPATH="spark.driver.extraClassPath"
50+
DRIVER_EXTRA_LIBRARY_PATH="spark.driver.extraLibraryPath"
51+
DRIVER_EXTRA_JAVA_OPTIONS=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_JAVA_OPTIONS" | sed "s/$DRIVER_EXTRA_JAVA_OPTIONS//g" | sed "s/^=//g")
52+
DRIVER_EXTRA_CLASSPATH=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_CLASSPATH" | sed "s/$DRIVER_EXTRA_CLASSPATH//g" | sed "s/^=//g")
53+
DRIVER_EXTRA_LIBRARY_PATH=$(sed "/^#/ d" "$PROPERTIES_FILE" | grep "$DRIVER_EXTRA_LIBRARY_PATH" | sed "s/$DRIVER_EXTRA_LIBRARY_PATH//g" | sed "s/^=//g")
54+
fi
55+
56+
echo "DEPLOY_MODE = $DEPLOY_MODE"
57+
echo "DRIVER_MEMORY = $DRIVER_MEMORY"
58+
echo "SPARK_DRIVER_MEMORY = $SPARK_DRIVER_MEMORY"
59+
echo "SPARK_SUBMIT_LIBRARY_PATH = $SPARK_SUBMIT_LIBRARY_PATH"
60+
echo "SPARK_SUBMIT_CLASSPATH = $SPARK_SUBMIT_CLASSPATH"
61+
echo "SPARK_SUBMIT_OPTS = $SPARK_SUBMIT_OPTS"
62+
echo "DRIVER_EXTRA_JAVA_OPTIONS = $DRIVER_EXTRA_JAVA_OPTIONS"
63+
echo "DRIVER_EXTRA_CLASSPATH = $DRIVER_EXTRA_CLASSPATH"
64+
echo "DRIVER_EXTRA_LIBRARY_PATH = $DRIVER_EXTRA_LIBRARY_PATH"
65+
66+
echo "exec $SPARK_HOME/bin/spark-class org.apache.spark.deploy.SparkSubmit "${ORIG_ARGS[@]}""
67+

0 commit comments

Comments
 (0)