aboutsummaryrefslogtreecommitdiffstats
path: root/config-provisioning
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2023-05-31 08:42:55 +0200
committerGitHub <noreply@github.com>2023-05-31 08:42:55 +0200
commitaf827dc5256e1372033ada8de82f3858f9db7dc0 (patch)
tree4e85cfb9e6ccf30a6672ea54857c501679e399de /config-provisioning
parent8714d5cdce3f9e6f7a995688deb3f6432c35356d (diff)
parent64ef5c1850f07d3a5569f485b2c3777bbb3daaf4 (diff)
Merge pull request #27214 from vespa-engine/jonmv/custom-host-ttl
Jonmv/custom host ttl
Diffstat (limited to 'config-provisioning')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java26
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/ClusterInfo.java20
-rw-r--r--config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java23
3 files changed, 40 insertions, 29 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java b/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
index f3c214da6ec..d75634d8c55 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
+import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
@@ -35,6 +36,8 @@ public final class Capacity {
if (max.smallerThan(min))
throw new IllegalArgumentException("The max capacity must be larger than the min capacity, but got min " +
min + " and max " + max);
+ if (cloudAccount.isEmpty() && ! clusterInfo.hostTTL().isZero())
+ throw new IllegalArgumentException("Cannot set hostTTL without a custom cloud account");
this.min = min;
this.max = max;
this.groupSize = groupSize;
@@ -105,22 +108,11 @@ public final class Capacity {
}
public static Capacity from(ClusterResources resources, boolean required, boolean canFail) {
- return from(resources, required, canFail, NodeType.tenant);
+ return from(resources, required, canFail, Duration.ZERO);
}
- // TODO: Remove after March 2023
- public static Capacity from(ClusterResources min, ClusterResources max, IntRange groupSize, boolean required, boolean canFail, Optional<CloudAccount> cloudAccount) {
- return new Capacity(min, max, groupSize, required, canFail, NodeType.tenant, cloudAccount, ClusterInfo.empty());
- }
-
- // TODO: Remove after March 2023
- public static Capacity from(ClusterResources min, ClusterResources max, boolean required, boolean canFail) {
- return new Capacity(min, max, IntRange.empty(), required, canFail, NodeType.tenant, Optional.empty(), ClusterInfo.empty());
- }
-
- // TODO: Remove after March 2023
- public static Capacity from(ClusterResources min, ClusterResources max, boolean required, boolean canFail, Optional<CloudAccount> cloudAccount) {
- return new Capacity(min, max, IntRange.empty(), required, canFail, NodeType.tenant, cloudAccount, ClusterInfo.empty());
+ public static Capacity from(ClusterResources resources, boolean required, boolean canFail, Duration hostTTL) {
+ return from(resources, required, canFail, NodeType.tenant, hostTTL);
}
public static Capacity from(ClusterResources min, ClusterResources max, IntRange groupSize, boolean required, boolean canFail,
@@ -130,11 +122,11 @@ public final class Capacity {
/** Creates this from a node type */
public static Capacity fromRequiredNodeType(NodeType type) {
- return from(new ClusterResources(0, 1, NodeResources.unspecified()), true, false, type);
+ return from(new ClusterResources(0, 1, NodeResources.unspecified()), true, false, type, Duration.ZERO);
}
- private static Capacity from(ClusterResources resources, boolean required, boolean canFail, NodeType type) {
- return new Capacity(resources, resources, IntRange.empty(), required, canFail, type, Optional.empty(), ClusterInfo.empty());
+ private static Capacity from(ClusterResources resources, boolean required, boolean canFail, NodeType type, Duration hostTTL) {
+ return new Capacity(resources, resources, IntRange.empty(), required, canFail, type, Optional.empty(), new ClusterInfo.Builder().hostTTL(hostTTL).build());
}
}
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterInfo.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterInfo.java
index fe8acb0c3c0..d9076557ac7 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterInfo.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterInfo.java
@@ -3,6 +3,8 @@ package com.yahoo.config.provision;
import java.time.Duration;
import java.util.Objects;
+import static ai.vespa.validation.Validation.requireAtLeast;
+
/**
* Auxiliary information about a cluster, provided by the config model to the node repo during a
* capacity request.
@@ -14,13 +16,18 @@ public class ClusterInfo {
private static final ClusterInfo empty = new ClusterInfo.Builder().build();
private final Duration bcpDeadline;
+ private final Duration hostTTL;
private ClusterInfo(Builder builder) {
this.bcpDeadline = builder.bcpDeadline;
+ this.hostTTL = builder.hostTTL;
+ requireAtLeast(hostTTL, "host TTL", Duration.ZERO);
}
public Duration bcpDeadline() { return bcpDeadline; }
+ public Duration hostTTL() { return hostTTL; }
+
public static ClusterInfo empty() { return empty; }
public boolean isEmpty() { return this.equals(empty); }
@@ -30,28 +37,35 @@ public class ClusterInfo {
if (o == this) return true;
if ( ! (o instanceof ClusterInfo other)) return false;
if ( ! other.bcpDeadline.equals(this.bcpDeadline)) return false;
+ if ( ! other.hostTTL.equals(this.hostTTL)) return false;
return true;
}
@Override
public int hashCode() {
- return Objects.hash(bcpDeadline);
+ return Objects.hash(bcpDeadline, hostTTL);
}
@Override
public String toString() {
- return "cluster info: [bcp deadline: " + bcpDeadline + "]";
+ return "cluster info: [bcp deadline: " + bcpDeadline + ", host TTL: " + hostTTL + "]";
}
public static class Builder {
- private Duration bcpDeadline = Duration.ofMinutes(0);
+ private Duration bcpDeadline = Duration.ZERO;
+ private Duration hostTTL = Duration.ZERO;
public Builder bcpDeadline(Duration duration) {
this.bcpDeadline = Objects.requireNonNull(duration);
return this;
}
+ public Builder hostTTL(Duration duration) {
+ this.hostTTL = Objects.requireNonNull(duration);
+ return this;
+ }
+
public ClusterInfo build() {
return new ClusterInfo(this);
}
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java
index a7614bbc016..b3d2e0afa7d 100644
--- a/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java
+++ b/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java
@@ -3,9 +3,11 @@ package com.yahoo.config.provision;
import org.junit.jupiter.api.Test;
+import java.time.Duration;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -35,20 +37,23 @@ public class CapacityTest {
new ClusterResources(4, 2, new NodeResources(1, 2, 3, 4)));
assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1, 2, 3, 5)),
new ClusterResources(4, 2, new NodeResources(1, 2, 3, 4)));
- // It's enough than one dimension is smaller also when the others are larger
+ // It's enough that one dimension is smaller also when the others are larger
assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1, 2, 3, 4)),
new ClusterResources(8, 4, new NodeResources(2, 1, 6, 8)));
+
+ assertEquals("Cannot set hostTTL without a custom cloud account",
+ assertThrows(IllegalArgumentException.class,
+ () -> Capacity.from(new ClusterResources(4, 2, new NodeResources(1, 2, 3, 4)),
+ new ClusterResources(4, 2, new NodeResources(1, 2, 3, 4)),
+ IntRange.empty(), false, true, Optional.empty(), new ClusterInfo.Builder().hostTTL(Duration.ofSeconds(1)).build()))
+ .getMessage());
}
private void assertValidationFailure(ClusterResources min, ClusterResources max) {
- try {
- Capacity.from(min, max, IntRange.empty(), false, true, Optional.empty(), ClusterInfo.empty());
- fail("Expected exception with min " + min + " and max " + max);
- }
- catch (IllegalArgumentException e) {
- assertEquals("The max capacity must be larger than the min capacity, but got min " + min + " and max " + max,
- e.getMessage());
- }
+ assertEquals("The max capacity must be larger than the min capacity, but got min " + min + " and max " + max,
+ assertThrows(IllegalArgumentException.class,
+ () -> Capacity.from(min, max, IntRange.empty(), false, true, Optional.empty(), ClusterInfo.empty()))
+ .getMessage());
}
}