aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/OsUpgradeActivator.java
blob: c5252f344dc1fb287d1bf86ac091ee490bf99734 (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
// 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.maintenance;

import com.yahoo.config.provision.NodeType;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeRepository;

import java.time.Duration;

/**
 * This maintainer (de)activates OS upgrades according to Vespa upgrade status of nodes in this repository.
 *
 * If a node is upgrading to a new Vespa version, any ongoing OS upgrade will be paused for all nodes of that type. OS
 * upgrades will resume once all nodes of that type have completed their Vespa upgrade.
 *
 * @author mpolden
 */
public class OsUpgradeActivator extends NodeRepositoryMaintainer {

    public OsUpgradeActivator(NodeRepository nodeRepository, Duration interval, Metric metric) {
        super(nodeRepository, interval, metric);
    }

    @Override
    protected double maintain() {
        for (var nodeType : NodeType.values()) {
            if (!nodeType.isHost()) continue;
            boolean resume = canUpgradeOsOf(nodeType);
            nodeRepository().osVersions().resumeUpgradeOf(nodeType, resume);
        }
        return 1.0;
    }

    /** Returns whether to allow OS upgrade of nodes of given type */
    private boolean canUpgradeOsOf(NodeType type) {
        return nodeRepository().nodes()
                               .list(Node.State.ready, Node.State.active)
                               .nodeType(type)
                               .changingVersion()
                               .isEmpty();
    }

}