summaryrefslogtreecommitdiffstats
path: root/config-application-package/src
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-10-05 09:31:37 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-10-05 09:31:37 +0200
commit9107ffc588f7ad0daa4cb32ee8192be3f7ee3df2 (patch)
tree5e92d72fad0e9125ec2219fde97861057476c451 /config-application-package/src
parent563e9f5502db4e583d88f26de33f0c97f3a1d408 (diff)
Require capacity that is explicitly specified
Diffstat (limited to 'config-application-package/src')
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java11
-rw-r--r--config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java128
-rw-r--r--config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java4
-rw-r--r--config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java3
4 files changed, 144 insertions, 2 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java b/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java
index 05a479960ed..32e9aec56cb 100644
--- a/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java
+++ b/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java
@@ -141,6 +141,9 @@ class OverrideProcessor implements PreProcessor {
}
}
+ if (bestMatch > 1) // there was a region/environment specific overriode
+ doElementSpecificProcessingOnOverride(bestMatchElement);
+
// Remove elements not specific
for (Element child : children) {
if (child != bestMatchElement) {
@@ -149,6 +152,14 @@ class OverrideProcessor implements PreProcessor {
}
}
+ /** Called on each element which is selected by matching some override condition */
+ private void doElementSpecificProcessingOnOverride(Element element) {
+ // if node capacity is specified explicitly for some evn/region we should require that capacity
+ if ( element.getTagName().equals("nodes"))
+ if (element.getChildNodes().getLength() == 0) // specifies capacity, not a list of nodes
+ element.setAttribute("required", "true");
+ }
+
/**
* Retains all elements where at least one element is overridden. Removes non-overridden elements from map.
*/
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java
new file mode 100644
index 00000000000..338302e9e57
--- /dev/null
+++ b/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java
@@ -0,0 +1,128 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config.application;
+
+import com.yahoo.config.provision.Environment;
+import com.yahoo.config.provision.RegionName;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.TransformerException;
+import java.io.IOException;
+import java.io.StringReader;
+
+/**
+ * @author bratseth
+ */
+public class HostedOverrideProcessorTest {
+
+ static {
+ XMLUnit.setIgnoreWhitespace(true);
+ }
+
+ private static final String input =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='1'/>" +
+ " <nodes deploy:environment=\"staging\" count='2'/>" +
+ " <nodes deploy:environment=\"prod\" count='3'/>" +
+ " <nodes deploy:environment=\"prod\" deploy:region=\"us-west\" count='4'/>" +
+ " </container>" +
+ "</services>";
+
+
+ @Test
+ public void testParsingDefault() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='1'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.test, RegionName.defaultName(), expected);
+ }
+
+ @Test
+ public void testParsingEnvironmentAndRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='4' required='true'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.from("prod"), RegionName.from("us-west"), expected);
+ }
+
+ @Test
+ public void testParsingEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='3' required='true'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.valueOf("prod"), RegionName.from("us-east"), expected);
+ }
+
+ @Test
+ public void testParsingEnvironmentNoRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='3' required='true'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.from("prod"), RegionName.defaultName(), expected);
+ }
+
+ @Test
+ public void testParsingUnknownEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='1'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.from("dev"), RegionName.defaultName(), expected);
+ }
+
+ @Test
+ public void testParsingUnknownEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='1'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.from("test"), RegionName.from("us-west"), expected);
+ }
+
+ @Test
+ public void testParsingInheritEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ String expected =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
+ "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
+ " <container id=\"foo\" version=\"1.0\">" +
+ " <nodes count='2' required='true'/>" +
+ " </container>" +
+ "</services>";
+ assertOverride(Environment.from("staging"), RegionName.from("us-west"), expected);
+ }
+
+ private void assertOverride(Environment environment, RegionName region, String expected) throws TransformerException {
+ Document inputDoc = Xml.getDocument(new StringReader(input));
+ Document newDoc = new OverrideProcessor(environment, region).process(inputDoc);
+ TestBase.assertDocument(expected, newDoc);
+ }
+
+}
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java
index 07068e236cd..6d9bf2cbfa5 100644
--- a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java
+++ b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java
@@ -17,6 +17,7 @@ import java.nio.file.NoSuchFileException;
* @since 5.22
*/
public class IncludeProcessorTest {
+
@Test
public void testInclude() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException {
File app = new File("src/test/resources/multienvapp");
@@ -68,7 +69,7 @@ public class IncludeProcessorTest {
"</jdisc></services>";
Document doc = (new IncludeProcessor(app)).process(docBuilder.parse(Xml.getServices(app)));
- System.out.println(Xml.documentAsString(doc));
+ // System.out.println(Xml.documentAsString(doc));
TestBase.assertDocument(expected, doc);
}
@@ -78,4 +79,5 @@ public class IncludeProcessorTest {
DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder();
(new IncludeProcessor(app)).process(docBuilder.parse(Xml.getServices(app)));
}
+
}
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java
index eecbb1e7313..f6528e84368 100644
--- a/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java
+++ b/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java
@@ -83,7 +83,7 @@ public class XmlPreprocessorTest {
"</services>";
Document docUsWest = (new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-west"))).run();
- System.out.println(Xml.documentAsString(docUsWest));
+ // System.out.println(Xml.documentAsString(docUsWest));
TestBase.assertDocument(expectedUsWest, docUsWest);
String expectedUsEast = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" +
@@ -162,4 +162,5 @@ public class XmlPreprocessorTest {
Document docDev = (new XmlPreProcessor(appDir, new StringReader(input), Environment.prod, RegionName.from("default")).run());
TestBase.assertDocument(expectedProd, docDev);
}
+
}