Search in sources :

Example 1 with RouteConfiguration

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RouteConfiguration(io.envoyproxy.envoy.config.route.v3.RouteConfiguration) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint) HashSet(java.util.HashSet)

Example 2 with RouteConfiguration

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;
}
Also used : ClusterSpecifierPlugin(io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NamedPluginConfig(io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig) PluginConfig(io.grpc.xds.ClusterSpecifierPlugin.PluginConfig)

Example 3 with RouteConfiguration

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();
}
Also used : Filter(io.envoyproxy.envoy.config.listener.v3.Filter) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) RouteConfiguration(io.envoyproxy.envoy.config.route.v3.RouteConfiguration) FilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain) FilterChainMatch(io.envoyproxy.envoy.config.listener.v3.FilterChainMatch) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) VirtualHost(io.envoyproxy.envoy.config.route.v3.VirtualHost)

Example 4 with RouteConfiguration

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);
}
Also used : DiscoveryResponse(io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse) RouteConfiguration(io.envoyproxy.envoy.config.route.v3.RouteConfiguration) Test(org.junit.Test)

Aggregations

RouteConfiguration (io.envoyproxy.envoy.config.route.v3.RouteConfiguration)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Filter (io.envoyproxy.envoy.config.listener.v3.Filter)1 FilterChain (io.envoyproxy.envoy.config.listener.v3.FilterChain)1 FilterChainMatch (io.envoyproxy.envoy.config.listener.v3.FilterChainMatch)1 ClusterSpecifierPlugin (io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin)1 VirtualHost (io.envoyproxy.envoy.config.route.v3.VirtualHost)1 HttpFilter (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter)1 DiscoveryResponse (io.envoyproxy.envoy.service.discovery.v3.DiscoveryResponse)1 NamedPluginConfig (io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig)1 PluginConfig (io.grpc.xds.ClusterSpecifierPlugin.PluginConfig)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1