use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.
the class NotRule method filter.
@Override
public EvaluationOutcome filter(Offer offer, PodInstance podInstance, Collection<TaskInfo> tasks) {
EvaluationOutcome child = rule.filter(offer, podInstance, tasks);
String reason = "Returning opposite of child rule";
if (child.isPassing()) {
return EvaluationOutcome.fail(this, reason).addChild(child).build();
} else {
return EvaluationOutcome.pass(this, reason).addChild(child).build();
}
}
use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.
the class RoundRobinByAttributeRuleTest method testRolloutWithAgentCount.
@Test
public void testRolloutWithAgentCount() throws TaskException, InvalidRequirementException {
PlacementRule rule = new RoundRobinByAttributeRule(ATTRIB_NAME, Optional.of(3), MATCHER);
// throw in some preexisting tasks to be ignored by our matcher:
List<TaskInfo> tasks = new ArrayList<>();
tasks.add(getTaskInfo("ignored1", "value1"));
tasks.add(getTaskInfo("ignored2", "value2"));
tasks.add(getTaskInfo("ignored3", "value3"));
tasks.add(getTaskInfo("ignored4", "value4"));
tasks.add(getTaskInfo("ignored5", "value5"));
tasks.add(getTaskInfo("ignored6", "foo", "value6"));
tasks.add(getTaskInfo("ignored7", "bar", "value7"));
tasks.add(getTaskInfo("ignored8", "baz", "value8"));
// 1st task fits on value1:
assertTrue(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
TaskInfo taskInfo1 = getTaskInfo("1", "value1");
PodInstance req1 = getPodInstance(taskInfo1);
// value1:1
tasks.add(taskInfo1);
// 2nd task doesn't fit on value1 which already has something, but does fit on value2/value3:
EvaluationOutcome outcome = rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks);
assertFalse(outcome.toString(), outcome.isPassing());
assertTrue(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
TaskInfo taskInfo2 = getTaskInfo("2", "value3");
PodInstance req2 = getPodInstance(taskInfo2);
// value1:1, value3:1
tasks.add(taskInfo2);
// duplicates of preexisting tasks 1/3 fit on their previous values:
assertTrue(rule.filter(offerWithAttribute("value1"), req1, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value3"), req2, tasks).isPassing());
// 3rd task doesnt fit on value1/value3, does fit on value2:
assertFalse(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertFalse(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
// value1:1, value2:1, value3:1
tasks.add(getTaskInfo("3", "value2"));
// 4th task fits on any value as the three values now have the same size:
assertTrue(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
// value1:1, value2:2, value3:1
tasks.add(getTaskInfo("4", "value2"));
// 5th task doesn't fit on value2 but does fit on value1/value3:
assertTrue(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
assertFalse(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
// value1:1, value2:2, value3:2
tasks.add(getTaskInfo("5", "value3"));
// 6th task is launched on erroneous value4 (host4 shouldn't exist: we were told there were only 3 values!)
assertTrue(rule.filter(offerWithAttribute("value4"), POD_INSTANCE, tasks).isPassing());
// value1:1, value2:2, value3:2, value4:1
tasks.add(getTaskInfo("6", "value4"));
// 7th task is launched on value4 as well:
assertTrue(rule.filter(offerWithAttribute("value4"), POD_INSTANCE, tasks).isPassing());
// value1:1, value2:2, value3:2, value4:2
tasks.add(getTaskInfo("7", "value4"));
// 8th task fails to launch on values2-4 as they now all have more occupancy than value1:
assertFalse(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertFalse(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
assertFalse(rule.filter(offerWithAttribute("value4"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
// value1:2, value2:2, value3:2, value4:2
tasks.add(getTaskInfo("8", "value1"));
// now all values1-4 have equal occupancy = 2. adding a task to any of them should work:
assertTrue(rule.filter(offerWithAttribute("value1"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value2"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value3"), POD_INSTANCE, tasks).isPassing());
assertTrue(rule.filter(offerWithAttribute("value4"), POD_INSTANCE, tasks).isPassing());
}
use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.
the class IsLocalRegionRuleTest method offerHasDomainLocalDomainUnset.
@Test
public void offerHasDomainLocalDomainUnset() {
EvaluationOutcome outcome = rule.filter(getOffer(TestConstants.LOCAL_DOMAIN_INFO), null, null);
Assert.assertTrue(outcome.isPassing());
}
use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.
the class IsLocalRegionRuleTest method offerMatchesLocalDomain.
@Test
public void offerMatchesLocalDomain() {
IsLocalRegionRule.setLocalDomain(TestConstants.LOCAL_DOMAIN_INFO);
EvaluationOutcome outcome = rule.filter(getOffer(TestConstants.LOCAL_DOMAIN_INFO), null, null);
Assert.assertTrue(outcome.isPassing());
}
use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.
the class FrameworkSchedulerTest method verifyDomainIsSet.
private static void verifyDomainIsSet(Protos.DomainInfo expectedDomain) {
// Infer the configured domain via a placement rule invocation
Protos.Offer offerWithExpectedDomain = getOffer().toBuilder().setDomain(expectedDomain).build();
EvaluationOutcome outcome = new IsLocalRegionRule().filter(offerWithExpectedDomain, null, null);
Assert.assertTrue(outcome.getReason(), outcome.isPassing());
}
Aggregations