|
| 1 | +#!/bin/bash |
| 2 | +# To use sparkR-submit, we assume the SparkR package in yarn-cluster mode |
| 3 | +# we assume that it has been installed to a standard location using |
| 4 | +# R CMD INSTALL pkg/ |
| 5 | + |
| 6 | +FWDIR="$(cd `dirname $0`; pwd)" |
| 7 | + |
| 8 | +export PROJECT_HOME="$FWDIR" |
| 9 | + |
| 10 | +export SPARKR_JAR_FILE="$FWDIR/lib/SparkR/sparkr-assembly-0.1.jar" |
| 11 | + |
| 12 | +# Exit if the user hasn't set SPARK_HOME |
| 13 | +if [ ! -f "$SPARK_HOME/bin/spark-submit" ]; then |
| 14 | + echo "SPARK_HOME must be set to use sparkR-submit" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +source "$SPARK_HOME/bin/utils.sh" |
| 19 | + |
| 20 | +function usage() { |
| 21 | + echo "Usage: ./sparkR-submit [options]" 1>&2 |
| 22 | + "$SPARK_HOME"/bin/spark-submit --help 2>&1 | grep -v Usage 1>&2 |
| 23 | + exit 0 |
| 24 | +} |
| 25 | + |
| 26 | +if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then |
| 27 | + usage |
| 28 | +fi |
| 29 | + |
| 30 | + |
| 31 | +# Add SparkR to .libPaths |
| 32 | +# If we are running an R program, only set libPaths and use Rscript |
| 33 | + |
| 34 | +export R_PROFILE_USER="/tmp/sparkR.profile" |
| 35 | + |
| 36 | +cat > /tmp/sparkR.profile << EOF |
| 37 | + .First <- function() { |
| 38 | + projecHome <- Sys.getenv("PROJECT_HOME") |
| 39 | + .libPaths(c(paste(projecHome,"/lib", sep=""), .libPaths())) |
| 40 | + Sys.setenv(NOAWT=1) |
| 41 | +} |
| 42 | +EOF |
| 43 | + |
| 44 | +# Build up arguments list manually to preserve quotes and backslashes. |
| 45 | +SUBMIT_USAGE_FUNCTION=usage |
| 46 | +gatherSparkSubmitOpts "$@" |
| 47 | + |
| 48 | +# If a R file is provided, directly run spark-submit. |
| 49 | +if [[ "$1" =~ \.R$ ]]; then |
| 50 | + primary="$1" |
| 51 | + shift |
| 52 | + gatherSparkSubmitOpts "$@" |
| 53 | + exec "$FWDIR"/bin/spark-submit --class edu.berkeley.cs.amplab.sparkr.SparkRRunner --files "$primary" "${SUBMISSION_OPTS[@]}" "$SPARKR_JAR_FILE" "$primary" "${APPLICATION_OPTS[@]}" |
| 54 | +else |
| 55 | + echo "sparkR-submit can only be used to run R programs. Please use sparkR to launch a shell" |
| 56 | +fi |
0 commit comments