diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2022-09-09 16:59:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 16:59:20 +0200 |
commit | d3aec39f4790cc4c706b5593dd7e2e8e00186f5c (patch) | |
tree | 3777c192ff465f2c717719477abf8eb4771eff92 /controller-server | |
parent | fe718f423e5e8c6abdc83de3e84642ab87a49058 (diff) | |
parent | 6816c1680ba4ff224475324fdc7946752a78c30e (diff) |
Merge pull request #23998 from vespa-engine/mpolden/routing-records
Use records in routing package
Diffstat (limited to 'controller-server')
8 files changed, 39 insertions, 240 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingId.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingId.java index 67eafe6235d..21c8b5aeb87 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingId.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingId.java @@ -12,42 +12,14 @@ import java.util.Objects; * * @author mpolden */ -public class RoutingId { +public record RoutingId(ApplicationId instance, + EndpointId endpointId, + TenantAndApplicationId application) { - private final TenantAndApplicationId application; - private final ApplicationId instance; - private final EndpointId endpointId; - - private RoutingId(ApplicationId instance, EndpointId endpointId) { - this.instance = Objects.requireNonNull(instance, "application must be non-null"); - this.endpointId = Objects.requireNonNull(endpointId, "endpointId must be non-null"); - - application = TenantAndApplicationId.from(instance); - } - - public TenantAndApplicationId application() { - return application; - } - - public ApplicationId instance() { - return instance; - } - - public EndpointId endpointId() { - return endpointId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RoutingId routingId = (RoutingId) o; - return application.equals(routingId.application) && instance.equals(routingId.instance) && endpointId.equals(routingId.endpointId); - } - - @Override - public int hashCode() { - return Objects.hash(application, instance, endpointId); + public RoutingId { + Objects.requireNonNull(instance, "application must be non-null"); + Objects.requireNonNull(endpointId, "endpointId must be non-null"); + Objects.requireNonNull(application, "application must be non-null"); } @Override @@ -56,7 +28,7 @@ public class RoutingId { } public static RoutingId of(ApplicationId instance, EndpointId endpoint) { - return new RoutingId(instance, endpoint); + return new RoutingId(instance, endpoint, TenantAndApplicationId.from(instance)); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java index fa6741ec8b8..585cda65e66 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicy.java @@ -23,14 +23,12 @@ import java.util.Set; * @author mortent * @author mpolden */ -public class RoutingPolicy { - - private final RoutingPolicyId id; - private final DomainName canonicalName; - private final Optional<String> dnsZone; - private final Set<EndpointId> instanceEndpoints; - private final Set<EndpointId> applicationEndpoints; - private final Status status; +public record RoutingPolicy(RoutingPolicyId id, + DomainName canonicalName, + Optional<String> dnsZone, + Set<EndpointId> instanceEndpoints, + Set<EndpointId> applicationEndpoints, + Status status) { /** DO NOT USE. Public for serialization purposes */ public RoutingPolicy(RoutingPolicyId id, DomainName canonicalName, Optional<String> dnsZone, @@ -123,15 +121,11 @@ public class RoutingPolicy { } /** The status of a routing policy */ - public static class Status { - - private final boolean active; - private final RoutingStatus routingStatus; + public record Status(boolean active, RoutingStatus routingStatus) { /** DO NOT USE. Public for serialization purposes */ - public Status(boolean active, RoutingStatus routingStatus) { - this.active = active; - this.routingStatus = Objects.requireNonNull(routingStatus, "globalRouting must be non-null"); + public Status { + Objects.requireNonNull(routingStatus, "routingStatus must be non-null"); } /** Returns whether this is considered active according to the load balancer status */ @@ -149,20 +143,6 @@ public class RoutingPolicy { return new Status(active, routingStatus); } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Status status = (Status) o; - return active == status.active && - routingStatus.equals(status.routingStatus); - } - - @Override - public int hashCode() { - return Objects.hash(active, routingStatus); - } - } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyId.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyId.java index d64241b1239..1c0b41155fd 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyId.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingPolicyId.java @@ -13,26 +13,12 @@ import java.util.Objects; * * @author mpolden */ -public class RoutingPolicyId { +public record RoutingPolicyId(ApplicationId owner, ClusterSpec.Id cluster, ZoneId zone) { - private final ApplicationId owner; - private final ClusterSpec.Id cluster; - private final ZoneId zone; - - public RoutingPolicyId(ApplicationId owner, ClusterSpec.Id cluster, ZoneId zone) { - this.owner = Objects.requireNonNull(owner, "owner must be non-null"); - this.cluster = Objects.requireNonNull(cluster, "cluster must be non-null"); - this.zone = Objects.requireNonNull(zone, "zone must be non-null"); - } - - /** The application owning this */ - public ApplicationId owner() { - return owner; - } - - /** The zone this applies to */ - public ZoneId zone() { - return zone; + public RoutingPolicyId { + Objects.requireNonNull(owner, "owner must be non-null"); + Objects.requireNonNull(cluster, "cluster must be non-null"); + Objects.requireNonNull(zone, "zone must be non-null"); } /** The deployment this applies to */ @@ -40,26 +26,6 @@ public class RoutingPolicyId { return new DeploymentId(owner, zone); } - /** The cluster this applies to */ - public ClusterSpec.Id cluster() { - return cluster; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RoutingPolicyId that = (RoutingPolicyId) o; - return owner.equals(that.owner) && - cluster.equals(that.cluster) && - zone.equals(that.zone); - } - - @Override - public int hashCode() { - return Objects.hash(owner, cluster, zone); - } - @Override public String toString() { return "routing policy for " + cluster + ", in " + zone + ", owned by " + owner; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingStatus.java index 58f0005d488..de16089e735 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/RoutingStatus.java @@ -13,19 +13,15 @@ import java.util.Objects; * * @author mpolden */ -public class RoutingStatus { +public record RoutingStatus(Value value, Agent agent, Instant changedAt) { public static final RoutingStatus DEFAULT = new RoutingStatus(Value.in, Agent.system, Instant.EPOCH); - private final Value value; - private final Agent agent; - private final Instant changedAt; - /** DO NOT USE. Public for serialization purposes */ - public RoutingStatus(Value value, Agent agent, Instant changedAt) { - this.value = Objects.requireNonNull(value, "value must be non-null"); - this.agent = Objects.requireNonNull(agent, "agent must be non-null"); - this.changedAt = Objects.requireNonNull(changedAt, "changedAt must be non-null"); + public RoutingStatus { + Objects.requireNonNull(value, "value must be non-null"); + Objects.requireNonNull(agent, "agent must be non-null"); + Objects.requireNonNull(changedAt, "changedAt must be non-null"); } /** @@ -47,21 +43,6 @@ public class RoutingStatus { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RoutingStatus that = (RoutingStatus) o; - return value == that.value && - agent == that.agent && - changedAt.equals(that.changedAt); - } - - @Override - public int hashCode() { - return Objects.hash(value, agent, changedAt); - } - - @Override public String toString() { return "status " + value + ", changed by " + agent + " @ " + changedAt; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/ZoneRoutingPolicy.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/ZoneRoutingPolicy.java index 60605df1002..a404be76507 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/ZoneRoutingPolicy.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/ZoneRoutingPolicy.java @@ -13,38 +13,11 @@ import java.util.Objects; * * @author mpolden */ -public class ZoneRoutingPolicy { +public record ZoneRoutingPolicy(ZoneId zone, RoutingStatus routingStatus) { - private final ZoneId zone; - private final RoutingStatus routingStatus; - - public ZoneRoutingPolicy(ZoneId zone, RoutingStatus routingStatus) { - this.zone = Objects.requireNonNull(zone, "zone must be non-null"); - this.routingStatus = Objects.requireNonNull(routingStatus, "globalRouting must be non-null"); - } - - /** The zone this applies to */ - public ZoneId zone() { - return zone; - } - - /** Routing status of this policy */ - public RoutingStatus routingStatus() { - return routingStatus; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ZoneRoutingPolicy that = (ZoneRoutingPolicy) o; - return zone.equals(that.zone) && - routingStatus.equals(that.routingStatus); - } - - @Override - public int hashCode() { - return Objects.hash(zone, routingStatus); + public ZoneRoutingPolicy { + Objects.requireNonNull(zone, "zone must be non-null"); + Objects.requireNonNull(routingStatus, "globalRouting must be non-null"); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/Rotation.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/Rotation.java index 8eeab8c20e3..ea97b1da4de 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/Rotation.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/Rotation.java @@ -10,14 +10,11 @@ import java.util.Objects; * * @author mpolden */ -public class Rotation { +public record Rotation(RotationId id, String name) { - private final RotationId id; - private final String name; - - public Rotation(RotationId id, String name) { - this.id = Objects.requireNonNull(id); - this.name = Objects.requireNonNull(name); + public Rotation { + Objects.requireNonNull(id); + Objects.requireNonNull(name); } /** The ID of the allocated rotation. This value is generated by global routing system */ @@ -31,19 +28,6 @@ public class Rotation { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Rotation)) return false; - final Rotation rotation = (Rotation) o; - return id().equals(rotation.id()) && name().equals(rotation.name()); - } - - @Override - public int hashCode() { - return Objects.hash(id(), name()); - } - - @Override public String toString() { return Text.format("rotation %s -> %s", id().asString(), name()); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationId.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationId.java index 4d97962a40a..95cebf7ea78 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationId.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationId.java @@ -1,20 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.routing.rotation; -import java.util.Objects; - /** * ID of a global rotation. * * @author mpolden */ -public class RotationId { - - private final String id; - - public RotationId(String id) { - this.id = id; - } +public record RotationId(String id) { /** Rotation ID, e.g. rotation-42.vespa.global.routing */ public String asString() { @@ -22,19 +14,6 @@ public class RotationId { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RotationId that = (RotationId) o; - return Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override public String toString() { return "rotation ID " + id; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationStatus.java index 6d95ad9a230..89247ca2a31 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/routing/rotation/RotationStatus.java @@ -13,13 +13,11 @@ import java.util.Objects; * * @author mpolden */ -public class RotationStatus { +public record RotationStatus(Map<RotationId, Targets> status) { public static final RotationStatus EMPTY = new RotationStatus(Map.of()); - private final Map<RotationId, Targets> status; - - private RotationStatus(Map<RotationId, Targets> status) { + public RotationStatus(Map<RotationId, Targets> status) { this.status = Map.copyOf(Objects.requireNonNull(status)); } @@ -46,31 +44,15 @@ public class RotationStatus { return "rotation status " + status; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RotationStatus that = (RotationStatus) o; - return status.equals(that.status); - } - - @Override - public int hashCode() { - return Objects.hash(status); - } - public static RotationStatus from(Map<RotationId, Targets> targets) { return targets.isEmpty() ? EMPTY : new RotationStatus(targets); } /** Targets of a rotation */ - public static class Targets { + public record Targets(Map<ZoneId, RotationState> targets, Instant lastUpdated) { public static final Targets NONE = new Targets(Map.of(), Instant.EPOCH); - private final Map<ZoneId, RotationState> targets; - private final Instant lastUpdated; - public Targets(Map<ZoneId, RotationState> targets, Instant lastUpdated) { this.targets = Map.copyOf(Objects.requireNonNull(targets, "states must be non-null")); this.lastUpdated = Objects.requireNonNull(lastUpdated, "lastUpdated must be non-null"); @@ -80,24 +62,6 @@ public class RotationStatus { return targets; } - public Instant lastUpdated() { - return lastUpdated; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Targets targets1 = (Targets) o; - return targets.equals(targets1.targets) && - lastUpdated.equals(targets1.lastUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(targets, lastUpdated); - } - } } |