Skip to content

Commit 3db404a

Browse files
committed
Run script fixes for Windows after package & assembly change
1 parent f957c26 commit 3db404a

File tree

10 files changed

+148
-83
lines changed

10 files changed

+148
-83
lines changed

bin/compute-classpath.cmd

+20-26
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,27 @@ set FWDIR=%~dp0..\
2828
rem Load environment variables from conf\spark-env.cmd, if it exists
2929
if exist "%FWDIR%conf\spark-env.cmd" call "%FWDIR%conf\spark-env.cmd"
3030

31-
set CORE_DIR=%FWDIR%core
32-
set REPL_DIR=%FWDIR%repl
33-
set EXAMPLES_DIR=%FWDIR%examples
34-
set BAGEL_DIR=%FWDIR%bagel
35-
set MLLIB_DIR=%FWDIR%mllib
36-
set TOOLS_DIR=%FWDIR%tools
37-
set YARN_DIR=%FWDIR%yarn
38-
set STREAMING_DIR=%FWDIR%streaming
39-
set PYSPARK_DIR=%FWDIR%python
40-
4131
rem Build up classpath
42-
set CLASSPATH=%SPARK_CLASSPATH%;%MESOS_CLASSPATH%;%FWDIR%conf;%CORE_DIR%\target\scala-%SCALA_VERSION%\classes
43-
set CLASSPATH=%CLASSPATH%;%CORE_DIR%\target\scala-%SCALA_VERSION%\test-classes;%CORE_DIR%\src\main\resources
44-
set CLASSPATH=%CLASSPATH%;%STREAMING_DIR%\target\scala-%SCALA_VERSION%\classes;%STREAMING_DIR%\target\scala-%SCALA_VERSION%\test-classes
45-
set CLASSPATH=%CLASSPATH%;%STREAMING_DIR%\lib\org\apache\kafka\kafka\0.7.2-spark\*
46-
set CLASSPATH=%CLASSPATH%;%REPL_DIR%\target\scala-%SCALA_VERSION%\classes;%EXAMPLES_DIR%\target\scala-%SCALA_VERSION%\classes
47-
set CLASSPATH=%CLASSPATH%;%FWDIR%lib_managed\jars\*
48-
set CLASSPATH=%CLASSPATH%;%FWDIR%lib_managed\bundles\*
49-
set CLASSPATH=%CLASSPATH%;%FWDIR%repl\lib\*
50-
set CLASSPATH=%CLASSPATH%;%FWDIR%python\lib\*
51-
set CLASSPATH=%CLASSPATH%;%BAGEL_DIR%\target\scala-%SCALA_VERSION%\classes
52-
set CLASSPATH=%CLASSPATH%;%MLLIB_DIR%\target\scala-%SCALA_VERSION%\classes
53-
set CLASSPATH=%CLASSPATH%;%TOOLS_DIR%\target\scala-%SCALA_VERSION%\classes
54-
set CLASSPATH=%CLASSPATH%;%YARN_DIR%\target\scala-%SCALA_VERSION%\classes
32+
set CLASSPATH=%SPARK_CLASSPATH%;%FWDIR%conf
33+
if exist "%FWDIR%RELEASE" (
34+
for %%d in ("%FWDIR%jars\spark-assembly*.jar") do (
35+
set ASSEMBLY_JAR=%%d
36+
)
37+
) else (
38+
for %%d in ("%FWDIR%assembly\target\scala-%SCALA_VERSION%\spark-assembly*hadoop*.jar") do (
39+
set ASSEMBLY_JAR=%%d
40+
)
41+
)
42+
set CLASSPATH=%CLASSPATH%;%ASSEMBLY_JAR%
43+
44+
if "x%SPARK_TESTING%"=="x1" (
45+
rem Add test clases to path
46+
set CLASSPATH=%CLASSPATH%;%FWDIR%core\target\scala-%SCALA_VERSION%\test-classes
47+
set CLASSPATH=%CLASSPATH%;%FWDIR%repl\target\scala-%SCALA_VERSION%\test-classes
48+
set CLASSPATH=%CLASSPATH%;%FWDIR%mllib\target\scala-%SCALA_VERSION%\test-classes
49+
set CLASSPATH=%CLASSPATH%;%FWDIR%bagel\target\scala-%SCALA_VERSION%\test-classes
50+
set CLASSPATH=%CLASSPATH%;%FWDIR%streaming\target\scala-%SCALA_VERSION%\test-classes
51+
)
5552

5653
rem Add hadoop conf dir - else FileSystem.*, etc fail
5754
rem Note, this assumes that there is either a HADOOP_CONF_DIR or YARN_CONF_DIR which hosts
@@ -64,9 +61,6 @@ if "x%YARN_CONF_DIR%"=="x" goto no_yarn_conf_dir
6461
set CLASSPATH=%CLASSPATH%;%YARN_CONF_DIR%
6562
:no_yarn_conf_dir
6663

67-
rem Add Scala standard library
68-
set CLASSPATH=%CLASSPATH%;%SCALA_HOME%\lib\scala-library.jar;%SCALA_HOME%\lib\scala-compiler.jar;%SCALA_HOME%\lib\jline.jar
69-
7064
rem A bit of a hack to allow calling this script within run2.cmd without seeing output
7165
if "%DONT_PRINT_CLASSPATH%"=="1" goto exit
7266

core/src/main/scala/org/apache/spark/SparkContext.scala

+17-11
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,26 @@ class SparkContext(
631631
* filesystems), or an HTTP, HTTPS or FTP URI.
632632
*/
633633
def addJar(path: String) {
634-
if (null == path) {
634+
if (path == null) {
635635
logWarning("null specified as parameter to addJar",
636636
new SparkException("null specified as parameter to addJar"))
637637
} else {
638-
val env = SparkEnv.get
639-
val uri = new URI(path)
640-
val key = uri.getScheme match {
641-
case null | "file" =>
642-
if (env.hadoop.isYarnMode()) {
643-
logWarning("local jar specified as parameter to addJar under Yarn mode")
644-
return
645-
}
646-
env.httpFileServer.addJar(new File(uri.getPath))
647-
case _ => path
638+
var key = ""
639+
if (path.contains("\\")) {
640+
// For local paths with backslashes on Windows, URI throws an exception
641+
key = env.httpFileServer.addJar(new File(path))
642+
} else {
643+
val uri = new URI(path)
644+
key = uri.getScheme match {
645+
case null | "file" =>
646+
if (env.hadoop.isYarnMode()) {
647+
logWarning("local jar specified as parameter to addJar under Yarn mode")
648+
return
649+
}
650+
env.httpFileServer.addJar(new File(uri.getPath))
651+
case _ =>
652+
path
653+
}
648654
}
649655
addedJars(key) = System.currentTimeMillis
650656
logInfo("Added JAR " + path + " at " + key + " with timestamp " + addedJars(key))

docs/spark-standalone.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ In addition to running on the Mesos or YARN cluster managers, Spark also provide
99

1010
You can start a standalone master server by executing:
1111

12-
./spark-class spark.deploy.master.Master
12+
./spark-class org.apache.spark.deploy.master.Master
1313

1414
Once started, the master will print out a `spark://HOST:PORT` URL for itself, which you can use to connect workers to it,
1515
or pass as the "master" argument to `SparkContext`. You can also find this URL on
1616
the master's web UI, which is [http://localhost:8080](http://localhost:8080) by default.
1717

1818
Similarly, you can start one or more workers and connect them to the master via:
1919

20-
./spark-class spark.deploy.worker.Worker spark://IP:PORT
20+
./spark-class org.apache.spark.deploy.worker.Worker spark://IP:PORT
2121

2222
Once you have started a worker, look at the master's web UI ([http://localhost:8080](http://localhost:8080) by default).
2323
You should see the new node listed there, along with its number of CPUs and memory (minus one gigabyte left for the OS).

run-example.cmd

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@echo off
2+
3+
rem
4+
rem Licensed to the Apache Software Foundation (ASF) under one or more
5+
rem contributor license agreements. See the NOTICE file distributed with
6+
rem this work for additional information regarding copyright ownership.
7+
rem The ASF licenses this file to You under the Apache License, Version 2.0
8+
rem (the "License"); you may not use this file except in compliance with
9+
rem the License. You may obtain a copy of the License at
10+
rem
11+
rem http://www.apache.org/licenses/LICENSE-2.0
12+
rem
13+
rem Unless required by applicable law or agreed to in writing, software
14+
rem distributed under the License is distributed on an "AS IS" BASIS,
15+
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
rem See the License for the specific language governing permissions and
17+
rem limitations under the License.
18+
rem
19+
20+
rem This is the entry point for running a Spark example. To avoid polluting
21+
rem the environment, it just launches a new cmd to do the real work.
22+
23+
cmd /V /E /C %~dp0run-example2.cmd %*

run-example2.cmd

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@echo off
2+
3+
rem
4+
rem Licensed to the Apache Software Foundation (ASF) under one or more
5+
rem contributor license agreements. See the NOTICE file distributed with
6+
rem this work for additional information regarding copyright ownership.
7+
rem The ASF licenses this file to You under the Apache License, Version 2.0
8+
rem (the "License"); you may not use this file except in compliance with
9+
rem the License. You may obtain a copy of the License at
10+
rem
11+
rem http://www.apache.org/licenses/LICENSE-2.0
12+
rem
13+
rem Unless required by applicable law or agreed to in writing, software
14+
rem distributed under the License is distributed on an "AS IS" BASIS,
15+
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
rem See the License for the specific language governing permissions and
17+
rem limitations under the License.
18+
rem
19+
20+
set SCALA_VERSION=2.9.3
21+
22+
rem Figure out where the Spark framework is installed
23+
set FWDIR=%~dp0
24+
25+
rem Export this as SPARK_HOME
26+
set SPARK_HOME=%FWDIR%
27+
28+
rem Load environment variables from conf\spark-env.cmd, if it exists
29+
if exist "%FWDIR%conf\spark-env.cmd" call "%FWDIR%conf\spark-env.cmd"
30+
31+
rem Test that an argument was given
32+
if not "x%1"=="x" goto arg_given
33+
echo Usage: run-example ^<example-class^> [^<args^>]
34+
goto exit
35+
:arg_given
36+
37+
set EXAMPLES_DIR=%FWDIR%examples
38+
39+
rem Figure out the JAR file that our examples were packaged into.
40+
set SPARK_EXAMPLES_JAR=
41+
for %%d in ("%EXAMPLES_DIR%\target\scala-%SCALA_VERSION%\spark-examples*assembly*.jar") do (
42+
set SPARK_EXAMPLES_JAR=%%d
43+
)
44+
if "x%SPARK_EXAMPLES_JAR%"=="x" (
45+
echo Failed to find Spark examples assembly JAR.
46+
echo You need to build Spark with sbt\sbt assembly before running this program.
47+
goto exit
48+
)
49+
50+
rem Compute Spark classpath using external script
51+
set DONT_PRINT_CLASSPATH=1
52+
call "%FWDIR%bin\compute-classpath.cmd"
53+
set DONT_PRINT_CLASSPATH=0
54+
set CLASSPATH=%SPARK_EXAMPLES_JAR%;%CLASSPATH%
55+
56+
rem Figure out where java is.
57+
set RUNNER=java
58+
if not "x%JAVA_HOME%"=="x" set RUNNER=%JAVA_HOME%\bin\java
59+
60+
"%RUNNER%" -cp "%CLASSPATH%" %JAVA_OPTS% %*
61+
:exit

sbt/sbt.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ if not "%MESOS_HOME%x"=="x" set EXTRA_ARGS=-Djava.library.path=%MESOS_HOME%\lib\
2222

2323
set SPARK_HOME=%~dp0..
2424

25-
java -Xmx1200M -XX:MaxPermSize=200m %EXTRA_ARGS% -jar %SPARK_HOME%\sbt\sbt-launch-0.11.3-2.jar "%*"
25+
java -Xmx1200M -XX:MaxPermSize=200m -XX:ReservedCodeCacheSize=256m %EXTRA_ARGS% -jar %SPARK_HOME%\sbt\sbt-launch-0.11.3-2.jar "%*"

spark-class

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if [ -e $FWDIR/conf/spark-env.sh ] ; then
3131
fi
3232

3333
if [ -z "$1" ]; then
34-
echo "Usage: run <spark-class> [<args>]" >&2
34+
echo "Usage: spark-class <class> [<args>]" >&2
3535
exit 1
3636
fi
3737

run.cmd renamed to spark-class.cmd

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ rem See the License for the specific language governing permissions and
1717
rem limitations under the License.
1818
rem
1919

20-
cmd /V /E /C %~dp0run2.cmd %*
20+
rem This is the entry point for running a Spark class. To avoid polluting
21+
rem the environment, it just launches a new cmd to do the real work.
22+
23+
cmd /V /E /C %~dp0spark-class2.cmd %*

run2.cmd renamed to spark-class2.cmd

+17-39
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if exist "%FWDIR%conf\spark-env.cmd" call "%FWDIR%conf\spark-env.cmd"
3030

3131
rem Test that an argument was given
3232
if not "x%1"=="x" goto arg_given
33-
echo Usage: run ^<spark-class^> [^<args^>]
33+
echo Usage: spark-class ^<class^> [^<args^>]
3434
goto exit
3535
:arg_given
3636

@@ -44,12 +44,6 @@ rem Do not overwrite SPARK_JAVA_OPTS environment variable in this script
4444
if "%RUNNING_DAEMON%"=="0" set OUR_JAVA_OPTS=%SPARK_JAVA_OPTS%
4545
if "%RUNNING_DAEMON%"=="1" set OUR_JAVA_OPTS=%SPARK_DAEMON_JAVA_OPTS%
4646

47-
rem Check that SCALA_HOME has been specified
48-
if not "x%SCALA_HOME%"=="x" goto scala_exists
49-
echo SCALA_HOME is not set
50-
goto exit
51-
:scala_exists
52-
5347
rem Figure out how much memory to use per executor and set it as an environment
5448
rem variable so that our process sees it and can report it to Mesos
5549
if "x%SPARK_MEM%"=="x" set SPARK_MEM=512m
@@ -58,43 +52,27 @@ rem Set JAVA_OPTS to be able to load native libraries and to set heap size
5852
set JAVA_OPTS=%OUR_JAVA_OPTS% -Djava.library.path=%SPARK_LIBRARY_PATH% -Xms%SPARK_MEM% -Xmx%SPARK_MEM%
5953
rem Attention: when changing the way the JAVA_OPTS are assembled, the change must be reflected in ExecutorRunner.scala!
6054

61-
set CORE_DIR=%FWDIR%core
62-
set EXAMPLES_DIR=%FWDIR%examples
63-
set REPL_DIR=%FWDIR%repl
55+
rem Test whether the user has built Spark
56+
if exist "%FWDIR%RELEASE" goto skip_build_test
57+
set FOUND_JAR=0
58+
for %%d in ("%FWDIR%assembly\target\scala-%SCALA_VERSION%\spark-assembly*hadoop*.jar") do (
59+
set FOUND_JAR=1
60+
)
61+
if "%FOUND_JAR%"=="0" (
62+
echo Failed to find Spark assembly JAR.
63+
echo You need to build Spark with sbt\sbt assembly before running this program.
64+
goto exit
65+
)
66+
:skip_build_test
6467

6568
rem Compute classpath using external script
6669
set DONT_PRINT_CLASSPATH=1
6770
call "%FWDIR%bin\compute-classpath.cmd"
6871
set DONT_PRINT_CLASSPATH=0
6972

70-
rem Figure out the JAR file that our examples were packaged into.
71-
rem First search in the build path from SBT:
72-
for %%d in ("examples/target/scala-%SCALA_VERSION%/spark-examples*.jar") do (
73-
set SPARK_EXAMPLES_JAR=examples/target/scala-%SCALA_VERSION%/%%d
74-
)
75-
rem Then search in the build path from Maven:
76-
for %%d in ("examples/target/spark-examples*hadoop*.jar") do (
77-
set SPARK_EXAMPLES_JAR=examples/target/%%d
78-
)
79-
80-
rem Figure out whether to run our class with java or with the scala launcher.
81-
rem In most cases, we'd prefer to execute our process with java because scala
82-
rem creates a shell script as the parent of its Java process, which makes it
83-
rem hard to kill the child with stuff like Process.destroy(). However, for
84-
rem the Spark shell, the wrapper is necessary to properly reset the terminal
85-
rem when we exit, so we allow it to set a variable to launch with scala.
86-
if "%SPARK_LAUNCH_WITH_SCALA%" NEQ 1 goto java_runner
87-
set RUNNER=%SCALA_HOME%\bin\scala
88-
# Java options will be passed to scala as JAVA_OPTS
89-
set EXTRA_ARGS=
90-
goto run_spark
91-
:java_runner
92-
set CLASSPATH=%CLASSPATH%;%SCALA_HOME%\lib\scala-library.jar;%SCALA_HOME%\lib\scala-compiler.jar;%SCALA_HOME%\lib\jline.jar
93-
set RUNNER=java
94-
if not "x%JAVA_HOME%"=="x" set RUNNER=%JAVA_HOME%\bin\java
95-
rem The JVM doesn't read JAVA_OPTS by default so we need to pass it in
96-
set EXTRA_ARGS=%JAVA_OPTS%
97-
:run_spark
73+
rem Figure out where java is.
74+
set RUNNER=java
75+
if not "x%JAVA_HOME%"=="x" set RUNNER=%JAVA_HOME%\bin\java
9876

99-
"%RUNNER%" -cp "%CLASSPATH%" %EXTRA_ARGS% %*
77+
"%RUNNER%" -cp "%CLASSPATH%" %JAVA_OPTS% %*
10078
:exit

spark-shell.cmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ rem limitations under the License.
1818
rem
1919

2020
set FWDIR=%~dp0
21-
set SPARK_LAUNCH_WITH_SCALA=1
22-
cmd /V /E /C %FWDIR%run2.cmd org.apache.spark.repl.Main %*
21+
22+
cmd /V /E /C %FWDIR%spark-class2.cmd org.apache.spark.repl.Main %*

0 commit comments

Comments
 (0)