Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.{SPARK_VERSION => sparkVersion, SparkConf}
import org.apache.spark.deploy.{Command, DeployMessages, DriverDescription}
import org.apache.spark.deploy.ClientArguments._
import org.apache.spark.internal.config
import org.apache.spark.launcher.SparkLauncher
import org.apache.spark.launcher.{JavaModuleOptions, SparkLauncher}
import org.apache.spark.resource.ResourceUtils
import org.apache.spark.rpc.RpcEndpointRef
import org.apache.spark.util.Utils
Expand Down Expand Up @@ -124,7 +124,10 @@ private[rest] class StandaloneSubmitRequestServlet(
* fields used by python applications since python is not supported in standalone
* cluster mode yet.
*/
private def buildDriverDescription(request: CreateSubmissionRequest): DriverDescription = {
private[rest] def buildDriverDescription(
request: CreateSubmissionRequest,
masterUrl: String,
masterRestPort: Int): DriverDescription = {
Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This private method arguments are revised for better testing by taking advantage of dependency injection pattern.

// Required fields, including the main class because python is not yet supported
val appResource = Option(request.appResource).getOrElse {
throw new SubmitRestMissingFieldException("Application jar is missing.")
Expand All @@ -149,7 +152,6 @@ private[rest] class StandaloneSubmitRequestServlet(
// the driver.
val masters = sparkProperties.get("spark.master")
val (_, masterPort) = Utils.extractHostPortFromSparkUrl(masterUrl)
val masterRestPort = this.conf.get(config.MASTER_REST_SERVER_PORT)
val updatedMasters = masters.map(
_.replace(s":$masterRestPort", s":$masterPort")).getOrElse(masterUrl)
val appArgs = request.appArgs
Expand All @@ -167,7 +169,8 @@ private[rest] class StandaloneSubmitRequestServlet(
.getOrElse(Seq.empty)
val extraJavaOpts = driverExtraJavaOptions.map(Utils.splitCommandString).getOrElse(Seq.empty)
val sparkJavaOpts = Utils.sparkJavaOpts(conf)
val javaOpts = sparkJavaOpts ++ defaultJavaOpts ++ extraJavaOpts
val javaModuleOptions = JavaModuleOptions.defaultModuleOptionArray().toSeq
val javaOpts = javaModuleOptions ++ sparkJavaOpts ++ defaultJavaOpts ++ extraJavaOpts
val command = new Command(
"org.apache.spark.deploy.worker.DriverWrapper",
Seq("{{WORKER_URL}}", "{{USER_JAR}}", mainClass) ++ appArgs, // args to the DriverWrapper
Expand All @@ -194,7 +197,8 @@ private[rest] class StandaloneSubmitRequestServlet(
responseServlet: HttpServletResponse): SubmitRestProtocolResponse = {
requestMessage match {
case submitRequest: CreateSubmissionRequest =>
val driverDescription = buildDriverDescription(submitRequest)
val driverDescription = buildDriverDescription(
submitRequest, masterUrl, conf.get(config.MASTER_REST_SERVER_PORT))
val response = masterEndpoint.askSync[DeployMessages.SubmitDriverResponse](
DeployMessages.RequestSubmitDriver(driverDescription))
val submitResponse = new CreateSubmissionResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ class StandaloneRestSubmitSuite extends SparkFunSuite {
assert(filteredVariables == Map("SPARK_VAR" -> "1", "MESOS_VAR" -> "1"))
}

test("SPARK-45197: Make StandaloneRestServer add JavaModuleOptions to drivers") {
val request = new CreateSubmissionRequest
request.appResource = ""
request.mainClass = ""
request.appArgs = Array.empty[String]
request.sparkProperties = Map.empty[String, String]
request.environmentVariables = Map.empty[String, String]
val servlet = new StandaloneSubmitRequestServlet(null, null, null)
val desc = servlet.buildDriverDescription(request, "spark://master:7077", 6066)
assert(desc.command.javaOpts.exists(_.startsWith("--add-opens")))
}

/* --------------------- *
| Helper methods |
* --------------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public class JavaModuleOptions {
public static String defaultModuleOptions() {
return String.join(" ", DEFAULT_MODULE_OPTIONS);
}

/**
* Returns the default Java option array related to `--add-opens' and
* `-XX:+IgnoreUnrecognizedVMOptions` used by Spark.
*/
public static String[] defaultModuleOptionArray() {
return DEFAULT_MODULE_OPTIONS;
}
}