aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-03-16 11:05:50 +0100
committerGitHub <noreply@github.com>2020-03-16 11:05:50 +0100
commit2133f64c1d2a80b41a245d0666976c5f2003d53f (patch)
treecff6920f1bc3f020022903d567d81f3aec4d2e27
parentacd8d9298c837a9005f0f54e8da062260d7339cc (diff)
Revert "Remove RoutingGenerator"
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java4
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingEndpoint.java60
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGenerator.java27
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java45
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/RoutingController.java10
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java25
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java3
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java12
8 files changed, 186 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
index ca939023245..978a00fbccf 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java
@@ -20,6 +20,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportCons
import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient;
import com.yahoo.vespa.hosted.controller.api.integration.resource.TenantCost;
import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService;
+import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator;
import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry;
import java.time.Clock;
@@ -40,6 +41,9 @@ public interface ServiceRegistry {
GlobalRoutingService globalRoutingService();
+ // TODO(mpolden): Remove
+ RoutingGenerator routingGenerator();
+
Mailer mailer();
EndpointCertificateProvider endpointCertificateProvider();
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingEndpoint.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingEndpoint.java
new file mode 100644
index 00000000000..c0ccd0722f3
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingEndpoint.java
@@ -0,0 +1,60 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.api.integration.routing;
+
+import java.util.Objects;
+
+/**
+ * @author smorgrav
+ */
+// TODO(mpolden): Remove together with RoutingGenerator and its implementations
+public class RoutingEndpoint {
+
+ private final boolean isGlobal;
+ private final String endpoint;
+ private final String hostname;
+ private final String upstreamName;
+
+ public RoutingEndpoint(String endpoint, String hostname, boolean isGlobal, String upstreamName) {
+ this.endpoint = endpoint;
+ this.hostname = hostname;
+ this.isGlobal = isGlobal;
+ this.upstreamName = upstreamName;
+ }
+
+ /** Whether this is a global endpoint */
+ public boolean isGlobal() {
+ return isGlobal;
+ }
+
+ /** URL for this endpoint */
+ public String endpoint() {
+ return endpoint;
+ }
+
+ /** First hostname for an upstream behind this endpoint */
+ public String hostname() {
+ return hostname;
+ }
+
+ /** The upstream name of this endpoint */
+ public String upstreamName() {
+ return upstreamName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RoutingEndpoint that = (RoutingEndpoint) o;
+ return isGlobal == that.isGlobal &&
+ endpoint.equals(that.endpoint) &&
+ hostname.equals(that.hostname) &&
+ upstreamName.equals(that.upstreamName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(isGlobal, endpoint, hostname, upstreamName);
+ }
+
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGenerator.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGenerator.java
new file mode 100644
index 00000000000..8150a99979e
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGenerator.java
@@ -0,0 +1,27 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.api.integration.routing;
+
+import com.yahoo.config.provision.ClusterSpec;
+import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author bratseth
+ * @author smorgrav
+ */
+// TODO(mpolden): Remove
+public interface RoutingGenerator {
+
+ /**
+ * @param deploymentId Specifying an application in a zone
+ * @return List of endpoints for that deploymentId
+ */
+ List<RoutingEndpoint> endpoints(DeploymentId deploymentId);
+
+ /** Returns the endpoints of each cluster in the given deployment — nothing global. */
+ Map<ClusterSpec.Id, URI> clusterEndpoints(DeploymentId deploymentId);
+
+}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java
new file mode 100644
index 00000000000..e768a090188
--- /dev/null
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java
@@ -0,0 +1,45 @@
+// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.controller.api.integration.routing;
+
+import com.yahoo.config.provision.ClusterSpec;
+import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+/**
+ * Returns a default set of endpoints on every query if it has no mappings, or those added by the user, otherwise.
+ *
+ * @author bratseth
+ * @author jonmv
+ */
+// TODO(mpolden): Remove
+public class RoutingGeneratorMock implements RoutingGenerator {
+
+ private final Map<DeploymentId, List<RoutingEndpoint>> routingTable = new ConcurrentHashMap<>();
+
+ @Override
+ public List<RoutingEndpoint> endpoints(DeploymentId deployment) {
+ return routingTable.getOrDefault(deployment, List.of());
+ }
+
+ @Override
+ public Map<ClusterSpec.Id, URI> clusterEndpoints(DeploymentId deployment) {
+ return endpoints(deployment).stream()
+ .limit(1)
+ .collect(Collectors.toMap(__ -> ClusterSpec.Id.from("default"),
+ endpoint -> URI.create(endpoint.endpoint())));
+ }
+
+ public void putEndpoints(DeploymentId deployment, List<RoutingEndpoint> endpoints) {
+ routingTable.put(deployment, endpoints);
+ }
+
+ public void removeEndpoints(DeploymentId deployment) {
+ routingTable.remove(deployment);
+ }
+
+}
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 6cfde326c50..1730f033d61 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
@@ -85,12 +85,22 @@ public class RoutingController {
/** Returns zone-scoped endpoints for given deployment */
public EndpointList endpointsOf(DeploymentId deployment) {
var endpoints = new LinkedHashSet<Endpoint>();
+ // TODO(mpolden): Remove this once all applications have deployed once and config server passes correct cluster
+ // id for combined cluster type
+ controller.serviceRegistry().routingGenerator().clusterEndpoints(deployment)
+ .forEach((cluster, url) -> endpoints.add(Endpoint.of(deployment.applicationId())
+ .target(cluster, deployment.zoneId())
+ .routingMethod(RoutingMethod.shared)
+ .on(Port.fromRoutingMethod(RoutingMethod.shared))
+ .in(controller.system())));
+ boolean hasSharedEndpoint = !endpoints.isEmpty();
// Avoid reading application more than once per call to this
var application = Suppliers.memoize(() -> controller.applications().requireApplication(TenantAndApplicationId.from(deployment.applicationId())));
for (var policy : routingPolicies.get(deployment).values()) {
if (!policy.status().isActive()) continue;
for (var routingMethod : controller.zoneRegistry().routingMethods(policy.id().zone())) {
if (routingMethod.isDirect() && !canRouteDirectlyTo(deployment, application.get())) continue;
+ if (hasSharedEndpoint && routingMethod == RoutingMethod.shared) continue;
endpoints.add(policy.endpointIn(controller.system(), routingMethod));
}
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
index a0d2630091b..ad8c7d7c328 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
@@ -26,6 +26,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.ApplicationV
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.api.integration.routing.RoutingEndpoint;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.Deployment;
import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics;
@@ -784,6 +785,30 @@ public class ControllerTest {
}
@Test
+ public void testDeployWithRoutingGeneratorEndpoints() {
+ var context = tester.newDeploymentContext();
+ var applicationPackage = new ApplicationPackageBuilder()
+ .upgradePolicy("default")
+ .environment(Environment.prod)
+ .region("us-west-1")
+ .build();
+
+ var zones = Set.of(systemTest.zone(tester.controller().system()),
+ stagingTest.zone(tester.controller().system()),
+ ZoneId.from("prod", "us-west-1"));
+ for (var zone : zones) {
+ tester.controllerTester().serviceRegistry().routingGeneratorMock()
+ .putEndpoints(context.deploymentIdIn(zone),
+ List.of(new RoutingEndpoint("http://legacy-endpoint", "hostname",
+ false, "upstreamName")));
+ }
+ // Defer load balancer provisioning in all environments so that routing controller uses routing generator
+ context.deferLoadBalancerProvisioningIn(zones.stream().map(ZoneId::environment).collect(Collectors.toSet()))
+ .submit(applicationPackage)
+ .deploy();
+ }
+
+ @Test
public void testDeployWithGlobalEndpointsAndMultipleRoutingMethods() {
var context = tester.newDeploymentContext();
var zone1 = ZoneId.from("prod", "us-west-1");
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
index c9ad121276f..21b6e729e41 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java
@@ -18,6 +18,7 @@ import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbi
import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction;
import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RestartAction;
import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ServiceInfo;
+import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.integration.LogEntry;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node;
@@ -177,6 +178,8 @@ public class InternalStepRunnerTest {
.deferLoadBalancerProvisioningIn(testZone.environment());
tester.newDeploymentContext(app.instanceId())
.deferLoadBalancerProvisioningIn(stagingZone.environment());
+ tester.controllerTester().serviceRegistry().routingGeneratorMock().putEndpoints(new DeploymentId(app.testerId().id(), testZone), List.of());
+ tester.controllerTester().serviceRegistry().routingGeneratorMock().putEndpoints(new DeploymentId(app.instanceId(), stagingZone), List.of());
tester.runner().run();
tester.configServer().convergeServices(app.instanceId(), JobType.stagingTest.zone(system()));
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
index 98178f2a19f..8863651e1b5 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java
@@ -21,6 +21,8 @@ import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportCons
import com.yahoo.vespa.hosted.controller.api.integration.resource.MockTenantCost;
import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService;
import com.yahoo.vespa.hosted.controller.api.integration.routing.MemoryGlobalRoutingService;
+import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator;
+import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGeneratorMock;
import com.yahoo.vespa.hosted.controller.api.integration.stubs.DummyOwnershipIssues;
import com.yahoo.vespa.hosted.controller.api.integration.stubs.LoggingDeploymentIssues;
import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMailer;
@@ -40,6 +42,7 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg
private final ConfigServerMock configServerMock;
private final MemoryNameService memoryNameService = new MemoryNameService();
private final MemoryGlobalRoutingService memoryGlobalRoutingService = new MemoryGlobalRoutingService();
+ private final RoutingGeneratorMock routingGeneratorMock = new RoutingGeneratorMock();
private final MockMailer mockMailer = new MockMailer();
private final EndpointCertificateMock endpointCertificateMock = new EndpointCertificateMock();
private final MockMeteringClient mockMeteringClient = new MockMeteringClient();
@@ -89,6 +92,11 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg
}
@Override
+ public RoutingGenerator routingGenerator() {
+ return routingGeneratorMock;
+ }
+
+ @Override
public MockMailer mailer() {
return mockMailer;
}
@@ -189,6 +197,10 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg
return memoryGlobalRoutingService;
}
+ public RoutingGeneratorMock routingGeneratorMock() {
+ return routingGeneratorMock;
+ }
+
public MockContactRetriever contactRetrieverMock() {
return mockContactRetriever;
}