aboutsummaryrefslogtreecommitdiff
path: root/bin/run-example
diff options
context:
space:
mode:
authorPatrick Wendell <pwendell@gmail.com>2014-05-08 22:26:17 -0700
committerPatrick Wendell <pwendell@gmail.com>2014-05-08 22:26:36 -0700
commit06b15baab25951d124bbe6b64906f4139e037deb (patch)
tree5d696f3f36535553478418c850882c0325e38af3 /bin/run-example
parent3f779d872d8459b262b3db9e4d12b011910b6ce9 (diff)
downloadspark-06b15baab25951d124bbe6b64906f4139e037deb.tar.gz
spark-06b15baab25951d124bbe6b64906f4139e037deb.tar.bz2
spark-06b15baab25951d124bbe6b64906f4139e037deb.zip
SPARK-1565 (Addendum): Replace `run-example` with `spark-submit`.
Gives a nicely formatted message to the user when `run-example` is run to tell them to use `spark-submit`. Author: Patrick Wendell <pwendell@gmail.com> Closes #704 from pwendell/examples and squashes the following commits: 1996ee8 [Patrick Wendell] Feedback form Andrew 3eb7803 [Patrick Wendell] Suggestions from TD 2474668 [Patrick Wendell] SPARK-1565 (Addendum): Replace `run-example` with `spark-submit`.
Diffstat (limited to 'bin/run-example')
-rwxr-xr-xbin/run-example71
1 files changed, 18 insertions, 53 deletions
diff --git a/bin/run-example b/bin/run-example
index d8a94f2e31..146951ac0e 100755
--- a/bin/run-example
+++ b/bin/run-example
@@ -17,28 +17,10 @@
# limitations under the License.
#
-cygwin=false
-case "`uname`" in
- CYGWIN*) cygwin=true;;
-esac
-
SCALA_VERSION=2.10
-# Figure out where the Scala framework is installed
FWDIR="$(cd `dirname $0`/..; pwd)"
-
-# Export this as SPARK_HOME
export SPARK_HOME="$FWDIR"
-
-. $FWDIR/bin/load-spark-env.sh
-
-if [ -z "$1" ]; then
- echo "Usage: run-example <example-class> [<args>]" >&2
- exit 1
-fi
-
-# Figure out the JAR file that our examples were packaged into. This includes a bit of a hack
-# to avoid the -sources and -doc packages that are built by publish-local.
EXAMPLES_DIR="$FWDIR"/examples
if [ -f "$FWDIR/RELEASE" ]; then
@@ -49,46 +31,29 @@ fi
if [[ -z $SPARK_EXAMPLES_JAR ]]; then
echo "Failed to find Spark examples assembly in $FWDIR/lib or $FWDIR/examples/target" >&2
- echo "You need to build Spark with sbt/sbt assembly before running this program" >&2
+ echo "You need to build Spark before running this program" >&2
exit 1
fi
+EXAMPLE_MASTER=${MASTER:-"local[*]"}
-# Since the examples JAR ideally shouldn't include spark-core (that dependency should be
-# "provided"), also add our standard Spark classpath, built using compute-classpath.sh.
-CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
-CLASSPATH="$SPARK_EXAMPLES_JAR:$CLASSPATH"
-
-if $cygwin; then
- CLASSPATH=`cygpath -wp $CLASSPATH`
- export SPARK_EXAMPLES_JAR=`cygpath -w $SPARK_EXAMPLES_JAR`
-fi
-
-# Find java binary
-if [ -n "${JAVA_HOME}" ]; then
- RUNNER="${JAVA_HOME}/bin/java"
-else
- if [ `command -v java` ]; then
- RUNNER="java"
- else
- echo "JAVA_HOME is not set" >&2
- exit 1
- fi
-fi
-
-# Set JAVA_OPTS to be able to load native libraries and to set heap size
-JAVA_OPTS="$SPARK_JAVA_OPTS"
-# Load extra JAVA_OPTS from conf/java-opts, if it exists
-if [ -e "$FWDIR/conf/java-opts" ] ; then
- JAVA_OPTS="$JAVA_OPTS `cat $FWDIR/conf/java-opts`"
+if [ -n "$1" ]; then
+ EXAMPLE_CLASS="$1"
+ shift
+else
+ echo "usage: ./bin/run-example <example-class> [example-args]"
+ echo " - set MASTER=XX to use a specific master"
+ echo " - can use abbreviated example class name (e.g. SparkPi, mllib.MovieLensALS)"
+ echo
+ exit -1
fi
-export JAVA_OPTS
-if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then
- echo -n "Spark Command: "
- echo "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
- echo "========================================"
- echo
+if [[ ! $EXAMPLE_CLASS == org.apache.spark.examples* ]]; then
+ EXAMPLE_CLASS="org.apache.spark.examples.$EXAMPLE_CLASS"
fi
-exec "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
+./bin/spark-submit \
+ --master $EXAMPLE_MASTER \
+ --class $EXAMPLE_CLASS \
+ $SPARK_EXAMPLES_JAR \
+ "$@"