blob: ec09e89568c147f725b5eccb71b3916aaa16ad42 (
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
|
// Copyright Yahoo. 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.config.provision.TenantName;
import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.flags.FlagSource;
import java.time.Clock;
import java.time.Duration;
import java.util.Set;
import java.util.logging.Level;
/**
* 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, FlagSource flagSource,
Duration interval, Clock clock) {
super(applicationRepository, curator, flagSource, applicationRepository.clock().instant(), interval, true);
this.ttlForUnusedTenant = defaultTtlForUnusedTenant;
this.clock = clock;
}
@Override
protected double maintain() {
if ( ! applicationRepository.configserverConfig().hostedVespa()) return 1.0;
Set<TenantName> tenants = applicationRepository.deleteUnusedTenants(ttlForUnusedTenant, clock.instant());
if (tenants.size() > 0) log.log(Level.INFO, "Deleted tenants " + tenants);
return 1.0;
}
}
|