diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2019-10-23 10:02:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-23 10:02:31 +0200 |
commit | 4296052d01bec2d87021cb352cdd1c64377b3ee6 (patch) | |
tree | 72fb38984070b1bc9de6be06183bd211740d73a1 /controller-api | |
parent | 3b70a26194dd1856c4d9ee4b87c979d5f22198c4 (diff) | |
parent | a2ac8ec8bae6fb2889e36fcbedbdf712bf68df67 (diff) |
Merge pull request #11002 from vespa-engine/olaa/tenant-cost
Added TenantCost
Diffstat (limited to 'controller-api')
6 files changed, 150 insertions, 3 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java index f545cb8ff47..dec5d9264a7 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java @@ -17,6 +17,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.Mailer; import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues; import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient; +import com.yahoo.vespa.hosted.controller.api.integration.resource.TenantCost; import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService; import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator; @@ -70,4 +71,6 @@ public interface ServiceRegistry { // TODO: No longer used. Remove this once untangled from test code BuildService buildService(); + TenantCost tenantCost(); + } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java new file mode 100644 index 00000000000..50c257acd23 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java @@ -0,0 +1,69 @@ +// 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.zone.ZoneId; + +import java.math.BigDecimal; + +/** + * @author olaa + */ +public class CostInfo { + + private final ApplicationId applicationId; + private final ZoneId zoneId; + private final BigDecimal cpuHours; + private final BigDecimal memoryHours; + private final BigDecimal diskHours; + private final int cpuCost; + private final int memoryCost; + private final int diskCost; + + + public CostInfo(ApplicationId applicationId, ZoneId zoneId, + BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, + int cpuCost, int memoryCost, int diskCost) { + this.applicationId = applicationId; + this.zoneId = zoneId; + this.cpuHours = cpuHours; + this.memoryHours = memoryHours; + this.diskHours = diskHours; + this.cpuCost = cpuCost; + this.memoryCost = memoryCost; + this.diskCost = diskCost; + } + + public ApplicationId getApplicationId() { + return applicationId; + } + + public ZoneId getZoneId() { + return zoneId; + } + + public BigDecimal getCpuHours() { + return cpuHours; + } + + public BigDecimal getMemoryHours() { + return memoryHours; + } + + public BigDecimal getDiskHours() { + return diskHours; + } + + public int getCpuCost() { + return cpuCost; + } + + public int getMemoryCost() { + return memoryCost; + } + + public int getDiskCost() { + return diskCost; + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java index 632dbaad419..3e06b24c6be 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringClient.java @@ -1,8 +1,10 @@ // 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.ApplicationName; +import com.yahoo.config.provision.TenantName; + import java.util.Collection; -import java.util.List; /** * Consumes and retrieves snapshots of resources allocated per application. @@ -13,6 +15,6 @@ public interface MeteringClient { void consume(Collection<ResourceSnapshot> resources); - MeteringInfo getResourceSnapshots(String tenantName, String applicationName); + MeteringInfo getResourceSnapshots(TenantName tenantName, ApplicationName applicationName); } 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 new file mode 100644 index 00000000000..03ba44e04c7 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java @@ -0,0 +1,37 @@ +// 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.TenantName; + +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * @author olaa + */ +public class MockTenantCost implements TenantCost { + + private Set<YearMonth> monthsOfMetering = Collections.emptySet(); + private List<CostInfo> costInfoList = Collections.emptyList(); + + @Override + public Set<YearMonth> monthsWithMetering(TenantName tenantName) { + return monthsOfMetering; + } + + @Override + public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + return costInfoList; + } + + public void setMonthsWithMetering(Set<YearMonth> monthsOfMetering) { + this.monthsOfMetering = monthsOfMetering; + } + + public void setCostInfoList(List<CostInfo> costInfoList) { + this.costInfoList = 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 new file mode 100644 index 00000000000..b4ca0cd7076 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java @@ -0,0 +1,34 @@ +// 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.TenantName; + +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * @author olaa + */ +public interface TenantCost { + + Set<YearMonth> monthsWithMetering(TenantName tenantName); + + List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month); + + static TenantCost empty() { + return new TenantCost() { + @Override + public Set<YearMonth> monthsWithMetering(TenantName tenantName) { + return Collections.emptySet(); + } + + @Override + public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + return Collections.emptyList(); + } + }; + } +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java index 10e1eb39c8a..45ead36f622 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockMeteringClient.java @@ -1,6 +1,8 @@ // 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.MeteringInfo; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot; @@ -26,7 +28,7 @@ public class MockMeteringClient implements MeteringClient { } @Override - public MeteringInfo getResourceSnapshots(String tenantName, String applicationName) { + public MeteringInfo getResourceSnapshots(TenantName tenantName, ApplicationName applicationName) { return meteringInfo.orElseGet(() -> { ResourceAllocation emptyAllocation = new ResourceAllocation(0, 0, 0); return new MeteringInfo(emptyAllocation, emptyAllocation, emptyAllocation, Collections.emptyMap()); |