summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2019-12-18 11:02:56 +0100
committerJon Marius Venstad <venstad@gmail.com>2019-12-18 13:08:52 +0100
commit68fd0022e873c0388691e6242ca340976ccca612 (patch)
treefd06aa4dbd92a6a3324fd068ee598b719d178167 /config-model-api
parentdf2c5af2a00f850f0e3c4919ad3b651efffea3fc (diff)
All empty deployment specs are the same
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java12
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java18
2 files changed, 19 insertions, 11 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java b/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
index 6f49f4e86fc..faa7c8cf932 100644
--- a/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
+++ b/config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java
@@ -92,10 +92,9 @@ public class DeploymentSpecXmlReader {
/** Reads a deployment spec from XML */
public DeploymentSpec read(String xmlForm) {
- if (DeploymentSpec.empty.xmlForm().equals(xmlForm))
- return DeploymentSpec.empty;
-
Element root = XML.getDocument(xmlForm).getDocumentElement();
+ if (isEmptySpec(root))
+ return DeploymentSpec.empty;
List<Step> steps = new ArrayList<>();
if ( ! containsTag(instanceTag, root)) { // deployment spec skipping explicit instance -> "default" instance
@@ -420,6 +419,13 @@ public class DeploymentSpecXmlReader {
"to control whether the region should receive production traffic");
}
+ private static boolean isEmptySpec(Element root) {
+ if ( ! XML.getChildren(root).isEmpty()) return false;
+ return root.getAttributes().getLength() == 0
+ || root.getAttributes().getLength() == 1 && root.hasAttribute("version");
+ }
+
+
private static class MutableOptional<T> {
private Optional<T> value = Optional.empty();
diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java
index b36c8299e66..b5e5946262a 100644
--- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java
+++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithoutInstanceTest.java
@@ -21,6 +21,7 @@ import static com.yahoo.config.application.api.Notifications.When.failing;
import static com.yahoo.config.application.api.Notifications.When.failingCommit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -575,9 +576,15 @@ public class DeploymentSpecWithoutInstanceTest {
}
@Test
- public void noNotifications() {
- assertEquals(Notifications.none(),
- DeploymentSpec.fromXml("<deployment />").requireInstance("default").notifications());
+ public void emptySpecs() {
+ assertEquals(DeploymentSpec.empty, DeploymentSpec.fromXml("<deployment>\n" +
+ "</deployment>"));
+ assertEquals(DeploymentSpec.empty, DeploymentSpec.fromXml("<deployment />"));
+ assertEquals(DeploymentSpec.empty, DeploymentSpec.fromXml("<deployment version=\"1.0\" />"));
+
+ assertNotEquals(DeploymentSpec.empty, DeploymentSpec.fromXml("<deployment version=\"1.0\" athenz-domain=\"domain\" athenz-service=\"service\"/>"));
+ assertNotEquals(DeploymentSpec.empty, DeploymentSpec.fromXml("<deployment athenz-domain=\"domain\" athenz-service=\"service\">\n" +
+ "</deployment>"));
}
@Test
@@ -618,11 +625,6 @@ public class DeploymentSpecWithoutInstanceTest {
}
@Test
- public void noEndpoints() {
- assertEquals(Collections.emptyList(), DeploymentSpec.fromXml("<deployment />").requireInstance("default").endpoints());
- }
-
- @Test
public void emptyEndpoints() {
var spec = DeploymentSpec.fromXml("<deployment><endpoints/></deployment>");
assertEquals(Collections.emptyList(), spec.requireInstance("default").endpoints());