aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@yahooinc.com>2022-06-15 13:38:25 +0200
committerØyvind Grønnesby <oyving@yahooinc.com>2022-06-15 14:18:13 +0200
commitd24217c7bbe0f0b297fbd87cb2e3b7f0e0d3b12c (patch)
treeb9816465a7f91f026b9675648662d1df8e09c772 /controller-api/src
parent82cc6b485145067f281a2cf68a0e823b8cde6e13 (diff)
Implement persisting and retrieval of scaling events
Diffstat (limited to 'controller-api/src')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java49
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java23
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClient.java10
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceDatabaseClientMock.java14
4 files changed, 95 insertions, 1 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java
new file mode 100644
index 00000000000..0565a916dfa
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/ClusterId.java
@@ -0,0 +1,49 @@
+package com.yahoo.vespa.hosted.controller.api.identifiers;
+
+import com.yahoo.config.provision.ClusterSpec;
+
+import java.util.Objects;
+
+/**
+ * DeploymentId x ClusterSpec.Id = ClusterId
+ *
+ * @author ogronnesby
+ */
+public class ClusterId {
+ private final DeploymentId deploymentId;
+ private final ClusterSpec.Id clusterId;
+
+ public ClusterId(DeploymentId deploymentId, ClusterSpec.Id clusterId) {
+ this.deploymentId = deploymentId;
+ this.clusterId = clusterId;
+ }
+
+ public DeploymentId deploymentId() {
+ return deploymentId;
+ }
+
+ public ClusterSpec.Id clusterId() {
+ return clusterId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ClusterId clusterId1 = (ClusterId) o;
+ return Objects.equals(deploymentId, clusterId1.deploymentId) && Objects.equals(clusterId, clusterId1.clusterId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(deploymentId, clusterId);
+ }
+
+ @Override
+ public String toString() {
+ return "ClusterId{" +
+ "deploymentId=" + deploymentId +
+ ", clusterId=" + clusterId +
+ '}';
+ }
+}
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 6e60ec76199..b500cd1c133 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
@@ -7,6 +7,7 @@ import com.yahoo.config.provision.ClusterSpec;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
/**
@@ -131,6 +132,28 @@ public class Cluster {
public Instant at() { return at; }
public Optional<Instant> completion() { return completion; }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ScalingEvent that = (ScalingEvent) o;
+ return Objects.equals(from, that.from) && Objects.equals(to, that.to) && Objects.equals(at, that.at) && Objects.equals(completion, that.completion);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(from, to, at, completion);
+ }
+
+ @Override
+ public String toString() {
+ return "ScalingEvent{" +
+ "from=" + from +
+ ", to=" + to +
+ ", at=" + at +
+ ", completion=" + completion +
+ '}';
+ }
}
}
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 8ae12c0e7ac..2e281b1759b 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,14 +1,18 @@
// 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.ApplicationId;
import com.yahoo.config.provision.TenantName;
+import com.yahoo.vespa.hosted.controller.api.identifiers.ClusterId;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
/**
@@ -22,6 +26,10 @@ public interface ResourceDatabaseClient {
void refreshMaterializedView();
+ void writeScalingEvents(ClusterId clusterId, Collection<Cluster.ScalingEvent> scalingEvents);
+
+ List<Cluster.ScalingEvent> scalingEvents(Instant from, Instant to, Optional<ApplicationId> application);
+
Set<YearMonth> getMonthsWithSnapshotsForTenant(TenantName tenantName);
List<ResourceSnapshot> getRawSnapshotHistoryForTenant(TenantName tenantName, YearMonth yearMonth);
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 e9bfc4fe78c..e2003e24332 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,9 +1,12 @@
// 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.TenantName;
+import com.yahoo.vespa.hosted.controller.api.identifiers.ClusterId;
import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan;
import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanRegistry;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
import java.math.BigDecimal;
import java.time.Duration;
@@ -30,6 +33,7 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
PlanRegistry planRegistry;
Map<TenantName, Plan> planMap = new HashMap<>();
List<ResourceSnapshot> resourceSnapshots = new ArrayList<>();
+ Map<ClusterId, List<Cluster.ScalingEvent>> scalingEvents = new HashMap<>();
private boolean hasRefreshedMaterializedView = false;
public ResourceDatabaseClientMock(PlanRegistry planRegistry) {
@@ -121,6 +125,16 @@ public class ResourceDatabaseClientMock implements ResourceDatabaseClient {
hasRefreshedMaterializedView = true;
}
+ @Override
+ public void writeScalingEvents(ClusterId clusterId, Collection<Cluster.ScalingEvent> scalingEvents) {
+ this.scalingEvents.put(clusterId, List.copyOf(scalingEvents));
+ }
+
+ @Override
+ public List<Cluster.ScalingEvent> scalingEvents(Instant from, Instant to, Optional<ApplicationId> application) {
+ return List.of();
+ }
+
public void setPlan(TenantName tenant, Plan plan) {
planMap.put(tenant, plan);
}