diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-30 18:33:57 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-30 18:33:57 +0200 |
commit | b4c05bdafb1cb6aa5f029dc52a9c3bb15986e30b (patch) | |
tree | 80db501df5e1e06436d2e6570c1de5cd00d7e134 /config-model-api/src/main/java | |
parent | 85afc7537760d00578bf4d528554fd2889995c13 (diff) |
Simplify
Diffstat (limited to 'config-model-api/src/main/java')
-rw-r--r-- | config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java | 25 |
1 files changed, 24 insertions, 1 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 ba68404b7ca..7f203c2b08b 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 @@ -73,7 +73,7 @@ public class DeploymentSpec { } /** Throw an IllegalArgumentException if any production zone is declared multiple times */ - private static void validateZones(List<Step> steps) { + private static void validateZonesOld(List<Step> steps) { // Collect both non-parallel and parallel zones List<DeclaredZone> zones = new ArrayList<>(); steps.stream() @@ -98,7 +98,25 @@ public class DeploymentSpec { "duplicated regions: " + duplicates); } } + + /** Throw an IllegalArgumentException if any production zone is declared multiple times */ + private void validateZones(List<Step> steps) { + Set<DeclaredZone> zones = new HashSet<>(); + + steps.stream().filter(step -> step instanceof DeclaredZone) + .map(DeclaredZone.class::cast) + .forEach(zone -> ensureUnique(zone, zones)); + steps.stream().filter(step -> step instanceof ParallelZones) + .map(ParallelZones.class::cast) + .flatMap(parallelZones -> parallelZones.zones().stream()) + .forEach(zone -> ensureUnique(zone, zones)); + } + private void ensureUnique(DeclaredZone zone, Set<DeclaredZone> zones) { + if ( ! zones.add(zone)) + throw new IllegalArgumentException(zone + " is listed twice in deployment.xml"); + } + /** Adds missing required steps and reorders steps to a permissible order */ private static List<Step> completeSteps(List<Step> steps) { // Ensure no duplicate deployments to the same zone @@ -399,6 +417,11 @@ public class DeploymentSpec { if ( ! this.region.equals(other.region())) return false; return true; } + + @Override + public String toString() { + return environment + ( region.isPresent() ? "." + region.get() : ""); + } } |