summaryrefslogtreecommitdiffstats
path: root/config-model-api
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-05-11 15:08:55 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-05-11 15:08:55 +0200
commit6a1e6abb67721b5b87da0d7cbd187eede0011b58 (patch)
tree60698e28113576df57e27c936fb30fe444345e1e /config-model-api
parentd5120622e144d884af22834f75b4bc874b3311e5 (diff)
Support creating from an XML string
Diffstat (limited to 'config-model-api')
-rw-r--r--config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java58
1 files changed, 33 insertions, 25 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 755067010dc..3c00702bd8f 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
@@ -80,37 +80,45 @@ public class DeploymentSpec {
*/
public static DeploymentSpec fromXml(Reader reader) {
try {
- String xmlForm = IOUtils.readAll(reader);
- List<DeclaredZone> zones = new ArrayList<>();
- Optional<String> globalServiceId = Optional.empty();
- Element root = XML.getDocument(xmlForm).getDocumentElement();
- for (Element environmentTag : XML.getChildren(root)) {
- if (!isEnvironmentName(environmentTag.getTagName())) continue;
- Environment environment = Environment.from(environmentTag.getTagName());
- List<Element> regionTags = XML.getChildren(environmentTag, "region");
- if (regionTags.isEmpty()) {
- zones.add(new DeclaredZone(environment, Optional.empty(), false));
- } else {
- for (Element regionTag : regionTags) {
- RegionName region = RegionName.from(XML.getValue(regionTag).trim());
- boolean active = environment == Environment.prod && readActive(regionTag);
- zones.add(new DeclaredZone(environment, Optional.of(region), active));
- }
- }
-
- if (Environment.prod.equals(environment)) {
- globalServiceId = readGlobalServiceId(environmentTag);
- } else if (readGlobalServiceId(environmentTag).isPresent()) {
- throw new IllegalArgumentException("Attribute 'global-service-id' is only valid on 'prod' tag.");
- }
- }
- return new DeploymentSpec(globalServiceId, readUpgradePolicy(root), zones, xmlForm);
+ return fromXml(IOUtils.readAll(reader));
}
catch (IOException e) {
throw new IllegalArgumentException("Could not read deployment spec", e);
}
}
+ /**
+ * Creates a deployment spec from XML.
+ *
+ * @throws IllegalArgumentException if the XML is invalid
+ */
+ public static DeploymentSpec fromXml(String xmlForm) {
+ List<DeclaredZone> zones = new ArrayList<>();
+ Optional<String> globalServiceId = Optional.empty();
+ Element root = XML.getDocument(xmlForm).getDocumentElement();
+ for (Element environmentTag : XML.getChildren(root)) {
+ if (!isEnvironmentName(environmentTag.getTagName())) continue;
+ Environment environment = Environment.from(environmentTag.getTagName());
+ List<Element> regionTags = XML.getChildren(environmentTag, "region");
+ if (regionTags.isEmpty()) {
+ zones.add(new DeclaredZone(environment, Optional.empty(), false));
+ } else {
+ for (Element regionTag : regionTags) {
+ RegionName region = RegionName.from(XML.getValue(regionTag).trim());
+ boolean active = environment == Environment.prod && readActive(regionTag);
+ zones.add(new DeclaredZone(environment, Optional.of(region), active));
+ }
+ }
+
+ if (Environment.prod.equals(environment)) {
+ globalServiceId = readGlobalServiceId(environmentTag);
+ } else if (readGlobalServiceId(environmentTag).isPresent()) {
+ throw new IllegalArgumentException("Attribute 'global-service-id' is only valid on 'prod' tag.");
+ }
+ }
+ return new DeploymentSpec(globalServiceId, readUpgradePolicy(root), zones, xmlForm);
+ }
+
private static boolean isEnvironmentName(String tagName) {
return tagName.equals("test") || tagName.equals("staging") || tagName.equals("prod");
}