Search in sources :

Example 1 with FractionMatcher

use of io.grpc.xds.internal.Matchers.FractionMatcher in project grpc-java by grpc.

the class ClientXdsClient method parseRouteMatch.

@VisibleForTesting
@Nullable
static StructOrError<RouteMatch> parseRouteMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch proto) {
    if (proto.getQueryParametersCount() != 0) {
        return null;
    }
    StructOrError<PathMatcher> pathMatch = parsePathMatcher(proto);
    if (pathMatch.getErrorDetail() != null) {
        return StructOrError.fromError(pathMatch.getErrorDetail());
    }
    FractionMatcher fractionMatch = null;
    if (proto.hasRuntimeFraction()) {
        StructOrError<FractionMatcher> parsedFraction = parseFractionMatcher(proto.getRuntimeFraction().getDefaultValue());
        if (parsedFraction.getErrorDetail() != null) {
            return StructOrError.fromError(parsedFraction.getErrorDetail());
        }
        fractionMatch = parsedFraction.getStruct();
    }
    List<HeaderMatcher> headerMatchers = new ArrayList<>();
    for (io.envoyproxy.envoy.config.route.v3.HeaderMatcher hmProto : proto.getHeadersList()) {
        StructOrError<HeaderMatcher> headerMatcher = parseHeaderMatcher(hmProto);
        if (headerMatcher.getErrorDetail() != null) {
            return StructOrError.fromError(headerMatcher.getErrorDetail());
        }
        headerMatchers.add(headerMatcher.getStruct());
    }
    return StructOrError.fromStruct(RouteMatch.create(pathMatch.getStruct(), headerMatchers, fractionMatch));
}
Also used : FractionMatcher(io.grpc.xds.internal.Matchers.FractionMatcher) HeaderMatcher(io.grpc.xds.internal.Matchers.HeaderMatcher) PathMatcher(io.grpc.xds.VirtualHost.Route.RouteMatch.PathMatcher) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Nullable(javax.annotation.Nullable)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 PathMatcher (io.grpc.xds.VirtualHost.Route.RouteMatch.PathMatcher)1 FractionMatcher (io.grpc.xds.internal.Matchers.FractionMatcher)1 HeaderMatcher (io.grpc.xds.internal.Matchers.HeaderMatcher)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1