aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java
blob: 2b26e93aeb875fae6aca1c8287501c282012e18d (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
43
44
45
46
47
48
49
50
51
52
// Copyright 2018 Yahoo Holdings. 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.google.inject.Inject;
import com.yahoo.config.provision.CloudName;
import com.yahoo.config.provision.SystemName;
import com.yahoo.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryClientInterface;
import com.yahoo.vespa.hosted.controller.restapi.cost.CostCalculator;
import com.yahoo.vespa.hosted.controller.restapi.cost.CostReportConsumer;
import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig;

import java.time.Clock;
import java.time.Duration;
import java.util.*;
import java.util.logging.Logger;

/**
 * Periodically calculate and store cost allocation for properties.
 *
 * @author ldalves
 * @author andreer
 */
public class CostReportMaintainer extends Maintainer {

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

    private final CostReportConsumer consumer;
    private final NodeRepositoryClientInterface nodeRepository;
    private final Clock clock;
    private final SelfHostedCostConfig selfHostedCostConfig;

    @Inject
    @SuppressWarnings("WeakerAccess")
    public CostReportMaintainer(Controller controller, Duration interval,
                                CostReportConsumer consumer,
                                JobControl jobControl,
                                NodeRepositoryClientInterface nodeRepository,
                                Clock clock,
                                SelfHostedCostConfig selfHostedCostConfig) {
        super(controller, interval, jobControl, "CostReportMaintainer", EnumSet.of(SystemName.main));
        this.consumer = consumer;
        this.nodeRepository = Objects.requireNonNull(nodeRepository, "node repository must be non-null");
        this.clock = clock;
        this.selfHostedCostConfig = selfHostedCostConfig;
    }

    @Override
    protected void maintain() {
        consumer.Consume(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller(), clock, selfHostedCostConfig, CloudName.from("yahoo")));
    }
}