diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-12-15 16:22:23 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-12-15 16:22:23 +0100 |
commit | cb4a8216381666cc7cece82f0431b1785853daf0 (patch) | |
tree | f4ffc5bae86efb00cdc7595eca41a51b75def217 /controller-server | |
parent | d4837a9ef23348bdf9a1ff86d4a1595fad90145d (diff) |
Convert AssignedRotation to record
Diffstat (limited to 'controller-server')
2 files changed, 21 insertions, 45 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/AssignedRotation.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/AssignedRotation.java index ab9304e75f3..eeeb822ecf5 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/AssignedRotation.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/AssignedRotation.java @@ -5,10 +5,8 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.RegionName; import com.yahoo.vespa.hosted.controller.routing.rotation.RotationId; -import java.util.Collection; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; /** * Contains the tuple of [clusterId, endpointId, rotationId, regions[]], to keep track @@ -16,11 +14,7 @@ import java.util.stream.Collectors; * * @author ogronnesby */ -public class AssignedRotation { - private final ClusterSpec.Id clusterId; - private final EndpointId endpointId; - private final RotationId rotationId; - private final Set<RegionName> regions; +public record AssignedRotation(ClusterSpec.Id clusterId, EndpointId endpointId, RotationId rotationId, Set<RegionName> regions) { public AssignedRotation(ClusterSpec.Id clusterId, EndpointId endpointId, RotationId rotationId, Set<RegionName> regions) { this.clusterId = requireNonEmpty(clusterId, clusterId.value(), "clusterId"); @@ -29,35 +23,14 @@ public class AssignedRotation { this.regions = Set.copyOf(Objects.requireNonNull(regions)); } - public ClusterSpec.Id clusterId() { return clusterId; } - public EndpointId endpointId() { return endpointId; } - public RotationId rotationId() { return rotationId; } - public Set<RegionName> regions() { return regions; } - @Override public String toString() { return "AssignedRotation{" + - "clusterId=" + clusterId + - ", endpointId='" + endpointId + '\'' + - ", rotationId=" + rotationId + - ", regions=" + regions + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AssignedRotation that = (AssignedRotation) o; - return clusterId.equals(that.clusterId) && - endpointId.equals(that.endpointId) && - rotationId.equals(that.rotationId) && - regions.equals(that.regions); - } - - @Override - public int hashCode() { - return Objects.hash(clusterId, endpointId, rotationId, regions); + "clusterId=" + clusterId + + ", endpointId='" + endpointId + '\'' + + ", rotationId=" + rotationId + + ", regions=" + regions + + '}'; } private static <T> T requireNonEmpty(T object, String value, String field) { @@ -69,13 +42,4 @@ public class AssignedRotation { return object; } - /** Convenience method intended for tests */ - public static AssignedRotation fromStrings(String clusterId, String endpointId, String rotationId, Collection<String> regions) { - return new AssignedRotation( - new ClusterSpec.Id(clusterId), - EndpointId.of(endpointId), - new RotationId(rotationId), - regions.stream().map(RegionName::from).collect(Collectors.toSet()) - ); - } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java index 40217890351..04a623f819b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java @@ -5,7 +5,8 @@ import com.yahoo.component.Version; import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.application.api.ValidationOverrides; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.SystemName; +import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.Tags; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.security.KeyUtils; @@ -23,6 +24,7 @@ import com.yahoo.vespa.hosted.controller.application.Change; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.DeploymentActivity; import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; +import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.QuotaUsage; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; import com.yahoo.vespa.hosted.controller.deployment.DeploymentContext; @@ -40,6 +42,7 @@ import java.security.PublicKey; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -47,6 +50,7 @@ import java.util.OptionalDouble; import java.util.OptionalInt; import java.util.OptionalLong; import java.util.Set; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -69,7 +73,6 @@ public class ApplicationSerializerTest { "pDhJeqczkyFcT2PysJ5sZwm7rKPEeXDOhzTPCyRvbUqc2SGdWbKUGGa/Yw==\n" + "-----END PUBLIC KEY-----\n"); - @Test void testSerialization() throws Exception { DeploymentSpec deploymentSpec = DeploymentSpec.fromXml("<deployment version='1.0'>\n" + @@ -133,7 +136,7 @@ public class ApplicationSerializerTest { Tags.fromString("tag1 tag2"), deployments, Map.of(DeploymentContext.systemTest, Instant.ofEpochMilli(333)), - List.of(AssignedRotation.fromStrings("foo", "default", "my-rotation", Set.of("us-west-1"))), + List.of(rotation("foo", "default", "my-rotation", Set.of("us-west-1"))), rotationStatus, Change.of(new Version("6.1"))), new Instance(id3, @@ -236,4 +239,13 @@ public class ApplicationSerializerTest { // ok if no error } + private static AssignedRotation rotation(String clusterId, String endpointId, String rotationId, Collection<String> regions) { + return new AssignedRotation( + new ClusterSpec.Id(clusterId), + EndpointId.of(endpointId), + new RotationId(rotationId), + regions.stream().map(RegionName::from).collect(Collectors.toSet()) + ); + } + } |