aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java
blob: 49a24296fd3ac0f0f7f640afb16c7097e04beb6c (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
56
57
58
59
60
61
62
// 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.resource;

import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.api.identifiers.ClusterId;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;


import java.time.Instant;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @author olaa
 */
public interface ResourceDatabaseClient {

    void writeResourceSnapshots(Collection<ResourceSnapshot> snapshots);

    List<ResourceUsage> getResourceSnapshotsForPeriod(TenantName tenantName, long startTimestamp, long endTimestamp);

    void refreshMaterializedView();

    void writeScalingEvents(ClusterId clusterId, Collection<Cluster.ScalingEvent> scalingEvents);

    Map<ClusterId, List<Cluster.ScalingEvent>> scalingEvents(Instant from, Instant to, DeploymentId deploymentId);

    Set<YearMonth> getMonthsWithSnapshotsForTenant(TenantName tenantName);

    List<ResourceSnapshot> getRawSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth);

    Set<TenantName> getTenants();

    Instant getOldestSnapshotTimestamp(Set<DeploymentId> deployments);

    default List<ResourceUsage> getResourceSnapshotsForMonth(TenantName tenantName, YearMonth month) {
        return getResourceSnapshotsForPeriod(tenantName, getMonthStartTimeStamp(month), getMonthEndTimeStamp(month));
    }

    private long getMonthStartTimeStamp(YearMonth month) {
        LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1);
        return startOfMonth.atStartOfDay(java.time.ZoneId.of("UTC"))
                .toInstant()
                .toEpochMilli();
    }
    private long getMonthEndTimeStamp(YearMonth month) {
        LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1);
        return startOfMonth.plus(1, ChronoUnit.MONTHS)
                .atStartOfDay(java.time.ZoneId.of("UTC"))
                .toInstant()
                .toEpochMilli();
    }

}