forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-42371][CONNECT] Add scripts to start and stop Spark Connect se…
…rver ### What changes were proposed in this pull request? This PR proposes to scripts to start and stop the Spark Connect server. ### Why are the changes needed? Currently, there is no proper way to start and stop the Spark Connect server. Now it requires you to start it with, for example, a Spark shell: ```bash # For development, ./bin/spark-shell \ --jars `ls connector/connect/server/target/**/spark-connect*SNAPSHOT.jar` \ --conf spark.plugins=org.apache.spark.sql.connect.SparkConnectPlugin ``` ```bash # For released Spark versions ./bin/spark-shell \ --packages org.apache.spark:spark-connect_2.12:3.4.0 \ --conf spark.plugins=org.apache.spark.sql.connect.SparkConnectPlugin ``` which is awkward. ### Does this PR introduce _any_ user-facing change? Yes, it adds new scripts to start and stop Spark Connect server. ### How was this patch tested? Manually tested: ```bash # For released Spark versions, #`sbin/start-connect-server.sh --packages org.apache.spark:spark-connect_2.12:3.4.0` sbin/start-connect-server.sh --jars `ls connector/connect/server/target/**/spark-connect*SNAPSHOT.jar` ``` ```bash bin/pyspark --remote sc://localhost:15002 ... ``` ```bash sbin/stop-connect-server.sh ps -fe | grep Spark ``` Closes apache#39928 from HyukjinKwon/exec-script. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
- Loading branch information
1 parent
839c56a
commit 1126031
Showing
6 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...nnect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.connect.service | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.sql.SparkSession | ||
|
||
/** | ||
* The Spark Connect server | ||
*/ | ||
object SparkConnectServer extends Logging { | ||
def main(args: Array[String]): Unit = { | ||
// Set the active Spark Session, and starts SparkEnv instance (via Spark Context) | ||
logInfo("Starting Spark session.") | ||
val session = SparkSession.builder.getOrCreate() | ||
try { | ||
try { | ||
SparkConnectService.start() | ||
logInfo("Spark Connect server started.") | ||
} catch { | ||
case e: Exception => | ||
logError("Error starting Spark Connect server", e) | ||
System.exit(-1) | ||
} | ||
SparkConnectService.server.awaitTermination() | ||
} finally { | ||
session.stop() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Enter posix mode for bash | ||
set -o posix | ||
|
||
# Shell script for starting the Spark Connect server | ||
if [ -z "${SPARK_HOME}" ]; then | ||
export SPARK_HOME="$(cd "`dirname "$0"`"/..; pwd)" | ||
fi | ||
|
||
# NOTE: This exact class name is matched downstream by SparkSubmit. | ||
# Any changes need to be reflected there. | ||
CLASS="org.apache.spark.sql.connect.service.SparkConnectServer" | ||
|
||
if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then | ||
echo "Usage: ./sbin/start-connect-server.sh [options]" | ||
|
||
"${SPARK_HOME}"/bin/spark-submit --help 2>&1 | grep -v Usage 1>&2 | ||
exit 1 | ||
fi | ||
|
||
. "${SPARK_HOME}/bin/load-spark-env.sh" | ||
|
||
exec "${SPARK_HOME}"/sbin/spark-daemon.sh submit $CLASS 1 --name "Spark Connect server" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Stops the connect server on the machine this script is executed on. | ||
|
||
if [ -z "${SPARK_HOME}" ]; then | ||
export SPARK_HOME="$(cd "`dirname "$0"`"/..; pwd)" | ||
fi | ||
|
||
"${SPARK_HOME}/sbin"/spark-daemon.sh stop org.apache.spark.sql.connect.service.SparkConnectServer 1 |