summaryrefslogtreecommitdiffstats
path: root/orchestrator/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@yahooinc.com>2023-08-01 11:23:57 +0200
committerHåkon Hallingstad <hakon@yahooinc.com>2023-08-01 11:23:57 +0200
commitad484e51eb9d86bb47288aa742ac06ad82f1a354 (patch)
tree1941a6053305935ee85aad1ae41219721cf64af5 /orchestrator/src/main/java/com/yahoo
parentf849e0010a6d5fe873990ca223472dc3947ffb83 (diff)
Make ClusterPolicyOverride available to ClusterApiImpl
Diffstat (limited to 'orchestrator/src/main/java/com/yahoo')
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java2
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java6
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterApiImpl.java5
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterPolicyOverride.java37
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java39
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java7
6 files changed, 88 insertions, 8 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java
index 49fab7522ba..20269951a1e 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java
@@ -84,6 +84,8 @@ public class OrchestratorImpl implements Orchestrator {
Clock.systemUTC(),
new ApplicationApiFactory(configServerConfig.zookeeperserver().size(),
orchestratorConfig.numProxies(),
+ orchestratorConfig.numProxiesAllowedDown(),
+ orchestratorConfig.numProxiesAllowedDownRatio(),
Clock.systemUTC()),
orchestratorConfig.serviceMonitorConvergenceLatencySeconds());
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java
index 0ad236c5a23..832b00f2294 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java
@@ -18,8 +18,10 @@ public class ApplicationApiFactory {
private final OrchestrationParams orchestrationParams;
private final Clock clock;
- public ApplicationApiFactory(int numberOfConfigServers, int numProxies, Clock clock) {
- this.orchestrationParams = HostedVespaOrchestration.create(numberOfConfigServers, numProxies);
+ public ApplicationApiFactory(int numberOfConfigServers, int numProxies, int numProxiesAllowedDown,
+ double numProxiesAllowedDownRatio, Clock clock) {
+ this.orchestrationParams = HostedVespaOrchestration.create(numberOfConfigServers, numProxies, numProxiesAllowedDown,
+ numProxiesAllowedDownRatio);
this.clock = clock;
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterApiImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterApiImpl.java
index 024a3bc58db..736b909a82f 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterApiImpl.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterApiImpl.java
@@ -41,6 +41,7 @@ class ClusterApiImpl implements ClusterApi {
private final Clock clock;
private final Set<ServiceInstance> servicesInGroup;
private final Set<ServiceInstance> servicesNotInGroup;
+ private final ClusterPolicyOverride clusterPolicyOverride;
/** Lazily initialized in servicesDownAndNotInGroup(), do not access directly. */
private Set<ServiceInstance> servicesDownAndNotInGroup = null;
@@ -71,6 +72,10 @@ class ClusterApiImpl implements ClusterApi {
this.hostInfos = hostInfos;
this.clusterControllerClientFactory = clusterControllerClientFactory;
this.clock = clock;
+ this.clusterPolicyOverride = new ClusterPolicyOverride(serviceCluster.serviceInstances().size(),
+ clusterParams.size(),
+ clusterParams.allowedDown(),
+ clusterParams.allowedDownRatio());
Map<Boolean, Set<ServiceInstance>> serviceInstancesByLocality =
serviceCluster.serviceInstances().stream()
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterPolicyOverride.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterPolicyOverride.java
new file mode 100644
index 00000000000..2bdfa1a6659
--- /dev/null
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ClusterPolicyOverride.java
@@ -0,0 +1,37 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.orchestrator.model;
+
+import java.util.OptionalDouble;
+import java.util.OptionalInt;
+
+/**
+ * @author hakonhall
+ */
+public record ClusterPolicyOverride(int deployedSize, OptionalInt expectedSize, OptionalInt allowedDown, OptionalDouble allowedDownRatio) {
+ public ClusterPolicyOverride {
+ if (deployedSize <= 0)
+ throw new IllegalArgumentException("deployedSize must be positive");
+
+ if (expectedSize.isPresent() && expectedSize.getAsInt() <= 0)
+ throw new IllegalArgumentException("expectedSize must be positive");
+
+ if (allowedDown.isPresent()) {
+ if (allowedDown.getAsInt() <= 0)
+ throw new IllegalArgumentException("allowedDown must be positive: " + allowedDown.getAsInt());
+ if (expectedSize.isPresent() && allowedDown.getAsInt() > expectedSize.getAsInt())
+ throw new IllegalArgumentException("allowedDown must be less than or equal to expectedSize (" + expectedSize.getAsInt() +
+ "): " + allowedDown.getAsInt());
+ }
+
+ if (allowedDownRatio.isPresent() && (allowedDownRatio.getAsDouble() < 0.0 || allowedDownRatio.getAsDouble() > 1.0))
+ throw new IllegalArgumentException("allowedDownRatio must be between 0.0 and 1.0: " + allowedDownRatio.getAsDouble());
+
+ }
+
+ public OptionalInt allowedDownPercentage() {
+ return allowedDownRatio.isPresent() ?
+ OptionalInt.of((int) Math.round(allowedDownRatio.getAsDouble() * 100.0)) :
+ OptionalInt.empty();
+ }
+
+}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java
index ab010da50ad..4048a27fda0 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java
@@ -2,6 +2,7 @@
package com.yahoo.vespa.orchestrator.policy;
import java.util.Objects;
+import java.util.OptionalDouble;
import java.util.OptionalInt;
/**
@@ -14,9 +15,13 @@ public class ClusterParams {
private static final ClusterParams DEFAULT = new ClusterParams.Builder().build();
private final int size;
+ private final int allowedDown;
+ private final double allowedDownRatio;
public static class Builder {
- private int size = 0;
+ private int size = -1;
+ private int allowedDown = -1;
+ private double allowedDownRatio = -1.0;
public Builder() {}
@@ -25,8 +30,18 @@ public class ClusterParams {
return this;
}
+ public Builder setAllowedDown(int allowedDown) {
+ this.allowedDown = allowedDown;
+ return this;
+ }
+
+ public Builder setAllowedDownRatio(double allowedDownRatio) {
+ this.allowedDownRatio = allowedDownRatio;
+ return this;
+ }
+
public ClusterParams build() {
- return new ClusterParams(size);
+ return new ClusterParams(size, allowedDown, allowedDownRatio);
}
}
@@ -34,8 +49,10 @@ public class ClusterParams {
return DEFAULT;
}
- private ClusterParams(int size) {
+ private ClusterParams(int size, int allowedDown, double allowedDownRatio) {
this.size = size;
+ this.allowedDown = allowedDown;
+ this.allowedDownRatio = allowedDownRatio;
}
/**
@@ -46,16 +63,28 @@ public class ClusterParams {
return size > 0 ? OptionalInt.of(size) : OptionalInt.empty();
}
+ /** The number of services that are allowed to be down. */
+ public OptionalInt allowedDown() {
+ return allowedDown > 0 ? OptionalInt.of(allowedDown) : OptionalInt.empty();
+ }
+
+ /** The ratio of services that are allowed to be down. */
+ public OptionalDouble allowedDownRatio() {
+ return 0.0 <= allowedDownRatio && allowedDownRatio <= 1.0 ?
+ OptionalDouble.of(allowedDownRatio) :
+ OptionalDouble.empty();
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClusterParams that = (ClusterParams) o;
- return size == that.size;
+ return size == that.size && allowedDown == that.allowedDown && Double.compare(that.allowedDownRatio, allowedDownRatio) == 0;
}
@Override
public int hashCode() {
- return Objects.hash(size);
+ return Objects.hash(size, allowedDown, allowedDownRatio);
}
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java
index eb2b863aefb..54d440f751f 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java
@@ -11,7 +11,8 @@ import com.yahoo.vespa.applicationmodel.ServiceType;
* @author hakonhall
*/
public class HostedVespaOrchestration {
- public static OrchestrationParams create(int numConfigServers, int numProxies) {
+ public static OrchestrationParams create(int numConfigServers, int numProxies, int numProxiesAllowedDown,
+ double numProxiesAllowedDownRatio) {
// We'll create parameters for both the controller and config server applications, even though
// only one of them is present, as (a) no harm is done by having the extra parameters, and
// (b) it leads to simpler code below.
@@ -75,6 +76,8 @@ public class HostedVespaOrchestration {
new ClusterParams
.Builder()
.setSize(numProxies)
+ .setAllowedDown(numProxiesAllowedDown)
+ .setAllowedDownRatio(numProxiesAllowedDownRatio)
.build())
.build())
@@ -87,6 +90,8 @@ public class HostedVespaOrchestration {
new ClusterParams
.Builder()
.setSize(numProxies)
+ .setAllowedDown(numProxiesAllowedDown)
+ .setAllowedDownRatio(numProxiesAllowedDownRatio)
.build())
.build())