Skip to content

Commit

Permalink
Escape arguments, cf d2iq-archive#33
Browse files Browse the repository at this point in the history
  • Loading branch information
Igosuki committed Feb 19, 2019
1 parent 0a4c03f commit ceda5b0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,14 @@ private[spark] class MesosClusterScheduler(

private def generateCmdOption(desc: MesosDriverDescription, sandboxPath: String): Seq[String] = {
var options = Seq(
"--name", desc.conf.get("spark.app.name"),
"--name", shellEscape(desc.conf.get("spark.app.name")),
"--master", s"mesos://${conf.get("spark.master")}",
"--driver-cores", desc.cores.toString,
"--driver-memory", s"${desc.mem}M")

// Assume empty main class means we're running python
if (!desc.command.mainClass.equals("")) {
options ++= Seq("--class", desc.command.mainClass)
options ++= Seq("--class", shellEscape(desc.command.mainClass))
}

desc.conf.getOption("spark.executor.memory").foreach { v =>
Expand All @@ -552,7 +552,7 @@ private[spark] class MesosClusterScheduler(
.filter { case (key, _) => !replicatedOptionsBlacklist.contains(key) }
.toMap
(defaultConf ++ driverConf).foreach { case (key, value) =>
options ++= Seq("--conf", s"${key}=${value}") }
options ++= Seq("--conf", s"$key=${shellEscape(value)}") }

options.map(shellEscape)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ class MesosClusterSchedulerSuite extends SparkFunSuite with LocalSparkContext wi
new Date())
}

test("escapes spark.app.name correctly") {
setScheduler()

val driverDesc = testDriverDescription("s1", Map[String, String](
"spark.app.name" -> "AnApp With $pecialChars.py",
"spark.mesos.executor.home" -> "test"
))

val cmdString = scheduler.getDriverCommandValue(driverDesc)
assert(cmdString.contains("AnApp With \\$pecialChars.py"))
}

test("escapes extraJavaOptions correctly") {
setScheduler()

val driverDesc = testDriverDescription("s1", Map[String, String](
"spark.app.name" -> "app.py",
"spark.mesos.executor.home" -> "test",
"spark.driver.extraJavaOptions" -> "-DparamA=\"val1 val2\" -Dpath=$PATH"
))

val cmdString = scheduler.getDriverCommandValue(driverDesc)
assert(cmdString.contains(
"spark.driver.extraJavaOptions=\"-DparamA=\\\"val1 val2\\\" -Dpath=\\$PATH"))
}

test("does not escape $MESOS_SANDBOX for --py-files when using a docker image") {
setScheduler()

val driverDesc = testDriverDescription("s1", Map[String, String](
"spark.app.name" -> "app.py",
"spark.mesos.executor.docker.image" -> "test/spark:01",
"spark.submit.pyFiles" -> "http://site.com/extraPythonFile.py"
))

val cmdString = scheduler.getDriverCommandValue(driverDesc)
assert(!cmdString.contains("\\$MESOS_SANDBOX/extraPythonFile.py"))
assert(cmdString.contains("$MESOS_SANDBOX/extraPythonFile.py"))
}

test("can queue drivers") {
setScheduler()

Expand Down

0 comments on commit ceda5b0

Please sign in to comment.