2010-03-30 03:17:55 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-09-25 01:12:48 +04:00
|
|
|
SCALA_VERSION=2.9.2
|
2011-05-27 13:20:34 +04:00
|
|
|
|
2010-03-30 03:17:55 +04:00
|
|
|
# Figure out where the Scala framework is installed
|
2010-10-16 23:18:02 +04:00
|
|
|
FWDIR="$(cd `dirname $0`; pwd)"
|
2010-03-30 03:17:55 +04:00
|
|
|
|
2010-10-16 06:42:26 +04:00
|
|
|
# Export this as SPARK_HOME
|
|
|
|
export SPARK_HOME="$FWDIR"
|
|
|
|
|
2010-07-20 05:00:30 +04:00
|
|
|
# Load environment variables from conf/spark-env.sh, if it exists
|
|
|
|
if [ -e $FWDIR/conf/spark-env.sh ] ; then
|
|
|
|
. $FWDIR/conf/spark-env.sh
|
|
|
|
fi
|
|
|
|
|
2013-02-07 02:34:46 +04:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Usage: run <spark-class> [<args>]" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If this is a standalone cluster daemon, reset SPARK_JAVA_OPTS and SPARK_MEM to reasonable
|
|
|
|
# values for that; it doesn't need a lot
|
|
|
|
if [ "$1" = "spark.deploy.master.Master" -o "$1" = "spark.deploy.worker.Worker" ]; then
|
|
|
|
SPARK_MEM=${SPARK_DAEMON_MEMORY:-512m}
|
|
|
|
SPARK_JAVA_OPTS=$SPARK_DAEMON_JAVA_OPTS # Empty by default
|
|
|
|
fi
|
|
|
|
|
2013-02-16 10:42:06 +04:00
|
|
|
|
|
|
|
# Add java opts for master, worker, executor. The opts maybe null
|
|
|
|
case "$1" in
|
2013-02-25 23:53:55 +04:00
|
|
|
'spark.deploy.master.Master')
|
|
|
|
SPARK_JAVA_OPTS+=" $SPARK_MASTER_OPTS"
|
|
|
|
;;
|
|
|
|
'spark.deploy.worker.Worker')
|
|
|
|
SPARK_JAVA_OPTS+=" $SPARK_WORKER_OPTS"
|
|
|
|
;;
|
|
|
|
'spark.executor.StandaloneExecutorBackend')
|
|
|
|
SPARK_JAVA_OPTS+=" $SPARK_EXECUTOR_OPTS"
|
|
|
|
;;
|
|
|
|
'spark.executor.MesosExecutorBackend')
|
|
|
|
SPARK_JAVA_OPTS+=" $SPARK_EXECUTOR_OPTS"
|
|
|
|
;;
|
|
|
|
'spark.repl.Main')
|
|
|
|
SPARK_JAVA_OPTS+=" $SPARK_REPL_OPTS"
|
|
|
|
;;
|
2013-02-16 10:42:06 +04:00
|
|
|
esac
|
|
|
|
|
2012-10-23 00:10:47 +04:00
|
|
|
if [ "$SPARK_LAUNCH_WITH_SCALA" == "1" ]; then
|
|
|
|
if [ `command -v scala` ]; then
|
|
|
|
RUNNER="scala"
|
|
|
|
else
|
|
|
|
if [ -z "$SCALA_HOME" ]; then
|
|
|
|
echo "SCALA_HOME is not set" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
RUNNER="${SCALA_HOME}/bin/scala"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ `command -v java` ]; then
|
|
|
|
RUNNER="java"
|
|
|
|
else
|
|
|
|
if [ -z "$JAVA_HOME" ]; then
|
|
|
|
echo "JAVA_HOME is not set" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
RUNNER="${JAVA_HOME}/bin/java"
|
|
|
|
fi
|
|
|
|
if [ -z "$SCALA_LIBRARY_PATH" ]; then
|
|
|
|
if [ -z "$SCALA_HOME" ]; then
|
|
|
|
echo "SCALA_HOME is not set" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
SCALA_LIBRARY_PATH="$SCALA_HOME/lib"
|
|
|
|
fi
|
2010-08-13 11:39:36 +04:00
|
|
|
fi
|
|
|
|
|
2012-03-18 00:39:14 +04:00
|
|
|
# Figure out how much memory to use per executor and set it as an environment
|
|
|
|
# variable so that our process sees it and can report it to Mesos
|
2012-07-09 01:00:04 +04:00
|
|
|
if [ -z "$SPARK_MEM" ] ; then
|
2011-08-02 00:54:48 +04:00
|
|
|
SPARK_MEM="512m"
|
2010-07-20 05:00:30 +04:00
|
|
|
fi
|
2012-03-18 00:39:14 +04:00
|
|
|
export SPARK_MEM
|
2010-07-20 05:00:30 +04:00
|
|
|
|
|
|
|
# Set JAVA_OPTS to be able to load native libraries and to set heap size
|
|
|
|
JAVA_OPTS="$SPARK_JAVA_OPTS"
|
2012-03-18 00:39:14 +04:00
|
|
|
JAVA_OPTS+=" -Djava.library.path=$SPARK_LIBRARY_PATH"
|
2010-07-20 05:00:30 +04:00
|
|
|
JAVA_OPTS+=" -Xms$SPARK_MEM -Xmx$SPARK_MEM"
|
|
|
|
# Load extra JAVA_OPTS from conf/java-opts, if it exists
|
2010-03-30 03:17:55 +04:00
|
|
|
if [ -e $FWDIR/conf/java-opts ] ; then
|
|
|
|
JAVA_OPTS+=" `cat $FWDIR/conf/java-opts`"
|
|
|
|
fi
|
|
|
|
export JAVA_OPTS
|
|
|
|
|
2012-03-18 00:39:14 +04:00
|
|
|
CORE_DIR="$FWDIR/core"
|
|
|
|
REPL_DIR="$FWDIR/repl"
|
|
|
|
EXAMPLES_DIR="$FWDIR/examples"
|
|
|
|
BAGEL_DIR="$FWDIR/bagel"
|
2012-07-29 07:03:26 +04:00
|
|
|
STREAMING_DIR="$FWDIR/streaming"
|
2013-01-02 02:48:45 +04:00
|
|
|
PYSPARK_DIR="$FWDIR/python"
|
2011-02-02 02:11:08 +03:00
|
|
|
|
2013-01-17 23:14:47 +04:00
|
|
|
# Exit if the user hasn't compiled Spark
|
|
|
|
if [ ! -e "$REPL_DIR/target" ]; then
|
|
|
|
echo "Failed to find Spark classes in $REPL_DIR/target" >&2
|
|
|
|
echo "You need to compile Spark before running this program" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-02-02 02:11:08 +03:00
|
|
|
# Build up classpath
|
2012-03-18 00:39:14 +04:00
|
|
|
CLASSPATH="$SPARK_CLASSPATH"
|
|
|
|
CLASSPATH+=":$FWDIR/conf"
|
|
|
|
CLASSPATH+=":$CORE_DIR/target/scala-$SCALA_VERSION/classes"
|
2012-10-07 08:19:16 +04:00
|
|
|
if [ -n "$SPARK_TESTING" ] ; then
|
|
|
|
CLASSPATH+=":$CORE_DIR/target/scala-$SCALA_VERSION/test-classes"
|
2013-02-25 04:24:52 +04:00
|
|
|
CLASSPATH+=":$STREAMING_DIR/target/scala-$SCALA_VERSION/test-classes"
|
2012-10-07 08:19:16 +04:00
|
|
|
fi
|
2012-07-01 03:43:27 +04:00
|
|
|
CLASSPATH+=":$CORE_DIR/src/main/resources"
|
2012-03-18 00:39:14 +04:00
|
|
|
CLASSPATH+=":$REPL_DIR/target/scala-$SCALA_VERSION/classes"
|
|
|
|
CLASSPATH+=":$EXAMPLES_DIR/target/scala-$SCALA_VERSION/classes"
|
2012-07-29 07:03:26 +04:00
|
|
|
CLASSPATH+=":$STREAMING_DIR/target/scala-$SCALA_VERSION/classes"
|
2013-02-25 04:24:52 +04:00
|
|
|
CLASSPATH+=":$STREAMING_DIR/lib/org/apache/kafka/kafka/0.7.2-spark/*" # <-- our in-project Kafka Jar
|
2012-12-11 03:12:59 +04:00
|
|
|
if [ -e "$FWDIR/lib_managed" ]; then
|
2013-01-09 00:44:33 +04:00
|
|
|
CLASSPATH+=":$FWDIR/lib_managed/jars/*"
|
|
|
|
CLASSPATH+=":$FWDIR/lib_managed/bundles/*"
|
2012-12-11 03:12:59 +04:00
|
|
|
fi
|
2013-01-09 00:44:33 +04:00
|
|
|
CLASSPATH+=":$REPL_DIR/lib/*"
|
2013-01-21 09:05:17 +04:00
|
|
|
if [ -e repl-bin/target ]; then
|
|
|
|
for jar in `find "repl-bin/target" -name 'spark-repl-*-shaded-hadoop*.jar'`; do
|
|
|
|
CLASSPATH+=":$jar"
|
|
|
|
done
|
|
|
|
fi
|
2012-07-09 01:00:04 +04:00
|
|
|
CLASSPATH+=":$BAGEL_DIR/target/scala-$SCALA_VERSION/classes"
|
2012-12-28 10:47:37 +04:00
|
|
|
for jar in `find $PYSPARK_DIR/lib -name '*jar'`; do
|
|
|
|
CLASSPATH+=":$jar"
|
|
|
|
done
|
2010-09-29 10:22:07 +04:00
|
|
|
export CLASSPATH # Needed for spark-shell
|
2010-03-30 03:17:55 +04:00
|
|
|
|
2013-02-26 07:34:32 +04:00
|
|
|
# Figure out the JAR file that our examples were packaged into.
|
|
|
|
if [ -e "$EXAMPLES_DIR/target/scala-$SCALA_VERSION/spark-examples"*".jar" ]; then
|
|
|
|
# Use the JAR from the SBT build
|
|
|
|
export SPARK_EXAMPLES_JAR=`ls "$EXAMPLES_DIR/target/scala-$SCALA_VERSION/spark-examples"*".jar"`
|
|
|
|
fi
|
|
|
|
if [ -e "$EXAMPLES_DIR/target/spark-examples-"*hadoop*".jar" ]; then
|
|
|
|
# Use the JAR from the Maven build
|
|
|
|
export SPARK_EXAMPLES_JAR=`ls "$EXAMPLES_DIR/target/spark-examples-"*hadoop*".jar"`
|
|
|
|
fi
|
|
|
|
|
2012-07-09 01:00:04 +04:00
|
|
|
# Figure out whether to run our class with java or with the scala launcher.
|
|
|
|
# In most cases, we'd prefer to execute our process with java because scala
|
|
|
|
# creates a shell script as the parent of its Java process, which makes it
|
|
|
|
# hard to kill the child with stuff like Process.destroy(). However, for
|
|
|
|
# the Spark shell, the wrapper is necessary to properly reset the terminal
|
|
|
|
# when we exit, so we allow it to set a variable to launch with scala.
|
|
|
|
if [ "$SPARK_LAUNCH_WITH_SCALA" == "1" ]; then
|
2012-07-29 06:53:31 +04:00
|
|
|
EXTRA_ARGS="" # Java options will be passed to scala as JAVA_OPTS
|
2010-03-30 03:17:55 +04:00
|
|
|
else
|
2012-10-23 00:10:47 +04:00
|
|
|
CLASSPATH+=":$SCALA_LIBRARY_PATH/scala-library.jar"
|
|
|
|
CLASSPATH+=":$SCALA_LIBRARY_PATH/scala-compiler.jar"
|
|
|
|
CLASSPATH+=":$SCALA_LIBRARY_PATH/jline.jar"
|
2012-07-29 06:53:31 +04:00
|
|
|
# The JVM doesn't read JAVA_OPTS by default so we need to pass it in
|
|
|
|
EXTRA_ARGS="$JAVA_OPTS"
|
2010-03-30 03:17:55 +04:00
|
|
|
fi
|
|
|
|
|
2012-07-29 06:53:31 +04:00
|
|
|
exec "$RUNNER" -cp "$CLASSPATH" $EXTRA_ARGS "$@"
|