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 1675bacb387..f3a61a8e45d 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 @@ -8,8 +8,10 @@ import com.yahoo.vespa.model.container.ContainerModel; import java.io.Reader; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Validate deployment spec (deployment.xml). @@ -27,6 +29,7 @@ public void validate(Context context) { Reader deploymentReader = deployment.get(); DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(deploymentReader); List containers = context.model().getRoot().configModelRepo().getModels(ContainerModel.class); + requireUniqueInstanceIds(context, deploymentSpec.instances()); for (DeploymentInstanceSpec instance : deploymentSpec.instances()) { instance.endpoints().forEach(endpoint -> { requireClusterId(context, containers, instance.name(), @@ -42,4 +45,12 @@ private static void requireClusterId(Context context, List conta "' specified in deployment.xml does not match any container cluster ID"); } + private static void requireUniqueInstanceIds(Context context, List instances) { + Set instanceNames = new HashSet<>(); + for (var instance : instances) { + if ( ! instanceNames.add(instance.name())) + context.illegal("Duplicate instance name '" + instance.name() + "' specified in deployment.xml."); + } + } + } 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 c9b014d9301..6f41577d55e 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 @@ -34,6 +34,25 @@ void testEndpointNonExistentContainerId() { "deployment.xml does not match any container cluster ID", deploymentXml); } + @Test + void requireUniqueInstanceId() { + String deploymentXml = """ + + + + aws-us-west-2a + + + + + aws-us-west-2a + + + + """; + assertValidationError("Duplicate instance name 'default' specified in deployment.xml.", deploymentXml); + } + private static void assertValidationError(String message, String deploymentXml) { var simpleHosts = "" + " " +