diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2020-04-30 14:50:28 +0200 |
---|---|---|
committer | Ola Aunrønning <olaa@verizonmedia.com> | 2020-04-30 14:50:28 +0200 |
commit | 7f24d22ab4317f0e5313c247ed19abc6740a4019 (patch) | |
tree | acdb70afdafc5f449e1df9db45b4f40f6fc2ae6b /controller-api | |
parent | a5e6a9170120c5efa9dd620d35eba5377581fbb1 (diff) |
Allow getting tenant cost of any period
Diffstat (limited to 'controller-api')
2 files changed, 23 insertions, 3 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java index 784f97d5296..fa3d28fe50c 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java @@ -22,7 +22,7 @@ public class MockTenantCost implements TenantCost { } @Override - public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp) { return costInfoList; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java index b0f8ca757b4..a2a91454366 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java @@ -3,7 +3,9 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.TenantName; +import java.time.LocalDate; import java.time.YearMonth; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; import java.util.Set; @@ -15,7 +17,11 @@ public interface TenantCost { Set<YearMonth> monthsWithMetering(TenantName tenantName); - List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month); + List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp); + + default List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + return getTenantCostOfPeriod(tenantName, getMonthStartTimeStamp(month), getMonthEndTimeStamp(month)); + } static TenantCost empty() { return new TenantCost() { @@ -25,9 +31,23 @@ public interface TenantCost { } @Override - public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTime, long endTime) { return Collections.emptyList(); } }; } + + 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(); + } } |