diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-06-01 16:36:15 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-06-01 16:36:15 +0200 |
commit | 9ee7ea37ba5ad9bcbc803579ec02bf2cc434ac52 (patch) | |
tree | 180e252244d456687f4fc595fdc6542138c36225 /config-model-api | |
parent | 52cd7858420e6ec7c1a908d8fab68250678ac678 (diff) |
Parse delay
Diffstat (limited to 'config-model-api')
-rw-r--r-- | config-model-api/src/main/java/com/yahoo/config/application/api/DeploymentSpec.java | 45 |
1 files changed, 32 insertions, 13 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 1682aaf69d2..7687ad1313f 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 @@ -140,27 +140,46 @@ public class DeploymentSpec { Optional<String> globalServiceId = Optional.empty(); Element root = XML.getDocument(xmlForm).getDocumentElement(); for (Element environmentTag : XML.getChildren(root)) { - if (!isEnvironmentName(environmentTag.getTagName())) continue; + if ( ! isEnvironmentName(environmentTag.getTagName())) continue; + Environment environment = Environment.from(environmentTag.getTagName()); - List<Element> regionTags = XML.getChildren(environmentTag, "region"); - if (regionTags.isEmpty()) { - steps.add(new ZoneDeployment(environment, Optional.empty(), false)); - } else { - for (Element regionTag : regionTags) { - RegionName region = RegionName.from(XML.getValue(regionTag).trim()); - boolean active = environment == Environment.prod && readActive(regionTag); - steps.add(new ZoneDeployment(environment, Optional.of(region), active)); + + if (environment == Environment.prod) { + for (Element stepTag : XML.getChildren(environmentTag)) { + if (stepTag.getTagName().equals("delay")) + steps.add(new Delay(Duration.ofSeconds(intAttribute("hours", stepTag) * 60 * 60 + + intAttribute("minutes", stepTag) * 60 + + intAttribute("seconds", stepTag)))); + else // a region: deploy step + steps.add(new ZoneDeployment(environment, + Optional.of(RegionName.from(XML.getValue(stepTag).trim())), + readActive(stepTag))); } } + else { + steps.add(new ZoneDeployment(environment)); + } - if (Environment.prod.equals(environment)) { + if (environment == Environment.prod) globalServiceId = readGlobalServiceId(environmentTag); - } else if (readGlobalServiceId(environmentTag).isPresent()) { + else if (readGlobalServiceId(environmentTag).isPresent()) throw new IllegalArgumentException("Attribute 'global-service-id' is only valid on 'prod' tag."); - } } return new DeploymentSpec(globalServiceId, readUpgradePolicy(root), steps, xmlForm); } + + /** Returns the given attribute as an integer, or 0 if it is not present */ + private static int intAttribute(String attributeName, Element tag) { + String value = tag.getAttribute(attributeName); + if (value == null || value.isEmpty()) return 0; + try { + return Integer.parseInt(value); + } + catch (NumberFormatException e) { + throw new IllegalArgumentException("Expected an integer for attribute '" + attributeName + + "' but got '" + value + "'"); + } + } private static boolean isEnvironmentName(String tagName) { return tagName.equals("test") || tagName.equals("staging") || tagName.equals("prod"); @@ -277,7 +296,7 @@ public class DeploymentSpec { private final boolean active; public ZoneDeployment(Environment environment) { - this(environment, Optional.empty(), true); + this(environment, Optional.empty(), false); } public ZoneDeployment(Environment environment, Optional<RegionName> region, boolean active) { |