diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-10-20 11:20:40 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-10-22 15:13:13 +0200 |
commit | dd6fde6bfd38f24b6fff64f0eb81bb834f109adb (patch) | |
tree | 43984e9e1546e13db2d9aa396bc370034916f214 /node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications | |
parent | aae6832c3aa905f063a9892ba7f799f0e7404d5a (diff) |
Store scaling events in ZooKeeper
Diffstat (limited to 'node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications')
4 files changed, 83 insertions, 11 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java index e9e91910281..fd92b5b0ca0 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java @@ -5,6 +5,7 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterResources; import com.yahoo.config.provision.ClusterSpec; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.HashMap; import java.util.Optional; @@ -56,7 +57,7 @@ public class Application { public Application withCluster(ClusterSpec.Id id, boolean exclusive, ClusterResources min, ClusterResources max) { Cluster cluster = clusters.get(id); if (cluster == null) - cluster = new Cluster(id, exclusive, min, max, Optional.empty(), Optional.empty()); + cluster = new Cluster(id, exclusive, min, max, Optional.empty(), Optional.empty(), List.of()); else cluster = cluster.withConfiguration(exclusive, min, max); return with(cluster); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Applications.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Applications.java index 9f45839f1c3..9db28652d0e 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Applications.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Applications.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.provision.applications; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ApplicationTransaction; import com.yahoo.config.provision.ProvisionLock; import com.yahoo.transaction.Mutex; import com.yahoo.transaction.NestedTransaction; @@ -42,17 +43,16 @@ public class Applications { // TODO: Require ProvisionLock instead of Mutex public void put(Application application, Mutex applicationLock) { NestedTransaction transaction = new NestedTransaction(); - put(application, transaction, applicationLock); + db.writeApplication(application, transaction); transaction.commit(); } - // TODO: Require ProvisionLock instead of Mutex - public void put(Application application, NestedTransaction transaction, Mutex applicationLock) { - db.writeApplication(application, transaction); + public void put(Application application, ApplicationTransaction transaction) { + db.writeApplication(application, transaction.nested()); } - public void remove(ApplicationId application, NestedTransaction transaction, @SuppressWarnings("unused") ProvisionLock lock) { - db.deleteApplication(application, transaction); + public void remove(ApplicationTransaction transaction) { + db.deleteApplication(transaction); } } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Cluster.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Cluster.java index 3aae47a9088..a17ee081447 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Cluster.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Cluster.java @@ -6,6 +6,7 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.lb.LoadBalancer; +import java.util.List; import java.util.Objects; import java.util.Optional; @@ -23,13 +24,15 @@ public class Cluster { private final ClusterResources min, max; private final Optional<ClusterResources> suggested; private final Optional<ClusterResources> target; + private final List<ScalingEvent> scalingEvents; public Cluster(ClusterSpec.Id id, boolean exclusive, ClusterResources minResources, ClusterResources maxResources, Optional<ClusterResources> suggestedResources, - Optional<ClusterResources> targetResources) { + Optional<ClusterResources> targetResources, + List<ScalingEvent> scalingEvents) { this.id = Objects.requireNonNull(id); this.exclusive = exclusive; this.min = Objects.requireNonNull(minResources); @@ -40,6 +43,7 @@ public class Cluster { this.target = Optional.empty(); else this.target = targetResources; + this.scalingEvents = scalingEvents; } public ClusterSpec.Id id() { return id; } @@ -66,16 +70,24 @@ public class Cluster { */ public Optional<ClusterResources> suggestedResources() { return suggested; } + /** Returns the recent scaling events in this cluster */ + public List<ScalingEvent> scalingEvents() { return scalingEvents; } + public Cluster withConfiguration(boolean exclusive, ClusterResources min, ClusterResources max) { - return new Cluster(id, exclusive, min, max, suggested, target); + return new Cluster(id, exclusive, min, max, suggested, target, scalingEvents); } public Cluster withSuggested(Optional<ClusterResources> suggested) { - return new Cluster(id, exclusive, min, max, suggested, target); + return new Cluster(id, exclusive, min, max, suggested, target, scalingEvents); } public Cluster withTarget(Optional<ClusterResources> target) { - return new Cluster(id, exclusive, min, max, suggested, target); + return new Cluster(id, exclusive, min, max, suggested, target, scalingEvents); + } + + public Cluster with(ScalingEvent scalingEvent) { + // NOTE: We're just storing the latest scaling event so far + return new Cluster(id, exclusive, min, max, suggested, target, List.of(scalingEvent)); } @Override diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/ScalingEvent.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/ScalingEvent.java new file mode 100644 index 00000000000..68e65d10d69 --- /dev/null +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/ScalingEvent.java @@ -0,0 +1,59 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.provision.applications; + +import com.yahoo.config.provision.ClusterResources; + +import java.time.Instant; +import java.util.Objects; + +/** + * A recording of a change in resources for an application cluster + * + * @author bratseth + */ +public class ScalingEvent { + + private final ClusterResources from, to; + private final long generation; + private final Instant at; + + public ScalingEvent(ClusterResources from, ClusterResources to, long generation, Instant at) { + this.from = from; + this.to = to; + this.generation = generation; + this.at = at; + } + + /** Returns the resources we changed from */ + public ClusterResources from() { return from; } + + /** Returns the resources we changed to */ + public ClusterResources to() { return to; } + + /** Returns the application config generation resulting from this deployment */ + public long generation() { return generation; } + + /** Returns the time of this deployment */ + public Instant at() { return at; } + + @Override + public int hashCode() { return Objects.hash(from, to, generation, at); } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if ( ! (o instanceof ScalingEvent)) return true; + ScalingEvent other = (ScalingEvent)o; + if ( other.generation != this.generation) return false; + if ( ! other.at.equals(this.at)) return false; + if ( ! other.from.equals(this.from)) return false; + if ( ! other.to.equals(this.to)) return false; + return true; + } + + @Override + public String toString() { + return "scaling event from " + from + " to " + to + ", generation " + generation + " at " + at; + } + +} |