diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-01-03 13:31:44 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-01-03 14:43:22 +0100 |
commit | b8eda7a354895a6f2d41f9950c3aa6965862bd82 (patch) | |
tree | be7ef3ac88a954ec6b91ea66c9797a5096c00344 /config-provisioning | |
parent | fac9b339288cf288390fe08920f27a5deaef9d25 (diff) |
Avoid changing allocation when switching to combined cluster type
Diffstat (limited to 'config-provisioning')
3 files changed, 42 insertions, 10 deletions
diff --git a/config-provisioning/abi-spec.json b/config-provisioning/abi-spec.json index 3cff2bb4da1..2a35dafedbd 100644 --- a/config-provisioning/abi-spec.json +++ b/config-provisioning/abi-spec.json @@ -249,12 +249,15 @@ "methods": [ "public static com.yahoo.config.provision.ClusterSpec$Type[] values()", "public static com.yahoo.config.provision.ClusterSpec$Type valueOf(java.lang.String)", + "public boolean isContent()", + "public boolean isContainer()", "public static com.yahoo.config.provision.ClusterSpec$Type from(java.lang.String)" ], "fields": [ "public static final enum com.yahoo.config.provision.ClusterSpec$Type admin", "public static final enum com.yahoo.config.provision.ClusterSpec$Type container", - "public static final enum com.yahoo.config.provision.ClusterSpec$Type content" + "public static final enum com.yahoo.config.provision.ClusterSpec$Type content", + "public static final enum com.yahoo.config.provision.ClusterSpec$Type combined" ] }, "com.yahoo.config.provision.ClusterSpec": { @@ -277,7 +280,7 @@ "public java.lang.String toString()", "public int hashCode()", "public boolean equals(java.lang.Object)", - "public boolean equalsIgnoringGroupAndVespaVersion(java.lang.Object)" + "public boolean satisfies(com.yahoo.config.provision.ClusterSpec)" ], "fields": [] }, 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 84b344791c8..f1a8b579866 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 @@ -85,14 +85,15 @@ public final class ClusterSpec { return true; } - /** Returns whether this is equal, disregarding the group value and wanted Vespa version */ - public boolean equalsIgnoringGroupAndVespaVersion(Object o) { - if (o == this) return true; - if ( ! (o instanceof ClusterSpec)) return false; - ClusterSpec other = (ClusterSpec)o; - if ( ! other.type.equals(this.type)) return false; - if ( ! other.id.equals(this.id)) return false; - return true; + /** + * Returns whether this satisfies other for allocation purposes. Only considers cluster ID and type, other fields + * are ignored. + */ + public boolean satisfies(ClusterSpec other) { + if ( ! other.id.equals(this.id)) return false; // ID mismatch + // TODO(mpolden): Remove this after January 2019, once all nodes in combined clusters have type combined. + if (other.type.isContent() || this.type.isContent()) return other.type.isContent() == this.type.isContent(); + return other.type.equals(this.type); } /** A cluster type */ diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterSpecTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterSpecTest.java index d91c76a4f7d..db90b0ebff9 100644 --- a/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterSpecTest.java +++ b/config-provisioning/src/test/java/com/yahoo/config/provision/ClusterSpecTest.java @@ -2,8 +2,14 @@ package com.yahoo.config.provision; import com.google.common.testing.EqualsTester; +import com.yahoo.component.Version; import org.junit.Test; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + /** * @author Ulf Lilleengen */ @@ -27,4 +33,26 @@ public class ClusterSpecTest { .testEquals(); } + @Test + public void testSatisfies() { + var tests = Map.of( + List.of(spec(ClusterSpec.Type.content, "id1"), spec(ClusterSpec.Type.content, "id2")), false, + List.of(spec(ClusterSpec.Type.admin, "id1"), spec(ClusterSpec.Type.container, "id1")), false, + List.of(spec(ClusterSpec.Type.admin, "id1"), spec(ClusterSpec.Type.content, "id1")), false, + List.of(spec(ClusterSpec.Type.combined, "id1"), spec(ClusterSpec.Type.container, "id1")), false, + List.of(spec(ClusterSpec.Type.combined, "id1"), spec(ClusterSpec.Type.content, "id1")), true, + List.of(spec(ClusterSpec.Type.content, "id1"), spec(ClusterSpec.Type.content, "id1")), true + ); + tests.forEach((specs, satisfies) -> { + var s1 = specs.get(0); + var s2 = specs.get(1); + assertEquals(s1 + (satisfies ? " satisfies " : " does not satisfy ") + s2, satisfies, s1.satisfies(s2)); + assertEquals(s2 + (satisfies ? " satisfies " : " does not satisfy ") + s1, satisfies, s2.satisfies(s1)); + }); + } + + private static ClusterSpec spec(ClusterSpec.Type type, String id) { + return ClusterSpec.from(type, ClusterSpec.Id.from(id), ClusterSpec.Group.from(1), Version.emptyVersion, false); + } + } |