summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-06-02 15:51:10 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-06-02 15:51:10 +0200
commit670cb1727b64208d3a3ad7c26bc7fd4fcffd08fd (patch)
treed43c9a7a49ac913c5d85d5bf12ca0af8c3717f41 /config-model-api
parent93c37dfef7736994f7c03db74228f051a35ac8b2 (diff)
Maintain backwards compatibility with earlier config models
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java41
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java9
2 files changed, 29 insertions, 21 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 556bcb78d31..d0e6b4a8580 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
@@ -19,6 +19,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Specifies the environments and regions to which an application should be deployed.
@@ -76,20 +77,20 @@ public class DeploymentSpec {
// Add staging if required and missing
if (steps.stream().anyMatch(step -> step.deploysTo(Environment.prod)) &&
steps.stream().noneMatch(step -> step.deploysTo(Environment.staging))) {
- steps.add(new ZoneDeployment(Environment.staging));
+ steps.add(new DeclaredZone(Environment.staging));
}
// Add test if required and missing
if (steps.stream().anyMatch(step -> step.deploysTo(Environment.staging)) &&
steps.stream().noneMatch(step -> step.deploysTo(Environment.test))) {
- steps.add(new ZoneDeployment(Environment.test));
+ steps.add(new DeclaredZone(Environment.test));
}
// Enforce order test, staging, prod
- ZoneDeployment testStep = remove(Environment.test, steps);
+ DeclaredZone testStep = remove(Environment.test, steps);
if (testStep != null)
steps.add(0, testStep);
- ZoneDeployment stagingStep = remove(Environment.staging, steps);
+ DeclaredZone stagingStep = remove(Environment.staging, steps);
if (stagingStep != null)
steps.add(1, stagingStep);
@@ -102,10 +103,10 @@ public class DeploymentSpec {
* @param environment
* @return the removed step, or null if it is not present
*/
- private static ZoneDeployment remove(Environment environment, List<Step> steps) {
+ private static DeclaredZone remove(Environment environment, List<Step> steps) {
for (int i = 0; i < steps.size(); i++) {
if (steps.get(i).deploysTo(environment))
- return (ZoneDeployment)steps.remove(i);
+ return (DeclaredZone)steps.remove(i);
}
return null;
}
@@ -120,7 +121,13 @@ public class DeploymentSpec {
/** Returns the deployment steps of this in the order they will be performed */
public List<Step> steps() { return steps; }
-
+
+ /** Returns only the DeclaredZone deployment steps of this in the order they will be performed */
+ public List<DeclaredZone> zones() {
+ return steps.stream().filter(step -> step instanceof DeclaredZone).map(DeclaredZone.class::cast)
+ .collect(Collectors.toList());
+ }
+
/** Returns the XML form of this spec, or null if it was not created by fromXml or is the empty spec */
public String xmlForm() { return xmlForm; }
@@ -162,17 +169,17 @@ public class DeploymentSpec {
if (environment == Environment.prod) {
for (Element stepTag : XML.getChildren(environmentTag)) {
if (stepTag.getTagName().equals("delay"))
- steps.add(new Delay(Duration.ofSeconds(longAttribute("hours", stepTag) * 60 * 60 +
+ steps.add(new Delay(Duration.ofSeconds(longAttribute("hours", stepTag) * 60 * 60 +
longAttribute("minutes", stepTag) * 60 +
longAttribute("seconds", stepTag))));
else // a region: deploy step
- steps.add(new ZoneDeployment(environment,
- Optional.of(RegionName.from(XML.getValue(stepTag).trim())),
- readActive(stepTag)));
+ steps.add(new DeclaredZone(environment,
+ Optional.of(RegionName.from(XML.getValue(stepTag).trim())),
+ readActive(stepTag)));
}
}
else {
- steps.add(new ZoneDeployment(environment));
+ steps.add(new DeclaredZone(environment));
}
if (environment == Environment.prod)
@@ -302,7 +309,7 @@ public class DeploymentSpec {
}
/** A deployment step which is to run deployment in a particular zone */
- public static class ZoneDeployment extends Step {
+ public static class DeclaredZone extends Step {
private final Environment environment;
@@ -310,11 +317,11 @@ public class DeploymentSpec {
private final boolean active;
- public ZoneDeployment(Environment environment) {
+ public DeclaredZone(Environment environment) {
this(environment, Optional.empty(), false);
}
- public ZoneDeployment(Environment environment, Optional<RegionName> region, boolean active) {
+ public DeclaredZone(Environment environment, Optional<RegionName> region, boolean active) {
if (environment != Environment.prod && region.isPresent())
throw new IllegalArgumentException("Non-prod environments cannot specify a region");
if (environment == Environment.prod && ! region.isPresent())
@@ -347,8 +354,8 @@ public class DeploymentSpec {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! (o instanceof ZoneDeployment)) return false;
- ZoneDeployment other = (ZoneDeployment)o;
+ if ( ! (o instanceof DeclaredZone)) return false;
+ DeclaredZone other = (DeclaredZone)o;
if (this.environment != other.environment) return false;
if ( ! this.region.equals(other.region())) return false;
return true;
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 bc1d0c55654..8de8a9c2da4 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
@@ -73,10 +73,10 @@ public class DeploymentSpecTest {
assertTrue(spec.steps().get(1).deploysTo(Environment.staging));
assertTrue(spec.steps().get(2).deploysTo(Environment.prod, Optional.of(RegionName.from("us-east1"))));
- assertFalse(((DeploymentSpec.ZoneDeployment)spec.steps().get(2)).active());
+ assertFalse(((DeploymentSpec.DeclaredZone)spec.steps().get(2)).active());
assertTrue(spec.steps().get(3).deploysTo(Environment.prod, Optional.of(RegionName.from("us-west1"))));
- assertTrue(((DeploymentSpec.ZoneDeployment)spec.steps().get(3)).active());
+ assertTrue(((DeploymentSpec.DeclaredZone)spec.steps().get(3)).active());
assertTrue(spec.includes(Environment.test, Optional.empty()));
assertFalse(spec.includes(Environment.test, Optional.of(RegionName.from("region1"))));
@@ -107,19 +107,20 @@ public class DeploymentSpecTest {
DeploymentSpec spec = DeploymentSpec.fromXml(r);
assertEquals(5, spec.steps().size());
+ assertEquals(4, spec.zones().size());
assertTrue(spec.steps().get(0).deploysTo(Environment.test));
assertTrue(spec.steps().get(1).deploysTo(Environment.staging));
assertTrue(spec.steps().get(2).deploysTo(Environment.prod, Optional.of(RegionName.from("us-east1"))));
- assertFalse(((DeploymentSpec.ZoneDeployment)spec.steps().get(2)).active());
+ assertFalse(((DeploymentSpec.DeclaredZone)spec.steps().get(2)).active());
assertTrue(spec.steps().get(3) instanceof DeploymentSpec.Delay);
assertEquals(3 * 60 * 60 + 30 * 60, ((DeploymentSpec.Delay)spec.steps().get(3)).duration().getSeconds());
assertTrue(spec.steps().get(4).deploysTo(Environment.prod, Optional.of(RegionName.from("us-west1"))));
- assertTrue(((DeploymentSpec.ZoneDeployment)spec.steps().get(4)).active());
+ assertTrue(((DeploymentSpec.DeclaredZone)spec.steps().get(4)).active());
assertTrue(spec.includes(Environment.test, Optional.empty()));
assertFalse(spec.includes(Environment.test, Optional.of(RegionName.from("region1"))));