From 93f51338fc01090e84aa0126f9671979255350b1 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 30 Jan 2023 13:37:46 +0100 Subject: Serialize groupSize if set --- .../java/com/yahoo/config/provision/IntRange.java | 1 + .../api/integration/configserver/Cluster.java | 6 +++++ .../integration/noderepository/ClusterData.java | 5 ++++ .../integration/noderepository/IntRangeData.java | 29 ++++++++++++++++++++++ .../restapi/application/ApplicationApiHandler.java | 8 ++++++ .../controller/integration/ConfigServerMock.java | 2 ++ .../responses/application-clusters.json | 3 +++ 7 files changed, 54 insertions(+) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/IntRangeData.java diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/IntRange.java b/config-provisioning/src/main/java/com/yahoo/config/provision/IntRange.java index 4a2a472a1ad..f24e86c96ef 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/IntRange.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/IntRange.java @@ -27,6 +27,7 @@ public class IntRange { /** Returns the maximum value which is in this range, or empty if it is open upwards. */ public OptionalInt to() { return to; } + /** Returns true if both from and to is open (not present). */ public boolean isEmpty() { return from.isEmpty() && to.isEmpty(); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java index b7a71cc7b91..788c1ea878b 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.configserver; import com.yahoo.config.provision.ClusterResources; import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.IntRange; import java.time.Duration; import java.time.Instant; @@ -19,6 +20,7 @@ public class Cluster { private final ClusterSpec.Type type; private final ClusterResources min; private final ClusterResources max; + private final IntRange groupSize; private final ClusterResources current; private final Autoscaling target; private final Autoscaling suggested; @@ -29,6 +31,7 @@ public class Cluster { ClusterSpec.Type type, ClusterResources min, ClusterResources max, + IntRange groupSize, ClusterResources current, Autoscaling target, Autoscaling suggested, @@ -38,6 +41,7 @@ public class Cluster { this.type = type; this.min = min; this.max = max; + this.groupSize = groupSize; this.current = current; this.target = target; this.suggested = suggested; @@ -53,6 +57,8 @@ public class Cluster { public ClusterResources max() { return max; } + public IntRange groupSize() { return groupSize; } + public ClusterResources current() { return current; } public Autoscaling target() { return target; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java index 539f0545c88..324836ccb93 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/ClusterData.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.IntRange; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster; import java.time.Duration; @@ -28,6 +29,9 @@ public class ClusterData { @JsonProperty("max") public ClusterResourcesData max; + @JsonProperty("groupSize") + public IntRangeData groupSize; + @JsonProperty("current") public ClusterResourcesData current; @@ -48,6 +52,7 @@ public class ClusterData { ClusterSpec.Type.from(type), min.toClusterResources(), max.toClusterResources(), + groupSize == null ? IntRange.empty() : groupSize.toRange(), current.toClusterResources(), target == null ? Cluster.Autoscaling.empty() : target.toAutoscaling(), suggested == null ? Cluster.Autoscaling.empty() : suggested.toAutoscaling(), diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/IntRangeData.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/IntRangeData.java new file mode 100644 index 00000000000..7d31448a756 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/IntRangeData.java @@ -0,0 +1,29 @@ +// 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.noderepository; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.yahoo.config.provision.IntRange; + +import java.util.OptionalInt; + +/** + * @author bratseth + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class IntRangeData { + + @JsonProperty("from") + public Integer from; + + @JsonProperty("to") + public Integer to; + + public IntRange toRange() { + return new IntRange(from == null ? OptionalInt.empty() : OptionalInt.of(from), + to == null ? OptionalInt.empty() : OptionalInt.of(to)); + } + +} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 8876cee5550..9407aa0ae74 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -22,6 +22,7 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.IntRange; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.ZoneEndpoint.AllowedUrn; @@ -1359,6 +1360,8 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { clusterObject.setString("type", cluster.type().name()); toSlime(cluster.min(), clusterObject.setObject("min")); toSlime(cluster.max(), clusterObject.setObject("max")); + if ( ! cluster.groupSize().isEmpty()) + toSlime(cluster.groupSize(), clusterObject.setObject("groupSize")); toSlime(cluster.current(), clusterObject.setObject("current")); toSlime(cluster.target(), clusterObject.setObject("target")); toSlime(cluster.suggested(), clusterObject.setObject("suggested")); @@ -2725,6 +2728,11 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { object.setDouble("cost", cost); } + private void toSlime(IntRange range, Cursor object) { + range.from().ifPresent(from -> object.setLong("from", from)); + range.to().ifPresent(to -> object.setLong("to", to)); + } + private void toSlime(Cluster.Autoscaling autoscaling, Cursor autoscalingObject) { autoscalingObject.setString("status", autoscaling.status()); autoscalingObject.setString("description", autoscaling.description()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java index 6f859ff3d15..aa31574859b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ConfigServerMock.java @@ -14,6 +14,7 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.DockerImage; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.IntRange; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.ZoneEndpoint.AllowedUrn; @@ -117,6 +118,7 @@ public class ConfigServerMock extends AbstractComponent implements ConfigServer ClusterSpec.Type.container, new ClusterResources(2, 1, new NodeResources(1, 4, 20, 1, slow, remote)), new ClusterResources(2, 1, new NodeResources(4, 16, 90, 1, slow, remote)), + IntRange.to(3), current, new Cluster.Autoscaling("ideal", "Cluster is ideally scaled", diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json index b5ae4efd752..eb4c3294fe0 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/application-clusters.json @@ -28,6 +28,9 @@ }, "cost": 0.43 }, + "groupSize": { + "to": 3 + }, "current": { "nodes": 2, "groups": 1, -- cgit v1.2.3