summaryrefslogtreecommitdiffstats
path: root/config-application-package
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-10-17 11:33:46 +0200
committerJon Bratseth <bratseth@oath.com>2018-10-17 11:33:46 +0200
commit20cef72bd64f76a4b702702d32d54c7020c2249a (patch)
treebda5d3400a7bf00dfa38e4648a24850c4fe7940f /config-application-package
parent40a36777c3de343207ed72482ecbbc5f1dc8fe96 (diff)
Allow subset matches
Diffstat (limited to 'config-application-package')
-rw-r--r--config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java13
-rw-r--r--config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java18
-rw-r--r--config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java48
3 files changed, 43 insertions, 36 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 16accb368fd..9443339624a 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
@@ -101,18 +101,17 @@ class OverrideProcessor implements PreProcessor {
retainMostSpecificEnvironmentAndRegion(parent, children, context);
}
- /**
- * Ensures that environment and region does not change from something non-default to something else.
- */
private void checkConsistentInheritance(List<Element> children, Context context) {
for (Element child : children) {
Set<Environment> environments = getEnvironments(child);
Set<RegionName> regions = getRegions(child);
- if ( ! environments.isEmpty() && ! context.environments.isEmpty() && !environments.equals(context.environments)) {
- throw new IllegalArgumentException("Environments in child (" + environments + ") differs from that inherited from parent (" + context.environments + ") at " + child);
+ if ( ! environments.isEmpty() && ! context.environments.isEmpty() && ! context.environments.containsAll(environments)) {
+ throw new IllegalArgumentException("Environments in child (" + environments +
+ ") are not a subset of those of the parent (" + context.environments + ") at " + child);
}
- if ( ! regions.isEmpty() && ! context.regions.isEmpty() && ! regions.equals(context.regions)) {
- throw new IllegalArgumentException("Regions in child (" + regions + ") differs from that inherited from parent (" + context.regions + ") at " + child);
+ if ( ! regions.isEmpty() && ! context.regions.isEmpty() && ! context.regions.containsAll(regions)) {
+ throw new IllegalArgumentException("Regions in child (" + regions +
+ ") are not a subset of those of the parent (" + context.regions + ") at " + child);
}
}
}
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
index d01faaaaea9..4c6a3eb3513 100644
--- 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
@@ -38,7 +38,7 @@ public class HostedOverrideProcessorTest {
@Test
- public void testParsingDefault() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException {
+ public void testParsingDefault() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -50,7 +50,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentAndRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentAndRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -62,7 +62,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentAndRegion2() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentAndRegion2() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -74,7 +74,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentAndRegion3() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentAndRegion3() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -86,7 +86,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentUnknownRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -98,7 +98,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentNoRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentNoRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -110,7 +110,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingUnknownEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingUnknownEnvironment() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -122,7 +122,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingUnknownEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingUnknownEnvironmentUnknownRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -134,7 +134,7 @@ public class HostedOverrideProcessorTest {
}
@Test
- public void testParsingInheritEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingInheritEnvironment() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java
index 32a1c4f847f..62e6671120b 100644
--- a/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java
+++ b/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java
@@ -34,7 +34,7 @@ public class OverrideProcessorTest {
" </admin>" +
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
- " <documents>" +
+ " <documents deploy:environment='staging prod'>" +
" <document mode='index' type='music'/>\n" +
" <document type='music2' mode='index' />\n" +
" <document deploy:environment='prod' deploy:region='us-east-3' mode='index' type='music'/>\n" +
@@ -42,6 +42,10 @@ public class OverrideProcessorTest {
" <document deploy:environment='prod' mode='index' type='music3'/>\n" +
" <document deploy:environment='prod' deploy:region='us-west' mode='index' type='music4'/>\n" +
" </documents>" +
+ " <documents>" +
+ " <document mode='store-only' type='music'/>\n" +
+ " <document type='music2' mode='streaming' />\n" +
+ " </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
" </nodes>" +
@@ -73,7 +77,7 @@ public class OverrideProcessorTest {
@Test
- public void testParsingDefault() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException {
+ public void testParsingDefault() throws TransformerException {
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
" <admin version=\"2.0\">" +
@@ -82,8 +86,8 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music\"/>" +
- " <document mode=\"index\" type=\"music2\"/>" +
+ " <document mode=\"store-only\" type=\"music\"/>" +
+ " <document mode=\"streaming\" type=\"music2\"/>" +
" </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
@@ -101,7 +105,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentAndRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentAndRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -133,7 +137,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentUnknownRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -143,7 +147,9 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music3\"/>" +
+ " <document mode='index' type='music'/>\n" +
+ " <document type='music2' mode='index' />\n" +
+ " <document mode='index' type='music3'/>" +
" </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
@@ -164,7 +170,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingEnvironmentNoRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingEnvironmentNoRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -174,7 +180,9 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music3\"/>" +
+ " <document mode='index' type='music'/>\n" +
+ " <document type='music2' mode='index' />\n" +
+ " <document mode='index' type='music3'/>" +
" </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
@@ -195,7 +203,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingUnknownEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingDevEnvironment() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -205,8 +213,8 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music\"/>" +
- " <document mode=\"index\" type=\"music2\"/>" +
+ " <document mode=\"store-only\" type=\"music\"/>" +
+ " <document mode=\"streaming\" type=\"music2\"/>" +
" </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
@@ -224,7 +232,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingUnknownEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingTestEnvironmentUnknownRegion() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -234,8 +242,8 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music\"/>" +
- " <document mode=\"index\" type=\"music2\"/>" +
+ " <document mode=\"store-only\" type=\"music\"/>" +
+ " <document mode=\"streaming\" type=\"music2\"/>" +
" </documents>" +
" <nodes>" +
" <node distribution-key=\"0\" hostalias=\"node0\"/>" +
@@ -253,7 +261,7 @@ public class OverrideProcessorTest {
}
@Test
- public void testParsingInheritEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingInheritEnvironment() throws TransformerException {
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
@@ -263,8 +271,8 @@ public class OverrideProcessorTest {
" <content id=\"foo\" version=\"1.0\">" +
" <redundancy>1</redundancy>" +
" <documents>" +
- " <document mode=\"index\" type=\"music\"/>" +
- " <document mode=\"index\" type=\"music2\"/>" +
+ " <document mode='index' type='music'/>\n" +
+ " <document type='music2' mode='index' />\n" +
" </documents>" +
" <nodes>" +
// node1 is specified for us-west but does not match because region overrides implies environment=prod
@@ -284,7 +292,7 @@ public class OverrideProcessorTest {
}
@Test(expected = IllegalArgumentException.class)
- public void testParsingDifferentEnvInParentAndChild() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingDifferentEnvInParentAndChild() throws TransformerException {
String in = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
" <admin deploy:environment=\"prod\" version=\"2.0\">" +
@@ -296,7 +304,7 @@ public class OverrideProcessorTest {
}
@Test(expected = IllegalArgumentException.class)
- public void testParsingDifferentRegionInParentAndChild() throws ParserConfigurationException, IOException, SAXException, TransformerException {
+ public void testParsingDifferentRegionInParentAndChild() throws TransformerException {
String in = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
"<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"?\" version=\"1.0\">" +
" <admin deploy:region=\"us-west\" version=\"2.0\">" +