diff options
author | Øyvind Grønnesby <oyving@yahooinc.com> | 2023-02-23 14:06:25 +0100 |
---|---|---|
committer | Øyvind Grønnesby <oyving@yahooinc.com> | 2023-02-23 14:06:25 +0100 |
commit | 3204ecd71bed82fe25bbc50688aa5516b55b989a (patch) | |
tree | e54110634e6350584674d3bb80881277e3359407 /controller-api | |
parent | 88a602d98d87475d1fb3757ae93295e84b936ee5 (diff) |
Use ResourceAllocation less. NodeResources does the job
Diffstat (limited to 'controller-api')
3 files changed, 24 insertions, 82 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java deleted file mode 100644 index 59ea8440701..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MeteringData.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Yahoo. 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 java.util.List; -import java.util.Map; - -/** - * @author olaa - */ -public class MeteringData { - - private final ResourceAllocation thisMonth; - private final ResourceAllocation lastMonth; - private final ResourceAllocation currentSnapshot; - Map<ApplicationId, List<ResourceSnapshot>> snapshotHistory; - - public MeteringData(ResourceAllocation thisMonth, ResourceAllocation lastMonth, ResourceAllocation currentSnapshot, Map<ApplicationId, List<ResourceSnapshot>> snapshotHistory) { - this.thisMonth = thisMonth; - this.lastMonth = lastMonth; - this.currentSnapshot = currentSnapshot; - this.snapshotHistory = snapshotHistory; - } - - public ResourceAllocation getThisMonth() { - return thisMonth; - } - - public ResourceAllocation getLastMonth() { - return lastMonth; - } - - public ResourceAllocation getCurrentSnapshot() { - return currentSnapshot; - } - - public Map<ApplicationId, List<ResourceSnapshot>> getSnapshotHistory() { - return snapshotHistory; - } - -} 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 d04d400d36f..c1d210e990d 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 @@ -78,11 +78,11 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { a.getApplicationId(), a.getZoneId(), plan, - a.getArchitecture(), + a.resources().architecture(), a.getVersion().getMajor(), - BigDecimal.valueOf(a.getCpuCores()).multiply(d), - BigDecimal.valueOf(a.getMemoryGb()).multiply(d), - BigDecimal.valueOf(a.getDiskGb()).multiply(d) + BigDecimal.valueOf(a.resources().vcpu()).multiply(d), + BigDecimal.valueOf(a.resources().memoryGb()).multiply(d), + BigDecimal.valueOf(a.resources().diskGb()).multiply(d) ); }) .toList(); @@ -114,7 +114,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient { .filter(snapshot -> snapshot.getTimestamp().isBefore(Instant.ofEpochMilli(end))) .filter(snapshot -> snapshot.getApplicationId().tenant().equals(tenantName)) .collect(Collectors.groupingBy( - usage -> Objects.hash(usage.getApplicationId(), usage.getZoneId(), tenantPlan.id().value(), usage.getArchitecture(), usage.getVersion().getMajor()) + usage -> Objects.hash(usage.getApplicationId(), usage.getZoneId(), tenantPlan.id().value(), usage.resources().architecture(), usage.getVersion().getMajor()) )) .values().stream() .map(snapshots -> resourceUsageFromSnapshots(tenantPlan, snapshots)) 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 4ff79706683..4a849b831b7 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 @@ -21,21 +21,21 @@ import java.util.stream.Collectors; public class ResourceSnapshot { private final ApplicationId applicationId; - private final ResourceAllocation resourceAllocation; + private final NodeResources resources; private final Instant timestamp; private final ZoneId zoneId; private final Version version; - public ResourceSnapshot(ApplicationId applicationId, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId, Version version) { + public ResourceSnapshot(ApplicationId applicationId, NodeResources resources, Instant timestamp, ZoneId zoneId, Version version) { this.applicationId = applicationId; - this.resourceAllocation = new ResourceAllocation(cpuCores, memoryGb, diskGb, architecture); + this.resources = resources; this.timestamp = timestamp; this.zoneId = zoneId; this.version = version; } - public static ResourceSnapshot from(ApplicationId applicationId, int nodes, double cpuCores, double memoryGb, double diskGb, NodeResources.Architecture architecture, Instant timestamp, ZoneId zoneId) { - return new ResourceSnapshot(applicationId, cpuCores * nodes, memoryGb * nodes, diskGb * nodes, architecture, timestamp, zoneId, Version.emptyVersion); + public static ResourceSnapshot from(ApplicationId applicationId, int nodes, NodeResources resources, Instant timestamp, ZoneId zoneId) { + return new ResourceSnapshot(applicationId, resources.multipliedBy(nodes), timestamp, zoneId, Version.emptyVersion); } public static ResourceSnapshot from(List<Node> nodes, Instant timestamp, ZoneId zoneId) { @@ -44,38 +44,26 @@ public class ResourceSnapshot { .map(node -> node.owner().get()) .collect(Collectors.toSet()); + Set<Version> versions = nodes.stream() + .map(Node::currentVersion) + .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 resources = nodes.stream() + .map(Node::resources) + .reduce(NodeResources.zero(), NodeResources::add); - return new ResourceSnapshot( - applicationIds.iterator().next(), - nodes.stream().map(Node::resources).mapToDouble(NodeResources::vcpu).sum(), - nodes.stream().map(Node::resources).mapToDouble(NodeResources::memoryGb).sum(), - nodes.stream().map(Node::resources).mapToDouble(NodeResources::diskGb).sum(), - nodes.stream().map(node -> node.resources().architecture()).findFirst().orElse(NodeResources.Architecture.getDefault()), - timestamp, - zoneId, - nodes.stream().map(Node::currentVersion).min(Version::compareTo).orElse(Version.emptyVersion) - ); + return new ResourceSnapshot(applicationIds.iterator().next(), resources, timestamp, zoneId, versions.iterator().next()); } public ApplicationId getApplicationId() { return applicationId; } - public ResourceAllocation allocation() { - return resourceAllocation; - } - - public double getCpuCores() { - return resourceAllocation.getCpuCores(); - } - - public double getMemoryGb() { - return resourceAllocation.getMemoryGb(); - } - - public double getDiskGb() { - return resourceAllocation.getDiskGb(); + public NodeResources resources() { + return resources; } public Instant getTimestamp() { @@ -90,10 +78,6 @@ public class ResourceSnapshot { return version; } - public NodeResources.Architecture getArchitecture() { - return resourceAllocation.getArchitecture(); - } - @Override public boolean equals(Object o) { if (this == o) return true; @@ -101,7 +85,7 @@ public class ResourceSnapshot { ResourceSnapshot other = (ResourceSnapshot) o; return this.applicationId.equals(other.applicationId) && - this.resourceAllocation.equals(other.resourceAllocation) && + this.resources.equals(other.resources) && this.timestamp.equals(other.timestamp) && this.zoneId.equals(other.zoneId) && this.version.equals(other.version); @@ -109,6 +93,6 @@ public class ResourceSnapshot { @Override public int hashCode(){ - return Objects.hash(applicationId, resourceAllocation, timestamp, zoneId, version); + return Objects.hash(applicationId, resources, timestamp, zoneId, version); } } |