use of io.envoyproxy.envoy.config.route.v3.RouteConfiguration in project grpc-java by grpc.
the class ClientXdsClient method handleRdsResponse.
@Override
public void handleRdsResponse(ServerInfo serverInfo, String versionInfo, List<Any> resources, String nonce) {
syncContext.throwIfNotInThisSynchronizationContext();
Map<String, ParsedResource> parsedResources = new HashMap<>(resources.size());
Set<String> unpackedResources = new HashSet<>(resources.size());
Set<String> invalidResources = new HashSet<>();
List<String> errors = new ArrayList<>();
for (int i = 0; i < resources.size(); i++) {
Any resource = resources.get(i);
// Unpack the RouteConfiguration.
RouteConfiguration routeConfig;
try {
routeConfig = unpackCompatibleType(resource, RouteConfiguration.class, ResourceType.RDS.typeUrl(), ResourceType.RDS.typeUrlV2());
} catch (InvalidProtocolBufferException e) {
errors.add("RDS response Resource index " + i + " - can't decode RouteConfiguration: " + e);
continue;
}
if (!isResourceNameValid(routeConfig.getName(), resource.getTypeUrl())) {
errors.add("Unsupported resource name: " + routeConfig.getName() + " for type: " + ResourceType.RDS);
continue;
}
String routeConfigName = canonifyResourceName(routeConfig.getName());
unpackedResources.add(routeConfigName);
// Process RouteConfiguration into RdsUpdate.
RdsUpdate rdsUpdate;
boolean isResourceV3 = resource.getTypeUrl().equals(ResourceType.RDS.typeUrl());
try {
rdsUpdate = processRouteConfiguration(routeConfig, filterRegistry, enableFaultInjection && isResourceV3);
} catch (ResourceInvalidException e) {
errors.add("RDS response RouteConfiguration '" + routeConfigName + "' validation error: " + e.getMessage());
invalidResources.add(routeConfigName);
continue;
}
parsedResources.put(routeConfigName, new ParsedResource(rdsUpdate, resource));
}
logger.log(XdsLogLevel.INFO, "Received RDS Response version {0} nonce {1}. Parsed resources: {2}", versionInfo, nonce, unpackedResources);
handleResourceUpdate(serverInfo, ResourceType.RDS, parsedResources, invalidResources, Collections.<String>emptySet(), versionInfo, nonce, errors);
}
use of io.envoyproxy.envoy.config.route.v3.RouteConfiguration in project grpc-java by grpc.
the class ClientXdsClient method extractVirtualHosts.
private static List<VirtualHost> extractVirtualHosts(RouteConfiguration routeConfig, FilterRegistry filterRegistry, boolean parseHttpFilter) throws ResourceInvalidException {
Map<String, PluginConfig> pluginConfigMap = new HashMap<>();
if (enableRouteLookup) {
List<ClusterSpecifierPlugin> plugins = routeConfig.getClusterSpecifierPluginsList();
for (ClusterSpecifierPlugin plugin : plugins) {
PluginConfig existing = pluginConfigMap.put(plugin.getExtension().getName(), parseClusterSpecifierPlugin(plugin));
if (existing != null) {
throw new ResourceInvalidException("Multiple ClusterSpecifierPlugins with the same name: " + plugin.getExtension().getName());
}
}
}
List<VirtualHost> virtualHosts = new ArrayList<>(routeConfig.getVirtualHostsCount());
for (io.envoyproxy.envoy.config.route.v3.VirtualHost virtualHostProto : routeConfig.getVirtualHostsList()) {
StructOrError<VirtualHost> virtualHost = parseVirtualHost(virtualHostProto, filterRegistry, parseHttpFilter, pluginConfigMap);
if (virtualHost.getErrorDetail() != null) {
throw new ResourceInvalidException("RouteConfiguration contains invalid virtual host: " + virtualHost.getErrorDetail());
}
virtualHosts.add(virtualHost.getStruct());
}
return virtualHosts;
}
use of io.envoyproxy.envoy.config.route.v3.RouteConfiguration in project grpc-java by grpc.
the class FakeControlPlaneXdsIntegrationTest method serverListener.
private static Listener serverListener(String name) {
HttpFilter routerFilter = HttpFilter.newBuilder().setName("terminal-filter").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build();
VirtualHost virtualHost = io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-0").addDomains("*").addRoutes(Route.newBuilder().setMatch(RouteMatch.newBuilder().setPrefix("/").build()).setNonForwardingAction(NonForwardingAction.newBuilder().build()).build()).build();
RouteConfiguration routeConfig = RouteConfiguration.newBuilder().addVirtualHosts(virtualHost).build();
Filter filter = Filter.newBuilder().setName("network-filter-0").setTypedConfig(Any.pack(HttpConnectionManager.newBuilder().setRouteConfig(routeConfig).addAllHttpFilters(Collections.singletonList(routerFilter)).build())).build();
FilterChainMatch filterChainMatch = FilterChainMatch.newBuilder().setSourceType(FilterChainMatch.ConnectionSourceType.ANY).build();
FilterChain filterChain = FilterChain.newBuilder().setName("filter-chain-0").setFilterChainMatch(filterChainMatch).addFilters(filter).build();
return Listener.newBuilder().setName(name).setTrafficDirection(TrafficDirection.INBOUND).addFilterChains(filterChain).build();
}
use of io.envoyproxy.envoy.config.route.v3.RouteConfiguration in project grpc-java by grpc.
the class MessagePrinterTest method printRdsResponse_v3.
@Test
public void printRdsResponse_v3() {
RouteConfiguration routeConfiguration = RouteConfiguration.newBuilder().setName("route-foo.googleapis.com").addVirtualHosts(VirtualHost.newBuilder().setName("virtualhost.googleapis.com").addDomains("foo.googleapis.com").addDomains("bar.googleapis.com").addRoutes(Route.newBuilder().setMatch(RouteMatch.newBuilder().setPath("foo.googleapis.com")).setRoute(RouteAction.newBuilder().setCluster("cluster.googleapis.com")))).build();
DiscoveryResponse response = DiscoveryResponse.newBuilder().setTypeUrl("type.googleapis.com/envoy.config.route.v3.RouteConfiguration").setVersionInfo("0").addResources(Any.pack(routeConfiguration)).setNonce("0000").build();
String expectedString = "{\n" + " \"versionInfo\": \"0\",\n" + " \"resources\": [{\n" + " \"@type\": \"type.googleapis.com/envoy.config.route.v3.RouteConfiguration\",\n" + " \"name\": \"route-foo.googleapis.com\",\n" + " \"virtualHosts\": [{\n" + " \"name\": \"virtualhost.googleapis.com\",\n" + " \"domains\": [\"foo.googleapis.com\", \"bar.googleapis.com\"],\n" + " \"routes\": [{\n" + " \"match\": {\n" + " \"path\": \"foo.googleapis.com\"\n" + " },\n" + " \"route\": {\n" + " \"cluster\": \"cluster.googleapis.com\"\n" + " }\n" + " }]\n" + " }]\n" + " }],\n" + " \"typeUrl\": \"type.googleapis.com/envoy.config.route.v3.RouteConfiguration\",\n" + " \"nonce\": \"0000\"\n" + "}";
String res = MessagePrinter.print(response);
assertThat(res).isEqualTo(expectedString);
}
Aggregations