From e61643c5e0e2c42a362c88613e321cd96b1488a9 Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Tue, 5 Nov 2019 13:40:08 +0100 Subject: Steps are either test or production --- .../controller/deployment/DeploymentSteps.java | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'controller-server') diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java index 33db6b95db1..d4fb97a6d87 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java @@ -14,10 +14,10 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; -import static java.util.Collections.singletonList; import static java.util.Comparator.comparingInt; import static java.util.stream.Collectors.collectingAndThen; @@ -40,7 +40,7 @@ public class DeploymentSteps { public List jobs() { return spec.steps().stream() .flatMap(step -> toJobs(step).stream()) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .collect(Collectors.toUnmodifiableList()); } /** Returns job status sorted according to deployment spec */ @@ -48,7 +48,7 @@ public class DeploymentSteps { List sortedJobs = jobs(); return jobStatus.stream() .sorted(comparingInt(job -> sortedJobs.indexOf(job.type()))) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .collect(Collectors.toUnmodifiableList()); } /** Returns deployments sorted according to declared zones */ @@ -56,7 +56,7 @@ public class DeploymentSteps { List productionZones = spec.zones().stream() .filter(z -> z.region().isPresent()) .map(z -> ZoneId.from(z.environment(), z.region().get())) - .collect(Collectors.toList()); + .collect(Collectors.toUnmodifiableList()); return deployments.stream() .sorted(comparingInt(deployment -> productionZones.indexOf(deployment.zone()))) .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); @@ -67,34 +67,35 @@ public class DeploymentSteps { return step.zones().stream() .map(this::toJob) .flatMap(Optional::stream) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .collect(Collectors.toUnmodifiableList()); } - /** Returns test jobs in this */ + /** Returns declared test jobs in this */ public List testJobs() { return toJobs(test()); } - /** Returns production jobs in this */ + /** Returns declared production jobs in this */ public List productionJobs() { return toJobs(production()); } - /** Returns test steps in this */ + /** Returns declared test steps in this */ public List test() { - if (spec.steps().isEmpty()) { - return singletonList(new DeploymentSpec.DeclaredZone(Environment.test)); - } return spec.steps().stream() - .filter(step -> step.deploysTo(Environment.test) || step.deploysTo(Environment.staging)) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .filter(step -> isTest(step)) + .collect(Collectors.toUnmodifiableList()); } - /** Returns production steps in this */ + /** Returns declared production steps in this */ public List production() { return spec.steps().stream() - .filter(step -> step.deploysTo(Environment.prod) || step.zones().isEmpty()) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .filter(step -> ! isTest(step)) + .collect(Collectors.toUnmodifiableList()); + } + + private boolean isTest(DeploymentSpec.Step step) { + return step.deploysTo(Environment.test) || step.deploysTo(Environment.staging); } /** Resolve job from deployment zone */ @@ -106,7 +107,7 @@ public class DeploymentSteps { private List toJobs(List steps) { return steps.stream() .flatMap(step -> toJobs(step).stream()) - .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .collect(Collectors.toUnmodifiableList()); } } -- cgit v1.2.3