aboutsummaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-12-02 13:57:37 +0100
committerMartin Polden <mpolden@mpolden.no>2021-12-02 14:40:17 +0100
commit71c31528f28438f09a9eb2a02fe3006ff4ade25b (patch)
tree3ce7b0c01cc8ef99ca05b738c8a362fc311d87f0 /config-model-api
parente242edefd31cc5740ec5a5f23613587cc208ced1 (diff)
Deprecate active and global-service-id attributes
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java45
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/xml/DeploymentSpecXmlReader.java12
2 files changed, 54 insertions, 3 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 97ece3a675e..88363db6e49 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
@@ -39,7 +39,8 @@ public class DeploymentSpec {
Optional.empty(),
Optional.empty(),
List.of(),
- "<deployment version='1.0'/>");
+ "<deployment version='1.0'/>",
+ List.of());
private final List<Step> steps;
@@ -48,6 +49,7 @@ public class DeploymentSpec {
private final Optional<AthenzDomain> athenzDomain;
private final Optional<AthenzService> athenzService;
private final List<Endpoint> endpoints;
+ private final List<DeprecatedElement> deprecatedElements;
private final String xmlForm;
@@ -56,13 +58,15 @@ public class DeploymentSpec {
Optional<AthenzDomain> athenzDomain,
Optional<AthenzService> athenzService,
List<Endpoint> endpoints,
- String xmlForm) {
+ String xmlForm,
+ List<DeprecatedElement> deprecatedElements) {
this.steps = List.copyOf(Objects.requireNonNull(steps));
this.majorVersion = Objects.requireNonNull(majorVersion);
this.athenzDomain = Objects.requireNonNull(athenzDomain);
this.athenzService = Objects.requireNonNull(athenzService);
this.xmlForm = Objects.requireNonNull(xmlForm);
this.endpoints = List.copyOf(Objects.requireNonNull(endpoints));
+ this.deprecatedElements = List.copyOf(Objects.requireNonNull(deprecatedElements));
validateTotalDelay(steps);
validateUpgradePoliciesOfIncreasingConservativeness(steps);
validateAthenz();
@@ -201,6 +205,11 @@ public class DeploymentSpec {
return endpoints;
}
+ /** Returns the deprecated elements used when creating this */
+ public List<DeprecatedElement> deprecatedElements() {
+ return deprecatedElements;
+ }
+
private static List<DeploymentInstanceSpec> instances(List<DeploymentSpec.Step> steps) {
return steps.stream()
.flatMap(DeploymentSpec::flatten)
@@ -576,5 +585,37 @@ public class DeploymentSpec {
}
+ /**
+ * Represents a deprecated XML element in {@link com.yahoo.config.application.api.DeploymentSpec}, or the deprecated
+ * attribute(s) of an element.
+ */
+ public static class DeprecatedElement {
+
+ private final String tagName;
+ private final List<String> attributes;
+ private final String message;
+
+ public DeprecatedElement(String tagName, List<String> attributes, String message) {
+ this.tagName = Objects.requireNonNull(tagName);
+ this.attributes = Objects.requireNonNull(attributes);
+ this.message = Objects.requireNonNull(message);
+ if (message.isBlank()) throw new IllegalArgumentException("message must be non-empty");
+ }
+
+ public String humanReadableString() {
+ if (attributes.isEmpty()) {
+ return "Element '" + tagName + "' is deprecated. " + message;
+ }
+ return "Element '" + tagName + "' contains deprecated attribute" + (attributes.size() > 1 ? "s" : "") + ": " +
+ attributes.stream().map(attr -> "'" + attr + "'").collect(Collectors.joining(", ")) +
+ ". " + message;
+ }
+
+ @Override
+ public String toString() {
+ return humanReadableString();
+ }
+
+ }
}
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 07b8462f4d1..aa985cd48bd 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
@@ -6,6 +6,7 @@ import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.application.api.DeploymentSpec.DeclaredTest;
import com.yahoo.config.application.api.DeploymentSpec.DeclaredZone;
import com.yahoo.config.application.api.DeploymentSpec.Delay;
+import com.yahoo.config.application.api.DeploymentSpec.DeprecatedElement;
import com.yahoo.config.application.api.DeploymentSpec.ParallelSteps;
import com.yahoo.config.application.api.DeploymentSpec.Step;
import com.yahoo.config.application.api.DeploymentSpec.Steps;
@@ -66,6 +67,7 @@ public class DeploymentSpecXmlReader {
private static final String testerFlavorAttribute = "tester-flavor";
private final boolean validate;
+ private final List<DeprecatedElement> deprecatedElements = new ArrayList<>();
/** Creates a validating reader */
public DeploymentSpecXmlReader() {
@@ -92,6 +94,7 @@ public class DeploymentSpecXmlReader {
/** Reads a deployment spec from XML */
public DeploymentSpec read(String xmlForm) {
+ deprecatedElements.clear();
Element root = XML.getDocument(xmlForm).getDocumentElement();
if ( ! root.getTagName().equals(deploymentTag))
illegal("The root tag must be <deployment>");
@@ -126,7 +129,8 @@ public class DeploymentSpecXmlReader {
stringAttribute(athenzDomainAttribute, root).map(AthenzDomain::from),
stringAttribute(athenzServiceAttribute, root).map(AthenzService::from),
applicationEndpoints,
- xmlForm);
+ xmlForm,
+ deprecatedElements);
}
/**
@@ -404,6 +408,7 @@ public class DeploymentSpecXmlReader {
private Optional<String> readGlobalServiceId(Element environmentTag) {
String globalServiceId = environmentTag.getAttribute("global-service-id");
if (globalServiceId == null || globalServiceId.isEmpty()) return Optional.empty();
+ deprecate(environmentTag, List.of("global-service-id"), "See https://cloud.vespa.ai/en/reference/routing#deprecated-syntax");
return Optional.of(globalServiceId);
}
@@ -478,12 +483,17 @@ 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");
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 static boolean isEmptySpec(Element root) {
if ( ! XML.getChildren(root).isEmpty()) return false;
return root.getAttributes().getLength() == 0