From b1626a36e9330fe2b848870c07c05b4532495638 Mon Sep 17 00:00:00 2001 From: jonmv Date: Thu, 23 May 2024 15:42:34 +0200 Subject: Read from deployment spec for test/staging/prod --- .../config/application/api/DeploymentSpec.java | 15 +++++---- .../api/xml/DeploymentSpecXmlReader.java | 21 +++++++++--- .../config/application/api/DeploymentSpecTest.java | 38 +++++++++++++++++++++- 3 files changed, 63 insertions(+), 11 deletions(-) (limited to 'config-model-api') 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 4308e0c2a0e..fdaa7d57074 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 @@ -435,15 +435,16 @@ public class DeploymentSpec { private final Optional region; private final Optional athenzService; private final Optional testerFlavor; + private final Optional testerNodes; private final Map cloudAccounts; private final Optional hostTTL; public DeclaredZone(Environment environment) { - this(environment, Optional.empty(), Optional.empty(), Optional.empty(), Map.of(), Optional.empty()); + this(environment, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Map.of(), Optional.empty()); } - public DeclaredZone(Environment environment, Optional region, - Optional athenzService, Optional testerFlavor, + public DeclaredZone(Environment environment, Optional region, Optional athenzService, + Optional testerFlavor, Optional testerNodes, Map cloudAccounts, Optional hostTTL) { if (environment != Environment.prod && region.isPresent()) illegal("Non-prod environments cannot specify a region"); @@ -454,6 +455,7 @@ public class DeploymentSpec { this.region = Objects.requireNonNull(region); this.athenzService = Objects.requireNonNull(athenzService); this.testerFlavor = Objects.requireNonNull(testerFlavor); + this.testerNodes = Objects.requireNonNull(testerNodes); this.cloudAccounts = Map.copyOf(cloudAccounts); this.hostTTL = Objects.requireNonNull(hostTTL); } @@ -463,11 +465,12 @@ public class DeploymentSpec { /** The region name, or empty if not declared */ public Optional region() { return region; } - // TODO(mpolden): Remove after Vespa < 8.203 is no longer in use - public boolean active() { return true; } - + // TODO jonmv: remove after 8.350. public Optional testerFlavor() { return testerFlavor; } + /** The XML <nodes> tag of the tester application for this zone, if specified. */ + public Optional testerNodes() { return testerNodes; } + Optional athenzService() { return athenzService; } Map cloudAccounts() { return cloudAccounts; } 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 23471264960..1f5fa228d8f 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,6 +92,8 @@ public class DeploymentSpecXmlReader { private static final String athenzServiceAttribute = "athenz-service"; private static final String athenzDomainAttribute = "athenz-domain"; private static final String testerFlavorAttribute = "tester-flavor"; + private static final String testerTag = "tester"; + private static final String nodesTag = "nodes"; private static final String majorVersionAttribute = "major-version"; private static final String cloudAccountAttribute = "cloud-account"; private static final String hostTTLAttribute = "empty-host-ttl"; @@ -265,6 +267,7 @@ public class DeploymentSpecXmlReader { private List readNonInstanceSteps(Element stepTag, Map prodAttributes, Element parentTag, Bcp defaultBcp) { Optional athenzService = mostSpecificAttribute(stepTag, athenzServiceAttribute).map(AthenzService::from); Optional testerFlavor = mostSpecificAttribute(stepTag, testerFlavorAttribute); + Optional testerNodes = mostSpecificSibling(stepTag, testerTag).map(tester -> XML.getChild(tester, nodesTag)).map(XML::toString); switch (stepTag.getTagName()) { case testTag: @@ -273,7 +276,7 @@ public class DeploymentSpecXmlReader { return List.of(new DeclaredTest(RegionName.from(XML.getValue(stepTag).trim()), readHostTTL(stepTag))); // A production test } case devTag, perfTag, stagingTag: // Intentional fallthrough from test tag. - return List.of(new DeclaredZone(Environment.from(stepTag.getTagName()), Optional.empty(), athenzService, testerFlavor, readCloudAccounts(stepTag), readHostTTL(stepTag))); + return List.of(new DeclaredZone(Environment.from(stepTag.getTagName()), Optional.empty(), athenzService, testerFlavor, testerNodes, readCloudAccounts(stepTag), readHostTTL(stepTag))); case prodTag: // regions, delay and parallel may be nested within, but we can flatten them return XML.getChildren(stepTag).stream() .flatMap(child -> readNonInstanceSteps(child, prodAttributes, stepTag, defaultBcp).stream()) @@ -291,7 +294,7 @@ public class DeploymentSpecXmlReader { .flatMap(child -> readSteps(child, prodAttributes, parentTag, defaultBcp).stream()) .toList())); case regionTag: - return List.of(readDeclaredZone(Environment.prod, athenzService, testerFlavor, stepTag)); + return List.of(readDeclaredZone(Environment.prod, athenzService, testerFlavor, testerNodes, stepTag)); default: return List.of(); } @@ -680,9 +683,9 @@ public class DeploymentSpecXmlReader { } private DeclaredZone readDeclaredZone(Environment environment, Optional athenzService, - Optional testerFlavor, Element regionTag) { + Optional testerFlavor, Optional testerNodes, Element regionTag) { return new DeclaredZone(environment, Optional.of(RegionName.from(XML.getValue(regionTag).trim())), - athenzService, testerFlavor, + athenzService, testerFlavor, testerNodes, readCloudAccounts(regionTag), readHostTTL(regionTag)); } @@ -808,6 +811,16 @@ public class DeploymentSpecXmlReader { return mostSpecificAttribute(tag, attributeName, true); } + /** Returns the first encountered sibling with the given name, or sibling of parent, or sibling of grandparent, etc.. */ + private static Optional mostSpecificSibling(Element tag, String siblingName) { + return Stream.iterate(tag, Objects::nonNull, Node::getParentNode) + .filter(Element.class::isInstance) + .map(Element.class::cast) + .map(element -> XML.getChild(element, siblingName)) + .filter(Objects::nonNull) + .findFirst(); + } + /** * Returns a string consisting of a number followed by "m", "h" or "d" to a duration given in that unit, * or zero duration if null or blank. 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 05807ae6cc1..a3df216eea7 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 @@ -1128,7 +1128,7 @@ public class DeploymentSpecTest { } @Test - public void customTesterFlavor() { + public void customLegacyTesterFlavor() { DeploymentSpec spec = DeploymentSpec.fromXml(""" @@ -1144,6 +1144,42 @@ public class DeploymentSpecTest { assertEquals(Optional.of("d-2-8-50"), spec.requireInstance("default").steps().get(2).zones().get(0).testerFlavor()); } + @Test + public void customTesterFlavor() { + DeploymentSpec spec = DeploymentSpec.fromXml(""" + + + + + + + + + + + + + + + + + us-north-7 + + + """); + assertEquals(Optional.of(""" + + + """), + spec.requireInstance("default").steps().get(0).zones().get(0).testerNodes()); + assertEquals(Optional.empty(), spec.requireInstance("default").steps().get(1).zones().get(0).testerNodes()); + assertEquals(Optional.of(""" + + + """), + spec.requireInstance("default").steps().get(2).zones().get(0).testerNodes()); + } + @Test public void noEndpoints() { DeploymentSpec spec = DeploymentSpec.fromXml(""" -- cgit v1.2.3