Search in sources :

Example 11 with Route

use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.

the class XdsNameResolverTest method generateServiceConfig_forClusterManagerLoadBalancingConfig.

@Test
public void generateServiceConfig_forClusterManagerLoadBalancingConfig() throws IOException {
    Route route1 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/hi"), RouteAction.forCluster("cluster-foo", Collections.emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.of());
    Route route2 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/hello"), RouteAction.forWeightedClusters(ImmutableList.of(ClusterWeight.create("cluster-bar", 50, ImmutableMap.of()), ClusterWeight.create("cluster-baz", 50, ImmutableMap.of())), ImmutableList.of(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.of());
    Map<String, ?> rlsConfig = ImmutableMap.of("lookupService", "rls.bigtable.google.com");
    Route route3 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/greetings"), RouteAction.forClusterSpecifierPlugin(NamedPluginConfig.create("plugin-foo", RlsPluginConfig.create(rlsConfig)), Collections.emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.of());
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
    VirtualHost virtualHost = VirtualHost.create("virtualhost", Collections.singletonList(AUTHORITY), ImmutableList.of(route1, route2, route3), ImmutableMap.of());
    xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    String expectedServiceConfigJson = "{\n" + "  \"loadBalancingConfig\": [{\n" + "    \"cluster_manager_experimental\": {\n" + "      \"childPolicy\": {\n" + "        \"cluster:cluster-foo\": {\n" + "          \"lbPolicy\": [{\n" + "            \"cds_experimental\": {\n" + "              \"cluster\": \"cluster-foo\"\n" + "            }\n" + "          }]\n" + "        },\n" + "        \"cluster:cluster-bar\": {\n" + "          \"lbPolicy\": [{\n" + "            \"cds_experimental\": {\n" + "              \"cluster\": \"cluster-bar\"\n" + "            }\n" + "          }]\n" + "        },\n" + "        \"cluster:cluster-baz\": {\n" + "          \"lbPolicy\": [{\n" + "            \"cds_experimental\": {\n" + "              \"cluster\": \"cluster-baz\"\n" + "            }\n" + "          }]\n" + "        },\n" + "        \"cluster_specifier_plugin:plugin-foo\": {\n" + "          \"lbPolicy\": [{\n" + "            \"rls_experimental\": {\n" + "              \"routeLookupConfig\": {\n" + "                \"lookupService\": \"rls.bigtable.google.com\"\n" + "              },\n" + "              \"childPolicy\": [\n" + "                {\"cds_experimental\": {}}\n" + "              ],\n" + "              \"childPolicyConfigTargetFieldName\": \"cluster\"\n" + "            }\n" + "          }]\n" + "        }\n" + "      }\n" + "    }\n" + "  }]\n" + "}";
    assertThat(resolutionResultCaptor.getValue().getServiceConfig().getConfig()).isEqualTo(JsonParser.parse(expectedServiceConfigJson));
}
Also used : Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 12 with Route

use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_fallbackToHttpMaxStreamDurationAsTimeout.

@Test
public void resolved_fallbackToHttpMaxStreamDurationAsTimeout() {
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    Route route = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), null, // per-route timeout unset
    null), ImmutableMap.<String, FilterConfig>of());
    VirtualHost virtualHost = VirtualHost.create("does not matter", Collections.singletonList(AUTHORITY), Collections.singletonList(route), ImmutableMap.<String, FilterConfig>of());
    xdsClient.deliverLdsUpdate(TimeUnit.SECONDS.toNanos(5L), Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    assertCallSelectClusterResult(call1, configSelector, cluster1, 5.0);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 13 with Route

use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.

the class XdsNameResolverTest method resolving_ldsResourceRevokedAndAddedBack.

@SuppressWarnings("unchecked")
@Test
public void resolving_ldsResourceRevokedAndAddedBack() {
    Route route = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of());
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
    assertThat(xdsClient.rdsResource).isEqualTo(RDS_RESOURCE_NAME);
    VirtualHost virtualHost = VirtualHost.create("virtualhost", Collections.singletonList(AUTHORITY), Collections.singletonList(route), ImmutableMap.<String, FilterConfig>of());
    xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
    reset(mockListener);
    // revoke LDS resource
    xdsClient.deliverLdsResourceNotFound();
    // stop subscribing to stale RDS resource
    assertThat(xdsClient.rdsResource).isNull();
    assertEmptyResolutionResult();
    reset(mockListener);
    xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
    // No name resolution result until new RDS resource update is received. Do not use stale config
    verifyNoInteractions(mockListener);
    assertThat(xdsClient.rdsResource).isEqualTo(RDS_RESOURCE_NAME);
    xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
}
Also used : HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 14 with Route

use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.

the class XdsServerTestHelper method buildTestListener.

static EnvoyServerProtoData.Listener buildTestListener(String name, String address, ImmutableList<Integer> sourcePorts, EnvoyServerProtoData.DownstreamTlsContext tlsContext, EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain, TlsContextManager tlsContextManager) {
    EnvoyServerProtoData.FilterChainMatch filterChainMatch1 = EnvoyServerProtoData.FilterChainMatch.create(0, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ConnectionSourceType.ANY, sourcePorts, ImmutableList.of(), "");
    EnvoyServerProtoData.FilterChainMatch defaultFilterChainMatch = EnvoyServerProtoData.FilterChainMatch.create(0, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ConnectionSourceType.ANY, ImmutableList.of(), ImmutableList.of(), "");
    VirtualHost virtualHost = VirtualHost.create("virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(), ImmutableMap.<String, FilterConfig>of());
    HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
    EnvoyServerProtoData.FilterChain filterChain1 = EnvoyServerProtoData.FilterChain.create("filter-chain-foo", filterChainMatch1, httpConnectionManager, tlsContext, tlsContextManager);
    EnvoyServerProtoData.FilterChain defaultFilterChain = EnvoyServerProtoData.FilterChain.create("filter-chain-bar", defaultFilterChainMatch, httpConnectionManager, tlsContextForDefaultFilterChain, tlsContextManager);
    EnvoyServerProtoData.Listener listener = EnvoyServerProtoData.Listener.create(name, address, ImmutableList.of(filterChain1), defaultFilterChain);
    return listener;
}
Also used : NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Listener(io.grpc.xds.EnvoyServerProtoData.Listener) Route(io.grpc.xds.VirtualHost.Route)

Aggregations

Route (io.grpc.xds.VirtualHost.Route)14 Test (org.junit.Test)12 NamedFilterConfig (io.grpc.xds.Filter.NamedFilterConfig)6 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)6 Server (io.grpc.Server)5 StatusException (io.grpc.StatusException)5 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Metadata (io.grpc.Metadata)4 ServerCall (io.grpc.ServerCall)4 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)4 FilterConfig (io.grpc.xds.Filter.FilterConfig)4 ResolutionResult (io.grpc.NameResolver.ResolutionResult)3 ServerCallHandler (io.grpc.ServerCallHandler)3 ServerInterceptor (io.grpc.ServerInterceptor)3 RouteMatch (io.grpc.xds.VirtualHost.Route.RouteMatch)3 ServerRoutingConfig (io.grpc.xds.XdsServerWrapper.ServerRoutingConfig)3 ArrayList (java.util.ArrayList)3 InternalConfigSelector (io.grpc.InternalConfigSelector)2