Search in sources :

Example 6 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.

the class RegionValidator method validate.

private static Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig, String podType) {
    if (!oldConfig.isPresent()) {
        return Collections.emptyList();
    }
    Optional<PodSpec> oldPod = getPodSpec(oldConfig.get(), podType);
    if (!oldPod.isPresent()) {
        return Collections.emptyList();
    }
    Optional<PodSpec> newPod = getPodSpec(newConfig, podType);
    if (!newPod.isPresent()) {
        throw new IllegalArgumentException(String.format("Unable to find requested pod=%s, in config: %s", podType, newConfig));
    }
    boolean oldReferencesRegions = PlacementUtils.placementRuleReferencesRegion(oldPod.get());
    boolean newReferencesRegions = PlacementUtils.placementRuleReferencesRegion(newPod.get());
    if (oldReferencesRegions != newReferencesRegions) {
        Optional<PlacementRule> oldRule = oldPod.get().getPlacementRule();
        Optional<PlacementRule> newRule = newPod.get().getPlacementRule();
        ConfigValidationError error = ConfigValidationError.transitionError(String.format("%s.PlacementRule", podType), oldRule.toString(), newRule.toString(), String.format("PlacementRule cannot change from %s to %s", oldRule, newRule));
        return Arrays.asList(error);
    }
    return Collections.emptyList();
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) ConfigValidationError(com.mesosphere.sdk.config.validate.ConfigValidationError) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)

Example 7 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.

the class TaskTypeRuleTest method getPodInstance.

private static PodInstance getPodInstance(TaskInfo taskInfo) {
    try {
        TaskLabelReader labels = new TaskLabelReader(taskInfo);
        ResourceSet resourceSet = PodInstanceRequirementTestUtils.getCpuResourceSet(1.0);
        PodSpec podSpec = PodInstanceRequirementTestUtils.getRequirement(resourceSet, labels.getType(), labels.getIndex()).getPodInstance().getPod();
        return new DefaultPodInstance(podSpec, labels.getIndex());
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) PodSpec(com.mesosphere.sdk.specification.PodSpec) ResourceSet(com.mesosphere.sdk.specification.ResourceSet) DefaultPodInstance(com.mesosphere.sdk.scheduler.plan.DefaultPodInstance) InvalidRequirementException(com.mesosphere.sdk.offer.InvalidRequirementException) IOException(java.io.IOException)

Example 8 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.

the class PlacementUtilsTest method emptyRuleNotRegion.

@Test
public void emptyRuleNotRegion() {
    PodSpec podSpec = getPodSpec();
    assertFalse(PlacementUtils.placementRuleReferencesRegion(podSpec));
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) Test(org.junit.Test)

Example 9 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.

the class PlacementUtilsTest method simpleRegionRuleSucceeds.

@Test
public void simpleRegionRuleSucceeds() {
    PlacementRule rule = new RegionRule(ExactMatcher.create("region"));
    PodSpec podSpec = getPodSpec(rule);
    assertTrue(PlacementUtils.placementRuleReferencesRegion(podSpec));
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) Test(org.junit.Test)

Example 10 with PodSpec

use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.

the class PlacementUtilsTest method nestedOrNotRegionRuleFails.

@Test
public void nestedOrNotRegionRuleFails() {
    PlacementRule regionRule = new AttributeRule(ExactMatcher.create("attribute"));
    PlacementRule zoneRule = new ZoneRule(ExactMatcher.create("zone"));
    PlacementRule orRule = new OrRule(regionRule, zoneRule);
    PlacementRule attributeRule = new AttributeRule(ExactMatcher.create("attribute"));
    PlacementRule andRule = new AndRule(attributeRule, orRule);
    PodSpec podSpec = getPodSpec(andRule);
    assertFalse(PlacementUtils.placementRuleReferencesRegion(podSpec));
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) Test(org.junit.Test)

Aggregations

PodSpec (com.mesosphere.sdk.specification.PodSpec)35 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)21 Test (org.junit.Test)16 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)10 PodInstance (com.mesosphere.sdk.specification.PodInstance)10 DefaultPodInstance (com.mesosphere.sdk.scheduler.plan.DefaultPodInstance)9 Protos (org.apache.mesos.Protos)8 Collectors (java.util.stream.Collectors)7 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)6 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)6 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)4 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)4 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)4 List (java.util.List)4 InvalidRequirementException (com.mesosphere.sdk.offer.InvalidRequirementException)3 TaskException (com.mesosphere.sdk.offer.TaskException)3 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 ConfigValidationError (com.mesosphere.sdk.config.validate.ConfigValidationError)2