diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-09-17 14:47:51 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-09-17 14:52:16 +0200 |
commit | dfc86a3d6dd39c57b623217e24e80730758888e4 (patch) | |
tree | 77366438dfbb4b3e1c448610ad17e30f4a8d608a /controller-api | |
parent | 55ef15053d73e5300d1d4112515de9303ccddfdc (diff) |
Check target OS version per zone
This change makes the controller check the target OS version per zone (retrieved
from `/nodes/v2/upgrade/`) when deciding whether to set a target.
In the node repository, the OS version value in `/nodes/v2/upgrade/` and the value of
each nodes `wantedOsVersion` are backed by the same ZK data.
To implement automatic pausing of OS upgrades we'll eventually start omitting
the `wantedOsVersion` node field when an OS version is deactivated. We therefore
make the controller read target version from `/nodes/v2/upgrade/` instead to
avoid the controller repeatedly setting a target version while upgrades to that
version are paused.
Diffstat (limited to 'controller-api')
2 files changed, 70 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java index e9b0c69e904..b36eba7d063 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java @@ -62,6 +62,9 @@ public interface NodeRepository { /** Upgrade OS for all nodes of given type to a new version */ void upgradeOs(ZoneId zone, NodeType type, Version version); + /** Get target versions for upgrades in given zone */ + TargetVersions targetVersionsOf(ZoneId zone); + /** Requests firmware checks on all hosts in the given zone. */ void requestFirmwareCheck(ZoneId zone); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/TargetVersions.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/TargetVersions.java new file mode 100644 index 00000000000..a14792241fc --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/TargetVersions.java @@ -0,0 +1,67 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.configserver; + +import com.yahoo.component.Version; +import com.yahoo.config.provision.NodeType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * Target versions for node upgrades in a zone. + * + * @author mpolden + */ +public class TargetVersions { + + public static final TargetVersions EMPTY = new TargetVersions(Map.of(), Map.of()); + + private final Map<NodeType, Version> vespaVersions; + private final Map<NodeType, Version> osVersions; + + public TargetVersions(Map<NodeType, Version> vespaVersions, Map<NodeType, Version> osVersions) { + this.vespaVersions = Map.copyOf(Objects.requireNonNull(vespaVersions, "vespaVersions must be non-null")); + this.osVersions = Map.copyOf(Objects.requireNonNull(osVersions, "osVersions must be non-null")); + } + + /** Returns a copy of this with Vespa version set for given node type */ + public TargetVersions withVespaVersion(NodeType nodeType, Version version) { + var vespaVersions = new HashMap<>(this.vespaVersions); + vespaVersions.put(nodeType, version); + return new TargetVersions(vespaVersions, osVersions); + } + + /** Returns a copy of this with OS version set for given node type */ + public TargetVersions withOsVersion(NodeType nodeType, Version version) { + var osVersions = new HashMap<>(this.osVersions); + osVersions.put(nodeType, version); + return new TargetVersions(vespaVersions, osVersions); + } + + /** Returns the target OS version of given node type, if any */ + public Optional<Version> osVersion(NodeType type) { + return Optional.ofNullable(osVersions.get(type)); + } + + /** Returns the target Vespa version of given node type, if any */ + public Optional<Version> vespaVersion(NodeType type) { + return Optional.ofNullable(vespaVersions.get(type)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TargetVersions that = (TargetVersions) o; + return vespaVersions.equals(that.vespaVersions) && + osVersions.equals(that.osVersions); + } + + @Override + public int hashCode() { + return Objects.hash(vespaVersions, osVersions); + } + +} |