diff options
Diffstat (limited to 'config-model-api/src')
-rw-r--r-- | config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java | 27 | ||||
-rw-r--r-- | config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java | 5 |
2 files changed, 28 insertions, 4 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java index 05f5f667287..ada5ee23a7c 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java @@ -47,7 +47,7 @@ public class DeploymentSpec { Optional.empty(), Optional.empty(), Notifications.none(), - Collections.emptyList()); + List.of()); private final Optional<String> globalServiceId; private final UpgradePolicy upgradePolicy; @@ -74,9 +74,10 @@ public class DeploymentSpec { this.athenzDomain = athenzDomain; this.athenzService = athenzService; this.notifications = notifications; - this.endpoints = Objects.requireNonNull(endpoints, "Missing endpoints parameter"); + this.endpoints = List.copyOf(Objects.requireNonNull(endpoints, "Missing endpoints parameter")); validateZones(this.steps); validateAthenz(); + validateEndpoints(this.steps, globalServiceId, this.endpoints); } /** Throw an IllegalArgumentException if the total delay exceeds 24 hours */ @@ -98,6 +99,26 @@ public class DeploymentSpec { ensureUnique(zone, zones); } + /** Throw an IllegalArgumentException if an endpoint refers to a region that is not declared in 'prod' */ + private void validateEndpoints(List<Step> steps, Optional<String> globalServiceId, List<Endpoint> endpoints) { + if (globalServiceId.isPresent() && ! endpoints.isEmpty()) { + throw new IllegalArgumentException("Providing both 'endpoints' and 'global-service-id'. Use only 'endpoints'."); + } + + var stepZones = steps.stream() + .flatMap(s -> s.zones().stream()) + .flatMap(z -> z.region.stream()) + .collect(Collectors.toSet()); + + for (var endpoint : endpoints){ + for (var endpointRegion : endpoint.regions()) { + if (! stepZones.contains(endpointRegion)) { + throw new IllegalArgumentException("Region used in endpoint that is not declared in 'prod': " + endpointRegion); + } + } + } + } + /* * Throw an IllegalArgumentException if Athenz configuration violates: * domain not configured -> no zone can configure service @@ -204,7 +225,7 @@ public class DeploymentSpec { public Notifications notifications() { return notifications; } /** Returns the rotations configuration */ - public List<Endpoint> endpoints() { return Collections.unmodifiableList(endpoints); } + public List<Endpoint> endpoints() { return endpoints; } /** Returns the XML form of this spec, or null if it was not created by fromXml, nor is empty */ public String xmlForm() { return xmlForm; } diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java index e783ee89729..3049d511bf1 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java @@ -469,6 +469,9 @@ public class DeploymentSpecTest { public void someEndpoints() { final var spec = DeploymentSpec.fromXml("" + "<deployment>" + + " <prod>" + + " <region active=\"true\">us-east</region>" + + " </prod>" + " <endpoints>" + " <endpoint id=\"foo\" container-id=\"bar\">" + " <region>us-east</region>" + @@ -488,6 +491,6 @@ public class DeploymentSpecTest { spec.endpoints().stream().map(Endpoint::containerId).collect(Collectors.toList()) ); - assertEquals(Set.of("us-east"), spec.endpoints().get(0).regions()); + assertEquals(Set.of(RegionName.from("us-east")), spec.endpoints().get(0).regions()); } } |