/** Parse a time window from the given day, hour and time zone specification */ public static TimeWindow from(String daySpec, String hourSpec, String zoneSpec) { List<DayOfWeek> days = parse(daySpec, TimeWindow::parseDays); List<Integer> hours = parse(hourSpec, TimeWindow::parseHours); ZoneId zone = zoneFrom(zoneSpec); return new TimeWindow(days, hours, zone); }
/** Returns a list of all hours occurring between startInclusive and endInclusive */ private static List<Integer> parseHours(String startInclusive, String endInclusive) { int start = hourFrom(startInclusive); int end = hourFrom(endInclusive); if (end < start) { throw new IllegalArgumentException(String.format("Invalid hour range '%s-%s'", startInclusive, endInclusive)); } return IntStream.rangeClosed(start, end).boxed() .collect(Collectors.toList()); }
/** Returns whether upgrade can occur at the given instant */ public boolean canUpgradeAt(Instant instant) { return changeBlockers.stream().filter(block -> block.blocksVersions()) .noneMatch(block -> block.window().includes(instant)); }
/** Returns a list of all days occurring between startInclusive and endInclusive */ private static List<DayOfWeek> parseDays(String startInclusive, String endInclusive) { DayOfWeek start = dayFrom(startInclusive); DayOfWeek end = dayFrom(endInclusive); if (end.getValue() < start.getValue()) { throw new IllegalArgumentException(String.format("Invalid day range '%s-%s'", startInclusive, endInclusive)); } return IntStream.rangeClosed(start.getValue(), end.getValue()).boxed() .map(DayOfWeek::of) .collect(Collectors.toList()); }
private List<DeploymentSpec.ChangeBlocker> readChangeBlockers(Element root) { List<DeploymentSpec.ChangeBlocker> changeBlockers = new ArrayList<>(); for (Element tag : XML.getChildren(root)) { if ( ! blockChangeTag.equals(tag.getTagName())) continue; boolean blockVersions = trueOrMissing(tag.getAttribute("version")); boolean blockRevisions = trueOrMissing(tag.getAttribute("revision")); String daySpec = tag.getAttribute("days"); String hourSpec = tag.getAttribute("hours"); String zoneSpec = tag.getAttribute("time-zone"); if (zoneSpec.isEmpty()) { // Default to UTC time zone zoneSpec = "UTC"; } changeBlockers.add(new DeploymentSpec.ChangeBlocker(blockRevisions, blockVersions, TimeWindow.from(daySpec, hourSpec, zoneSpec))); } return Collections.unmodifiableList(changeBlockers); }
/** Returns whether an application revision change can occur at the given instant */ public boolean canChangeRevisionAt(Instant instant) { return changeBlockers.stream().filter(block -> block.blocksRevisions()) .noneMatch(block -> block.window().includes(instant)); }