Skip to content

Commit 6599f50

Browse files
gvramanaJoshRosen
authored andcommitted
[SPARK-4504][Examples] fix run-example failure if multiple assembly jars exist
Fix run-example script to fail fast with useful error message if multiple example assembly JARs are present. Author: Venkata Ramana Gollamudi <[email protected]> Closes #3377 from gvramana/run-example_fails and squashes the following commits: fa7f481 [Venkata Ramana Gollamudi] Fixed review comments, avoiding ls output scanning. 6aa1ab7 [Venkata Ramana Gollamudi] Fix run-examples script error during multiple jars (cherry picked from commit 74de94e) Signed-off-by: Josh Rosen <[email protected]> Conflicts: bin/compute-classpath.sh
1 parent 5d5ee40 commit 6599f50

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

bin/compute-classpath.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,25 @@ else
6868
assembly_folder="$ASSEMBLY_DIR"
6969
fi
7070

71-
num_jars="$(ls "$assembly_folder" | grep "spark-assembly.*hadoop.*\.jar" | wc -l)"
72-
if [ "$num_jars" -eq "0" ]; then
73-
echo "Failed to find Spark assembly in $assembly_folder"
74-
echo "You need to build Spark before running this program."
75-
exit 1
76-
fi
71+
num_jars=0
72+
73+
for f in ${assembly_folder}/spark-assembly*hadoop*.jar; do
74+
if [[ ! -e "$f" ]]; then
75+
echo "Failed to find Spark assembly in $assembly_folder" 1>&2
76+
echo "You need to build Spark before running this program." 1>&2
77+
exit 1
78+
fi
79+
ASSEMBLY_JAR="$f"
80+
num_jars=$((num_jars+1))
81+
done
82+
7783
if [ "$num_jars" -gt "1" ]; then
78-
jars_list=$(ls "$assembly_folder" | grep "spark-assembly.*hadoop.*.jar")
79-
echo "Found multiple Spark assembly jars in $assembly_folder:"
80-
echo "$jars_list"
81-
echo "Please remove all but one jar."
84+
echo "Found multiple Spark assembly jars in $assembly_folder:" 1>&2
85+
ls ${assembly_folder}/spark-assembly*hadoop*.jar 1>&2
86+
echo "Please remove all but one jar." 1>&2
8287
exit 1
8388
fi
8489

85-
ASSEMBLY_JAR="$(ls "$assembly_folder"/spark-assembly*hadoop*.jar 2>/dev/null)"
86-
8790
# Verify that versions of java used to build the jars and run Spark are compatible
8891
jar_error_check=$("$JAR_CMD" -tf "$ASSEMBLY_JAR" nonexistent/class/path 2>&1)
8992
if [[ "$jar_error_check" =~ "invalid CEN header" ]]; then

bin/run-example

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,32 @@ else
3535
fi
3636

3737
if [ -f "$FWDIR/RELEASE" ]; then
38-
export SPARK_EXAMPLES_JAR="`ls "$FWDIR"/lib/spark-examples-*hadoop*.jar`"
39-
elif [ -e "$EXAMPLES_DIR"/target/scala-$SPARK_SCALA_VERSION/spark-examples-*hadoop*.jar ]; then
40-
export SPARK_EXAMPLES_JAR="`ls "$EXAMPLES_DIR"/target/scala-$SPARK_SCALA_VERSION/spark-examples-*hadoop*.jar`"
38+
JAR_PATH="${FWDIR}/lib"
39+
else
40+
JAR_PATH="${EXAMPLES_DIR}/target/scala-${SPARK_SCALA_VERSION}"
4141
fi
4242

43-
if [[ -z "$SPARK_EXAMPLES_JAR" ]]; then
44-
echo "Failed to find Spark examples assembly in $FWDIR/lib or $FWDIR/examples/target" 1>&2
45-
echo "You need to build Spark before running this program" 1>&2
43+
JAR_COUNT=0
44+
45+
for f in ${JAR_PATH}/spark-examples-*hadoop*.jar; do
46+
if [[ ! -e "$f" ]]; then
47+
echo "Failed to find Spark examples assembly in $FWDIR/lib or $FWDIR/examples/target" 1>&2
48+
echo "You need to build Spark before running this program" 1>&2
49+
exit 1
50+
fi
51+
SPARK_EXAMPLES_JAR="$f"
52+
JAR_COUNT=$((JAR_COUNT+1))
53+
done
54+
55+
if [ "$JAR_COUNT" -gt "1" ]; then
56+
echo "Found multiple Spark examples assembly jars in ${JAR_PATH}" 1>&2
57+
ls ${JAR_PATH}/spark-examples-*hadoop*.jar 1>&2
58+
echo "Please remove all but one jar." 1>&2
4659
exit 1
4760
fi
4861

62+
export SPARK_EXAMPLES_JAR
63+
4964
EXAMPLE_MASTER=${MASTER:-"local[*]"}
5065

5166
if [[ ! $EXAMPLE_CLASS == org.apache.spark.examples* ]]; then

0 commit comments

Comments
 (0)