summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java
blob: 80caef1709d08a2183b03bfb609eeb87b61081d8 (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
53
54
55
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.stubs;

import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringData;
import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation;
import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot;
import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient;

import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author olaa
 */
public class MockMeteringClient implements MeteringClient {

    private Collection<ResourceSnapshot> resources = new ArrayList<>();
    private Optional<MeteringData> meteringData;

    @Override
    public void consume(Collection<ResourceSnapshot> resources){
        this.resources = resources;
    }

    @Override
    public MeteringData getMeteringData(TenantName tenantName, ApplicationName applicationName) {
        return meteringData.orElseGet(() -> {
            ResourceAllocation emptyAllocation = new ResourceAllocation(0, 0, 0);
            return new MeteringData(emptyAllocation, emptyAllocation, emptyAllocation, Collections.emptyMap());
        });
    }

    @Override
    public List<ResourceSnapshot> getSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth) {
        return new ArrayList<>(resources);
    }

    public Collection<ResourceSnapshot> consumedResources() {
        return this.resources;
    }

    public void setMeteringData(MeteringData meteringData) {
        this.meteringData = Optional.of(meteringData);
        this.resources = meteringData.getSnapshotHistory().entrySet().stream().map(Map.Entry::getValue).flatMap(List::stream).collect(Collectors.toList());
        boolean a = false;
    }
}