aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CloudAccountVerifier.java
blob: fedfea792f31e2dcfecb22d1b9019e76793cb91c (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.maintenance;

import com.yahoo.config.provision.SystemName;
import com.yahoo.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.tenant.CloudAccountInfo;
import com.yahoo.vespa.hosted.controller.tenant.Tenant;

import java.time.Duration;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

import static java.util.logging.Level.WARNING;

/**
 * Verifies the cloud accounts that may be used by a given user have applied the enclave template
 * and extracts the version of the applied template.
 *
 * All maintainers that operate on external cloud accounts should use the list on the Tenant instance
 * maintained by this class rather than the cloud-accounts feature flag.
 *
 * The template version can be used to determine if new features can be enabled for the cloud account.
 *
 * @author freva
 */
public class CloudAccountVerifier extends ControllerMaintainer {

    private static final Logger logger = Logger.getLogger(CloudAccountVerifier.class.getName());

    CloudAccountVerifier(Controller controller, Duration interval) {
        super(controller, interval, null, Set.of(SystemName.PublicCd, SystemName.Public));
    }

    @Override
    protected double maintain() {
        int attempts = 0, failures = 0;
        for (Tenant tenant : controller().tenants().asList()) {
            try {
                attempts++;
                List<CloudAccountInfo> cloudAccountInfos = controller().applications().accountsOf(tenant.name()).stream()
                        .flatMap(account -> controller().serviceRegistry()
                                .archiveService()
                                .getEnclaveTemplateVersion(account)
                                .map(version -> new CloudAccountInfo(account, version))
                                .stream())
                        .toList();
                controller().tenants().updateCloudAccounts(tenant.name(), cloudAccountInfos);
            } catch (RuntimeException e) {
                logger.log(WARNING, "Failed to verify cloud accounts for tenant " + tenant.name(), e);
                failures++;
            }
        }
        return asSuccessFactorDeviation(attempts, failures);
    }
}