From 071242cb90a62e867e81b0d923a9c7bc0c6a76c0 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 13 Sep 2019 14:49:41 +0200 Subject: Move RoutingGeneratorMock to controller-api --- .../integration/routing/RoutingGeneratorMock.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/routing/RoutingGeneratorMock.java (limited to 'controller-api/src') 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 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> routingTable = new ConcurrentHashMap<>(); + private final List defaultEndpoints; + + public RoutingGeneratorMock() { + this(List.of()); + } + + public RoutingGeneratorMock(List endpoints) { + this.defaultEndpoints = List.copyOf(endpoints); + } + + @Override + public List endpoints(DeploymentId deployment) { + if (routingTable.isEmpty()) return defaultEndpoints; + return routingTable.getOrDefault(deployment, List.of()); + } + + @Override + public Map 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 endpoints) { + routingTable.put(deployment, endpoints); + } + + public void removeEndpoints(DeploymentId deployment) { + routingTable.remove(deployment); + } + +} -- cgit v1.2.3