diff --git a/xds/src/main/java/io/grpc/xds/EnvoyProtoData.java b/xds/src/main/java/io/grpc/xds/EnvoyProtoData.java index abb3bd8bc193..be691337f224 100644 --- a/xds/src/main/java/io/grpc/xds/EnvoyProtoData.java +++ b/xds/src/main/java/io/grpc/xds/EnvoyProtoData.java @@ -418,6 +418,7 @@ static DropOverload fromEnvoyProtoDropOverload( break; case MILLION: break; + case UNRECOGNIZED: default: throw new IllegalArgumentException("Unknown denominator type of " + percent); } @@ -444,6 +445,7 @@ static DropOverload fromEnvoyProtoDropOverloadV2( break; case MILLION: break; + case UNRECOGNIZED: default: throw new IllegalArgumentException("Unknown denominator type of " + percent); } diff --git a/xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java b/xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java index cf2877b49a93..c0ab9083fb97 100644 --- a/xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java +++ b/xds/src/main/java/io/grpc/xds/EnvoyServerProtoData.java @@ -19,6 +19,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.Any; import com.google.protobuf.InvalidProtocolBufferException; +import io.envoyproxy.envoy.config.core.v3.Address; +import io.envoyproxy.envoy.config.core.v3.SocketAddress; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext; import io.grpc.Internal; import java.util.ArrayList; @@ -355,10 +357,9 @@ static final class Listener { this.filterChains = Collections.unmodifiableList(filterChains); } - private static String convertEnvoyAddressToString( - io.envoyproxy.envoy.config.core.v3.Address proto) { + private static String convertEnvoyAddressToString(Address proto) { if (proto.hasSocketAddress()) { - io.envoyproxy.envoy.config.core.v3.SocketAddress socketAddress = proto.getSocketAddress(); + SocketAddress socketAddress = proto.getSocketAddress(); String address = socketAddress.getAddress(); switch (socketAddress.getPortSpecifierCase()) { case NAMED_PORT: diff --git a/xds/src/main/java/io/grpc/xds/XdsClientImpl.java b/xds/src/main/java/io/grpc/xds/XdsClientImpl.java index eba1ee0786d9..f559595bce3b 100644 --- a/xds/src/main/java/io/grpc/xds/XdsClientImpl.java +++ b/xds/src/main/java/io/grpc/xds/XdsClientImpl.java @@ -35,12 +35,14 @@ import io.envoyproxy.envoy.api.v2.DiscoveryRequest; import io.envoyproxy.envoy.api.v2.DiscoveryResponse; import io.envoyproxy.envoy.api.v2.core.Node; +import io.envoyproxy.envoy.api.v2.core.SocketAddress; import io.envoyproxy.envoy.config.cluster.v3.Cluster; import io.envoyproxy.envoy.config.cluster.v3.Cluster.DiscoveryType; import io.envoyproxy.envoy.config.cluster.v3.Cluster.EdsClusterConfig; import io.envoyproxy.envoy.config.cluster.v3.Cluster.LbPolicy; import io.envoyproxy.envoy.config.core.v3.Address; import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; +import io.envoyproxy.envoy.config.endpoint.v3.LbEndpoint; import io.envoyproxy.envoy.config.listener.v3.FilterChain; import io.envoyproxy.envoy.config.listener.v3.FilterChainMatch; import io.envoyproxy.envoy.config.listener.v3.Listener; @@ -468,7 +470,7 @@ private void updateNodeMetadataForListenerRequest(int port) { io.envoyproxy.envoy.api.v2.core.Address listeningAddress = io.envoyproxy.envoy.api.v2.core.Address.newBuilder() .setSocketAddress( - io.envoyproxy.envoy.api.v2.core.SocketAddress.newBuilder() + SocketAddress.newBuilder() .setAddress("0.0.0.0") .setPortValue(port) .build()) @@ -1191,8 +1193,7 @@ private void handleEdsResponse(DiscoveryResponse edsResponse) { priorities.add(localityPriority); // The endpoint field of each lb_endpoints must be set. // Inside of it: the address field must be set. - for (io.envoyproxy.envoy.config.endpoint.v3.LbEndpoint lbEndpoint - : localityLbEndpoints.getLbEndpointsList()) { + for (LbEndpoint lbEndpoint : localityLbEndpoints.getLbEndpointsList()) { if (!lbEndpoint.getEndpoint().hasAddress()) { errorMessage = "ClusterLoadAssignment " + clusterName + " : endpoint with no address."; break; diff --git a/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProvider.java b/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProvider.java index 13a398789d2b..823d38d1e983 100644 --- a/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProvider.java +++ b/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProvider.java @@ -16,6 +16,7 @@ package io.grpc.xds.internal.certprovider; +import io.grpc.Status; import java.io.Closeable; import java.security.PrivateKey; import java.security.cert.X509Certificate; @@ -38,7 +39,7 @@ public interface Watcher { void updateTrustedRoots(List trustedRoots); - void onError(io.grpc.Status errorStatus); + void onError(Status errorStatus); } /** diff --git a/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProviderProvider.java b/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProviderProvider.java index 1bfc0d0cfbe8..c99738ef8d03 100644 --- a/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProviderProvider.java +++ b/xds/src/main/java/io/grpc/xds/internal/certprovider/CertificateProviderProvider.java @@ -35,5 +35,5 @@ interface CertificateProviderProvider { * @param notifyCertUpdates See {@link CertificateProvider#CertificateProvider(Watcher, boolean)} */ CertificateProvider createCertificateProvider( - Object config, Watcher watcher, boolean notifyCertUpdates) throws IllegalArgumentException; + Object config, Watcher watcher, boolean notifyCertUpdates); } diff --git a/xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java b/xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java index d943601ac67e..7e633d55bd5c 100644 --- a/xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java +++ b/xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java @@ -22,8 +22,13 @@ import com.google.protobuf.BoolValue; import com.google.protobuf.UInt32Value; import com.google.re2j.Pattern; +import io.envoyproxy.envoy.config.core.v3.RuntimeFractionalPercent; import io.envoyproxy.envoy.config.route.v3.QueryParameterMatcher; import io.envoyproxy.envoy.config.route.v3.RedirectAction; +import io.envoyproxy.envoy.config.route.v3.WeightedCluster; +import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher; +import io.envoyproxy.envoy.type.v3.FractionalPercent; +import io.envoyproxy.envoy.type.v3.Int64Range; import io.grpc.xds.EnvoyProtoData.ClusterWeight; import io.grpc.xds.EnvoyProtoData.Locality; import io.grpc.xds.EnvoyProtoData.Route; @@ -210,8 +215,7 @@ public void convertRouteMatch_pathMatching() { // path_specifier = safe_regex io.envoyproxy.envoy.config.route.v3.RouteMatch proto4 = io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder() - .setSafeRegex( - io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex(".")) + .setSafeRegex(RegexMatcher.newBuilder().setRegex(".")) .build(); StructOrError struct4 = Route.convertEnvoyProtoRouteMatch(proto4); assertThat(struct4.getErrorDetail()).isNull(); @@ -277,13 +281,11 @@ public void convertRouteMatch_withRuntimeFraction() { io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder() .setPrefix("") .setRuntimeFraction( - io.envoyproxy.envoy.config.core.v3.RuntimeFractionalPercent.newBuilder() + RuntimeFractionalPercent.newBuilder() .setDefaultValue( - io.envoyproxy.envoy.type.v3.FractionalPercent.newBuilder() + FractionalPercent.newBuilder() .setNumerator(30) - .setDenominator( - io.envoyproxy.envoy.type.v3.FractionalPercent.DenominatorType - .HUNDRED))) + .setDenominator(FractionalPercent.DenominatorType.HUNDRED))) .build(); StructOrError struct = Route.convertEnvoyProtoRouteMatch(proto); assertThat(struct.getErrorDetail()).isNull(); @@ -318,9 +320,9 @@ public void convertRouteAction() { io.envoyproxy.envoy.config.route.v3.RouteAction proto3 = io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() .setWeightedClusters( - io.envoyproxy.envoy.config.route.v3.WeightedCluster.newBuilder() + WeightedCluster.newBuilder() .addClusters( - io.envoyproxy.envoy.config.route.v3.WeightedCluster.ClusterWeight + WeightedCluster.ClusterWeight .newBuilder() .setName("cluster-baz") .setWeight(UInt32Value.newBuilder().setValue(100)))) @@ -356,8 +358,7 @@ public void convertHeaderMatcher() { io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto3 = io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder() .setName(":method") - .setSafeRegexMatch( - io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex("P*")) + .setSafeRegexMatch(RegexMatcher.newBuilder().setRegex("P*")) .build(); StructOrError struct3 = Route.convertEnvoyProtoHeaderMatcher(proto3); assertThat(struct3.getErrorDetail()).isNull(); @@ -368,8 +369,7 @@ public void convertHeaderMatcher() { io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto4 = io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder() .setName("timeout") - .setRangeMatch( - io.envoyproxy.envoy.type.v3.Int64Range.newBuilder().setStart(10L).setEnd(20L)) + .setRangeMatch(Int64Range.newBuilder().setStart(10L).setEnd(20L)) .build(); StructOrError struct4 = Route.convertEnvoyProtoHeaderMatcher(proto4); assertThat(struct4.getErrorDetail()).isNull(); @@ -424,8 +424,7 @@ public void convertHeaderMatcher_malformedRegExPattern() { io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto = io.envoyproxy.envoy.config.route.v3.HeaderMatcher.newBuilder() .setName(":method") - .setSafeRegexMatch( - io.envoyproxy.envoy.type.matcher.v3.RegexMatcher.newBuilder().setRegex("[")) + .setSafeRegexMatch(RegexMatcher.newBuilder().setRegex("[")) .build(); StructOrError struct = Route.convertEnvoyProtoHeaderMatcher(proto); assertThat(struct.getErrorDetail()).isNotNull(); diff --git a/xds/src/test/java/io/grpc/xds/internal/sds/CommonTlsContextTestsUtil.java b/xds/src/test/java/io/grpc/xds/internal/sds/CommonTlsContextTestsUtil.java index 86f4c2ffebeb..b6782b256263 100644 --- a/xds/src/test/java/io/grpc/xds/internal/sds/CommonTlsContextTestsUtil.java +++ b/xds/src/test/java/io/grpc/xds/internal/sds/CommonTlsContextTestsUtil.java @@ -20,6 +20,8 @@ import com.google.protobuf.BoolValue; import com.google.protobuf.Struct; import com.google.protobuf.Value; +import io.envoyproxy.envoy.api.v2.core.ApiConfigSource.ApiType; +import io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc; import io.envoyproxy.envoy.config.core.v3.ApiConfigSource; import io.envoyproxy.envoy.config.core.v3.ConfigSource; import io.envoyproxy.envoy.config.core.v3.DataSource; @@ -87,18 +89,16 @@ static io.envoyproxy.envoy.api.v2.auth.SdsSecretConfig buildSdsSecretConfigV2( */ private static io.envoyproxy.envoy.api.v2.core.ConfigSource buildConfigSourceV2( String targetUri, String channelType) { - io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc.Builder googleGrpcBuilder = - io.envoyproxy.envoy.api.v2.core.GrpcService.GoogleGrpc.newBuilder().setTargetUri(targetUri); + GoogleGrpc.Builder googleGrpcBuilder = GoogleGrpc.newBuilder().setTargetUri(targetUri); if (channelType != null) { - Struct.Builder structBuilder = Struct.newBuilder(); - structBuilder.putFields( - "channelType", Value.newBuilder().setStringValue(channelType).build()); + Struct.Builder structBuilder = Struct.newBuilder() + .putFields("channelType", Value.newBuilder().setStringValue(channelType).build()); googleGrpcBuilder.setConfig(structBuilder.build()); } return io.envoyproxy.envoy.api.v2.core.ConfigSource.newBuilder() .setApiConfigSource( io.envoyproxy.envoy.api.v2.core.ApiConfigSource.newBuilder() - .setApiType(io.envoyproxy.envoy.api.v2.core.ApiConfigSource.ApiType.GRPC) + .setApiType(ApiType.GRPC) .addGrpcServices( io.envoyproxy.envoy.api.v2.core.GrpcService.newBuilder() .setGoogleGrpc(googleGrpcBuilder.build()) @@ -116,9 +116,8 @@ private static ConfigSource buildConfigSource(String targetUri, String channelTy GrpcService.GoogleGrpc.Builder googleGrpcBuilder = GrpcService.GoogleGrpc.newBuilder().setTargetUri(targetUri); if (channelType != null) { - Struct.Builder structBuilder = Struct.newBuilder(); - structBuilder.putFields( - "channelType", Value.newBuilder().setStringValue(channelType).build()); + Struct.Builder structBuilder = Struct.newBuilder() + .putFields("channelType", Value.newBuilder().setStringValue(channelType).build()); googleGrpcBuilder.setConfig(structBuilder.build()); } return ConfigSource.newBuilder() @@ -193,13 +192,14 @@ static CommonTlsContext buildCommonTlsContextFromSdsConfigForTlsCertificate( .addAllVerifySubjectAltName(verifySubjectAltNames).build(); if (sdsSecretConfig != null && certValidationContext != null) { - io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext.Builder - combinedBuilder = + io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext + combined = io.envoyproxy.envoy.api.v2.auth.CommonTlsContext.CombinedCertificateValidationContext .newBuilder() .setDefaultValidationContext(certValidationContext) - .setValidationContextSdsSecretConfig(sdsSecretConfig); - builder.setCombinedValidationContext(combinedBuilder); + .setValidationContextSdsSecretConfig(sdsSecretConfig) + .build(); + builder.setCombinedValidationContext(combined); } else if (sdsSecretConfig != null) { builder.setValidationContextSdsSecretConfig(sdsSecretConfig); } else if (certValidationContext != null) {