aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationMetaDataGarbageCollector.java
blob: c8c5a1834c736d56e00c26111c404cd7d79dbec7 (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
// Copyright Yahoo. 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 java.time.Duration;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author jvenstad
 */
public class ApplicationMetaDataGarbageCollector extends ControllerMaintainer {

    private static final Logger log = Logger.getLogger(ApplicationMetaDataGarbageCollector.class.getName());

    private final Duration timeToLive;

    public ApplicationMetaDataGarbageCollector(Controller controller, Duration interval) {
        super(controller, interval);
        this.timeToLive = controller.system().isCd() ? Duration.ofDays(7) : Duration.ofDays(365);
    }

    @Override
    protected double maintain() {
        try {
            controller().applications().applicationStore().pruneMeta(controller().clock().instant().minus(timeToLive));
            return 1.0;
        }
        catch (Exception e) {
            log.log(Level.WARNING, "Exception pruning old application meta data", e);
            return 0.0;
        }
    }

}