本文整理汇总了Scala中org.apache.mesos.Protos.Resource类的典型用法代码示例。如果您正苦于以下问题:Scala Resource类的具体用法?Scala Resource怎么用?Scala Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: VolumeConstraints
//设置package包名称以及导入依赖的类
package mesosphere.mesos
import mesosphere.marathon.Protos.Constraint
import mesosphere.marathon.Protos.Constraint.Operator
import mesosphere.marathon.state.DiskSource
import org.apache.mesos.Protos.Resource
object VolumeConstraints {
import ResourceHelpers._
class VolumeConstraintsMatcher(diskResource: Resource, constraint: Constraint) {
val field = constraint.getField
val value = constraint.getValue
def isMatch: Boolean = {
if (field == "path") {
checkPath
} else {
false
}
}
val diskSource = DiskSource.fromMesos(diskResource.getSourceOption)
private def getPath: String =
diskSource.path.getOrElse("")
private def checkPath: Boolean =
constraint.getOperator match {
case Operator.LIKE => getPath.matches(value)
case Operator.UNLIKE => !getPath.matches(value)
case _ => false
}
}
def meetsConstraint(diskResource: Resource, constraint: Constraint): Boolean = {
new VolumeConstraintsMatcher(diskResource: Resource, constraint: Constraint).isMatch
}
def meetsAllConstraints(diskResource: Resource, constraints: Set[Constraint]): Boolean = {
constraints.forall(meetsConstraint(diskResource, _))
}
}