diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-06-11 13:30:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 13:30:51 +0200 |
commit | 1307945954b7ca541b640a30fb06e5a27e43fdf3 (patch) | |
tree | dc5e873edd8e44302ebf27d2547555ff735ea8ee /config-provisioning | |
parent | bf0f7ced58968e26eafa632cb68cfb3757d4dd2f (diff) | |
parent | 70b15c19f0cf69fcae619edab1aa32dc88613e40 (diff) |
Merge pull request #9744 from vespa-engine/mpolden/remove-rotations-serialization
Remove serialization of ClusterSpec rotations
Diffstat (limited to 'config-provisioning')
4 files changed, 14 insertions, 51 deletions
diff --git a/config-provisioning/abi-spec.json b/config-provisioning/abi-spec.json index e88947b3fdb..aa9b196c0e4 100644 --- a/config-provisioning/abi-spec.json +++ b/config-provisioning/abi-spec.json @@ -260,7 +260,6 @@ "public com.yahoo.component.Version vespaVersion()", "public java.util.Optional group()", "public boolean isExclusive()", - "public java.util.Set rotations()", "public com.yahoo.config.provision.ClusterSpec with(java.util.Optional)", "public com.yahoo.config.provision.ClusterSpec exclusive(boolean)", "public static com.yahoo.config.provision.ClusterSpec request(com.yahoo.config.provision.ClusterSpec$Type, com.yahoo.config.provision.ClusterSpec$Id, com.yahoo.component.Version, boolean)", 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 c0099878b45..f041823bf04 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 @@ -3,14 +3,9 @@ package com.yahoo.config.provision; import com.yahoo.component.Version; -import java.util.Arrays; -import java.util.Collections; -import java.util.Set; -import java.util.stream.Collectors; - /** * A node's membership in a cluster. This is a value object. - * The format is "clusterType/clusterId/groupId/index[/exclusive][/retired][/rotationId,...]" + * The format is "clusterType/clusterId/groupId/index[/exclusive][/retired]" * * @author bratseth */ @@ -25,26 +20,23 @@ public class ClusterMembership { private ClusterMembership(String stringValue, Version vespaVersion) { String[] components = stringValue.split("/"); - if (components.length < 4 || components.length > 7) + if (components.length < 4) throw new RuntimeException("Could not parse '" + stringValue + "' to a cluster membership. " + - "Expected 'clusterType/clusterId/groupId/index[/retired][/exclusive][/rotationId,...]'"); + "Expected 'clusterType/clusterId/groupId/index[/retired][/exclusive]'"); boolean exclusive = false; - Set<RotationName> rotations = Collections.emptySet(); if (components.length > 4) { for (int i = 4; i < components.length; i++) { String component = components[i]; switch (component) { case "exclusive": exclusive = true; break; case "retired": retired = true; break; - default: rotations = rotationsFrom(component); break; } } } this.cluster = ClusterSpec.from(ClusterSpec.Type.valueOf(components[0]), ClusterSpec.Id.from(components[1]), - ClusterSpec.Group.from(Integer.valueOf(components[2])), vespaVersion, exclusive, - rotations); + ClusterSpec.Group.from(Integer.valueOf(components[2])), vespaVersion, exclusive); this.index = Integer.parseInt(components[3]); this.stringValue = toStringValue(); } @@ -62,8 +54,7 @@ public class ClusterMembership { (cluster.group().isPresent() ? "/" + cluster.group().get().index() : "") + "/" + index + ( cluster.isExclusive() ? "/exclusive" : "") + - ( retired ? "/retired" : "") + - ( !cluster.rotations().isEmpty() ? "/" + rotationsAsString(cluster.rotations()) : ""); + ( retired ? "/retired" : ""); } @@ -121,12 +112,4 @@ public class ClusterMembership { return new ClusterMembership(cluster, index, true); } - private static Set<RotationName> rotationsFrom(String s) { - return Arrays.stream(s.split(",")).map(RotationName::from).collect(Collectors.toUnmodifiableSet()); - } - - private static String rotationsAsString(Set<RotationName> rotations) { - return rotations.stream().map(RotationName::value).collect(Collectors.joining(",")); - } - } diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java index 35ee538178a..8ed56b98705 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterSpec.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.provision; -import com.google.common.collect.ImmutableSortedSet; import com.yahoo.component.Version; import java.util.Objects; @@ -23,19 +22,13 @@ public final class ClusterSpec { private final Optional<Group> groupId; private final Version vespaVersion; private boolean exclusive; - private final Set<RotationName> rotations; - private ClusterSpec(Type type, Id id, Optional<Group> groupId, Version vespaVersion, boolean exclusive, - Set<RotationName> rotations) { - if (type != Type.container && !rotations.isEmpty()) { - throw new IllegalArgumentException("Rotations can only be declared for clusters of type " + Type.container); - } + private ClusterSpec(Type type, Id id, Optional<Group> groupId, Version vespaVersion, boolean exclusive) { this.type = type; this.id = id; this.groupId = groupId; this.vespaVersion = vespaVersion; this.exclusive = exclusive; - this.rotations = ImmutableSortedSet.copyOf(rotations); } /** Returns the cluster type */ @@ -57,35 +50,30 @@ public final class ClusterSpec { */ public boolean isExclusive() { return exclusive; } - /** Returns the rotations of which this cluster should be a member */ - public Set<RotationName> rotations() { - return rotations; - } - public ClusterSpec with(Optional<Group> newGroup) { - return new ClusterSpec(type, id, newGroup, vespaVersion, exclusive, rotations); + return new ClusterSpec(type, id, newGroup, vespaVersion, exclusive); } public ClusterSpec exclusive(boolean exclusive) { - return new ClusterSpec(type, id, groupId, vespaVersion, exclusive, rotations); + return new ClusterSpec(type, id, groupId, vespaVersion, exclusive); } public static ClusterSpec request(Type type, Id id, Version vespaVersion, boolean exclusive) { - return new ClusterSpec(type, id, Optional.empty(), vespaVersion, exclusive, Set.of()); + return new ClusterSpec(type, id, Optional.empty(), vespaVersion, exclusive); } // TODO: Remove after June 2019 public static ClusterSpec request(Type type, Id id, Version vespaVersion, boolean exclusive, Set<RotationName> rotations) { - return new ClusterSpec(type, id, Optional.empty(), vespaVersion, exclusive, rotations); + return new ClusterSpec(type, id, Optional.empty(), vespaVersion, exclusive); } public static ClusterSpec from(Type type, Id id, Group groupId, Version vespaVersion, boolean exclusive) { - return new ClusterSpec(type, id, Optional.of(groupId), vespaVersion, exclusive, Set.of()); + return new ClusterSpec(type, id, Optional.of(groupId), vespaVersion, exclusive); } // TODO: Remove after June 2019 public static ClusterSpec from(Type type, Id id, Group groupId, Version vespaVersion, boolean exclusive, Set<RotationName> rotations) { - return new ClusterSpec(type, id, Optional.of(groupId), vespaVersion, exclusive, rotations); + return new ClusterSpec(type, id, Optional.of(groupId), vespaVersion, exclusive); } @Override 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 9bd0680b691..5eee55a1886 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 @@ -6,7 +6,6 @@ import com.yahoo.component.Vtag; import org.junit.Test; import java.util.Collections; -import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -37,26 +36,25 @@ public class ClusterMembershipTest { assertTrue(instance.cluster().isExclusive()); } + // TODO: Remove after June 2019. This ensures stale rotation data is handled { ClusterMembership instance = ClusterMembership.from("container/id1/4/37/rotation1,rotation2", Vtag.currentVersion); assertFalse(instance.retired()); assertFalse(instance.cluster().isExclusive()); - assertEquals(Set.of(RotationName.from("rotation1"), RotationName.from("rotation2")), instance.cluster().rotations()); } { ClusterMembership instance = ClusterMembership.from("container/id1/4/37/exclusive/rotation1,rotation2", Vtag.currentVersion); assertFalse(instance.retired()); assertTrue(instance.cluster().isExclusive()); - assertEquals(Set.of(RotationName.from("rotation1"), RotationName.from("rotation2")), instance.cluster().rotations()); } { ClusterMembership instance = ClusterMembership.from("container/id1/4/37/exclusive/retired/rotation1,rotation2", Vtag.currentVersion); assertTrue(instance.retired()); assertTrue(instance.cluster().isExclusive()); - assertEquals(Set.of(RotationName.from("rotation1"), RotationName.from("rotation2")), instance.cluster().rotations()); } + // end TODO } @Test @@ -101,7 +99,6 @@ public class ClusterMembershipTest { assertFalse(instance.cluster().group().isPresent()); assertEquals(3, instance.index()); assertEquals("container/id1/3", instance.stringValue()); - assertTrue(instance.cluster().rotations().isEmpty()); } private void assertContentService(ClusterMembership instance) { @@ -111,7 +108,6 @@ public class ClusterMembershipTest { assertEquals(37, instance.index()); assertFalse(instance.retired()); assertEquals("content/id1/37", instance.stringValue()); - assertTrue(instance.cluster().rotations().isEmpty()); } private void assertContentServiceWithGroup(ClusterMembership instance) { @@ -121,7 +117,6 @@ public class ClusterMembershipTest { assertEquals(37, instance.index()); assertFalse(instance.retired()); assertEquals("content/id1/4/37", instance.stringValue()); - assertTrue(instance.cluster().rotations().isEmpty()); } /** Serializing a spec without a group assigned works, but not deserialization */ @@ -131,7 +126,6 @@ public class ClusterMembershipTest { assertEquals(37, instance.index()); assertTrue(instance.retired()); assertEquals("content/id1/37/retired", instance.stringValue()); - assertTrue(instance.cluster().rotations().isEmpty()); } private void assertContentServiceWithGroupAndRetire(ClusterMembership instance) { @@ -141,7 +135,6 @@ public class ClusterMembershipTest { assertEquals(37, instance.index()); assertTrue(instance.retired()); assertEquals("content/id1/4/37/retired", instance.stringValue()); - assertTrue(instance.cluster().rotations().isEmpty()); } } |