Search in sources :

Example 11 with PodSpec

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

the class PlacementUtilsTest method orRegionRuleSucceeds.

@Test
public void orRegionRuleSucceeds() {
    PlacementRule regionRule = new RegionRule(ExactMatcher.create("region"));
    PlacementRule zoneRule = new ZoneRule(ExactMatcher.create("zone"));
    PlacementRule orRule = new OrRule(regionRule, zoneRule);
    PodSpec podSpec = getPodSpec(orRule);
    assertTrue(PlacementUtils.placementRuleReferencesRegion(podSpec));
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) DefaultPodSpec(com.mesosphere.sdk.specification.DefaultPodSpec) Test(org.junit.Test)

Example 12 with PodSpec

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

the class PlacementUtilsTest method orNotRegionRuleFails.

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

Example 13 with PodSpec

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

the class PlacementRuleIsValid method validate.

@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
    List<PodSpec> podSpecs = newConfig.getPods().stream().filter(podSpec -> podSpec.getPlacementRule().isPresent()).collect(Collectors.toList());
    List<ConfigValidationError> errors = new ArrayList<>();
    for (final PodSpec podSpec : podSpecs) {
        PlacementRule placementRule = podSpec.getPlacementRule().get();
        if (!isValid(placementRule)) {
            String errMsg = String.format("The PlacementRule for PodSpec '%s' had invalid constraints", podSpec.getType());
            errors.add(ConfigValidationError.valueError("PlacementRule", placementRule.toString(), errMsg));
        }
    }
    return errors;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) List(java.util.List) OrRule(com.mesosphere.sdk.offer.evaluate.placement.OrRule) InvalidPlacementRule(com.mesosphere.sdk.offer.evaluate.placement.InvalidPlacementRule) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) Collection(java.util.Collection) Optional(java.util.Optional) Collectors(java.util.stream.Collectors) AndRule(com.mesosphere.sdk.offer.evaluate.placement.AndRule) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) ArrayList(java.util.ArrayList) PodSpec(com.mesosphere.sdk.specification.PodSpec) InvalidPlacementRule(com.mesosphere.sdk.offer.evaluate.placement.InvalidPlacementRule) PlacementRule(com.mesosphere.sdk.offer.evaluate.placement.PlacementRule) ArrayList(java.util.ArrayList)

Example 14 with PodSpec

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

the class PodSpecsCannotShrink method validate.

@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
    if (!oldConfig.isPresent()) {
        return Collections.emptyList();
    }
    Map<String, PodSpec> newPods;
    try {
        newPods = newConfig.getPods().stream().collect(Collectors.toMap(podSpec -> podSpec.getType(), podSpec -> podSpec));
    } catch (IllegalStateException e) {
        return Arrays.asList(ConfigValidationError.valueError("PodSpecs", "null", "Duplicate pod types detected."));
    }
    // Check for PodSpecs in the old config which are missing or smaller in the new config.
    // Adding new PodSpecs or increasing the size of tasksets are allowed.
    Collection<ConfigValidationError> errors = new ArrayList<>();
    for (PodSpec oldPod : oldConfig.get().getPods()) {
        PodSpec newPod = newPods.get(oldPod.getType());
        if (newPod == null) {
            // layout, with an interim release marking a pod with allow-decommission before it's removed entirely.
            if (!oldPod.getAllowDecommission()) {
                errors.add(ConfigValidationError.transitionError(String.format("PodSpec[name:%s]", oldPod.getType()), String.valueOf(oldPod.getCount()), "null", String.format("New config is missing PodSpec named '%s' (expected present with >= %d tasks)", oldPod.getType(), oldPod.getCount())));
            }
            continue;
        }
        if (newPod.getCount() < oldPod.getCount() && !newPod.getAllowDecommission()) {
            // New pod is present and is smaller than old pod.
            // Only allow the new pod to be shrunk if its allow-decommission bit is set. We intentionally check
            // allow-decommission against the new pod instead of the old pod with the following reasoning:
            // - Older version disallows, newer version allows: Allow count to decrease now that it's supported
            // - Older version allows, newer version disallows: Disallow count from decreasing now that it's no
            // longer supported
            errors.add(ConfigValidationError.transitionError(String.format("PodSpec[name:%s]", newPod.getType()), String.valueOf(oldPod.getCount()), String.valueOf(newPod.getCount()), String.format("New config's PodSpec named '%s' has %d tasks, expected >=%d tasks", newPod.getType(), newPod.getCount(), oldPod.getCount())));
        }
    }
    return errors;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec)

Example 15 with PodSpec

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

the class DefaultPhaseFactory method getSteps.

private List<Step> getSteps(PodSpec podSpec) {
    List<Step> steps = new ArrayList<>();
    for (int i = 0; i < podSpec.getCount(); i++) {
        PodInstance podInstance = new DefaultPodInstance(podSpec, i);
        List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
        steps.add(stepFactory.getStep(podInstance, tasksToLaunch));
    }
    return steps;
}
Also used : PodSpec(com.mesosphere.sdk.specification.PodSpec) List(java.util.List) SerialStrategy(com.mesosphere.sdk.scheduler.plan.strategy.SerialStrategy) Strategy(com.mesosphere.sdk.scheduler.plan.strategy.Strategy) PodInstance(com.mesosphere.sdk.specification.PodInstance) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PodInstance(com.mesosphere.sdk.specification.PodInstance) ArrayList(java.util.ArrayList)

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