This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-21000][MESOS] Add Mesos labels support to the Spark Dispatcher
## What changes were proposed in this pull request? Add Mesos labels support to the Spark Dispatcher ## How was this patch tested? unit tests Author: Michael Gummelt <[email protected]> Closes apache#18220 from mgummelt/SPARK-21000-dispatcher-labels.
- Loading branch information
Michael Gummelt
authored and
ArtRand
committed
Aug 21, 2017
1 parent
3a85009
commit 9c33e12
Showing
7 changed files
with
154 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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
53 changes: 53 additions & 0 deletions
53
...agers/mesos/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosProtoUtils.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 scala.collection.JavaConverters._ | ||
|
||
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 = { | ||
val labels: Seq[Protos.Label] = if (labelsStr == "") { | ||
Seq() | ||
} else { | ||
labelsStr.split("""(?<!\\),""").toSeq.map { labelStr => | ||
val parts = labelStr.split("""(?<!\\):""") | ||
if (parts.length != 2) { | ||
throw new SparkException(s"Malformed label: ${labelStr}") | ||
} | ||
|
||
val cleanedParts = parts | ||
.map(part => part.replaceAll("""\\,""", ",")) | ||
.map(part => part.replaceAll("""\\:""", ":")) | ||
|
||
Protos.Label.newBuilder() | ||
.setKey(cleanedParts(0)) | ||
.setValue(cleanedParts(1)) | ||
.build() | ||
} | ||
} | ||
|
||
Protos.Labels.newBuilder().addAllLabels(labels.asJava) | ||
} | ||
} |
This file contains 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 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
48 changes: 48 additions & 0 deletions
48
.../mesos/src/test/scala/org/apache/spark/scheduler/cluster/mesos/MesosProtoUtilsSuite.scala
This file contains 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 |
---|---|---|
@@ -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") | ||
} | ||
} |