aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/TenantRoleCleanupMaintainer.java
blob: 5539c62be98cae7da0fe41d3b7ac9a4ec0427109 (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
// 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.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.tenant.Tenant;

import java.time.Duration;

public class TenantRoleCleanupMaintainer extends ControllerMaintainer {

    public TenantRoleCleanupMaintainer(Controller controller, Duration interval) {
        super(controller, interval);
    }

    @Override
    protected double maintain() {
        var roleService = controller().serviceRegistry().roleService();

        var deletedTenants = controller().tenants().asList(true).stream()
                .filter(tenant -> tenant.type() == Tenant.Type.deleted)
                .map(Tenant::name)
                .toList();
        roleService.cleanupRoles(deletedTenants);

        if (controller().system().isPublic()) {
            controller().serviceRegistry().tenantSecretService().cleanupSecretStores(deletedTenants);
        }

        return 0.0;
    }
}