summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainer.java
blob: d3865f287cd3f54c3c57bdc4bc5ca7e5d90cee27 (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
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.maintenance;

import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.curator.Curator;

import java.time.Clock;
import java.time.Duration;

/**
 * Removes unused tenants (has no applications and was created more than 7 days ago)
 *
 * @author hmusum
 */
public class TenantsMaintainer extends ConfigServerMaintainer {

    static final Duration defaultTtlForUnusedTenant = Duration.ofDays(7);

    private final Duration ttlForUnusedTenant;
    private final Clock clock;

    TenantsMaintainer(ApplicationRepository applicationRepository, Curator curator, Duration interval, Clock clock) {
        super(applicationRepository, curator, interval, interval);
        this.ttlForUnusedTenant = defaultTtlForUnusedTenant;
        this.clock = clock;
    }

    @Override
    protected void maintain() {
        applicationRepository.deleteUnusedTenants(ttlForUnusedTenant, clock.instant());
    }
}