forked from mesos/chronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds support for `constraints` as described in mesos#256. The format to define constraints of a job is the same as in Marathon. Note that currently only the `CLUSTER` constraint has been implemented.
- Loading branch information
Showing
9 changed files
with
131 additions
and
9 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
7 changes: 7 additions & 0 deletions
7
src/main/scala/org/apache/mesos/chronos/scheduler/jobs/constraints/Constraint.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,7 @@ | ||
package org.apache.mesos.chronos.scheduler.jobs.constraints | ||
|
||
import org.apache.mesos.Protos | ||
|
||
trait Constraint { | ||
def matches(attributes: Seq[Protos.Attribute]): Boolean | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/scala/org/apache/mesos/chronos/scheduler/jobs/constraints/EqualsConstraint.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,19 @@ | ||
package org.apache.mesos.chronos.scheduler.jobs.constraints | ||
|
||
import org.apache.mesos.Protos | ||
|
||
case class EqualsConstraint(attribute: String, value: String) extends Constraint { | ||
|
||
def matches(attributes: Seq[Protos.Attribute]): Boolean = { | ||
attributes.foreach { a => | ||
if (a.getName == attribute && a.getText.getValue == value) { | ||
return true | ||
} | ||
} | ||
false | ||
} | ||
} | ||
|
||
object EqualsConstraint { | ||
val OPERATOR = "EQUALS" | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.apache.mesos.chronos.scheduler.api | ||
|
||
import org.apache.mesos.chronos.scheduler.jobs.constraints.EqualsConstraint | ||
import org.apache.mesos.chronos.scheduler.jobs.{DependencyBasedJob, DockerContainer, EnvironmentVariable, ScheduleBasedJob, _} | ||
import org.apache.mesos.chronos.utils.{JobDeserializer, JobSerializer} | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
|
@@ -33,10 +34,12 @@ class SerDeTest extends SpecificationWithJUnit { | |
"-testOne" | ||
) | ||
|
||
val constraints = List(EqualsConstraint("rack", "rack-1")) | ||
|
||
val a = new DependencyBasedJob(Set("B", "C", "D", "E"), "A", "noop", Minutes.minutes(5).toPeriod, 10L, | ||
20L, "fooexec", "fooflags", 7, "[email protected]", "Foo", "Test dependency-based job", "TODAY", | ||
"YESTERDAY", true, container = container, environmentVariables = environmentVariables, | ||
shell = false, arguments = arguments, softError = true) | ||
shell = false, arguments = arguments, softError = true, constraints = constraints) | ||
|
||
val aStr = objectMapper.writeValueAsString(a) | ||
val aCopy = objectMapper.readValue(aStr, classOf[DependencyBasedJob]) | ||
|
@@ -67,10 +70,12 @@ class SerDeTest extends SpecificationWithJUnit { | |
"-testOne" | ||
) | ||
|
||
val constraints = List(EqualsConstraint("rack", "rack-1")) | ||
|
||
val a = new ScheduleBasedJob("FOO/BAR/BAM", "A", "noop", Minutes.minutes(5).toPeriod, 10L, 20L, | ||
"fooexec", "fooflags", 7, "[email protected]", "Foo", "Test schedule-based job", "TODAY", | ||
"YESTERDAY", true, container = container, environmentVariables = environmentVariables, | ||
shell = true, arguments = arguments, softError = true) | ||
shell = true, arguments = arguments, softError = true, constraints = constraints) | ||
|
||
val aStr = objectMapper.writeValueAsString(a) | ||
val aCopy = objectMapper.readValue(aStr, classOf[ScheduleBasedJob]) | ||
|
32 changes: 32 additions & 0 deletions
32
...test/scala/org/apache/mesos/chronos/scheduler/jobs/constraints/EqualsConstraintSpec.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,32 @@ | ||
package org.apache.mesos.chronos.scheduler.jobs.constraints | ||
|
||
import org.apache.mesos.Protos | ||
import org.specs2.mutable.SpecificationWithJUnit | ||
|
||
class EqualsConstraintSpec extends SpecificationWithJUnit { | ||
|
||
def createAttribute(name: String, value: String): Protos.Attribute = { | ||
Protos.Attribute.newBuilder() | ||
.setName(name) | ||
.setText(Protos.Value.Text.newBuilder().setValue(value)) | ||
.setType(Protos.Value.Type.TEXT) | ||
.build() | ||
} | ||
|
||
"matches attributes" in { | ||
val attributes = List(createAttribute("dc", "north"), createAttribute("rack", "rack-1")) | ||
|
||
val constraint = EqualsConstraint("rack", "rack-1") | ||
|
||
constraint.matches(attributes) must_== true | ||
} | ||
|
||
"does not match attributes" in { | ||
val attributes = List(createAttribute("dc", "north"), createAttribute("rack", "rack-1")) | ||
|
||
val constraint = EqualsConstraint("rack", "rack-2") | ||
|
||
constraint.matches(attributes) must_== false | ||
} | ||
|
||
} |