use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class PreReservationCannotChange method validate.
@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
if (!oldConfig.isPresent()) {
return Collections.emptyList();
}
final Map<String, PodSpec> newPods = newConfig.getPods().stream().collect(Collectors.toMap(podSpec -> podSpec.getType(), podSpec -> podSpec));
final List<ConfigValidationError> errors = new ArrayList<>();
for (final PodSpec oldPod : oldConfig.get().getPods()) {
final PodSpec newPod = newPods.get(oldPod.getType());
if (newPod == null) {
continue;
}
final String oldPodPreReservedRole = oldPod.getPreReservedRole();
final String newPodPreReservedRole = newPod.getPreReservedRole();
if (!StringUtils.equals(newPodPreReservedRole, oldPodPreReservedRole)) {
errors.add(ConfigValidationError.transitionError(String.format("PodSpec[pre-reserved-role:%s]", oldPodPreReservedRole), oldPodPreReservedRole, newPodPreReservedRole, String.format("New config has changed the pre-reserved-role of PodSpec named '%s'" + " (expected it to stay '%s')", oldPod.getType(), oldPodPreReservedRole)));
}
}
return errors;
}
use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class PodSpecsCannotChangeNetworkRegime 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 the PodSpecs to make sure none of them make a transition from a state where they use host ports
// to one where they don't (or vice versa).
Collection<ConfigValidationError> errors = new ArrayList<>();
Map<String, PodSpec> oldPods = oldConfig.get().getPods().stream().collect(Collectors.toMap(PodSpec::getType, podSpec -> podSpec));
for (Map.Entry<String, PodSpec> kv : newPods.entrySet()) {
PodSpec newPod = kv.getValue();
// first we check that the new pod's networks (if present) do not erroneously use port mapping
List<String> offendingNetworkNames = getNetworksWithInvalidPortMappings(newPod);
if (offendingNetworkNames.size() > 0) {
errors.add(ConfigValidationError.transitionError(String.format("PodSpec[name:%s]", newPod.getType()), "null", newPod.getNetworks().toString(), String.format("New config has pod %s that indicates port mapping for virtual network(s) %s, " + "that do not support port mapping.", newPod.getType(), StringUtils.join(offendingNetworkNames, ", "))));
}
// now we check that the none of the new pods move from not using host ports to using them (or vice
// versa)
PodSpec oldPod = oldPods.get(kv.getKey());
if (oldPod != null && podSpecUsesHostPorts(oldPod) != podSpecUsesHostPorts(newPod)) {
errors.add(ConfigValidationError.transitionError(String.format("PodSpec[name:%s]", oldPod.getType()), oldPod.getNetworks().toString(), newPod.getNetworks().toString(), String.format("New config has pod %s moving networks from %s to %s, changing its " + "host ports requirements from %s to %s, not allowed.", newPod.getType(), oldPod.getNetworks().toString(), newPod.getNetworks().toString(), podSpecUsesHostPorts(oldPod), podSpecUsesHostPorts(newPod))));
}
}
return errors;
}
use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class UserCannotChange method checkForUserEqualityAmongPods.
private List<ConfigValidationError> checkForUserEqualityAmongPods(Map<String, PodSpec> oldPods, List<PodSpec> newPods) {
List<ConfigValidationError> errors = new ArrayList<>();
PodSpec oldPod;
for (PodSpec newPod : newPods) {
// about not updating the user for existing pods in this validation.
if (oldPods.containsKey(newPod.getType())) {
oldPod = oldPods.get(newPod.getType());
if (!oldPod.getUser().equals(newPod.getUser())) {
errors.add(ConfigValidationError.transitionError("user", oldPod.getUser().isPresent() ? oldPod.getUser().get() : null, newPod.getUser().isPresent() ? newPod.getUser().get() : null, String.format(USER_CHANGED_ERROR_MESSAGE, oldPod.getType())));
}
}
}
return errors;
}
use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class UserCannotChange method validate.
@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
if (!oldConfig.isPresent()) {
return Collections.emptyList();
}
List<ConfigValidationError> errors = new ArrayList<>();
if (oldConfig.get().getUser() != null && !oldConfig.get().getUser().equals(newConfig.getUser())) {
errors.add(ConfigValidationError.transitionError("user", oldConfig.get().getUser(), newConfig.getUser(), "User for old service must remain the same across deployments."));
}
// We can't rely on the order of pods to test new pods against olds ones.
Map<String, PodSpec> oldPods = new HashMap<>();
for (PodSpec oldPod : oldConfig.get().getPods()) {
oldPods.put(oldPod.getType(), oldPod);
}
errors.addAll(checkForUserEqualityAmongPods(oldPods, newConfig.getPods()));
return errors;
}
use of com.mesosphere.sdk.specification.PodSpec in project dcos-commons by mesosphere.
the class RoundRobinByAttributeRuleTest 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);
}
}
Aggregations