Search in sources :

Example 1 with RouteLookupConfig

use of io.grpc.lookup.v1.RouteLookupConfig in project grpc-java by grpc.

the class RouteLookupServiceClusterSpecifierPluginTest method parseConfigWithAllFieldsGiven.

@Test
public void parseConfigWithAllFieldsGiven() {
    RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1").setMethod("method1")).addNames(Name.newBuilder().setService("service2").setMethod("method2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true)).setExtraKeys(ExtraKeys.newBuilder().setHost("host1").setService("service1").setMethod("method1")).putConstantKeys("key2", "value2")).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setMaxAge(Durations.fromMillis(56789)).setStaleAge(Durations.fromMillis(1000)).setCacheSizeBytes(5000).addValidTargets("valid-target").setDefaultTarget("default-target").build();
    RouteLookupClusterSpecifier specifier = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build();
    RlsPluginConfig config = RouteLookupServiceClusterSpecifierPlugin.INSTANCE.parsePlugin(Any.pack(specifier)).config;
    assertThat(config.typeUrl()).isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier");
    assertThat(config.config()).isEqualTo(ImmutableMap.builder().put("grpcKeybuilders", ImmutableList.of(ImmutableMap.of("names", ImmutableList.of(ImmutableMap.of("service", "service1", "method", "method1"), ImmutableMap.of("service", "service2", "method", "method2")), "headers", ImmutableList.of(ImmutableMap.of("key", "key1", "names", ImmutableList.of("v1"), "requiredMatch", true)), "extraKeys", ImmutableMap.of("host", "host1", "service", "service1", "method", "method1"), "constantKeys", ImmutableMap.of("key2", "value2")))).put("lookupService", "rls-cbt.googleapis.com").put("lookupServiceTimeout", "1.234s").put("maxAge", "56.789s").put("staleAge", "1s").put("cacheSizeBytes", "5000").put("validTargets", ImmutableList.of("valid-target")).put("defaultTarget", "default-target").build());
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) RlsPluginConfig(io.grpc.xds.RouteLookupServiceClusterSpecifierPlugin.RlsPluginConfig) Test(org.junit.Test)

Example 2 with RouteLookupConfig

use of io.grpc.lookup.v1.RouteLookupConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_pluginNameNotFound.

@Test
public void parseHttpConnectionManager_pluginNameNotFound() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build();
    TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier)).build();
    io.envoyproxy.envoy.config.route.v3.Route route = io.envoyproxy.envoy.config.route.v3.Route.newBuilder().setName("route-1").setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")).setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder().setClusterSpecifierPlugin("invalid-plugin-name")).build();
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setRouteConfig(RouteConfiguration.newBuilder().addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig).build()).addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-1").addRoutes(route))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("ClusterSpecifierPlugin for [invalid-plugin-name] not found");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) TypedExtensionConfig(io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig) Test(org.junit.Test)

Example 3 with RouteLookupConfig

use of io.grpc.lookup.v1.RouteLookupConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_duplicatePluginName.

@Test
public void parseHttpConnectionManager_duplicatePluginName() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    RouteLookupConfig routeLookupConfig1 = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier1 = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig1).build();
    RouteLookupConfig routeLookupConfig2 = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service3")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier2 = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig2).build();
    TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier1)).build();
    TypedExtensionConfig typedExtensionConfig2 = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier2)).build();
    io.envoyproxy.envoy.config.route.v3.Route route = io.envoyproxy.envoy.config.route.v3.Route.newBuilder().setName("route-1").setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")).setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder().setClusterSpecifierPlugin("rls-plugin-1")).build();
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setRouteConfig(RouteConfiguration.newBuilder().addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig).build()).addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig2).build()).addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-1").addRoutes(route))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("Multiple ClusterSpecifierPlugins with the same name: rls-plugin-1");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) TypedExtensionConfig(io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig) Test(org.junit.Test)

Example 4 with RouteLookupConfig

use of io.grpc.lookup.v1.RouteLookupConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_clusterSpecifierPlugin.

@Test
public void parseHttpConnectionManager_clusterSpecifierPlugin() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build();
    TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder().setName("rls-plugin-1").setTypedConfig(Any.pack(specifier)).build();
    io.envoyproxy.envoy.config.route.v3.Route route = io.envoyproxy.envoy.config.route.v3.Route.newBuilder().setName("route-1").setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")).setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder().setClusterSpecifierPlugin("rls-plugin-1")).build();
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setRouteConfig(RouteConfiguration.newBuilder().addClusterSpecifierPlugins(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder().setExtension(typedExtensionConfig).build()).addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-1").addRoutes(route))).build();
    io.grpc.xds.HttpConnectionManager parsedHcm = ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* parseHttpFilter */
    true);
    VirtualHost virtualHost = Iterables.getOnlyElement(parsedHcm.virtualHosts());
    Route parsedRoute = Iterables.getOnlyElement(virtualHost.routes());
    NamedPluginConfig namedPluginConfig = parsedRoute.routeAction().namedClusterSpecifierPluginConfig();
    assertThat(namedPluginConfig.name()).isEqualTo("rls-plugin-1");
    assertThat(namedPluginConfig.config()).isInstanceOf(RlsPluginConfig.class);
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) NamedPluginConfig(io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig) HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) TypedExtensionConfig(io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig) RBACPerRoute(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 5 with RouteLookupConfig

use of io.grpc.lookup.v1.RouteLookupConfig in project grpc-java by grpc.

the class RouteLookupServiceClusterSpecifierPluginTest method parseConfigWithOptionalFieldsUnspecified.

@Test
public void parseConfigWithOptionalFieldsUnspecified() {
    RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder().addGrpcKeybuilders(GrpcKeyBuilder.newBuilder().addNames(Name.newBuilder().setService("service1")).addNames(Name.newBuilder().setService("service2")).addHeaders(NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))).setLookupService("rls-cbt.googleapis.com").setLookupServiceTimeout(Durations.fromMillis(1234)).setCacheSizeBytes(5000).addValidTargets("valid-target").build();
    RouteLookupClusterSpecifier specifier = RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build();
    RlsPluginConfig config = RouteLookupServiceClusterSpecifierPlugin.INSTANCE.parsePlugin(Any.pack(specifier)).config;
    assertThat(config.typeUrl()).isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier");
    assertThat(config.config()).isEqualTo(ImmutableMap.builder().put("grpcKeybuilders", ImmutableList.of(ImmutableMap.of("names", ImmutableList.of(ImmutableMap.of("service", "service1"), ImmutableMap.of("service", "service2")), "headers", ImmutableList.of(ImmutableMap.of("key", "key1", "names", ImmutableList.of("v1"), "requiredMatch", true))))).put("lookupService", "rls-cbt.googleapis.com").put("lookupServiceTimeout", "1.234s").put("cacheSizeBytes", "5000").put("validTargets", ImmutableList.of("valid-target")).build());
}
Also used : RouteLookupClusterSpecifier(io.grpc.lookup.v1.RouteLookupClusterSpecifier) RouteLookupConfig(io.grpc.lookup.v1.RouteLookupConfig) RlsPluginConfig(io.grpc.xds.RouteLookupServiceClusterSpecifierPlugin.RlsPluginConfig) Test(org.junit.Test)

Aggregations

RouteLookupClusterSpecifier (io.grpc.lookup.v1.RouteLookupClusterSpecifier)5 RouteLookupConfig (io.grpc.lookup.v1.RouteLookupConfig)5 Test (org.junit.Test)5 TypedExtensionConfig (io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig)3 HttpConnectionManager (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager)3 RlsPluginConfig (io.grpc.xds.RouteLookupServiceClusterSpecifierPlugin.RlsPluginConfig)2 RBACPerRoute (io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute)1 NamedPluginConfig (io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig)1 Route (io.grpc.xds.VirtualHost.Route)1