From 7f0b02ec8e4e6cad99560073963338ddf6746e90 Mon Sep 17 00:00:00 2001 From: Ola Aunrønning Date: Thu, 17 Oct 2019 10:41:15 +0200 Subject: Added TenantCost --- .../api/integration/ServiceRegistry.java | 3 + .../api/integration/resource/CostInfo.java | 67 ++++++++++++++++++++++ .../api/integration/resource/MeteringClient.java | 6 +- .../api/integration/resource/MockTenantCost.java | 37 ++++++++++++ .../api/integration/resource/TenantCost.java | 19 ++++++ .../api/integration/stubs/MockMeteringClient.java | 4 +- 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java (limited to 'controller-api') 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..ed63b1608ca --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostInfo.java @@ -0,0 +1,67 @@ +// 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; + +/** + * @author olaa + */ +public class CostInfo { + + private final ApplicationId applicationId; + private final ZoneId zoneId; + private final double cpuHours; + private final double memoryHours; + private final double diskHours; + private final int cpuCost; + private final int memoryCost; + private final int diskCost; + + + public CostInfo(ApplicationId applicationId, ZoneId zoneId, + double cpuHours, double memoryHours, double 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 double getCpuHours() { + return cpuHours; + } + + public double getMemoryHours() { + return memoryHours; + } + + public double 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 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 monthsOfMetering = Collections.emptySet(); + private List costInfoList = Collections.emptyList(); + + @Override + public Set monthsWithMetering(TenantName tenantName) { + return monthsOfMetering; + } + + @Override + public List getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + return costInfoList; + } + + public void setMonthsWithMetering(Set monthsOfMetering) { + this.monthsOfMetering = monthsOfMetering; + } + + public void setCostInfoList(List 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..f9b7aaabcdc --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java @@ -0,0 +1,19 @@ +// 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.List; +import java.util.Set; + +/** + * @author olaa + */ +public interface TenantCost { + + Set monthsWithMetering(TenantName tenantName); + + List getTenantCostOfMonth(TenantName tenantName, YearMonth month); +} 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()); -- cgit v1.2.3