2013-07-17 20:51:18 -04:00
|
|
|
#!/usr/bin/env bash
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-07-16 20:21:33 -04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2013-12-15 21:39:30 -05:00
|
|
|
cygwin=false
|
|
|
|
case "`uname`" in
|
|
|
|
CYGWIN*) cygwin=true;;
|
|
|
|
esac
|
|
|
|
|
2013-09-14 13:24:10 -04:00
|
|
|
SCALA_VERSION=2.10
|
2010-03-29 19:17:55 -04:00
|
|
|
|
|
|
|
# Figure out where the Scala framework is installed
|
2013-09-23 04:13:46 -04:00
|
|
|
FWDIR="$(cd `dirname $0`/..; pwd)"
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2010-10-15 22:42:26 -04:00
|
|
|
# Export this as SPARK_HOME
|
|
|
|
export SPARK_HOME="$FWDIR"
|
|
|
|
|
2014-03-25 01:24:21 -04:00
|
|
|
. $FWDIR/bin/load-spark-env.sh
|
2010-07-19 21:00:30 -04:00
|
|
|
|
2013-02-06 17:34:46 -05:00
|
|
|
if [ -z "$1" ]; then
|
2013-09-01 19:45:57 -04:00
|
|
|
echo "Usage: spark-class <class> [<args>]" >&2
|
2013-02-06 17:34:46 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-03-09 14:08:39 -04:00
|
|
|
if [ -n "$SPARK_MEM" ]; then
|
|
|
|
echo "Warning: SPARK_MEM is deprecated, please use a more specific config option"
|
|
|
|
echo "(e.g., spark.executor.memory or SPARK_DRIVER_MEMORY)."
|
2013-02-06 17:34:46 -05:00
|
|
|
fi
|
|
|
|
|
2014-03-09 14:08:39 -04:00
|
|
|
# Use SPARK_MEM or 512m as the default memory, to be overridden by specific options
|
|
|
|
DEFAULT_MEM=${SPARK_MEM:-512m}
|
|
|
|
|
|
|
|
SPARK_DAEMON_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS -Dspark.akka.logLifecycleEvents=true"
|
2013-02-16 01:42:06 -05:00
|
|
|
|
2014-03-09 14:08:39 -04:00
|
|
|
# Add java opts and memory settings for master, worker, executors, and repl.
|
2013-02-16 01:42:06 -05:00
|
|
|
case "$1" in
|
2014-03-09 14:08:39 -04:00
|
|
|
# Master and Worker use SPARK_DAEMON_JAVA_OPTS (and specific opts) + SPARK_DAEMON_MEMORY.
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.deploy.master.Master')
|
2014-03-09 14:08:39 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS $SPARK_MASTER_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_DAEMON_MEMORY:-$DEFAULT_MEM}
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.deploy.worker.Worker')
|
2014-03-09 14:08:39 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS $SPARK_WORKER_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_DAEMON_MEMORY:-$DEFAULT_MEM}
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2014-03-09 14:08:39 -04:00
|
|
|
|
|
|
|
# Executors use SPARK_JAVA_OPTS + SPARK_EXECUTOR_MEMORY.
|
2013-12-15 14:53:44 -05:00
|
|
|
'org.apache.spark.executor.CoarseGrainedExecutorBackend')
|
2014-03-09 14:08:39 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_JAVA_OPTS $SPARK_EXECUTOR_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_EXECUTOR_MEMORY:-$DEFAULT_MEM}
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.executor.MesosExecutorBackend')
|
2014-03-09 14:08:39 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_JAVA_OPTS $SPARK_EXECUTOR_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_EXECUTOR_MEMORY:-$DEFAULT_MEM}
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2014-03-09 14:08:39 -04:00
|
|
|
|
|
|
|
# All drivers use SPARK_JAVA_OPTS + SPARK_DRIVER_MEMORY. The repl also uses SPARK_REPL_OPTS.
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.repl.Main')
|
2014-03-09 14:08:39 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_JAVA_OPTS $SPARK_REPL_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_DRIVER_MEMORY:-$DEFAULT_MEM}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
OUR_JAVA_OPTS="$SPARK_JAVA_OPTS"
|
|
|
|
OUR_JAVA_MEM=${SPARK_DRIVER_MEMORY:-$DEFAULT_MEM}
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-02-16 01:42:06 -05:00
|
|
|
esac
|
|
|
|
|
2013-08-24 02:30:17 -04:00
|
|
|
# Find the java binary
|
|
|
|
if [ -n "${JAVA_HOME}" ]; then
|
|
|
|
RUNNER="${JAVA_HOME}/bin/java"
|
2012-10-22 16:10:47 -04:00
|
|
|
else
|
2013-08-24 02:30:17 -04:00
|
|
|
if [ `command -v java` ]; then
|
|
|
|
RUNNER="java"
|
2012-10-22 16:10:47 -04:00
|
|
|
else
|
2013-08-24 02:30:17 -04:00
|
|
|
echo "JAVA_HOME is not set" >&2
|
|
|
|
exit 1
|
2012-10-22 16:10:47 -04:00
|
|
|
fi
|
2012-07-08 17:00:04 -04:00
|
|
|
fi
|
|
|
|
|
2010-07-19 21:00:30 -04:00
|
|
|
# Set JAVA_OPTS to be able to load native libraries and to set heap size
|
2013-02-24 15:24:30 -05:00
|
|
|
JAVA_OPTS="$OUR_JAVA_OPTS"
|
2013-05-11 01:42:22 -04:00
|
|
|
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$SPARK_LIBRARY_PATH"
|
2014-03-09 14:08:39 -04:00
|
|
|
JAVA_OPTS="$JAVA_OPTS -Xms$OUR_JAVA_MEM -Xmx$OUR_JAVA_MEM"
|
2010-07-19 21:00:30 -04:00
|
|
|
# Load extra JAVA_OPTS from conf/java-opts, if it exists
|
2013-09-29 10:00:19 -04:00
|
|
|
if [ -e "$FWDIR/conf/java-opts" ] ; then
|
2013-05-11 01:42:22 -04:00
|
|
|
JAVA_OPTS="$JAVA_OPTS `cat $FWDIR/conf/java-opts`"
|
2010-03-29 19:17:55 -04:00
|
|
|
fi
|
|
|
|
export JAVA_OPTS
|
2013-02-15 08:11:34 -05:00
|
|
|
# Attention: when changing the way the JAVA_OPTS are assembled, the change must be reflected in ExecutorRunner.scala!
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-06-28 20:18:35 -04:00
|
|
|
if [ ! -f "$FWDIR/RELEASE" ]; then
|
|
|
|
# Exit if the user hasn't compiled Spark
|
2013-10-25 21:57:42 -04:00
|
|
|
num_jars=$(ls "$FWDIR"/assembly/target/scala-$SCALA_VERSION/ | grep "spark-assembly.*hadoop.*.jar" | wc -l)
|
|
|
|
jars_list=$(ls "$FWDIR"/assembly/target/scala-$SCALA_VERSION/ | grep "spark-assembly.*hadoop.*.jar")
|
|
|
|
if [ "$num_jars" -eq "0" ]; then
|
|
|
|
echo "Failed to find Spark assembly in $FWDIR/assembly/target/scala-$SCALA_VERSION/" >&2
|
2014-01-06 01:12:47 -05:00
|
|
|
echo "You need to build Spark with 'sbt/sbt assembly' before running this program." >&2
|
2013-10-25 21:57:42 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "$num_jars" -gt "1" ]; then
|
|
|
|
echo "Found multiple Spark assembly jars in $FWDIR/assembly/target/scala-$SCALA_VERSION:" >&2
|
|
|
|
echo "$jars_list"
|
|
|
|
echo "Please remove all but one jar."
|
2013-06-28 20:18:35 -04:00
|
|
|
exit 1
|
2013-06-24 18:39:52 -04:00
|
|
|
fi
|
2013-01-21 00:05:17 -05:00
|
|
|
fi
|
2013-05-16 17:31:38 -04:00
|
|
|
|
2013-12-30 15:46:09 -05:00
|
|
|
TOOLS_DIR="$FWDIR"/tools
|
|
|
|
SPARK_TOOLS_JAR=""
|
|
|
|
if [ -e "$TOOLS_DIR"/target/scala-$SCALA_VERSION/*assembly*[0-9Tg].jar ]; then
|
|
|
|
# Use the JAR from the SBT build
|
|
|
|
export SPARK_TOOLS_JAR=`ls "$TOOLS_DIR"/target/scala-$SCALA_VERSION/*assembly*[0-9Tg].jar`
|
|
|
|
fi
|
|
|
|
if [ -e "$TOOLS_DIR"/target/spark-tools*[0-9Tg].jar ]; then
|
|
|
|
# Use the JAR from the Maven build
|
|
|
|
# TODO: this also needs to become an assembly!
|
|
|
|
export SPARK_TOOLS_JAR=`ls "$TOOLS_DIR"/target/spark-tools*[0-9Tg].jar`
|
2013-11-09 16:37:11 -05:00
|
|
|
fi
|
|
|
|
|
2013-06-25 18:21:00 -04:00
|
|
|
# Compute classpath using external script
|
|
|
|
CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
|
2014-03-25 00:20:23 -04:00
|
|
|
if [[ "$1" =~ org.apache.spark.tools.* ]]; then
|
2013-12-30 15:46:09 -05:00
|
|
|
CLASSPATH="$CLASSPATH:$SPARK_TOOLS_JAR"
|
|
|
|
fi
|
2013-12-15 21:39:30 -05:00
|
|
|
|
|
|
|
if $cygwin; then
|
2013-12-24 16:37:13 -05:00
|
|
|
CLASSPATH=`cygpath -wp $CLASSPATH`
|
2013-12-30 15:46:09 -05:00
|
|
|
if [ "$1" == "org.apache.spark.tools.JavaAPICompletenessChecker" ]; then
|
|
|
|
export SPARK_TOOLS_JAR=`cygpath -w $SPARK_TOOLS_JAR`
|
|
|
|
fi
|
2013-12-15 21:39:30 -05:00
|
|
|
fi
|
2013-06-25 18:21:00 -04:00
|
|
|
export CLASSPATH
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-08-02 19:58:19 -04:00
|
|
|
if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then
|
2013-08-24 02:30:17 -04:00
|
|
|
echo -n "Spark Command: "
|
|
|
|
echo "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
|
2013-08-04 00:30:15 -04:00
|
|
|
echo "========================================"
|
2013-08-02 19:58:19 -04:00
|
|
|
echo
|
2010-03-29 19:17:55 -04:00
|
|
|
fi
|
|
|
|
|
2013-08-24 02:30:17 -04:00
|
|
|
exec "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
|