use of io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig 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);
}
use of io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig 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);
}
use of io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig 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);
}
use of io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig in project grpc-java by grpc.
the class ClientXdsClient method parseClusterSpecifierPlugin.
@VisibleForTesting
static PluginConfig parseClusterSpecifierPlugin(ClusterSpecifierPlugin pluginProto, ClusterSpecifierPluginRegistry registry) throws ResourceInvalidException {
TypedExtensionConfig extension = pluginProto.getExtension();
String pluginName = extension.getName();
Any anyConfig = extension.getTypedConfig();
String typeUrl = anyConfig.getTypeUrl();
Message rawConfig = anyConfig;
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA) || typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
try {
TypedStruct typedStruct = unpackCompatibleType(anyConfig, TypedStruct.class, TYPE_URL_TYPED_STRUCT_UDPA, TYPE_URL_TYPED_STRUCT);
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} catch (InvalidProtocolBufferException e) {
throw new ResourceInvalidException("ClusterSpecifierPlugin [" + pluginName + "] contains invalid proto", e);
}
}
io.grpc.xds.ClusterSpecifierPlugin plugin = registry.get(typeUrl);
if (plugin == null) {
throw new ResourceInvalidException("Unsupported ClusterSpecifierPlugin type: " + typeUrl);
}
ConfigOrError<? extends PluginConfig> pluginConfigOrError = plugin.parsePlugin(rawConfig);
if (pluginConfigOrError.errorDetail != null) {
throw new ResourceInvalidException(pluginConfigOrError.errorDetail);
}
return pluginConfigOrError.config;
}
Aggregations