diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2021-11-15 15:22:51 +0100 |
---|---|---|
committer | Morten Tokle <mortent@verizonmedia.com> | 2021-11-16 14:53:29 +0100 |
commit | b1c0459ee626212f582dcfc0d150b5b2ff4f9009 (patch) | |
tree | e2d7ffbd69835d9d31574ef43caf0358aa8ef3db | |
parent | 1f7022d4f8d6fd78e74b9d12899f158d06a58ab6 (diff) |
Include clusterId
5 files changed, 41 insertions, 10 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/ApplicationClusterEndpoint.java b/config-model-api/src/main/java/com/yahoo/config/model/api/ApplicationClusterEndpoint.java index 38a122c4fab..1c45e4ba5dd 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/ApplicationClusterEndpoint.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/ApplicationClusterEndpoint.java @@ -26,13 +26,15 @@ public class ApplicationClusterEndpoint { private final RoutingMethod routingMethod; private final int weight; private final List<String> hostNames; + private final String clusterId; - private ApplicationClusterEndpoint(DnsName dnsName, Scope scope, RoutingMethod routingMethod, int weight, List<String> hostNames) { - this.dnsName = dnsName; - this.scope = scope; - this.routingMethod = routingMethod; + private ApplicationClusterEndpoint(DnsName dnsName, Scope scope, RoutingMethod routingMethod, int weight, List<String> hostNames, String clusterId) { + this.dnsName = Objects.requireNonNull(dnsName); + this.scope = Objects.requireNonNull(scope); + this.routingMethod = Objects.requireNonNull(routingMethod); this.weight = weight; - this.hostNames = List.copyOf(hostNames); + this.hostNames = List.copyOf(Objects.requireNonNull(hostNames)); + this.clusterId = Objects.requireNonNull(clusterId); } public DnsName dnsName() { @@ -55,6 +57,10 @@ public class ApplicationClusterEndpoint { return hostNames; } + public String clusterId() { + return clusterId; + } + public static Builder builder() { return new Builder(); } @@ -66,6 +72,7 @@ public class ApplicationClusterEndpoint { private RoutingMethod routingMethod; private int weigth = 1; private List<String> hosts; + private String clusterId; public Builder dnsName(DnsName name) { this.dnsName = name; @@ -102,8 +109,13 @@ public class ApplicationClusterEndpoint { return this; } + public Builder clusterId(String clusterId) { + this.clusterId = clusterId; + return this; + } + public ApplicationClusterEndpoint build() { - return new ApplicationClusterEndpoint(dnsName, scope, routingMethod, weigth, hosts); + return new ApplicationClusterEndpoint(dnsName, scope, routingMethod, weigth, hosts, clusterId); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java index a5dc26e19e3..f7e8afc2d94 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java @@ -218,6 +218,7 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat .sharedL4Routing() .dnsName(l4Name) .hosts(hosts) + .clusterId(getName()) .build()); // L7 @@ -230,6 +231,7 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat .sharedRouting() .dnsName(l7Name) .hosts(hosts) + .clusterId(getName()) .build()); } @@ -243,6 +245,7 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat .sharedL4Routing() .dnsName(ApplicationClusterEndpoint.DnsName.from(name)) .hosts(hosts) + .clusterId(getName()) .build()) )); endpointList = List.copyOf(endpoints); diff --git a/configdefinitions/src/vespa/lb-services.def b/configdefinitions/src/vespa/lb-services.def index 5f33d3120b3..5a277eaed9d 100644 --- a/configdefinitions/src/vespa/lb-services.def +++ b/configdefinitions/src/vespa/lb-services.def @@ -23,6 +23,7 @@ tenants{}.applications{}.hosts{}.services{}.endpointaliases[] string tenants{}.applications{}.endpoints[].dnsName string +tenants{}.applications{}.endpoints[].clusterId string tenants{}.applications{}.endpoints[].scope enum {application, global, zone} tenants{}.applications{}.endpoints[].routingMethod enum {shared, sharedLayer4} tenants{}.applications{}.endpoints[].weight int default=1 diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java index 7ef65bda46d..dccabca2858 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java @@ -105,7 +105,8 @@ public class LbServicesProducer implements LbServicesConfig.Producer { .scope(LbServicesConfig.Tenants.Applications.Endpoints.Scope.Enum.valueOf(clusterEndpoints.scope().name())) .routingMethod(LbServicesConfig.Tenants.Applications.Endpoints.RoutingMethod.Enum.valueOf(clusterEndpoints.routingMethod().name())) .weight(clusterEndpoints.weight()) - .hosts(clusterEndpoints.hostNames()); + .hosts(clusterEndpoints.hostNames()) + .clusterId(clusterEndpoints.clusterId()); } private boolean getActiveRotation(ApplicationInfo app) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java index 2163d8738ab..fb5fb27cd7a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java @@ -38,7 +38,6 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; import static com.yahoo.cloud.config.LbServicesConfig.Tenants.Applications.Endpoints.RoutingMethod.Enum.sharedLayer4; import static com.yahoo.cloud.config.LbServicesConfig.Tenants.Applications.Endpoints.Scope.Enum.application; @@ -47,6 +46,7 @@ import static com.yahoo.cloud.config.LbServicesConfig.Tenants.Applications.Endpo import static com.yahoo.config.model.api.container.ContainerServiceType.QRSERVER; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -54,7 +54,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; /** * @author Ulf Lilleengen @@ -177,15 +176,19 @@ public class LbServicesProducerTest { .filter(e -> e.routingMethod() == sharedLayer4) .map(Endpoints::dnsName).collect(Collectors.toList()), containsInAnyOrder("mydisc.foo.foo.endpoint1.suffix", "mydisc.foo.foo.endpoint2.suffix")); + assertContainsEndpoint(zoneEndpoints, "mydisc.foo.foo.endpoint1.suffix", "mydisc", zone, sharedLayer4, 1, List.of("foo.foo.yahoo.com")); + assertContainsEndpoint(zoneEndpoints, "mydisc.foo.foo.endpoint2.suffix", "mydisc", zone, sharedLayer4, 1, List.of("foo.foo.yahoo.com")); List<Endpoints> globalEndpoints = endpointList.stream().filter(e -> e.scope() == global).collect(Collectors.toList()); assertEquals(2, globalEndpoints.size()); assertThat(globalEndpoints.stream().map(Endpoints::dnsName).collect(Collectors.toList()), containsInAnyOrder("rotation-1", "rotation-2")); + assertContainsEndpoint(globalEndpoints, "rotation-1", "mydisc", global, sharedLayer4, 1, List.of("foo.foo.yahoo.com")); + assertContainsEndpoint(globalEndpoints, "rotation-2", "mydisc", global, sharedLayer4, 1, List.of("foo.foo.yahoo.com")); List<Endpoints> applicationEndpoints = endpointList.stream().filter(e -> e.scope() == application).collect(Collectors.toList()); assertEquals(1, applicationEndpoints.size()); assertThat(applicationEndpoints.stream().map(Endpoints::dnsName).collect(Collectors.toList()), containsInAnyOrder("app-endpoint")); - + assertContainsEndpoint(applicationEndpoints, "app-endpoint", "mydisc", application, sharedLayer4, 1, List.of("foo.foo.yahoo.com")); } @@ -205,6 +208,17 @@ public class LbServicesProducerTest { .applications("baz:prod:default:custom-t")); } + private void assertContainsEndpoint(List<Endpoints> endpoints, String dnsName, String clusterId, Endpoints.Scope.Enum scope, Endpoints.RoutingMethod.Enum routingMethod, int weight, List<String> hosts) { + assertThat(endpoints, hasItem(new Endpoints.Builder() + .dnsName(dnsName) + .clusterId(clusterId) + .scope(scope) + .routingMethod(routingMethod) + .weight(weight) + .hosts(hosts) + .build())); + } + private Map<TenantName, Set<ApplicationInfo>> randomizeApplications(Map<TenantName, Set<ApplicationInfo>> testModel, int seed) { Map<TenantName, Set<ApplicationInfo>> randomizedApplications = new LinkedHashMap<>(); List<TenantName> keys = new ArrayList<>(testModel.keySet()); |