Search in sources :

Example 6 with EvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.

the class OrRule method filter.

@Override
public EvaluationOutcome filter(Offer offer, PodInstance podInstance, Collection<TaskInfo> tasks) {
    int passingCount = 0;
    Collection<EvaluationOutcome> children = new ArrayList<>();
    for (PlacementRule rule : rules) {
        EvaluationOutcome child = rule.filter(offer, podInstance, tasks);
        if (child.isPassing()) {
            passingCount++;
        }
        children.add(child);
    }
    if (passingCount != 0) {
        return EvaluationOutcome.pass(this, "%d of %d rules are passing:", passingCount, rules.size()).addAllChildren(children).build();
    } else {
        return EvaluationOutcome.fail(this, "%d of %d rules are passing:", passingCount, rules.size()).addAllChildren(children).build();
    }
}
Also used : ArrayList(java.util.ArrayList) EvaluationOutcome(com.mesosphere.sdk.offer.evaluate.EvaluationOutcome)

Example 7 with EvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.

the class AndRule method filter.

@Override
public EvaluationOutcome filter(Offer offer, PodInstance podInstance, Collection<TaskInfo> tasks) {
    if (rules.isEmpty()) {
        return EvaluationOutcome.fail(this, "No rules to AND together is treated as 'always fail'").build();
    }
    int passingCount = 0;
    Collection<EvaluationOutcome> children = new ArrayList<>();
    for (PlacementRule rule : rules) {
        EvaluationOutcome child = rule.filter(offer, podInstance, tasks);
        if (child.isPassing()) {
            passingCount++;
        }
        children.add(child);
    }
    if (passingCount == rules.size()) {
        return EvaluationOutcome.pass(this, "%d of %d rules are passing:", passingCount, rules.size()).addAllChildren(children).build();
    } else {
        return EvaluationOutcome.fail(this, "%d of %d rules are passing:", passingCount, rules.size()).addAllChildren(children).build();
    }
}
Also used : ArrayList(java.util.ArrayList) EvaluationOutcome(com.mesosphere.sdk.offer.evaluate.EvaluationOutcome)

Example 8 with EvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.

the class IsLocalRegionRuleTest method offerLacksDomain.

@Test
public void offerLacksDomain() {
    EvaluationOutcome outcome = rule.filter(getOffer(), null, null);
    Assert.assertTrue(outcome.isPassing());
}
Also used : EvaluationOutcome(com.mesosphere.sdk.offer.evaluate.EvaluationOutcome) Test(org.junit.Test)

Example 9 with EvaluationOutcome

use of com.mesosphere.sdk.offer.evaluate.EvaluationOutcome in project dcos-commons by mesosphere.

the class IsLocalRegionRuleTest method offerMismatchesLocalDomain.

@Test
public void offerMismatchesLocalDomain() {
    IsLocalRegionRule.setLocalDomain(TestConstants.LOCAL_DOMAIN_INFO);
    EvaluationOutcome outcome = rule.filter(getOffer(TestConstants.REMOTE_DOMAIN_INFO), null, null);
    Assert.assertFalse(outcome.isPassing());
}
Also used : EvaluationOutcome(com.mesosphere.sdk.offer.evaluate.EvaluationOutcome) Test(org.junit.Test)

Aggregations

EvaluationOutcome (com.mesosphere.sdk.offer.evaluate.EvaluationOutcome)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 IsLocalRegionRule (com.mesosphere.sdk.offer.evaluate.placement.IsLocalRegionRule)1 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)1 PodInstance (com.mesosphere.sdk.specification.PodInstance)1 Protos (org.apache.mesos.Protos)1 TaskInfo (org.apache.mesos.Protos.TaskInfo)1