blob: 436181f99ba6ca6118fd0bbe4f45116fed524a63 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.os;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.flags.IntFlag;
import com.yahoo.vespa.flags.PermanentFlags;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeList;
import com.yahoo.vespa.hosted.provision.NodeRepository;
import java.time.Duration;
import java.time.Instant;
/**
* Interface for an OS upgrader.
*
* @author mpolden
*/
public abstract class OsUpgrader {
private final IntFlag maxActiveUpgrades;
final NodeRepository nodeRepository;
public OsUpgrader(NodeRepository nodeRepository) {
this.nodeRepository = nodeRepository;
this.maxActiveUpgrades = PermanentFlags.MAX_OS_UPGRADES.bindTo(nodeRepository.flagSource());
}
/** Trigger upgrade to given target */
abstract void upgradeTo(OsVersionTarget target);
/** Disable OS upgrade for all nodes of given type */
abstract void disableUpgrade(NodeType type);
/** Returns the number of upgrade slots available for given target */
final int upgradeSlots(OsVersionTarget target, NodeList candidates) {
if (!candidates.stream().allMatch(node -> node.type() == target.nodeType())) {
throw new IllegalArgumentException("All node types must type of OS version target " + target.nodeType());
}
int max = target.nodeType() == NodeType.host ? maxActiveUpgrades.value() : 1;
int upgrading = candidates.changingOsVersionTo(target.version()).size();
return Math.max(0, max - upgrading);
}
/** Returns whether node can change version at given instant */
final boolean canUpgradeAt(Instant instant, Node node) {
return node.status().osVersion().downgrading() || // Fast-track downgrades
node.history().age(instant).compareTo(gracePeriod()) > 0;
}
/** The duration this leaves new nodes alone before scheduling any upgrade */
private Duration gracePeriod() {
return nodeRepository.zone().system().isCd() ? Duration.ofHours(4) : Duration.ofDays(1);
}
}
|