aboutsummaryrefslogtreecommitdiffstats
path: root/config-provisioning
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@vespa.ai>2023-07-09 19:41:42 +0200
committerJon Bratseth <bratseth@vespa.ai>2023-07-09 19:41:42 +0200
commit57c4cf79afacfe51daf39a21921502db7e04b6f0 (patch)
treea110c69fbc9def3ba2fef24cf811041bc157f852 /config-provisioning
parentc6a0d441b4493f4cdc8a8d3e8cb221f070dfc305 (diff)
Handle legacy spec strings
Diffstat (limited to 'config-provisioning')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/ClusterMembership.java22
-rw-r--r--config-provisioning/src/test/java/com/yahoo/config/provision/ClusterMembershipTest.java10
2 files changed, 24 insertions, 8 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterMembership.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterMembership.java
index 36f77a179ca..7de3d41817a 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterMembership.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterMembership.java
@@ -22,16 +22,28 @@ public class ClusterMembership {
private ClusterMembership(String stringValue, Version vespaVersion, Optional<DockerImage> dockerImageRepo,
ZoneEndpoint zoneEndpoint) {
String[] components = stringValue.split("/");
- if (components.length < 4)
+ if (components.length < 3)
throw new RuntimeException("Could not parse '" + stringValue + "' to a cluster membership. " +
"Expected 'clusterType/clusterId/groupId/index[/retired][/exclusive][/stateful][/combinedId]'");
+ Integer groupIndex = components[2].isEmpty() ? null : Integer.parseInt(components[2]);
+ Integer nodeIndex;
+ int missingElements = 0;
+ try {
+ nodeIndex = Integer.parseInt(components[3]);
+ } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
+ // Legacy form missing the group component
+ nodeIndex = groupIndex;
+ groupIndex = null;
+ missingElements = 1;
+ }
+
boolean exclusive = false;
boolean stateful = false;
var combinedId = Optional.<String>empty();
boolean retired = false;
- if (components.length > 4) {
- for (int i = 4; i < components.length; i++) {
+ if (components.length > (4 - missingElements)) {
+ for (int i = (4 - missingElements); i < components.length; i++) {
String component = components[i];
switch (component) {
case "exclusive" -> exclusive = true;
@@ -44,7 +56,7 @@ public class ClusterMembership {
this.cluster = ClusterSpec.specification(ClusterSpec.Type.valueOf(components[0]),
ClusterSpec.Id.from(components[1]))
- .group(components[2].isEmpty() ? null : ClusterSpec.Group.from(Integer.parseInt(components[2])))
+ .group(groupIndex == null ? null : ClusterSpec.Group.from(groupIndex))
.vespaVersion(vespaVersion)
.exclusive(exclusive)
.combinedId(combinedId.map(ClusterSpec.Id::from))
@@ -52,7 +64,7 @@ public class ClusterMembership {
.loadBalancerSettings(zoneEndpoint)
.stateful(stateful)
.build();
- this.index = Integer.parseInt(components[3]);
+ this.index = nodeIndex;
this.retired = retired;
this.stringValue = toStringValue();
}
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterMembershipTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterMembershipTest.java
index b1195b6a54b..292aec60e39 100644
--- a/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterMembershipTest.java
+++ b/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterMembershipTest.java
@@ -100,7 +100,9 @@ public class ClusterMembershipTest {
assertEquals("id1", instance.cluster().id().value());
assertFalse(instance.cluster().group().isPresent());
assertEquals(3, instance.index());
- assertEquals("container/id1/3", instance.stringValue());
+ assertEquals("container/id1//3", instance.stringValue());
+ // Legacy form:
+ assertEquals(instance, ClusterMembership.from("container/id1/3", instance.cluster().vespaVersion(), Optional.empty()));
}
private void assertContentService(ClusterMembership instance) {
@@ -109,7 +111,7 @@ public class ClusterMembershipTest {
assertFalse(instance.cluster().group().isPresent());
assertEquals(37, instance.index());
assertFalse(instance.retired());
- assertEquals("content/id1/37/stateful", instance.stringValue());
+ assertEquals("content/id1//37/stateful", instance.stringValue());
}
private void assertContentServiceWithGroup(ClusterMembership instance) {
@@ -127,7 +129,9 @@ public class ClusterMembershipTest {
assertEquals("id1", instance.cluster().id().value());
assertEquals(37, instance.index());
assertTrue(instance.retired());
- assertEquals("content/id1/37/retired/stateful", instance.stringValue());
+ assertEquals("content/id1//37/retired/stateful", instance.stringValue());
+ // Legacy form:
+ assertEquals(instance, ClusterMembership.from("content/id1/37/retired/stateful", instance.cluster().vespaVersion(), Optional.empty()));
}
private void assertContentServiceWithGroupAndRetire(ClusterMembership instance) {