-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-21000][MESOS] Add Mesos labels support to the Spark Dispatcher #18220
Changes from 5 commits
ee10af6
9c21758
e09f55a
3d847a1
b32eb8a
40707fe
79c119c
a381419
616c1b1
218ab0d
fe916b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,8 +382,9 @@ See the [configuration page](configuration.html) for information on Spark config | |
<td>(none)</td> | ||
<td> | ||
Set the Mesos labels to add to each task. Labels are free-form key-value pairs. | ||
Key-value pairs should be separated by a colon, and commas used to list more than one. | ||
Ex. key:value,key2:value2. | ||
Key-value pairs should be separated by a colon, and commas used to | ||
list more than one. If your label includes a colon or comma, you | ||
can escape it with a backslash. Ex. key:value,key2:a\:b. | ||
</td> | ||
</tr> | ||
<tr> | ||
|
@@ -468,6 +469,15 @@ See the [configuration page](configuration.html) for information on Spark config | |
If unset it will point to Spark's internal web UI. | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><code>spark.mesos.driver.labels</code></td> | ||
<td><code>(none)</code></td> | ||
<td> | ||
Mesos labels to add to the driver. See spark.mesos.task.labels | ||
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. Nit: format props and code with 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. fixed |
||
for formatting information. | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td><code>spark.mesos.driverEnv.[EnvironmentVariableName]</code></td> | ||
<td><code>(none)</code></td> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.scheduler.cluster.mesos | ||
|
||
import org.apache.mesos.Protos | ||
|
||
import org.apache.spark.SparkException | ||
import org.apache.spark.internal.Logging | ||
|
||
object MesosProtoUtils extends Logging { | ||
|
||
/** Parses a label string of the format specified in spark.mesos.task.labels. */ | ||
def mesosLabels(labelsStr: String): Protos.Labels.Builder = { | ||
var key: Option[String] = None | ||
var value: Option[String] = None | ||
var currStr = "" | ||
var i = 0 | ||
val labels = Protos.Labels.newBuilder() | ||
|
||
// 0 -> parsing key | ||
// 1 -> parsing value | ||
var state = 0 | ||
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. This all looks excessively complex. Can't you do this with a regex in a few lines? 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 simplified it, but I can't do a simple regex splitting, because I have to condition the match on characters (the escape sequence), that shouldn't actually be considered part of the matched string. So I just wrote a custom |
||
|
||
def addLabel() = { | ||
value = Some(currStr) | ||
if (key.isEmpty) { | ||
throw new SparkException(s"Error while parsing label string: ${labelsStr}. " + | ||
s"Empty label key.") | ||
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. Nit, don't need interpolation but whatever 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. Fixed |
||
} else { | ||
val label = Protos.Label.newBuilder().setKey(key.get).setValue(value.get) | ||
labels.addLabels(label) | ||
|
||
key = None | ||
value = None | ||
currStr = "" | ||
state = 0 | ||
} | ||
} | ||
|
||
while(i < labelsStr.length) { | ||
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. Ideally, this would be more functional. I tried to model it with map/fold, but I'm not smart enough. If someone cares, I can try to rewrite it to be recursive, at least. 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. Nit: space after while 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. this code was removed, so this is fixed. |
||
val c = labelsStr(i) | ||
|
||
if (c == ',') { | ||
addLabel() | ||
} else if (c == ':') { | ||
key = Some(currStr) | ||
currStr = "" | ||
state = 1 | ||
} else if (c == '\\') { | ||
if (i == labelsStr.length - 1) { | ||
if (state == 1) { | ||
value = value.map(_ + '\\') | ||
} else { | ||
throw new SparkException(s"Error while parsing label string: ${labelsStr}. " + | ||
"Key has no value.") | ||
} | ||
} else { | ||
val c2 = labelsStr(i + 1) | ||
if (c2 == ',' || c2 == ':') { | ||
currStr += c2 | ||
i += 1 | ||
} else { | ||
currStr += c | ||
} | ||
} | ||
} else { | ||
currStr += c | ||
} | ||
|
||
i += 1 | ||
} | ||
|
||
if (key.isDefined) { | ||
addLabel() | ||
} | ||
|
||
labels | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.scheduler.cluster.mesos | ||
|
||
import org.apache.spark.SparkFunSuite | ||
|
||
class MesosProtoUtilsSuite extends SparkFunSuite { | ||
test("mesosLabels") { | ||
val labels = MesosProtoUtils.mesosLabels("key:value") | ||
assert(labels.getLabelsCount == 1) | ||
val label = labels.getLabels(0) | ||
assert(label.getKey == "key") | ||
assert(label.getValue == "value") | ||
|
||
val labels2 = MesosProtoUtils.mesosLabels("key:value\\:value") | ||
assert(labels2.getLabelsCount == 1) | ||
val label2 = labels2.getLabels(0) | ||
assert(label2.getKey == "key") | ||
assert(label2.getValue == "value:value") | ||
|
||
val labels3 = MesosProtoUtils.mesosLabels("key:value,key2:value2") | ||
assert(labels3.getLabelsCount == 2) | ||
assert(labels3.getLabels(0).getKey == "key") | ||
assert(labels3.getLabels(0).getValue == "value") | ||
assert(labels3.getLabels(1).getKey == "key2") | ||
assert(labels3.getLabels(1).getValue == "value2") | ||
|
||
val labels4 = MesosProtoUtils.mesosLabels("key:value\\,value") | ||
assert(labels4.getLabelsCount == 1) | ||
assert(labels4.getLabels(0).getKey == "key") | ||
assert(labels4.getLabels(0).getValue == "value,value") | ||
} | ||
} |
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.
This naming differs a bit from the YARN label property, but I suppose it's supporting an expression. And we have .task.labels already. OK.