diff options
Diffstat (limited to 'controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource')
9 files changed, 55 insertions, 24 deletions
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 index a05d8c9d52b..0dcfb2d9823 100644 --- 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 @@ -1,7 +1,8 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.CloudAccount; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; @@ -24,11 +25,14 @@ public class CostInfo { private final BigDecimal gpuCost; private final NodeResources.Architecture architecture; private final int majorVersion; + private final CloudAccount cloudAccount; public CostInfo(ApplicationId applicationId, ZoneId zoneId, BigDecimal cpuHours, BigDecimal memoryHours, BigDecimal diskHours, BigDecimal gpuHours, - BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, BigDecimal gpuCost, NodeResources.Architecture architecture, int majorVersion) { + BigDecimal cpuCost, BigDecimal memoryCost, BigDecimal diskCost, BigDecimal gpuCost, NodeResources.Architecture architecture, + int majorVersion, CloudAccount cloudAccount) + { this.applicationId = applicationId; this.zoneId = zoneId; this.cpuHours = cpuHours; @@ -41,6 +45,7 @@ public class CostInfo { this.gpuCost = gpuCost; this.architecture = architecture; this.majorVersion = majorVersion; + this.cloudAccount = cloudAccount; } public ApplicationId getApplicationId() { @@ -95,4 +100,7 @@ public class CostInfo { return majorVersion; } + public CloudAccount getCloudAccount() { + return cloudAccount; + } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumer.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumer.java index b5927b40324..8de327fdd88 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumer.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumer.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.vespa.hosted.controller.api.identifiers.Property; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumerMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumerMock.java index 40637065f7e..2c15d23d03f 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumerMock.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/CostReportConsumerMock.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.vespa.hosted.controller.api.identifiers.Property; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java index 8191540e898..3443d9b2f3f 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.NodeResources; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java index 49a24296fd3..38c6ed767fa 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java @@ -1,4 +1,4 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java index 570ca87e538..81dfdf4656c 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java @@ -1,4 +1,4 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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; @@ -80,6 +80,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { plan, a.resources().architecture(), a.getMajorVersion(), + a.getAccount(), BigDecimal.valueOf(a.resources().vcpu()).multiply(d), BigDecimal.valueOf(a.resources().memoryGb()).multiply(d), BigDecimal.valueOf(a.resources().diskGb()).multiply(d), @@ -93,12 +94,14 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { assert a.getZoneId().equals(b.getZoneId()); assert a.getPlan().equals(b.getPlan()); assert a.getArchitecture().equals(b.getArchitecture()); + assert a.getCloudAccount().equals(b.getCloudAccount()); return new ResourceUsage( a.getApplicationId(), a.getZoneId(), a.getPlan(), a.getArchitecture(), a.getMajorVersion(), + a.getCloudAccount(), a.getCpuMillis().add(b.getCpuMillis()), a.getMemoryMillis().add(b.getMemoryMillis()), a.getDiskMillis().add(b.getDiskMillis()), diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java index b3a91767465..dc14a043183 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java @@ -1,16 +1,16 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.component.Version; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.CloudAccount; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node; import java.time.Instant; +import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.Set; import java.util.stream.Collectors; /** @@ -32,37 +32,40 @@ public class ResourceSnapshot { private final Instant timestamp; private final ZoneId zoneId; private final int majorVersion; + private final CloudAccount account; - public ResourceSnapshot(ApplicationId applicationId, NodeResources resources, Instant timestamp, ZoneId zoneId, int majorVersion) { + public ResourceSnapshot(ApplicationId applicationId, NodeResources resources, Instant timestamp, ZoneId zoneId, int majorVersion, CloudAccount account) { this.applicationId = applicationId; this.resources = resources; this.timestamp = timestamp; this.zoneId = zoneId; this.majorVersion = majorVersion; + this.account = account; } public static ResourceSnapshot from(ApplicationId applicationId, int nodes, NodeResources resources, Instant timestamp, ZoneId zoneId) { - return new ResourceSnapshot(applicationId, resources.multipliedBy(nodes), timestamp, zoneId, 0); + return new ResourceSnapshot(applicationId, resources.multipliedBy(nodes), timestamp, zoneId, 0, CloudAccount.empty); } public static ResourceSnapshot from(List<Node> nodes, Instant timestamp, ZoneId zoneId) { - Set<ApplicationId> applicationIds = nodes.stream() - .filter(node -> node.owner().isPresent()) - .map(node -> node.owner().get()) - .collect(Collectors.toSet()); + var application = exactlyOne("application", nodes.stream() + .filter(node -> node.owner().isPresent()) + .map(node -> node.owner().get()) + .collect(Collectors.toSet())); - Set<Integer> versions = nodes.stream() + var version = exactlyOne("version", nodes.stream() .map(n -> n.wantedVersion().getMajor()) - .collect(Collectors.toSet()); + .collect(Collectors.toSet())); - if (applicationIds.size() != 1) throw new IllegalArgumentException("List of nodes can only represent one application"); - if (versions.size() != 1) throw new IllegalArgumentException("List of nodes can only represent one version"); + var account = exactlyOne("account", nodes.stream() + .map(Node::cloudAccount) + .collect(Collectors.toSet())); var resources = nodes.stream() .map(Node::resources) .reduce(zero, ResourceSnapshot::addResources); - return new ResourceSnapshot(applicationIds.iterator().next(), resources, timestamp, zoneId, versions.iterator().next()); + return new ResourceSnapshot(application, resources, timestamp, zoneId, version, account); } public ApplicationId getApplicationId() { @@ -85,6 +88,10 @@ public class ResourceSnapshot { return majorVersion; } + public CloudAccount getAccount() { + return account; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -122,4 +129,9 @@ public class ResourceSnapshot { a.architecture() == NodeResources.Architecture.any ? b.architecture() : a.architecture(), a.gpuResources().plus(b.gpuResources())); } + + private static <T> T exactlyOne(String resource, Collection<T> collection) { + if (collection.size() != 1) throw new IllegalArgumentException("More than one '" + resource + "', was: " + collection.size()); + return collection.iterator().next(); + } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java index 0834cf52ec1..3cb611af8a0 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java @@ -1,8 +1,9 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. 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.component.Version; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.CloudAccount; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; @@ -20,9 +21,11 @@ public class ResourceUsage { private final BigDecimal gpuMillis; private final NodeResources.Architecture architecture; private final int majorVersion; + private final CloudAccount cloudAccount; public ResourceUsage(ApplicationId applicationId, ZoneId zoneId, Plan plan, NodeResources.Architecture architecture, - int majorVersion, BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis, BigDecimal gpuMillis) { + int majorVersion, CloudAccount cloudAccount, BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis, BigDecimal gpuMillis) + { this.applicationId = applicationId; this.zoneId = zoneId; this.cpuMillis = cpuMillis; @@ -32,6 +35,7 @@ public class ResourceUsage { this.plan = plan; this.architecture = architecture; this.majorVersion = majorVersion; + this.cloudAccount = cloudAccount; } public ApplicationId getApplicationId() { @@ -67,4 +71,8 @@ public class ResourceUsage { public NodeResources.Architecture getArchitecture() { return architecture; } + + public CloudAccount getCloudAccount(){ + return cloudAccount; + } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/package-info.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/package-info.java index 0d39059f449..127fcc4e5d3 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/package-info.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/package-info.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage package com.yahoo.vespa.hosted.controller.api.integration.resource; |