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));
}
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));
}
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;
}
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;
}
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;
}
Aggregations