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 @@ -174,6 +174,11 @@ private[rest] class StandaloneSubmitRequestServlet(
conf: SparkConf)
extends SubmitRequestServlet {

private def replacePlaceHolder(variable: String) = variable match {
case s"{{$name}}" if System.getenv(name) != null => System.getenv(name)
case _ => variable
}

/**
* Build a driver description from the fields specified in the submit request.
*
Expand Down Expand Up @@ -214,8 +219,10 @@ private[rest] class StandaloneSubmitRequestServlet(
_.replace(s":$masterRestPort", s":$masterPort")).getOrElse(masterUrl)
val appArgs = request.appArgs
// Filter SPARK_LOCAL_(IP|HOSTNAME) environment variables from being set on the remote system.
Copy link
Member

Choose a reason for hiding this comment

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

Let's also update this comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

// In addition, the placeholders are replaced into the values of environment variables.
val environmentVariables =
request.environmentVariables.filterNot(x => x._1.matches("SPARK_LOCAL_(IP|HOSTNAME)"))
.map(x => (x._1, replacePlaceHolder(x._2)))

// Construct driver description
val conf = new SparkConf(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ class StandaloneRestSubmitSuite extends SparkFunSuite {
assert(filteredVariables == Map("SPARK_VAR" -> "1"))
}

test("SPARK-49033: Support server-side environment variable replacement in REST Submission API") {
val request = new CreateSubmissionRequest
request.appResource = ""
request.mainClass = ""
request.appArgs = Array.empty[String]
request.sparkProperties = Map.empty[String, String]
request.environmentVariables = Map("AWS_ENDPOINT_URL" -> "{{SPARK_SCALA_VERSION}}")
val servlet = new StandaloneSubmitRequestServlet(null, null, null)
val desc = servlet.buildDriverDescription(request, "spark://master:7077", 6066)
assert(desc.command.environment.get("AWS_ENDPOINT_URL") === Some("2.13"))
}

test("SPARK-45197: Make StandaloneRestServer add JavaModuleOptions to drivers") {
val request = new CreateSubmissionRequest
request.appResource = ""
Expand Down