summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-06-02 08:41:06 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-06-02 08:41:06 +0200
commit34174157360ed81f8b3bbefda37032332fa4cfe6 (patch)
tree82377eb5d06b1b60e641f27b40db3fd81d46c598 /config-model-api
parentbc3ace91b60d8a3e49c46640e0de55af1374a1b1 (diff)
Actually parse long. Ensure unique deployments
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java24
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java2
2 files changed, 23 insertions, 3 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 ff965b5a5df..556bcb78d31 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
@@ -4,7 +4,6 @@ package com.yahoo.config.application.api;
import com.google.common.collect.ImmutableList;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
-import com.yahoo.config.provision.Zone;
import com.yahoo.io.IOUtils;
import com.yahoo.text.XML;
import org.w3c.dom.Element;
@@ -16,9 +15,10 @@ import java.io.Reader;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
+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.
@@ -70,6 +70,9 @@ public class DeploymentSpec {
/** 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
+ steps = new ArrayList<>(new LinkedHashSet<>(steps));
+
// Add staging if required and missing
if (steps.stream().anyMatch(step -> step.deploysTo(Environment.prod)) &&
steps.stream().noneMatch(step -> step.deploysTo(Environment.staging))) {
@@ -185,7 +188,7 @@ public class DeploymentSpec {
String value = tag.getAttribute(attributeName);
if (value == null || value.isEmpty()) return 0;
try {
- return Integer.parseInt(value);
+ return Long.parseLong(value);
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Expected an integer for attribute '" + attributeName +
@@ -335,6 +338,21 @@ public class DeploymentSpec {
if (region.isPresent() && ! region.equals(this.region)) return false;
return true;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(environment, region);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if ( ! (o instanceof ZoneDeployment)) return false;
+ ZoneDeployment other = (ZoneDeployment)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 c6bff6124ba..bc1d0c55654 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
@@ -94,9 +94,11 @@ public class DeploymentSpecTest {
StringReader r = new StringReader(
"<deployment version='1.0'>" +
" <test/>" +
+ " <test/>" +
" <staging/>" +
" <prod>" +
" <region active='false'>us-east1</region>" +
+ " <region active='false'>us-east1</region>" +
" <delay hours='3' minutes='30'/>" +
" <region active='true'>us-west1</region>" +
" </prod>" +