summaryrefslogtreecommitdiffstats
path: root/controller-api
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 /controller-api
parentacd8d9298c837a9005f0f54e8da062260d7339cc (diff)
Revert "Remove RoutingGenerator"
Diffstat (limited to 'controller-api')
-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
4 files changed, 136 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);
+ }
+
+}