All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.config.server.maintenance.TenantsMaintainer Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. 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, Duration interval, Clock clock) {
        super(applicationRepository, curator, applicationRepository.flagSource(), applicationRepository.clock(), interval, true);
        this.ttlForUnusedTenant = defaultTtlForUnusedTenant;
        this.clock = clock;
    }

    @Override
    protected double maintain() {
        if ( ! applicationRepository.configserverConfig().hostedVespa()) return 1.0;

        Set tenants = applicationRepository.deleteUnusedTenants(ttlForUnusedTenant, clock.instant());
        if (tenants.size() > 0) log.log(Level.INFO, "Deleted tenants " + tenants);
        return 1.0;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy