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