aboutsummaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2022-05-30 15:52:35 +0200
committerMartin Polden <mpolden@mpolden.no>2022-05-30 15:57:43 +0200
commitcfc49c3b93988100bb0bc49776f70ce8d9fdd9b9 (patch)
treedc3aea3421b62538fcc107c1923ab706f91d9173 /config-model-api
parent66392862e61c2f7d9d6d709429be5ab1bc2d7d0e (diff)
Reject deployment spec using elements deprecated on previous major
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java16
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java8
2 files changed, 16 insertions, 8 deletions
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 22ffdeb7262..c4fec6e668e 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
@@ -637,21 +637,29 @@ public class DeploymentSpec {
private final String tagName;
private final List<String> attributes;
private final String message;
+ private final int majorVersion;
- public DeprecatedElement(String tagName, List<String> attributes, String message) {
+ public DeprecatedElement(int majorVersion, String tagName, List<String> attributes, String message) {
this.tagName = Objects.requireNonNull(tagName);
this.attributes = Objects.requireNonNull(attributes);
this.message = Objects.requireNonNull(message);
+ this.majorVersion = majorVersion;
if (message.isBlank()) throw new IllegalArgumentException("message must be non-empty");
}
+ /** Returns the major version that deprecated this element */
+ public int majorVersion() {
+ return majorVersion;
+ }
+
public String humanReadableString() {
+ String deprecationDescription = "deprecated since major version " + majorVersion;
if (attributes.isEmpty()) {
- return "Element '" + tagName + "' is deprecated. " + message;
+ return "Element '" + tagName + "' is " + deprecationDescription + ". " + message;
}
- return "Element '" + tagName + "' contains deprecated attribute" + (attributes.size() > 1 ? "s" : "") + ": " +
+ return "Element '" + tagName + "' contains attribute" + (attributes.size() > 1 ? "s " : " ") +
attributes.stream().map(attr -> "'" + attr + "'").collect(Collectors.joining(", ")) +
- ". " + message;
+ " " + deprecationDescription + ". " + message;
}
@Override
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 2f73bff83b8..09d61835ae3 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
@@ -439,7 +439,7 @@ public class DeploymentSpecXmlReader {
private Optional<String> readGlobalServiceId(Element environmentTag) {
String globalServiceId = environmentTag.getAttribute(globalServiceIdAttribute);
if (globalServiceId.isEmpty()) return Optional.empty();
- deprecate(environmentTag, List.of(globalServiceIdAttribute), "See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax");
+ deprecate(environmentTag, List.of(globalServiceIdAttribute), 7, "See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax");
return Optional.of(globalServiceId);
}
@@ -524,15 +524,15 @@ public class DeploymentSpecXmlReader {
private boolean readActive(Element regionTag) {
String activeValue = regionTag.getAttribute("active");
if ("".equals(activeValue)) return true; // Default to active
- deprecate(regionTag, List.of("active"), "See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax");
+ deprecate(regionTag, List.of("active"), 7, "See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax");
if ("true".equals(activeValue)) return true;
if ("false".equals(activeValue)) return false;
throw new IllegalArgumentException("Value of 'active' attribute in region tag must be 'true' or 'false' " +
"to control whether this region should receive traffic from the global endpoint of this application");
}
- private void deprecate(Element element, List<String> attributes, String message) {
- deprecatedElements.add(new DeprecatedElement(element.getTagName(), attributes, message));
+ private void deprecate(Element element, List<String> attributes, int majorVersion, String message) {
+ deprecatedElements.add(new DeprecatedElement(majorVersion, element.getTagName(), attributes, message));
}
private static boolean isEmptySpec(Element root) {