diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-07-16 08:53:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-16 08:53:14 +0200 |
commit | 5d95bfb487229d05d67554a6890e056db0db001f (patch) | |
tree | 3799fb6b074e13fe31584a7684c0ee909532d8d4 | |
parent | c3e4fdeb920dabf96b1c007d7d7972faaf997d14 (diff) | |
parent | b36bd27081ea348c04ee01f5ecdc54abcd6bc5b3 (diff) |
Merge pull request #10032 from vespa-engine/mpolden/cleanup
Replace usages of RotationName with EndpointId
14 files changed, 104 insertions, 113 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/RotationName.java b/config-provisioning/src/main/java/com/yahoo/config/provision/RotationName.java index 5d9ac3699b3..fb6d9dc09e6 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/RotationName.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/RotationName.java @@ -8,6 +8,7 @@ import java.util.Objects; * * @author mpolden */ +// TODO(mpolden): Remove this once all usages have been replaced public class RotationName implements Comparable<RotationName> { private final String name; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index 60fd095eb04..7406795d0e3 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -279,7 +279,7 @@ public class ApplicationController { /** Deploys an application. If the application does not exist it is created. */ // TODO: Get rid of the options arg - // TODO jvenstad: Split this, and choose between deployDirectly and deploy in handler, excluding internally built from the latter. + // TODO(jvenstad): Split this, and choose between deployDirectly and deploy in handler, excluding internally built from the latter. public ActivateResult deploy(ApplicationId applicationId, ZoneId zone, Optional<ApplicationPackage> applicationPackageFromDeployer, Optional<ApplicationVersion> applicationVersionFromDeployer, @@ -333,11 +333,12 @@ public class ApplicationController { validateRun(application.get(), zone, platformVersion, applicationVersion); } - // TODO: Remove this when all packages are validated upon submission, as in ApplicationApiHandler.submit(...). + // TODO(jvenstad): Remove this when all packages are validated upon submission, as in ApplicationApiHandler.submit(...). verifyApplicationIdentityConfiguration(applicationId.tenant(), applicationPackage, deployingIdentity); - // Assign global rotation + // TODO(ogronnesby): Remove feature flag and replace calls to withRotationLegacy with withRotation + // TODO(mpolden): Remove all handling of legacy endpoints once withRotationLegacy disappears if (useMultipleEndpoints.with(FetchVector.Dimension.APPLICATION_ID, application.get().id().serializedForm()).value()) { application = withRotation(application, zone); @@ -373,7 +374,7 @@ public class ApplicationController { if ( ! preferOldestVersion && ! application.get().deploymentJobs().deployedInternally() && ! zone.environment().isManuallyDeployed()) - // TODO jvenstad: Store only on submissions + // TODO(jvenstad): Store only on submissions storeWithUpdatedConfig(application, applicationPackage); } // Release application lock while doing the deployment, which is a lengthy task. @@ -495,21 +496,16 @@ public class ApplicationController { } private List<AssignedRotation> createDefaultGlobalIdRotation(Application application, Rotation rotation) { - // This is guaranteed by .withRotationLegacy, but add this to make inspections accept the use of .get() below - assert application.deploymentSpec().globalServiceId().isPresent(); - - final Set<RegionName> regions = application.deploymentSpec().zones().stream() - .filter(zone -> zone.environment().isProduction()) - .flatMap(zone -> zone.region().stream()) - .collect(Collectors.toSet()); - - final var assignment = new AssignedRotation( + Set<RegionName> regions = application.deploymentSpec().zones().stream() + .filter(zone -> zone.environment().isProduction()) + .flatMap(zone -> zone.region().stream()) + .collect(Collectors.toSet()); + var assignment = new AssignedRotation( ClusterSpec.Id.from(application.deploymentSpec().globalServiceId().get()), EndpointId.default_(), rotation.id(), regions ); - return List.of(assignment); } @@ -517,7 +513,7 @@ public class ApplicationController { private LockedApplication withRotation(LockedApplication application, ZoneId zone) { if (zone.environment() == Environment.prod) { try (RotationLock rotationLock = rotationRepository.lock()) { - final var rotations = rotationRepository.getOrAssignRotations(application.get(), rotationLock); + var rotations = rotationRepository.getOrAssignRotations(application.get(), rotationLock); application = application.with(rotations); store(application); // store assigned rotation even if deployment fails registerAssignedRotationCnames(application.get()); @@ -528,16 +524,12 @@ public class ApplicationController { private void registerAssignedRotationCnames(Application application) { application.assignedRotations().forEach(assignedRotation -> { - final var endpoints = application - .endpointsIn(controller.system(), assignedRotation.endpointId()) - .scope(Endpoint.Scope.global); - - final var maybeRotation = rotationRepository.getRotation(assignedRotation.rotationId()); - + var endpoints = application.endpointsIn(controller.system(), assignedRotation.endpointId()) + .scope(Endpoint.Scope.global); + var maybeRotation = rotationRepository.getRotation(assignedRotation.rotationId()); maybeRotation.ifPresent(rotation -> { - endpoints.main().ifPresent(mainEndpoint -> { - registerCname(mainEndpoint.dnsName(), rotation.name()); - }); + // For rotations assigned using <endpoints/> syntax, we only register the non-legacy name in DNS. + endpoints.main().ifPresent(mainEndpoint -> registerCname(mainEndpoint.dnsName(), rotation.name())); }); }); } @@ -545,7 +537,7 @@ public class ApplicationController { private LockedApplication withApplicationCertificate(LockedApplication application) { ApplicationId applicationId = application.get().id(); - // TODO: Verify that the application is deploying to a zone where certificate provisioning is enabled + // TODO(tokle): Verify that the application is deploying to a zone where certificate provisioning is enabled boolean provisionCertificate = provisionApplicationCertificate.with(FetchVector.Dimension.APPLICATION_ID, applicationId.serializedForm()).value(); if (provisionCertificate) { application = application.withApplicationCertificate( @@ -640,7 +632,7 @@ public class ApplicationController { .orElse(id.applicationId().instance().isTester())) throw new NotExistsException("Deployment", id.toString()); - // TODO jvenstad: Swap to use routingPolicies first, when this is ready. + // TODO(jvenstad): Swap to use routingPolicies first, when this is ready. try { var endpoints = routingGenerator.clusterEndpoints(id); if ( ! endpoints.isEmpty()) @@ -699,12 +691,12 @@ public class ApplicationController { applicationStore.removeAll(TesterId.of(id)); application.get().assignedRotations().forEach(assignedRotation -> { - final var endpoints = application.get().endpointsIn(controller.system(), assignedRotation.endpointId()); + var endpoints = application.get().endpointsIn(controller.system(), assignedRotation.endpointId()); endpoints.asList().stream() - .map(Endpoint::dnsName) - .forEach(name -> { - controller.nameServiceForwarder().removeRecords(Record.Type.CNAME, RecordName.from(name), Priority.normal); - }); + .map(Endpoint::dnsName) + .forEach(name -> { + controller.nameServiceForwarder().removeRecords(Record.Type.CNAME, RecordName.from(name), Priority.normal); + }); }); log.info("Deleted " + application); 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 ec13066d069..e23230b8503 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 @@ -72,7 +72,7 @@ public class AssignedRotation { public static AssignedRotation fromStrings(String clusterId, String endpointId, String rotationId, Collection<String> regions) { return new AssignedRotation( new ClusterSpec.Id(clusterId), - new EndpointId(endpointId), + EndpointId.of(endpointId), new RotationId(rotationId), regions.stream().map(RegionName::from).collect(Collectors.toSet()) ); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Endpoint.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Endpoint.java index 5dccd5c8120..4041c955cc4 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Endpoint.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/Endpoint.java @@ -3,7 +3,6 @@ package com.yahoo.vespa.hosted.controller.application; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; @@ -216,7 +215,6 @@ public class Endpoint { private ZoneId zone; private ClusterSpec.Id cluster; - private RotationName rotation; private EndpointId endpointId; private Port port; private boolean legacy = false; @@ -228,7 +226,7 @@ public class Endpoint { /** Sets the cluster and zone target of this */ public EndpointBuilder target(ClusterSpec.Id cluster, ZoneId zone) { - if (rotation != null || endpointId != null) { + if (endpointId != null) { throw new IllegalArgumentException("Cannot set multiple target types"); } this.cluster = cluster; @@ -236,18 +234,9 @@ public class Endpoint { return this; } - /** Sets the rotation target of this */ - public EndpointBuilder target(RotationName rotation) { - if ((cluster != null && zone != null) || endpointId != null) { - throw new IllegalArgumentException("Cannot set multiple target types"); - } - this.rotation = rotation; - return this; - } - /** Sets the endpoint ID as defines in deployments.xml */ public EndpointBuilder named(EndpointId endpointId) { - if (rotation != null || cluster != null || zone != null) { + if (cluster != null || zone != null) { throw new IllegalArgumentException("Cannot set multiple target types"); } this.endpointId = endpointId; @@ -277,8 +266,6 @@ public class Endpoint { String name; if (cluster != null && zone != null) { name = cluster.value(); - } else if (rotation != null) { - name = rotation.value(); } else if (endpointId != null) { name = endpointId.id(); } else { diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointId.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointId.java index 13c242c7b5f..7c88b94a2ae 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointId.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointId.java @@ -1,5 +1,7 @@ package com.yahoo.vespa.hosted.controller.application; +import org.jetbrains.annotations.NotNull; + import java.util.Objects; /** @@ -8,12 +10,13 @@ import java.util.Objects; * * @author ogronnesby */ -public class EndpointId { +public class EndpointId implements Comparable<EndpointId> { + private static final EndpointId DEFAULT = new EndpointId("default"); private final String id; - public EndpointId(String id) { + private EndpointId(String id) { this.id = requireNotEmpty(id); } @@ -50,4 +53,10 @@ public class EndpointId { public static EndpointId default_() { return DEFAULT; } public static EndpointId of(String id) { return new EndpointId(id); } + + @Override + public int compareTo(@NotNull EndpointId o) { + return id.compareTo(o.id); + } + } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointList.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointList.java index d9aea783880..c4613db27d1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointList.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/EndpointList.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.controller.application; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.hosted.controller.application.Endpoint.Port; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingId.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingId.java index c9378e27b61..7b0ec3d27ba 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingId.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingId.java @@ -2,31 +2,30 @@ package com.yahoo.vespa.hosted.controller.application; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.RotationName; import java.util.Objects; /** - * Unique identifier for a global routing table entry (application x rotation name). + * Unique identifier for a global routing table entry (application x endpoint ID). * * @author mpolden */ public class RoutingId { private final ApplicationId application; - private final RotationName rotation; + private final EndpointId endpointId; - public RoutingId(ApplicationId application, RotationName rotation) { + public RoutingId(ApplicationId application, EndpointId endpointId) { this.application = Objects.requireNonNull(application, "application must be non-null"); - this.rotation = Objects.requireNonNull(rotation, "rotation must be non-null"); + this.endpointId = Objects.requireNonNull(endpointId, "endpointId must be non-null"); } public ApplicationId application() { return application; } - public RotationName rotation() { - return rotation; + public EndpointId endpointId() { + return endpointId; } @Override @@ -35,12 +34,12 @@ public class RoutingId { if (o == null || getClass() != o.getClass()) return false; RoutingId that = (RoutingId) o; return application.equals(that.application) && - rotation.equals(that.rotation); + endpointId.equals(that.endpointId); } @Override public int hashCode() { - return Objects.hash(application, rotation); + return Objects.hash(application, endpointId); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingPolicy.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingPolicy.java index e0145e6b94c..a86bbaa317e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingPolicy.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/application/RoutingPolicy.java @@ -5,7 +5,6 @@ import com.google.common.collect.ImmutableSortedSet; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.application.Endpoint.Port; @@ -27,17 +26,17 @@ public class RoutingPolicy { private final ZoneId zone; private final HostName canonicalName; private final Optional<String> dnsZone; - private final Set<RotationName> rotations; + private final Set<EndpointId> endpoints; /** DO NOT USE. Public for serialization purposes */ public RoutingPolicy(ApplicationId owner, ClusterSpec.Id cluster, ZoneId zone, HostName canonicalName, - Optional<String> dnsZone, Set<RotationName> rotations) { + Optional<String> dnsZone, Set<EndpointId> endpoints) { 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"); this.canonicalName = Objects.requireNonNull(canonicalName, "canonicalName must be non-null"); this.dnsZone = Objects.requireNonNull(dnsZone, "dnsZone must be non-null"); - this.rotations = ImmutableSortedSet.copyOf(Objects.requireNonNull(rotations, "rotations must be non-null")); + this.endpoints = ImmutableSortedSet.copyOf(Objects.requireNonNull(endpoints, "endpoints must be non-null")); } /** The application owning this */ @@ -65,9 +64,9 @@ public class RoutingPolicy { return dnsZone; } - /** The rotations in this policy */ - public Set<RotationName> rotations() { - return rotations; + /** The endpoints of this policy */ + public Set<EndpointId> endpoints() { + return endpoints; } /** Returns the endpoint of this */ @@ -77,7 +76,7 @@ public class RoutingPolicy { /** Returns rotation endpoints of this */ public EndpointList rotationEndpointsIn(SystemName system) { - return EndpointList.of(rotations.stream().map(rotation -> endpointOf(owner, rotation, system))); + return EndpointList.of(endpoints.stream().map(endpointId -> endpointOf(owner, endpointId, system))); } @Override @@ -95,14 +94,14 @@ public class RoutingPolicy { @Override public String toString() { - return String.format("%s [rotations: %s%s], %s owned by %s, in %s", canonicalName, rotations, + return String.format("%s [rotations: %s%s], %s owned by %s, in %s", canonicalName, endpoints, dnsZone.map(z -> ", DNS zone: " + z).orElse(""), cluster, owner.toShortString(), zone.value()); } /** Returns the endpoint of given rotation */ - public static Endpoint endpointOf(ApplicationId application, RotationName rotation, SystemName system) { - return Endpoint.of(application).target(rotation).on(Port.tls()).directRouting().in(system); + public static Endpoint endpointOf(ApplicationId application, EndpointId endpointId, SystemName system) { + return Endpoint.of(application).named(endpointId).on(Port.tls()).directRouting().in(system); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicies.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicies.java index 4a98cb49227..d23ae913889 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicies.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicies.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.curator.Lock; import com.yahoo.vespa.hosted.controller.Controller; @@ -12,6 +13,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData; import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName; import com.yahoo.vespa.hosted.controller.application.Endpoint; +import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.RoutingId; import com.yahoo.vespa.hosted.controller.application.RoutingPolicy; import com.yahoo.vespa.hosted.controller.dns.NameServiceQueue.Priority; @@ -89,7 +91,7 @@ public class RoutingPolicies { // Create DNS record for each routing ID for (Map.Entry<RoutingId, List<RoutingPolicy>> routeEntry : routingTable.entrySet()) { - Endpoint endpoint = RoutingPolicy.endpointOf(routeEntry.getKey().application(), routeEntry.getKey().rotation(), + Endpoint endpoint = RoutingPolicy.endpointOf(routeEntry.getKey().application(), routeEntry.getKey().endpointId(), controller.system()); Set<AliasTarget> targets = routeEntry.getValue() .stream() @@ -117,9 +119,14 @@ public class RoutingPolicies { /** Create a policy for given load balancer and register a CNAME for it */ private RoutingPolicy createPolicy(ApplicationId application, ZoneId zone, LoadBalancer loadBalancer) { + // TODO(mpolden): Remove rotations from LoadBalancer. Use endpoints from deployment spec instead + Set<EndpointId> endpoints = loadBalancer.rotations().stream() + .map(RotationName::value) + .map(EndpointId::of) + .collect(Collectors.toSet()); RoutingPolicy routingPolicy = new RoutingPolicy(application, loadBalancer.cluster(), zone, loadBalancer.hostname(), loadBalancer.dnsZone(), - loadBalancer.rotations()); + endpoints); RecordName name = RecordName.from(routingPolicy.endpointIn(controller.system()).dnsName()); RecordData data = RecordData.fqdn(loadBalancer.hostname().value()); controller.nameServiceForwarder().createCname(name, data, Priority.normal); @@ -151,7 +158,7 @@ public class RoutingPolicies { var activeRoutingIds = routingIdsFrom(loadBalancers.list); removalCandidates.removeAll(activeRoutingIds); for (var id : removalCandidates) { - Endpoint endpoint = RoutingPolicy.endpointOf(id.application(), id.rotation(), controller.system()); + Endpoint endpoint = RoutingPolicy.endpointOf(id.application(), id.endpointId(), controller.system()); controller.nameServiceForwarder().removeRecords(Record.Type.ALIAS, RecordName.from(endpoint.dnsName()), Priority.normal); } } @@ -161,7 +168,7 @@ public class RoutingPolicies { Set<RoutingId> routingIds = new LinkedHashSet<>(); for (var loadBalancer : loadBalancers) { for (var rotation : loadBalancer.rotations()) { - routingIds.add(new RoutingId(loadBalancer.application(), rotation)); + routingIds.add(new RoutingId(loadBalancer.application(), EndpointId.of(rotation.value()))); } } return Collections.unmodifiableSet(routingIds); @@ -171,7 +178,7 @@ public class RoutingPolicies { private static Map<RoutingId, List<RoutingPolicy>> routingTableFrom(Set<RoutingPolicy> routingPolicies) { var routingTable = new LinkedHashMap<RoutingId, List<RoutingPolicy>>(); for (var policy : routingPolicies) { - for (var rotation : policy.rotations()) { + for (var rotation : policy.endpoints()) { var id = new RoutingId(policy.owner(), rotation); routingTable.putIfAbsent(id, new ArrayList<>()); routingTable.get(id).add(policy); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java index 9cfce8dc16a..80858e713c2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializer.java @@ -4,11 +4,10 @@ package com.yahoo.vespa.hosted.controller.persistence; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.slime.ArrayTraverser; -import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; +import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.RoutingPolicy; import java.util.Collections; @@ -39,36 +38,36 @@ public class RoutingPolicySerializer { private static final String rotationsField = "rotations"; public Slime toSlime(Set<RoutingPolicy> routingPolicies) { - Slime slime = new Slime(); - Cursor root = slime.setObject(); - Cursor policyArray = root.setArray(routingPoliciesField); + var slime = new Slime(); + var root = slime.setObject(); + var policyArray = root.setArray(routingPoliciesField); routingPolicies.forEach(policy -> { - Cursor policyObject = policyArray.addObject(); + var policyObject = policyArray.addObject(); policyObject.setString(clusterField, policy.cluster().value()); policyObject.setString(zoneField, policy.zone().value()); policyObject.setString(canonicalNameField, policy.canonicalName().value()); policy.dnsZone().ifPresent(dnsZone -> policyObject.setString(dnsZoneField, dnsZone)); - Cursor rotationArray = policyObject.setArray(rotationsField); - policy.rotations().forEach(rotation -> { - rotationArray.addString(rotation.value()); + var rotationArray = policyObject.setArray(rotationsField); + policy.endpoints().forEach(endpointId -> { + rotationArray.addString(endpointId.id()); }); }); return slime; } public Set<RoutingPolicy> fromSlime(ApplicationId owner, Slime slime) { - Set<RoutingPolicy> policies = new LinkedHashSet<>(); - Cursor root = slime.get(); - Cursor field = root.field(routingPoliciesField); + var policies = new LinkedHashSet<RoutingPolicy>(); + var root = slime.get(); + var field = root.field(routingPoliciesField); field.traverse((ArrayTraverser) (i, inspect) -> { - Set<RotationName> rotations = new LinkedHashSet<>(); - inspect.field(rotationsField).traverse((ArrayTraverser) (j, rotation) -> rotations.add(RotationName.from(rotation.asString()))); + var endpointIds = new LinkedHashSet<EndpointId>(); + inspect.field(rotationsField).traverse((ArrayTraverser) (j, endpointId) -> endpointIds.add(EndpointId.of(endpointId.asString()))); policies.add(new RoutingPolicy(owner, ClusterSpec.Id.from(inspect.field(clusterField).asString()), ZoneId.from(inspect.field(zoneField).asString()), HostName.from(inspect.field(canonicalNameField).asString()), Serializers.optionalField(inspect.field(dnsZoneField), Function.identity()), - rotations)); + endpointIds)); }); return Collections.unmodifiableSet(policies); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/EndpointTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/EndpointTest.java index f5047a82e2f..bf798d2f004 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/EndpointTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/application/EndpointTest.java @@ -3,7 +3,6 @@ package com.yahoo.vespa.hosted.controller.application; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.application.Endpoint.Port; @@ -23,51 +22,51 @@ public class EndpointTest { @Test public void test_global_endpoints() { - RotationName rotation = RotationName.from("default"); // Always default for non-direct routing + EndpointId endpointId = EndpointId.default_(); Map<String, Endpoint> tests = Map.of( // Legacy endpoint "http://a1.t1.global.vespa.yahooapis.com:4080/", - Endpoint.of(app1).target(rotation).on(Port.plain(4080)).legacy().in(SystemName.main), + Endpoint.of(app1).named(endpointId).on(Port.plain(4080)).legacy().in(SystemName.main), // Legacy endpoint with TLS "https://a1--t1.global.vespa.yahooapis.com:4443/", - Endpoint.of(app1).target(rotation).on(Port.tls(4443)).legacy().in(SystemName.main), + Endpoint.of(app1).named(endpointId).on(Port.tls(4443)).legacy().in(SystemName.main), // Main endpoint "https://a1--t1.global.vespa.oath.cloud:4443/", - Endpoint.of(app1).target(rotation).on(Port.tls(4443)).in(SystemName.main), + Endpoint.of(app1).named(endpointId).on(Port.tls(4443)).in(SystemName.main), // Main endpoint in CD "https://cd--a1--t1.global.vespa.oath.cloud:4443/", - Endpoint.of(app1).target(rotation).on(Port.tls(4443)).in(SystemName.cd), + Endpoint.of(app1).named(endpointId).on(Port.tls(4443)).in(SystemName.cd), // Main endpoint with direct routing and default TLS port "https://a1.t1.global.vespa.oath.cloud/", - Endpoint.of(app1).target(rotation).on(Port.tls()).directRouting().in(SystemName.main), + Endpoint.of(app1).named(endpointId).on(Port.tls()).directRouting().in(SystemName.main), // Main endpoint with custom rotation name "https://r1.a1.t1.global.vespa.oath.cloud/", - Endpoint.of(app1).target(RotationName.from("r1")).on(Port.tls()).directRouting().in(SystemName.main), + Endpoint.of(app1).named(EndpointId.of("r1")).on(Port.tls()).directRouting().in(SystemName.main), // Main endpoint for custom instance in default rotation "https://a2.t2.global.vespa.oath.cloud/", - Endpoint.of(app2).target(rotation).on(Port.tls()).directRouting().in(SystemName.main), + Endpoint.of(app2).named(endpointId).on(Port.tls()).directRouting().in(SystemName.main), // Main endpoint for custom instance with custom rotation name "https://r2.a2.t2.global.vespa.oath.cloud/", - Endpoint.of(app2).target(RotationName.from("r2")).on(Port.tls()).directRouting().in(SystemName.main), + Endpoint.of(app2).named(EndpointId.of("r2")).on(Port.tls()).directRouting().in(SystemName.main), // Main endpoint in public system "https://a1.t1.global.public.vespa.oath.cloud/", - Endpoint.of(app1).target(rotation).on(Port.tls()).directRouting().in(SystemName.Public) + Endpoint.of(app1).named(endpointId).on(Port.tls()).directRouting().in(SystemName.Public) ); tests.forEach((expected, endpoint) -> assertEquals(expected, endpoint.url().toString())); } @Test public void test_global_endpoints_with_endpoint_id() { - final var endpointId = EndpointId.default_(); + var endpointId = EndpointId.default_(); Map<String, Endpoint> tests = Map.of( // Legacy endpoint @@ -111,9 +110,9 @@ public class EndpointTest { @Test public void test_zone_endpoints() { - ClusterSpec.Id cluster = ClusterSpec.Id.from("default"); // Always default for non-direct routing - ZoneId prodZone = ZoneId.from("prod", "us-north-1"); - ZoneId testZone = ZoneId.from("test", "us-north-2"); + var cluster = ClusterSpec.Id.from("default"); // Always default for non-direct routing + var prodZone = ZoneId.from("prod", "us-north-1"); + var testZone = ZoneId.from("test", "us-north-2"); Map<String, Endpoint> tests = Map.of( // Legacy endpoint (always contains environment) diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPoliciesTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPoliciesTest.java index f0344cb8d12..600fca4f45e 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPoliciesTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPoliciesTest.java @@ -105,7 +105,7 @@ public class RoutingPoliciesTest { Set<RoutingPolicy> policies = tester.controller().curator().readRoutingPolicies(app1.id()); assertEquals(clustersPerZone * numberOfDeployments, policies.size()); assertTrue("Rotation membership is removed from all policies", - policies.stream().allMatch(policy -> policy.rotations().isEmpty())); + policies.stream().allMatch(policy -> policy.endpoints().isEmpty())); assertEquals("Rotations for " + app2 + " are not removed", 2, records3.get().size()); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java index a0e95bd0393..e99cc302ffe 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java @@ -5,8 +5,8 @@ import com.google.common.collect.ImmutableSet; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.RoutingPolicy; import org.junit.Test; @@ -26,19 +26,19 @@ public class RoutingPolicySerializerTest { @Test public void test_serialization() { var owner = ApplicationId.defaultId(); - var rotations = Set.of(RotationName.from("r1"), RotationName.from("r2")); + var endpoints = Set.of(EndpointId.of("r1"), EndpointId.of("r2")); var policies = ImmutableSet.of(new RoutingPolicy(owner, ClusterSpec.Id.from("my-cluster1"), ZoneId.from("prod", "us-north-1"), HostName.from("long-and-ugly-name"), Optional.of("zone1"), - rotations), + endpoints), new RoutingPolicy(owner, ClusterSpec.Id.from("my-cluster2"), ZoneId.from("prod", "us-north-2"), HostName.from("long-and-ugly-name-2"), Optional.empty(), - rotations)); + endpoints)); var serialized = serializer.fromSlime(owner, serializer.toSlime(policies)); assertEquals(policies.size(), serialized.size()); for (Iterator<RoutingPolicy> it1 = policies.iterator(), it2 = serialized.iterator(); it1.hasNext();) { @@ -49,7 +49,7 @@ public class RoutingPolicySerializerTest { assertEquals(expected.zone(), actual.zone()); assertEquals(expected.canonicalName(), actual.canonicalName()); assertEquals(expected.dnsZone(), actual.dnsZone()); - assertEquals(expected.rotations(), actual.rotations()); + assertEquals(expected.endpoints(), actual.endpoints()); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 577b8491bd2..41d8edbabc0 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -11,7 +11,6 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.RegionName; -import com.yahoo.config.provision.RotationName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.slime.Cursor; @@ -44,6 +43,7 @@ import com.yahoo.vespa.hosted.controller.application.ClusterUtilization; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.DeploymentJobs; import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; +import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.JobStatus; import com.yahoo.vespa.hosted.controller.application.RotationStatus; import com.yahoo.vespa.hosted.controller.application.RoutingPolicy; @@ -1380,7 +1380,7 @@ public class ApplicationApiTest extends ControllerContainerTest { ClusterSpec.Id.from("default"), ZoneId.from(Environment.prod, RegionName.from("us-west-1")), HostName.from("lb-0-canonical-name"), - Optional.of("dns-zone-1"), Set.of(RotationName.from("c0"))); + Optional.of("dns-zone-1"), Set.of(EndpointId.of("c0"))); tester.controller().curator().writeRoutingPolicies(app.id(), Set.of(policy)); // GET application |