diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-05-22 20:42:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-22 20:42:10 +0200 |
commit | ecfc56c93befe391dcc5ee2f671f4a6fe9a2bbbc (patch) | |
tree | 059369396ade3b4a1b2519e6b52fb86fb010962c | |
parent | adbccf21b980f16486af7a516d4db7adc1a813a0 (diff) | |
parent | 904a347a61df65ac186c64b1316e286c09ec6d5d (diff) |
Merge pull request #5894 from vespa-engine/jvenstad/top-sort
Use top-sort and a DAG to express deps and parallelism
2 files changed, 21 insertions, 16 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/SystemApplication.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/SystemApplication.java index f264251361a..0d2c9fbda8b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/SystemApplication.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/SystemApplication.java @@ -18,14 +18,17 @@ public enum SystemApplication { configServerHost(ApplicationId.from("hosted-vespa", "configserver-host", "default"), NodeType.confighost), proxyHost(ApplicationId.from("hosted-vespa", "proxy-host", "default"), NodeType.proxyhost), configServer(ApplicationId.from("hosted-vespa", "zone-config-servers", "default"), NodeType.config), - zone(ApplicationId.from("hosted-vespa", "routing", "default"), NodeType.proxy); + zone(ApplicationId.from("hosted-vespa", "routing", "default"), NodeType.proxy, + configServerHost, proxyHost, configServer); private final ApplicationId id; private final NodeType nodeType; + private final List<SystemApplication> prerequisites; - SystemApplication(ApplicationId id, NodeType nodeType) { + SystemApplication(ApplicationId id, NodeType nodeType, SystemApplication ... prerequisites) { this.id = id; this.nodeType = nodeType; + this.prerequisites = Arrays.asList(prerequisites); } public ApplicationId id() { @@ -37,16 +40,14 @@ public enum SystemApplication { return nodeType; } + /** Returns the system applications that should upgrade before this */ + public List<SystemApplication> prerequisites() { return prerequisites; } + /** Returns whether this system application has an application package */ public boolean hasApplicationPackage() { return nodeType == NodeType.proxy; } - /** Returns whether this system application must be upgraded in the declared order */ - public boolean upgradeInOrder() { - return nodeType != NodeType.confighost && nodeType != NodeType.proxyhost; - } - /** All known system applications */ public static List<SystemApplication> all() { return Arrays.asList(values()); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java index d6addf19b44..25b501e94fa 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java @@ -37,31 +37,35 @@ public class SystemUpgrader extends Maintainer { if (!target.isPresent()) { return; } - deploy(SystemApplication.all(), target.get()); + converge(SystemApplication.all(), target.get()); } - /** Deploy a list of system applications on given version */ - private void deploy(List<SystemApplication> applications, Version target) { + /** Deploy a list of system applications until they converge on the given version */ + private void converge(List<SystemApplication> applications, Version target) { for (List<ZoneId> zones : controller().zoneRegistry().upgradePolicy().asList()) { + boolean converged = true; for (SystemApplication application : applications) { - if (!deploy(zones, application, target) && application.upgradeInOrder()) { - return; + if (application.prerequisites().stream().allMatch(prerequisite -> converged(zones, prerequisite, target))) { + deploy(zones, application, target); } + converged &= converged(zones, application, target); } + if (!converged) break; } } /** Deploy application on given version. Returns true when all allocated nodes are on requested version */ - private boolean deploy(List<ZoneId> zones, SystemApplication application, Version target) { - boolean completed = true; + private void deploy(List<ZoneId> zones, SystemApplication application, Version target) { for (ZoneId zone : zones) { if (!wantedVersion(zone, application.id(), target).equals(target)) { log.info(String.format("Deploying %s version %s in %s", application.id(), target, zone)); controller().applications().deploy(application, zone, target); } - completed = completed && currentVersion(zone, application.id(), target).equals(target); } - return completed; + } + + private boolean converged(List<ZoneId> zones, SystemApplication application, Version target) { + return zones.stream().allMatch(zone -> currentVersion(zone, application.id(), target).equals(target)); } private Version wantedVersion(ZoneId zone, ApplicationId application, Version defaultVersion) { |