diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-07-27 12:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 12:21:14 +0200 |
commit | 2921d5bc1358b094db2e131970c969dcad481502 (patch) | |
tree | 2ffff84602408dd610cc27b56bcca024ad33ccbf /config-model | |
parent | 2b43a46817cc779dccedd82ea8460802367a448a (diff) |
Revert "Remove global-service-id"
Diffstat (limited to 'config-model')
14 files changed, 130 insertions, 59 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidator.java index d919a35c7ef..0193eacba3a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidator.java @@ -29,6 +29,9 @@ public class DeploymentSpecValidator extends Validator { DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(deploymentReader); List<ContainerModel> containers = model.getRoot().configModelRepo().getModels(ContainerModel.class); for (DeploymentInstanceSpec instance : deploymentSpec.instances()) { + instance.globalServiceId().ifPresent(globalServiceId -> { + requireClusterId(containers, instance.name(), "Attribute 'globalServiceId'", globalServiceId); + }); instance.endpoints().forEach(endpoint -> { requireClusterId(containers, instance.name(), "Endpoint '" + endpoint.endpointId() + "'", endpoint.containerId()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 31f8eba48bf..1036a615bb5 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -10,6 +10,7 @@ import com.yahoo.config.application.Xml; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.config.application.api.DeploymentInstanceSpec; import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.model.ConfigModelContext; import com.yahoo.config.model.api.ApplicationClusterEndpoint; @@ -359,16 +360,24 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { context.getDeployState().getProperties().athenzDnsSuffix(), context.getDeployState().zone(), deploymentSpec); - addRotationProperties(cluster, context.getDeployState().getEndpoints()); + addRotationProperties(cluster, context.getDeployState().zone(), context.getDeployState().getEndpoints(), deploymentSpec); } - private void addRotationProperties(ApplicationContainerCluster cluster, Set<ContainerEndpoint> endpoints) { + private void addRotationProperties(ApplicationContainerCluster cluster, Zone zone, Set<ContainerEndpoint> endpoints, DeploymentSpec spec) { cluster.getContainers().forEach(container -> { setRotations(container, endpoints, cluster.getName()); - container.setProp("activeRotation", "true"); // TODO(mpolden): This is unused and should be removed + container.setProp("activeRotation", Boolean.toString(zoneHasActiveRotation(zone, spec))); }); } + private boolean zoneHasActiveRotation(Zone zone, DeploymentSpec spec) { + Optional<DeploymentInstanceSpec> instance = spec.instance(app.getApplicationId().instance()); + if (instance.isEmpty()) return false; + return instance.get().zones().stream() + .anyMatch(declaredZone -> declaredZone.concerns(zone.environment(), Optional.of(zone.region())) && + declaredZone.active()); + } + private void setRotations(Container container, Set<ContainerEndpoint> endpoints, String containerClusterName) { var rotationsProperty = endpoints.stream() .filter(endpoint -> endpoint.clusterId().equals(containerClusterName)) @@ -585,7 +594,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { private void addDefaultConnectorHostedFilterBinding(ApplicationContainerCluster cluster) { cluster.getHttp().getAccessControl() - .ifPresent(accessControl -> accessControl.configureDefaultHostedConnector(cluster.getHttp())); + .ifPresent(accessControl -> accessControl.configureDefaultHostedConnector(cluster.getHttp())); ; } private void addCloudMtlsConnector(DeployState state, ApplicationContainerCluster cluster) { diff --git a/config-model/src/main/resources/schema/deployment.rnc b/config-model/src/main/resources/schema/deployment.rnc index 87783c1ee20..d47ce81eaac 100644 --- a/config-model/src/main/resources/schema/deployment.rnc +++ b/config-model/src/main/resources/schema/deployment.rnc @@ -122,6 +122,7 @@ Perf = element perf { } Prod = element prod { + attribute global-service-id { text }? & attribute athenz-service { xsd:string }? & attribute tester-flavor { xsd:string }? & attribute cloud-account { xsd:string }? & diff --git a/config-model/src/test/cfg/application/app1/deployment.xml b/config-model/src/test/cfg/application/app1/deployment.xml index 25954df1c7d..a8771123ecc 100644 --- a/config-model/src/test/cfg/application/app1/deployment.xml +++ b/config-model/src/test/cfg/application/app1/deployment.xml @@ -2,8 +2,8 @@ <deployment version="1.0"> <test/> <staging/> - <prod> - <region>us-east-3</region> - <region>us-west-1</region> + <prod global-service-id="query"> + <region active="true">us-east-3</region> + <region active="false">us-west-1</region> </prod> </deployment> diff --git a/config-model/src/test/cfg/application/app_complicated_deployment_spec/deployment.xml b/config-model/src/test/cfg/application/app_complicated_deployment_spec/deployment.xml index e30c02cdd84..3d3bfd35845 100644 --- a/config-model/src/test/cfg/application/app_complicated_deployment_spec/deployment.xml +++ b/config-model/src/test/cfg/application/app_complicated_deployment_spec/deployment.xml @@ -5,24 +5,24 @@ <instance id='instance' athenz-service='in-service'> <prod> <parallel> - <region>us-west-1</region> + <region active='true'>us-west-1</region> <steps> - <region>us-east-3</region> + <region active='true'>us-east-3</region> <delay hours='2' /> - <region>eu-west-1</region> + <region active='true'>eu-west-1</region> <delay hours='2' /> </steps> <steps> <delay hours='3' /> - <region>aws-us-east-1a</region> + <region active='true'>aws-us-east-1a</region> <parallel> - <region athenz-service='no-service'>ap-northeast-1</region> - <region>ap-southeast-2</region> + <region active='true' athenz-service='no-service'>ap-northeast-1</region> + <region active='true'>ap-southeast-2</region> </parallel> </steps> <delay hours='3' minutes='30' /> </parallel> - <region>us-north-7</region> + <region active='true'>us-north-7</region> </prod> </instance> <instance id='other'> @@ -30,7 +30,7 @@ <block-change days='sat' hours='10' time-zone='CET' /> <test /> <prod> - <region>eu-central-2</region> + <region active='true'>eu-central-2</region> </prod> <notifications when='failing'> <email role='author' /> diff --git a/config-model/src/test/cfg/application/app_invalid_deployment_xml/deployment.xml b/config-model/src/test/cfg/application/app_invalid_deployment_xml/deployment.xml index 43f7d74ca69..738a3397aad 100644 --- a/config-model/src/test/cfg/application/app_invalid_deployment_xml/deployment.xml +++ b/config-model/src/test/cfg/application/app_invalid_deployment_xml/deployment.xml @@ -2,7 +2,7 @@ <deployment version="1.0"> <test/> <staging/> - <prod> + <prod global-service-id="query"> <region>us-east-3</region> <region invalid="invalid">us-west-1</region> </prod> diff --git a/config-model/src/test/cfg/application/invalid_parallel_deployment_xml/deployment.xml b/config-model/src/test/cfg/application/invalid_parallel_deployment_xml/deployment.xml index 24e1ec69507..4eaf7926078 100644 --- a/config-model/src/test/cfg/application/invalid_parallel_deployment_xml/deployment.xml +++ b/config-model/src/test/cfg/application/invalid_parallel_deployment_xml/deployment.xml @@ -2,7 +2,7 @@ <deployment version="1.0"> <test/> <staging/> - <prod> + <prod global-service-id="query"> <parallel> <instance id="hello" /> </parallel> diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java index e975421002e..c00b2846021 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model; +import com.google.common.io.Files; import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.UnparsedConfigDefinition; @@ -34,12 +35,7 @@ import java.util.Map; import java.util.Set; import java.util.jar.JarEntry; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; public class ApplicationDeployTest { @@ -198,7 +194,7 @@ public class ApplicationDeployTest { void testThatAppWithInvalidParallelDeploymentFails() throws IOException { String expectedMessage = """ 4: <staging/> - 5: <prod> + 5: <prod global-service-id="query"> 6: <parallel> 7: <instance id="hello" /> 8: </parallel> diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java index 9ce853ad0f2..dba8205c0e7 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/DeploymentSpecValidatorTest.java @@ -19,12 +19,25 @@ import static org.junit.jupiter.api.Assertions.fail; public class DeploymentSpecValidatorTest { @Test + void testDeploymentWithNonExistentGlobalId() { + var deploymentXml = "<?xml version='1.0' encoding='UTF-8'?>" + + "<deployment version='1.0'>" + + " <test />" + + " <prod global-service-id='non-existing'>" + + " <region active='true'>us-east</region>" + + " </prod>" + + "</deployment>"; + assertValidationError("Attribute 'globalServiceId' in instance default: 'non-existing' specified in " + + "deployment.xml does not match any container cluster ID", deploymentXml); + } + + @Test void testEndpointNonExistentContainerId() { var deploymentXml = "<?xml version='1.0' encoding='UTF-8'?>" + "<deployment version='1.0'>" + " <test />" + " <prod>" + - " <region>us-east</region>" + + " <region active='true'>us-east</region>" + " </prod>" + " <endpoints>" + " <endpoint container-id='non-existing'/>" + diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java index 94d98f526a0..f0c39ecc920 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java @@ -790,6 +790,42 @@ public class ContainerModelBuilderTest extends ContainerModelBuilderTestBase { } } + @Test + void logs_deployment_spec_deprecations() throws Exception { + String containerService = joinLines("<container id='foo' version='1.0'>", + " <nodes>", + " <node hostalias='host1' />", + " </nodes>", + "</container>"); + String deploymentXml = joinLines("<deployment version='1.0'>", + " <prod global-service-id='foo'>", + " <region active='true'>us-east-1</region>", + " </prod>", + "</deployment>"); + + ApplicationPackage applicationPackage = new MockApplicationPackage.Builder() + .withServices(containerService) + .withDeploymentSpec(deploymentXml) + .build(); + + TestLogger logger = new TestLogger(); + DeployState deployState = new DeployState.Builder() + .applicationPackage(applicationPackage) + .zone(new Zone(Environment.prod, RegionName.from("us-east-1"))) + .properties(new TestProperties().setHostedVespa(true)) + .deployLogger(logger) + .build(); + + createModel(root, deployState, null, DomBuilderTest.parse(containerService)); + assertFalse(logger.msgs.isEmpty()); + assertEquals(Level.WARNING, logger.msgs.get(0).getFirst()); + assertEquals(Level.WARNING, logger.msgs.get(1).getFirst()); + assertEquals("Element 'prod' contains attribute 'global-service-id' deprecated since major version 7. See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax", + logger.msgs.get(0).getSecond()); + assertEquals("Element 'region' contains attribute 'active' deprecated since major version 7. See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax", + logger.msgs.get(1).getSecond()); + } + private void assertComponentConfigured(ApplicationContainer container, String id) { assertTrue(container.getComponents().getComponents().stream().anyMatch(component -> id.equals(component.getComponentId().getName()))); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/IdentityBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/IdentityBuilderTest.java index 08877b3d3a9..78269d00cf3 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/IdentityBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/IdentityBuilderTest.java @@ -24,7 +24,7 @@ public class IdentityBuilderTest extends ContainerModelBuilderTestBase { String deploymentXml = "<deployment version='1.0' athenz-domain='domain' athenz-service='service'>\n" + " <test/>\n" + " <prod>\n" + - " <region>default</region>\n" + + " <region active='true'>default</region>\n" + " </prod>\n" + "</deployment>\n"; diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/RoutingBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/RoutingBuilderTest.java index 2bf50103b10..58b9462978f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/RoutingBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/RoutingBuilderTest.java @@ -10,12 +10,14 @@ import com.yahoo.config.model.test.MockRoot; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.Zone; -import com.yahoo.vespa.model.container.ApplicationContainer; import com.yahoo.vespa.model.container.ApplicationContainerCluster; +import com.yahoo.vespa.model.container.ApplicationContainer; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; +import org.xml.sax.SAXException; -import java.util.List; +import java.io.IOException; +import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,32 +27,43 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class RoutingBuilderTest extends ContainerModelBuilderTestBase { @Test - void setsRotationActive() { + void setsRotationActiveAccordingToDeploymentSpec() throws IOException, SAXException { Element clusterElem = DomBuilderTest.parse( "<container id='default' version='1.0'><search /></container>"); - String deploymentSpec = """ - <deployment> - <prod> - <region>us-north-1</region> - <parallel> - <region>us-north-2</region> - <region>us-north-3</region> - </parallel> - <region>us-north-4</region> - </prod> - </deployment>"""; + String deploymentSpec = "<deployment>\n" + + " <prod> \n" + + " <region active='true'>us-north-1</region>\n" + + " <parallel>\n" + + " <region active='false'>us-north-2</region>\n" + + " <region active='true'>us-north-3</region>\n" + + " </parallel>\n" + + " <region active='false'>us-north-4</region>\n" + + " </prod>\n" + + "</deployment>"; ApplicationPackage applicationPackage = new MockApplicationPackage.Builder() .withDeploymentSpec(deploymentSpec) .build(); - - for (String region : List.of("us-north-1", "us-north-2", "us-north-3", "us-north-4")) { + //root = new MockRoot("root", applicationPackage); + for (String region : Arrays.asList("us-north-1", "us-north-3")) { ApplicationContainer container = getContainer(applicationPackage, region, clusterElem); + assertEquals("true", container.getServicePropertyString("activeRotation"), "Region " + region + " is active"); } + for (String region : Arrays.asList("us-north-2", "us-north-4")) { + ApplicationContainer container = getContainer(applicationPackage, region, clusterElem); + + assertEquals("false", + container.getServicePropertyString("activeRotation"), + "Region " + region + " is inactive"); + } + ApplicationContainer container = getContainer(applicationPackage, "unknown", clusterElem); + assertEquals("false", + container.getServicePropertyString("activeRotation"), + "Unknown region is inactive"); } diff --git a/config-model/src/test/schema-test-files/deployment-with-instances.xml b/config-model/src/test/schema-test-files/deployment-with-instances.xml index c9f3af49ac2..3b872f4c1cf 100644 --- a/config-model/src/test/schema-test-files/deployment-with-instances.xml +++ b/config-model/src/test/schema-test-files/deployment-with-instances.xml @@ -9,19 +9,19 @@ <instance id="one,two"> <block-change days="mon,tue" hours="14,15" time-zone="CET"/> - <prod athenz-service='other-service'> - <region>us-west-1</region> + <prod global-service-id='qrs' athenz-service='other-service'> + <region active='true'>us-west-1</region> <delay hours='3'/> - <region>us-central-1</region> + <region active='true'>us-central-1</region> <delay hours='3' minutes='7' seconds='13'/> - <region>us-east-3</region> + <region active='true'>us-east-3</region> <parallel> - <region>us-north-1</region> - <region>us-south-1</region> + <region active='true'>us-north-1</region> + <region active='true'>us-south-1</region> </parallel> <parallel> - <region>us-north-2</region> - <region>us-south-2</region> + <region active='true'>us-north-2</region> + <region active='true'>us-south-2</region> </parallel> </prod> <endpoints> @@ -55,7 +55,7 @@ <upgrade policy='conservative'/> <block-change days="mon,tue,wed" hours="14,15"/> <prod> - <region>us-central-1</region> + <region active='true'>us-central-1</region> </prod> <endpoints> <endpoint container-id="barz" /> diff --git a/config-model/src/test/schema-test-files/deployment.xml b/config-model/src/test/schema-test-files/deployment.xml index 8317bf4b80c..bc0f070d88c 100644 --- a/config-model/src/test/schema-test-files/deployment.xml +++ b/config-model/src/test/schema-test-files/deployment.xml @@ -5,19 +5,19 @@ <staging/> <block-change revision='true' version='false' days="mon,tue" hours="14,15"/> <block-change days="mon,tue" hours="14,15" time-zone="CET"/> - <prod athenz-service='other-service'> - <region>us-west-1</region> + <prod global-service-id='qrs' athenz-service='other-service'> + <region active='true'>us-west-1</region> <delay hours='3'/> - <region>us-central-1</region> + <region active='true'>us-central-1</region> <delay hours='3' minutes='7' seconds='13'/> - <region>us-east-3</region> + <region active='true'>us-east-3</region> <parallel> - <region>us-north-1</region> - <region>us-south-1</region> + <region active='true'>us-north-1</region> + <region active='true'>us-south-1</region> </parallel> <parallel> - <region>us-north-2</region> - <region>us-south-2</region> + <region active='true'>us-north-2</region> + <region active='true'>us-south-2</region> </parallel> </prod> <endpoints> |