diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-09-13 14:49:41 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-09-13 14:49:41 +0200 |
commit | 071242cb90a62e867e81b0d923a9c7bc0c6a76c0 (patch) | |
tree | d16025abb3df6c46f9ccc95756d2bfc6faf5c0a3 /controller-api/src | |
parent | a75d98e927fcd4b574f697bdfaa4f01930afc12e (diff) |
Move RoutingGeneratorMock to controller-api
Diffstat (limited to 'controller-api/src')
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java | 61 |
1 files changed, 61 insertions, 0 deletions
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..a7dc5f81bc0 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java @@ -0,0 +1,61 @@ +// 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; +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 + */ +public class RoutingGeneratorMock implements RoutingGenerator { + + public static final List<RoutingEndpoint> TEST_ENDPOINTS = + List.of(new RoutingEndpoint("http://old-endpoint.vespa.yahooapis.com:4080", "host1", false, "upstream3"), + new RoutingEndpoint("http://qrs-endpoint.vespa.yahooapis.com:4080", "host1", false, "upstream1"), + new RoutingEndpoint("http://feeding-endpoint.vespa.yahooapis.com:4080", "host2", false, "upstream2"), + new RoutingEndpoint("http://global-endpoint.vespa.yahooapis.com:4080", "host1", true, "upstream1"), + new RoutingEndpoint("http://alias-endpoint.vespa.yahooapis.com:4080", "host1", true, "upstream1")); + + private final Map<DeploymentId, List<RoutingEndpoint>> routingTable = new ConcurrentHashMap<>(); + private final List<RoutingEndpoint> defaultEndpoints; + + public RoutingGeneratorMock() { + this(List.of()); + } + + public RoutingGeneratorMock(List<RoutingEndpoint> endpoints) { + this.defaultEndpoints = List.copyOf(endpoints); + } + + @Override + public List<RoutingEndpoint> endpoints(DeploymentId deployment) { + if (routingTable.isEmpty()) return defaultEndpoints; + 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); + } + +} |