diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-03-13 13:14:03 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-03-14 10:15:16 +0100 |
commit | e1d512b26b48f581d166d6de54212e40130cae1d (patch) | |
tree | b17bb36dd20fa0213351414ce6bf1627d8456024 /controller-server | |
parent | 6c814045134cf2a0762b90414dedeb18e864aff7 (diff) |
Disallow direct access to global endpoints list
Diffstat (limited to 'controller-server')
2 files changed, 39 insertions, 47 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java index 31812b9346b..6cfde326c50 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java @@ -21,6 +21,7 @@ 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.Deployment; import com.yahoo.vespa.hosted.controller.application.Endpoint; +import com.yahoo.vespa.hosted.controller.application.Endpoint.Port; import com.yahoo.vespa.hosted.controller.application.EndpointList; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; import com.yahoo.vespa.hosted.controller.dns.NameServiceQueue.Priority; @@ -111,11 +112,9 @@ public class RoutingController { var deployments = rotation.regions().stream() .map(region -> new DeploymentId(instance.id(), ZoneId.from(Environment.prod, region))) .collect(Collectors.toList()); - var targets = deployments.stream().map(DeploymentId::zoneId).collect(Collectors.toList()); - EndpointList.global(RoutingId.of(instance.id(), rotation.endpointId()), controller.system(), targets, - routingMethodsOfAll(deployments, application)) - .requiresRotation() - .forEach(endpoints::add); + computeGlobalEndpoints(RoutingId.of(instance.id(), rotation.endpointId()), + application, deployments).requiresRotation() + .forEach(endpoints::add); } // Add global endpoints provided by routing policies var deploymentsByRoutingId = new LinkedHashMap<RoutingId, List<DeploymentId>>(); @@ -128,10 +127,7 @@ public class RoutingController { } } deploymentsByRoutingId.forEach((routingId, deployments) -> { - var targets = deployments.stream().map(DeploymentId::zoneId).collect(Collectors.toList()); - EndpointList.global(routingId, controller.system(), targets, routingMethodsOfAll(deployments, application)) - .not().requiresRotation() - .forEach(endpoints::add); + computeGlobalEndpoints(routingId, application, deployments).not().requiresRotation().forEach(endpoints::add); }); return EndpointList.copyOf(endpoints); } @@ -293,4 +289,38 @@ public class RoutingController { .value(); } + /** Compute global endpoints for given routing ID, application and deployments */ + private EndpointList computeGlobalEndpoints(RoutingId routingId, Application application, List<DeploymentId> deployments) { + var endpoints = new ArrayList<Endpoint>(); + var directMethods = 0; + var targets = deployments.stream().map(DeploymentId::zoneId).collect(Collectors.toList()); + for (var method : routingMethodsOfAll(deployments, application)) { + if (method.isDirect() && ++directMethods > 1) { + throw new IllegalArgumentException("Invalid routing methods for " + routingId + ": Exceeded maximum " + + "direct methods"); + } + endpoints.add(Endpoint.of(routingId.application()) + .named(routingId.endpointId(), targets) + .on(Port.fromRoutingMethod(method)) + .routingMethod(method) + .in(controller.system())); + // TODO(mpolden): Remove this once all applications have migrated away from legacy endpoints + if (method == RoutingMethod.shared) { + endpoints.add(Endpoint.of(routingId.application()) + .named(routingId.endpointId(), targets) + .on(Port.plain(4080)) + .legacy() + .routingMethod(method) + .in(controller.system())); + endpoints.add(Endpoint.of(routingId.application()) + .named(routingId.endpointId(), targets) + .on(Port.tls(4443)) + .legacy() + .routingMethod(method) + .in(controller.system())); + } + } + return EndpointList.copyOf(endpoints); + } + } 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 a4c7a57247c..7cb284e6308 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,13 +2,8 @@ package com.yahoo.vespa.hosted.controller.application; import com.yahoo.collections.AbstractFilteringList; -import com.yahoo.config.provision.SystemName; -import com.yahoo.config.provision.zone.RoutingMethod; import com.yahoo.config.provision.zone.ZoneId; -import com.yahoo.vespa.hosted.controller.application.Endpoint.Port; -import com.yahoo.vespa.hosted.controller.routing.RoutingId; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -67,39 +62,6 @@ public class EndpointList extends AbstractFilteringList<Endpoint, EndpointList> return matching(endpoint -> endpoint.scope() == scope); } - /** Returns all global endpoints for given routing ID and system provided by given routing methods */ - public static EndpointList global(RoutingId routingId, SystemName system, List<ZoneId> targets, List<RoutingMethod> routingMethods) { - var endpoints = new ArrayList<Endpoint>(); - var directMethods = 0; - for (var method : routingMethods) { - if (method.isDirect() && ++directMethods > 1) { - throw new IllegalArgumentException("Invalid routing methods for " + routingId + ": Exceeded maximum " + - "direct methods, got " + routingMethods); - } - endpoints.add(Endpoint.of(routingId.application()) - .named(routingId.endpointId(), targets) - .on(Port.fromRoutingMethod(method)) - .routingMethod(method) - .in(system)); - // TODO(mpolden): Remove this once all applications have migrated away from legacy endpoints - if (method == RoutingMethod.shared) { - endpoints.add(Endpoint.of(routingId.application()) - .named(routingId.endpointId(), targets) - .on(Port.plain(4080)) - .legacy() - .routingMethod(method) - .in(system)); - endpoints.add(Endpoint.of(routingId.application()) - .named(routingId.endpointId(), targets) - .on(Port.tls(4443)) - .legacy() - .routingMethod(method) - .in(system)); - } - } - return new EndpointList(endpoints); - } - public static EndpointList copyOf(Collection<Endpoint> endpoints) { return new EndpointList(endpoints); } |