Github user ankurcha commented on a diff in the pull request: https://github.com/apache/spark/pull/5563#discussion_r30431641 --- Diff: core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosUtils.scala --- @@ -0,0 +1,112 @@ +/* + * 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 java.util.{List => JList} + +import com.google.common.base.Splitter +import org.apache.mesos.Protos +import org.apache.mesos.Protos._ + +import scala.collection.JavaConversions._ +import scala.collection.mutable + + +object MesosUtils { + + /** Helper method to get the key,value-set pair for a Mesos Attribute protobuf */ + private[mesos] def getAttribute(attr: Attribute) = + (attr.getName, attr.getText.getValue.split(',').toSet) + + /** Helper function to pull out a resource from a Mesos Resources protobuf */ + private[mesos] def getResource(res: JList[Resource], name: String): Double = { + for (r <- res if r.getName == name) { + return r.getScalar.getValue + } + 0 + } + + /** Build a Mesos resource protobuf object */ + private[mesos] def createResource(resourceName: String, quantity: Double): Protos.Resource = { + Resource.newBuilder() + .setName(resourceName) + .setType(Value.Type.SCALAR) + .setScalar(Value.Scalar.newBuilder().setValue(quantity).build()) + .build() + } + + + /** + * Match the requirements (if any) to the offer attributes. + * if attribute requirements are not specified - return true + * else if attribute is defined and no values are given, simple attribute presence is preformed + * else if attribute name and value is specified, subset match is performed on slave attributes + */ + private[mesos] def matchesAttributeRequirements( + slaveOfferConstraints: Map[String, Set[String]], + offerAttributes: Map[String, Set[String]]) = + if (slaveOfferConstraints.isEmpty) { + true + } else { + slaveOfferConstraints.forall { --- End diff -- Yes, that is true. I just don't know of a good way to say "prefer matches" in a constaint string. Hard constraints seemed like a good way to start the feature and open the conversation.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org