Search in sources :

Example 1 with Rds

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds in project grpc-java by grpc.

the class ClientXdsClient method parseHttpConnectionManager.

@VisibleForTesting
static io.grpc.xds.HttpConnectionManager parseHttpConnectionManager(HttpConnectionManager proto, Set<String> rdsResources, FilterRegistry filterRegistry, boolean parseHttpFilter, boolean isForClient) throws ResourceInvalidException {
    if (enableRbac && proto.getXffNumTrustedHops() != 0) {
        throw new ResourceInvalidException("HttpConnectionManager with xff_num_trusted_hops unsupported");
    }
    if (enableRbac && !proto.getOriginalIpDetectionExtensionsList().isEmpty()) {
        throw new ResourceInvalidException("HttpConnectionManager with " + "original_ip_detection_extensions unsupported");
    }
    // Obtain max_stream_duration from Http Protocol Options.
    long maxStreamDuration = 0;
    if (proto.hasCommonHttpProtocolOptions()) {
        HttpProtocolOptions options = proto.getCommonHttpProtocolOptions();
        if (options.hasMaxStreamDuration()) {
            maxStreamDuration = Durations.toNanos(options.getMaxStreamDuration());
        }
    }
    // Parse http filters.
    List<NamedFilterConfig> filterConfigs = null;
    if (parseHttpFilter) {
        if (proto.getHttpFiltersList().isEmpty()) {
            throw new ResourceInvalidException("Missing HttpFilter in HttpConnectionManager.");
        }
        filterConfigs = new ArrayList<>();
        Set<String> names = new HashSet<>();
        for (int i = 0; i < proto.getHttpFiltersCount(); i++) {
            io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter httpFilter = proto.getHttpFiltersList().get(i);
            String filterName = httpFilter.getName();
            if (!names.add(filterName)) {
                throw new ResourceInvalidException("HttpConnectionManager contains duplicate HttpFilter: " + filterName);
            }
            StructOrError<FilterConfig> filterConfig = parseHttpFilter(httpFilter, filterRegistry, isForClient);
            if ((i == proto.getHttpFiltersCount() - 1) && (filterConfig == null || !isTerminalFilter(filterConfig.struct))) {
                throw new ResourceInvalidException("The last HttpFilter must be a terminal filter: " + filterName);
            }
            if (filterConfig == null) {
                continue;
            }
            if (filterConfig.getErrorDetail() != null) {
                throw new ResourceInvalidException("HttpConnectionManager contains invalid HttpFilter: " + filterConfig.getErrorDetail());
            }
            if ((i < proto.getHttpFiltersCount() - 1) && isTerminalFilter(filterConfig.getStruct())) {
                throw new ResourceInvalidException("A terminal HttpFilter must be the last filter: " + filterName);
            }
            filterConfigs.add(new NamedFilterConfig(filterName, filterConfig.struct));
        }
    }
    // Parse inlined RouteConfiguration or RDS.
    if (proto.hasRouteConfig()) {
        List<VirtualHost> virtualHosts = extractVirtualHosts(proto.getRouteConfig(), filterRegistry, parseHttpFilter);
        return io.grpc.xds.HttpConnectionManager.forVirtualHosts(maxStreamDuration, virtualHosts, filterConfigs);
    }
    if (proto.hasRds()) {
        Rds rds = proto.getRds();
        if (!rds.hasConfigSource()) {
            throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: missing config_source");
        }
        if (!rds.getConfigSource().hasAds() && !rds.getConfigSource().hasSelf()) {
            throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
        }
        // Collect the RDS resource referenced by this HttpConnectionManager.
        rdsResources.add(rds.getRouteConfigName());
        return io.grpc.xds.HttpConnectionManager.forRdsName(maxStreamDuration, rds.getRouteConfigName(), filterConfigs);
    }
    throw new ResourceInvalidException("HttpConnectionManager neither has inlined route_config nor RDS");
}
Also used : Rds(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) HttpProtocolOptions(io.envoyproxy.envoy.config.core.v3.HttpProtocolOptions) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterConfig(io.grpc.xds.Filter.FilterConfig) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with Rds

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_validateRdsConfigSource.

@Test
public void parseHttpConnectionManager_validateRdsConfigSource() throws Exception {
    ClientXdsClient.enableRouteLookup = true;
    Set<String> rdsResources = new HashSet<>();
    HttpConnectionManager hcm1 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))).build();
    ClientXdsClient.parseHttpConnectionManager(hcm1, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
    HttpConnectionManager hcm2 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setSelf(SelfConfigSource.getDefaultInstance()))).build();
    ClientXdsClient.parseHttpConnectionManager(hcm2, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
    HttpConnectionManager hcm3 = HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName("rds-config-foo").setConfigSource(ConfigSource.newBuilder().setPath("foo-path"))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
    ClientXdsClient.parseHttpConnectionManager(hcm3, rdsResources, filterRegistry, false, /* parseHttpFilter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Rds

use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpConnectionManager_missingRdsAndInlinedRouteConfiguration.

@Test
public void parseHttpConnectionManager_missingRdsAndInlinedRouteConfiguration() throws ResourceInvalidException {
    HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setCommonHttpProtocolOptions(HttpProtocolOptions.newBuilder().setMaxStreamDuration(Durations.fromNanos(1000L))).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("HttpConnectionManager neither has inlined route_config nor RDS");
    ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, false, /* does not matter */
    true);
}
Also used : HttpConnectionManager(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager) Test(org.junit.Test)

Aggregations

HttpConnectionManager (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HttpProtocolOptions (io.envoyproxy.envoy.config.core.v3.HttpProtocolOptions)1 Rds (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.Rds)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 FilterConfig (io.grpc.xds.Filter.FilterConfig)1 NamedFilterConfig (io.grpc.xds.Filter.NamedFilterConfig)1