This repository was archived by the owner on Oct 23, 2024. It is now read-only.
forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 7
[DCOS-34549] Mesos label NPE fix #60
Merged
rpalaznik
merged 8 commits into
d2iq-archive:custom-branch-2.4.x
from
rpalaznik:dcos-34549-mesos-label-npe-fix
Jun 3, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a49d0c6
DCOS-34549: Fix NPE that happens when handling SparkException, before…
42661e9
DCOS-34549: Adds label properties validation during submission
7840a6f
DCOS-34549: Removes stack trace logging for malformed label error
62da58d
DCOS-34549: Adds valid format explanation.
8e90028
DCOS-34549: Moved the list of label properties from the arguments ins…
d9e546f
DCOS-34549: the rest of suggested changes
c8511d5
DCOS-34549: adds a unit tests, fixes a warning
26eb21a
DCOS-34549: Pluralize method name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -23,11 +23,11 @@ import java.util.{Date, Locale} | |
| import java.util.concurrent.atomic.AtomicLong | ||
| import javax.servlet.http.HttpServletResponse | ||
|
|
||
| import org.apache.spark.{SPARK_VERSION => sparkVersion, SparkConf} | ||
| import org.apache.spark.{SPARK_VERSION => sparkVersion, SparkConf, SparkException} | ||
| import org.apache.spark.deploy.Command | ||
| import org.apache.spark.deploy.mesos.MesosDriverDescription | ||
| import org.apache.spark.deploy.rest._ | ||
| import org.apache.spark.scheduler.cluster.mesos.MesosClusterScheduler | ||
| import org.apache.spark.deploy.rest.{SubmitRestProtocolException, _} | ||
| import org.apache.spark.scheduler.cluster.mesos.{MesosClusterScheduler, MesosProtoUtils} | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| /** | ||
|
|
@@ -70,7 +70,7 @@ private[mesos] class MesosSubmitRequestServlet( | |
| // These defaults copied from YARN | ||
| private val MEMORY_OVERHEAD_FACTOR = 0.10 | ||
| private val MEMORY_OVERHEAD_MIN = 384 | ||
|
|
||
| /** | ||
| * Build a driver description from the fields specified in the submit request. | ||
| * | ||
|
|
@@ -107,6 +107,8 @@ private[mesos] class MesosSubmitRequestServlet( | |
| val driverCores = sparkProperties.get("spark.driver.cores") | ||
| val name = request.sparkProperties.getOrElse("spark.app.name", mainClass) | ||
|
|
||
| validateLabelsFormat(sparkProperties) | ||
|
|
||
| // Construct driver description | ||
| val defaultConf = this.conf.getAllWithPrefix("spark.mesos.dispatcher.driverDefault.").toMap | ||
| val driverConf = new SparkConf(false) | ||
|
|
@@ -129,7 +131,7 @@ private[mesos] class MesosSubmitRequestServlet( | |
| val submissionId = newDriverId(submitDate) | ||
|
|
||
| new MesosDriverDescription( | ||
| name, appResource, actualDriverMemory + actualDriverMemoryOverhead, actualDriverCores, | ||
| name, appResource, actualDriverMemory + actualDriverMemoryOverhead, actualDriverCores, | ||
| actualSuperviseDriver, command, driverConf.getAll.toMap, submissionId, submitDate) | ||
| } | ||
|
|
||
|
|
@@ -139,20 +141,40 @@ private[mesos] class MesosSubmitRequestServlet( | |
| responseServlet: HttpServletResponse): SubmitRestProtocolResponse = { | ||
| requestMessage match { | ||
| case submitRequest: CreateSubmissionRequest => | ||
| val driverDescription = buildDriverDescription(submitRequest) | ||
| val s = scheduler.submitDriver(driverDescription) | ||
| s.serverSparkVersion = sparkVersion | ||
| val unknownFields = findUnknownFields(requestMessageJson, requestMessage) | ||
| if (unknownFields.nonEmpty) { | ||
| // If there are fields that the server does not know about, warn the client | ||
| s.unknownFields = unknownFields | ||
| try { | ||
| val driverDescription = buildDriverDescription(submitRequest) | ||
| val s = scheduler.submitDriver(driverDescription) | ||
| s.serverSparkVersion = sparkVersion | ||
| val unknownFields = findUnknownFields(requestMessageJson, requestMessage) | ||
| if (unknownFields.nonEmpty) { | ||
| // If there are fields that the server does not know about, warn the client | ||
| s.unknownFields = unknownFields | ||
| } | ||
| s | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't you but man... single char variable names are the worst! |
||
| } catch { | ||
| case ex: SubmitRestProtocolException => | ||
| responseServlet.setStatus(HttpServletResponse.SC_BAD_REQUEST) | ||
| handleError(s"Bad request: ${ex.getMessage}") | ||
| } | ||
| s | ||
| case unexpected => | ||
| responseServlet.setStatus(HttpServletResponse.SC_BAD_REQUEST) | ||
| handleError(s"Received message of unexpected type ${unexpected.messageType}.") | ||
| } | ||
| } | ||
|
|
||
| private[mesos] def validateLabelsFormat(properties: Map[String, String]): Unit = { | ||
| List("spark.mesos.network.labels", "spark.mesos.task.labels", "spark.mesos.driver.labels") | ||
| .foreach { name => | ||
| properties.get(name) foreach { label => | ||
| try { | ||
| MesosProtoUtils.mesosLabels(label) | ||
| } catch { | ||
| case _ : SparkException => throw new SubmitRestProtocolException("Malformed label in " + | ||
| s"${name}: ${label}. Valid label format: ${name}=key1:value1,key2:value2") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private[mesos] class MesosKillRequestServlet(scheduler: MesosClusterScheduler, conf: SparkConf) | ||
|
|
@@ -172,3 +194,5 @@ private[mesos] class MesosStatusRequestServlet(scheduler: MesosClusterScheduler, | |
| d | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import org.mockito.Mockito.mock | |
|
|
||
| import org.apache.spark.{SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.TestPrematureExit | ||
| import org.apache.spark.deploy.rest.CreateSubmissionRequest | ||
| import org.apache.spark.deploy.rest.{CreateSubmissionRequest, SubmitRestProtocolException} | ||
| import org.apache.spark.scheduler.cluster.mesos.MesosClusterScheduler | ||
|
|
||
| class MesosSubmitRequestServletSuite extends SparkFunSuite | ||
|
|
@@ -50,4 +50,24 @@ class MesosSubmitRequestServletSuite extends SparkFunSuite | |
| assert("test_network" == driverConf.get("spark.mesos.network.name")) | ||
| assert("k0:v0,k1:v1" == driverConf.get("spark.mesos.network.labels")) | ||
| } | ||
|
|
||
| test("test a job with malformed labels is not submitted") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you change to |
||
| val conf = new SparkConf(loadDefaults = false) | ||
|
|
||
| val submitRequestServlet = new MesosSubmitRequestServlet( | ||
| scheduler = mock(classOf[MesosClusterScheduler]), | ||
| conf | ||
| ) | ||
|
|
||
| val request = new CreateSubmissionRequest | ||
| request.appResource = "hdfs://test.jar" | ||
| request.mainClass = "foo.Bar" | ||
| request.appArgs = Array.empty[String] | ||
| request.sparkProperties = Map("spark.mesos.network.labels" -> "k0,k1:v1") // malformed label | ||
| request.environmentVariables = Map.empty[String, String] | ||
|
|
||
| assertThrows[SubmitRestProtocolException] { | ||
| submitRequestServlet.buildDriverDescription(request) | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While exceptions have been used in
buildDriverDescriptionbefore, this approach doesn't look quite right. When we have a method returning value or throwing an error it's a natural use case for Scala'sEitherorTry. On the other hand, there're no usages ofEitherorTryinmesospackage. On the other hand, havingtry-catchblock here is a good defensive approach which can save us from surprises.Given the status of the codebase for Mesos Scheduler in general, a more severe refactoring is needed so I'd say, let's keep the current code as is.