Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require unique instance names in deployment.xml #32962

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -27,6 +29,7 @@ public void validate(Context context) {
Reader deploymentReader = deployment.get();
DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(deploymentReader);
List<ContainerModel> 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(),
Expand All @@ -42,4 +45,12 @@ private static void requireClusterId(Context context, List<ContainerModel> conta
"' specified in deployment.xml does not match any container cluster ID");
}

private static void requireUniqueInstanceIds(Context context, List<DeploymentInstanceSpec> instances) {
Set<InstanceName> instanceNames = new HashSet<>();
for (var instance : instances) {
if ( ! instanceNames.add(instance.name()))
context.illegal("Duplicate instance name '" + instance.name() + "' specified in deployment.xml.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ void testEndpointNonExistentContainerId() {
"deployment.xml does not match any container cluster ID", deploymentXml);
}

@Test
void requireUniqueInstanceId() {
String deploymentXml = """
<deployment version="1.0" cloud-account="aws:010438471985">
<instance id="default" tags="search">
<prod>
<region>aws-us-west-2a</region>
</prod>
</instance>
<instance id="default" tags="canary">
<prod>
<region>aws-us-west-2a</region>
</prod>
</instance>
</deployment>
""";
assertValidationError("Duplicate instance name 'default' specified in deployment.xml.", deploymentXml);
}

private static void assertValidationError(String message, String deploymentXml) {
var simpleHosts = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<hosts> " +
Expand Down