From ee581bfdfa03e7b0f96fd99e287f5a326648bc42 Mon Sep 17 00:00:00 2001 From: markb74 <57717302+markb74@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:11:54 +0100 Subject: [PATCH 0001/1995] buildscripts: add config for building grpc-binder artifact (#8722) --- buildscripts/kokoro/linux_artifacts.sh | 9 ++++++++- buildscripts/kokoro/upload_artifacts.sh | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/buildscripts/kokoro/linux_artifacts.sh b/buildscripts/kokoro/linux_artifacts.sh index 17402fe89b3..c4386b94e07 100755 --- a/buildscripts/kokoro/linux_artifacts.sh +++ b/buildscripts/kokoro/linux_artifacts.sh @@ -10,7 +10,7 @@ readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" "$GRPC_JAVA_DIR"/buildscripts/build_docker.sh "$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh /grpc-java/buildscripts/build_artifacts_in_docker.sh -# grpc-android and grpc-cronet require the Android SDK, so build outside of Docker and +# grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and # use --include-build for its grpc-core dependency echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3" LOCAL_MVN_TEMP=$(mktemp -d) @@ -28,6 +28,13 @@ pushd "$GRPC_JAVA_DIR/cronet" -PrepositoryDir="$LOCAL_MVN_TEMP" popd +pushd "$GRPC_JAVA_DIR/binder" +../gradlew publish \ + -Dorg.gradle.parallel=false \ + -PskipCodegen=true \ + -PrepositoryDir="$LOCAL_MVN_TEMP" +popd + readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}" mkdir -p "$MVN_ARTIFACT_DIR" cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/ diff --git a/buildscripts/kokoro/upload_artifacts.sh b/buildscripts/kokoro/upload_artifacts.sh index 20e16c38a2f..06d037831ec 100644 --- a/buildscripts/kokoro/upload_artifacts.sh +++ b/buildscripts/kokoro/upload_artifacts.sh @@ -24,6 +24,9 @@ LOCAL_OTHER_ARTIFACTS="$KOKORO_GFILE_DIR"/github/grpc-java/artifacts/ # cronet artifact from linux job: [[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-cronet-*.aar' | wc -l)" != '0' ]] +# binder artifact from linux job: +[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'grpc-binder-*.aar' | wc -l)" != '0' ]] + # from linux job: [[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_64.exe' | wc -l)" != '0' ]] [[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_32.exe' | wc -l)" != '0' ]] From a4334eb5c30c40419701835378b357fc0d2bcd27 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Mon, 29 Nov 2021 08:48:51 -0800 Subject: [PATCH 0002/1995] census: fix NPE in calling recordFinishedAttempt() (#8706) Fix the NPE as shown in the following stacktrace: ``` Caused by: java.lang.RuntimeException: java.lang.NullPointerException with message: null at io.grpc.census.CensusStatsModule$ClientTracer.recordFinishedAttempt(CensusStatsModule.java:388) ~[grpc-census-1.42.0.jar:1.42.0] at io.grpc.census.CensusStatsModule$CallAttemptsTracerFactory.recordFinishedCall(CensusStatsModule.java:525) ~[grpc-census-1.42.0.jar:1.42.0] at io.grpc.census.CensusStatsModule$CallAttemptsTracerFactory.attemptEnded(CensusStatsModule.java:492) ~[grpc-census-1.42.0.jar:1.42.0] at io.grpc.census.CensusStatsModule$ClientTracer.streamClosed(CensusStatsModule.java:345) ~[grpc-census-1.42.0.jar:1.42.0] at io.grpc.internal.StatsTraceContext.streamClosed(StatsTraceContext.java:155) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.closeListener(AbstractClientStream.java:458) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.access$400(AbstractClientStream.java:221) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState$1.run(AbstractClientStream.java:442) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.deframerClosed(AbstractClientStream.java:278) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.Http2ClientStreamTransportState.deframerClosed(Http2ClientStreamTransportState.java:31) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.MessageDeframer.close(MessageDeframer.java:233) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.MessageDeframer.closeWhenComplete(MessageDeframer.java:191) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractStream$TransportState.closeDeframer(AbstractStream.java:200) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.transportReportStatus(AbstractClientStream.java:445) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.transportReportStatus(AbstractClientStream.java:401) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.AbstractClientStream$TransportState.inboundTrailersReceived(AbstractClientStream.java:384) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.internal.Http2ClientStreamTransportState.transportTrailersReceived(Http2ClientStreamTransportState.java:183) ~[grpc-core-1.42.0.jar:1.42.0] at io.grpc.netty.shaded.io.grpc.netty.NettyClientStream$TransportState.transportHeadersReceived(NettyClientStream.java:334) ~[grpc-netty-shaded-1.42.0.jar:1.42.0] at io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler.onHeadersRead(NettyClientHandler.java:372) ~[grpc-netty-shaded-1.42.0.jar:1.42.0] at io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler.access$1200(NettyClientHandler.java:91) ~[grpc-netty-shaded-1.42.0.jar:1.42.0] at io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler$FrameListener.onHeadersRead(NettyClientHandler.java:934) ~[grpc-netty-shaded-1.42.0.jar:1.42.0] ``` The NPE can happen when `ClientCall.Listener.onClose()` and `StatsTraceContext.streamClosed()` (or `ClientStreamListener.closed()`) are invoked concurrently in different threads. Note that `CensusStatsModule$CallAttemptsTracerFactory.attemptEnded()` in the above stack trace would observe `callEnded==true` in such a race condition. The following are the possible scenarios that the race between `ClientCall.Listener.onClose()` and `ClientStreamListener.closed()` can happen: - Deadline exceeded but the underlying real stream is [not committed](https://github.com/grpc/grpc-java/blob/v1.42.0/core/src/main/java/io/grpc/internal/RetriableStream.java#L486-L495), the `ClientCall.Listener` may be closed earlier than the stream listener. (This is the case of the above stack trace, in which the inbound end-of-stream is received observing `callEnded==true`. Even if nothing inbound is received, there is still a chance that the NPE can happen.) - DelayedClientTransport.PendingStream has created a realStream but `setStream(realStream)` is [not called yet](https://github.com/grpc/grpc-java/blob/v1.42.0/core/src/main/java/io/grpc/internal/DelayedClientTransport.java#L366-L372), when deadline exceeded. (This has little chance to happen, only for the very first RPC on the channel.) - Hedging case. In deadline-exceeded cases, the shorter the deadline is, the more likely the race can happen. --- census/src/main/java/io/grpc/census/CensusStatsModule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/census/src/main/java/io/grpc/census/CensusStatsModule.java b/census/src/main/java/io/grpc/census/CensusStatsModule.java index 4b2832c5989..487e49e5005 100644 --- a/census/src/main/java/io/grpc/census/CensusStatsModule.java +++ b/census/src/main/java/io/grpc/census/CensusStatsModule.java @@ -342,7 +342,6 @@ public void outboundMessage(int seqNo) { @Override public void streamClosed(Status status) { - attemptsState.attemptEnded(); stopwatch.stop(); roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS); Deadline deadline = info.getCallOptions().getDeadline(); @@ -355,6 +354,7 @@ public void streamClosed(Status status) { statusCode = Code.DEADLINE_EXCEEDED; } } + attemptsState.attemptEnded(); if (inboundReceivedOrClosed.compareAndSet(false, true)) { if (module.recordFinishedRpcs) { // Stream is closed early. So no need to record metrics for any inbound events after this @@ -522,6 +522,8 @@ void recordFinishedCall() { tracer.statusCode = status.getCode(); tracer.recordFinishedAttempt(); } else if (inboundMetricTracer != null) { + // activeStreams has been decremented to 0 by attemptEnded(), + // so inboundMetricTracer.statusCode is guaranteed to be assigned already. inboundMetricTracer.recordFinishedAttempt(); } if (!module.recordRetryMetrics) { From cb4b91418c34364b91ece9e9ca6fb5845abad1bf Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Mon, 29 Nov 2021 10:22:32 -0800 Subject: [PATCH 0003/1995] javadoc: update new API `@since` version (#8727) The @since version in commits 5a3b8e2 and a2398ce were missing and incorrect respectively. --- .../java/io/grpc/alts/GoogleDefaultChannelCredentials.java | 4 ++-- okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java index fe8c005da45..d9c2ddaaed7 100644 --- a/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java +++ b/alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java @@ -50,7 +50,7 @@ public static ChannelCredentials create() { /** * Returns a new instance of {@link Builder}. * - * @since 1.42.0 + * @since 1.43.0 */ public static Builder newBuilder() { return new Builder(); @@ -59,7 +59,7 @@ public static Builder newBuilder() { /** * Builder for {@link GoogleDefaultChannelCredentials} instances. * - * @since 1.42.0 + * @since 1.43.0 */ public static final class Builder { private CallCredentials callCredentials; diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java index b3e90d158fa..68ff6dbd787 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java @@ -413,6 +413,8 @@ public OkHttpChannelBuilder connectionSpec( * * @param tlsVersions List of tls versions. * @param cipherSuites List of cipher suites. + * + * @since 1.43.0 */ public OkHttpChannelBuilder tlsConnectionSpec( String[] tlsVersions, String[] cipherSuites) { From 2330922c3809b978f8eb08d14501553ed7f6fb5b Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 30 Nov 2021 08:36:20 -0800 Subject: [PATCH 0004/1995] rls: overhaul RouteLookupConfig validation (#8645) The `RlsProtoData.RouteLookupConfig` class is out-of-date. - Some of the fields were long, but now are of `Duration` type. - Some of the fields are deleted. - The validation of some of the fields either have been changed or were wrong since beginning. Now overhaul all the fields in `RlsProtoData.RouteLookupConfig` class based on the spec http://go/grpc-rls-lb-policy-design#heading=h.y3h669gfpown. Also move the validation logic in json parsing rather than in the constructor of `RouteLookupConfig`. --- .../java/io/grpc/rls/CachingRlsLbClient.java | 6 +- .../io/grpc/rls/RlsLoadBalancerProvider.java | 16 - .../java/io/grpc/rls/RlsProtoConverters.java | 120 ++++-- .../main/java/io/grpc/rls/RlsProtoData.java | 142 ++---- .../java/io/grpc/rls/RlsRequestFactory.java | 6 - .../io/grpc/rls/CachingRlsLbClientTest.java | 15 +- .../java/io/grpc/rls/RlsLoadBalancerTest.java | 8 +- .../io/grpc/rls/RlsProtoConvertersTest.java | 408 +++++++++++++++++- .../java/io/grpc/rls/RlsProtoDataTest.java | 56 --- .../io/grpc/rls/RlsRequestFactoryTest.java | 37 +- 10 files changed, 527 insertions(+), 287 deletions(-) delete mode 100644 rls/src/test/java/io/grpc/rls/RlsProtoDataTest.java diff --git a/rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java b/rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java index 87d01360f49..7bd9f4b68e3 100644 --- a/rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java +++ b/rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java @@ -128,9 +128,9 @@ private CachingRlsLbClient(Builder builder) { synchronizationContext = helper.getSynchronizationContext(); lbPolicyConfig = checkNotNull(builder.lbPolicyConfig, "lbPolicyConfig"); RouteLookupConfig rlsConfig = lbPolicyConfig.getRouteLookupConfig(); - maxAgeNanos = TimeUnit.MILLISECONDS.toNanos(rlsConfig.getMaxAgeInMillis()); - staleAgeNanos = TimeUnit.MILLISECONDS.toNanos(rlsConfig.getStaleAgeInMillis()); - callTimeoutNanos = TimeUnit.MILLISECONDS.toNanos(rlsConfig.getLookupServiceTimeoutInMillis()); + maxAgeNanos = rlsConfig.getMaxAgeInNanos(); + staleAgeNanos = rlsConfig.getStaleAgeInNanos(); + callTimeoutNanos = rlsConfig.getLookupServiceTimeoutInNanos(); timeProvider = checkNotNull(builder.timeProvider, "timeProvider"); throttler = checkNotNull(builder.throttler, "throttler"); linkedHashLruCache = diff --git a/rls/src/main/java/io/grpc/rls/RlsLoadBalancerProvider.java b/rls/src/main/java/io/grpc/rls/RlsLoadBalancerProvider.java index ca1ed714e82..3755fe3f77c 100644 --- a/rls/src/main/java/io/grpc/rls/RlsLoadBalancerProvider.java +++ b/rls/src/main/java/io/grpc/rls/RlsLoadBalancerProvider.java @@ -67,22 +67,6 @@ public ConfigOrError parseLoadBalancingPolicyConfig(Map rawLoadBalanc JsonUtil.getString(rawLoadBalancingConfigPolicy, "childPolicyConfigTargetFieldName"), JsonUtil.checkObjectList( checkNotNull(JsonUtil.getList(rawLoadBalancingConfigPolicy, "childPolicy")))); - // Checking all valid targets to make sure the config is always valid. This strict check - // prevents child policy to handle invalid child policy. - for (String validTarget : routeLookupConfig.getValidTargets()) { - ConfigOrError childPolicyConfigOrError = - lbPolicy - .getEffectiveLbProvider() - .parseLoadBalancingPolicyConfig(lbPolicy.getEffectiveChildPolicy(validTarget)); - if (childPolicyConfigOrError.getError() != null) { - return - ConfigOrError.fromError( - childPolicyConfigOrError - .getError() - .augmentDescription( - "failed to parse childPolicy for validTarget: " + validTarget)); - } - } return ConfigOrError.fromConfig(new LbPolicyConfiguration(routeLookupConfig, lbPolicy)); } catch (Exception e) { return ConfigOrError.fromError( diff --git a/rls/src/main/java/io/grpc/rls/RlsProtoConverters.java b/rls/src/main/java/io/grpc/rls/RlsProtoConverters.java index ce89def4467..b4d3fcc3b29 100644 --- a/rls/src/main/java/io/grpc/rls/RlsProtoConverters.java +++ b/rls/src/main/java/io/grpc/rls/RlsProtoConverters.java @@ -18,8 +18,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.SECONDS; import com.google.common.base.Converter; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.internal.JsonUtil; import io.grpc.lookup.v1.RouteLookupRequest; @@ -29,10 +33,13 @@ import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name; import io.grpc.rls.RlsProtoData.NameMatcher; import io.grpc.rls.RlsProtoData.RouteLookupConfig; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; +import java.util.Set; import javax.annotation.Nullable; /** @@ -41,6 +48,12 @@ */ final class RlsProtoConverters { + private static final long MAX_AGE_NANOS = MINUTES.toNanos(5); + private static final long MAX_CACHE_SIZE = 5 * 1024 * 1024; // 5MiB + private static final long DEFAULT_LOOKUP_SERVICE_TIMEOUT = SECONDS.toNanos(10); + private static final ImmutableList EXTRA_KEY_NAMES = + ImmutableList.of("host", "service", "method"); + /** * RouteLookupRequestConverter converts between {@link RouteLookupRequest} and {@link * RlsProtoData.RouteLookupRequest}. @@ -96,31 +109,49 @@ static final class RouteLookupConfigConverter @Override protected RouteLookupConfig doForward(Map json) { List grpcKeyBuilders = - GrpcKeyBuilderConverter - .covertAll(JsonUtil.checkObjectList(JsonUtil.getList(json, "grpcKeyBuilders"))); + GrpcKeyBuilderConverter.covertAll( + checkNotNull(JsonUtil.getListOfObjects(json, "grpcKeyBuilders"), "grpcKeyBuilders")); + checkArgument(!grpcKeyBuilders.isEmpty(), "must have at least one GrpcKeyBuilder"); + Set names = new HashSet<>(); + for (GrpcKeyBuilder keyBuilder : grpcKeyBuilders) { + for (Name name : keyBuilder.getNames()) { + checkArgument(names.add(name), "duplicate names in grpc_keybuilders: " + name); + } + } String lookupService = JsonUtil.getString(json, "lookupService"); - long timeout = - TimeUnit.SECONDS.toMillis( - orDefault( - JsonUtil.getNumberAsLong(json, "lookupServiceTimeout"), - 0L)); - Long maxAge = - convertTimeIfNotNull( - TimeUnit.SECONDS, TimeUnit.MILLISECONDS, JsonUtil.getNumberAsLong(json, "maxAge")); - Long staleAge = - convertTimeIfNotNull( - TimeUnit.SECONDS, TimeUnit.MILLISECONDS, JsonUtil.getNumberAsLong(json, "staleAge")); - long cacheSize = orDefault(JsonUtil.getNumberAsLong(json, "cacheSizeBytes"), Long.MAX_VALUE); - List validTargets = JsonUtil.checkStringList(JsonUtil.getList(json, "validTargets")); - String defaultTarget = JsonUtil.getString(json, "defaultTarget"); + checkArgument(!Strings.isNullOrEmpty(lookupService), "lookupService must not be empty"); + try { + new URI(lookupService); + } catch (URISyntaxException e) { + throw new IllegalArgumentException( + "The lookupService field is not valid URI: " + lookupService, e); + } + long timeout = orDefault( + JsonUtil.getStringAsDuration(json, "lookupServiceTimeout"), + DEFAULT_LOOKUP_SERVICE_TIMEOUT); + checkArgument(timeout > 0, "lookupServiceTimeout should be positive"); + Long maxAge = JsonUtil.getStringAsDuration(json, "maxAge"); + Long staleAge = JsonUtil.getStringAsDuration(json, "staleAge"); + if (maxAge == null) { + checkArgument(staleAge == null, "to specify staleAge, must have maxAge"); + maxAge = MAX_AGE_NANOS; + } + if (staleAge == null) { + staleAge = MAX_AGE_NANOS; + } + maxAge = Math.min(maxAge, MAX_AGE_NANOS); + staleAge = Math.min(staleAge, maxAge); + long cacheSize = orDefault(JsonUtil.getNumberAsLong(json, "cacheSizeBytes"), MAX_CACHE_SIZE); + checkArgument(cacheSize > 0, "cacheSize must be positive"); + cacheSize = Math.min(cacheSize, MAX_CACHE_SIZE); + String defaultTarget = Strings.emptyToNull(JsonUtil.getString(json, "defaultTarget")); return new RouteLookupConfig( grpcKeyBuilders, lookupService, - /* lookupServiceTimeoutInMillis= */ timeout, - /* maxAgeInMillis= */ maxAge, - /* staleAgeInMillis= */ staleAge, + /* lookupServiceTimeoutInNanos= */ timeout, + /* maxAgeInNanos= */ maxAge, + /* staleAgeInNanos= */ staleAge, /* cacheSizeBytes= */ cacheSize, - validTargets, defaultTarget); } @@ -131,13 +162,6 @@ private static T orDefault(@Nullable T value, T defaultValue) { return value; } - private static Long convertTimeIfNotNull(TimeUnit from, TimeUnit to, Long value) { - if (value == null) { - return null; - } - return to.convert(value, from); - } - @Override protected Map doBackward(RouteLookupConfig routeLookupConfig) { throw new UnsupportedOperationException(); @@ -155,25 +179,29 @@ public static List covertAll(List> keyBuilders) { @SuppressWarnings("unchecked") static GrpcKeyBuilder convert(Map keyBuilder) { - List> rawNames = - JsonUtil.checkObjectList(JsonUtil.getList(keyBuilder, "names")); + List rawRawNames = JsonUtil.getList(keyBuilder, "names"); + checkArgument( + rawRawNames != null && !rawRawNames.isEmpty(), + "each keyBuilder must have at least one name"); + List> rawNames = JsonUtil.checkObjectList(rawRawNames); List names = new ArrayList<>(); for (Map rawName : rawNames) { - names.add( - new Name( - JsonUtil.getString(rawName, "service"), JsonUtil.getString(rawName, "method"))); + String serviceName = JsonUtil.getString(rawName, "service"); + checkArgument(!Strings.isNullOrEmpty(serviceName), "service must not be empty or null"); + names.add(new Name(serviceName, JsonUtil.getString(rawName, "method"))); } + List rawRawHeaders = JsonUtil.getList(keyBuilder, "headers"); List> rawHeaders = - JsonUtil.checkObjectList(JsonUtil.getList(keyBuilder, "headers")); + rawRawHeaders == null + ? new ArrayList>() : JsonUtil.checkObjectList(rawRawHeaders); List nameMatchers = new ArrayList<>(); for (Map rawHeader : rawHeaders) { - NameMatcher matcher = - new NameMatcher( - JsonUtil.getString(rawHeader, "key"), - (List) rawHeader.get("names"), - (Boolean) rawHeader.get("optional")); + Boolean requiredMatch = JsonUtil.getBoolean(rawHeader, "requiredMatch"); checkArgument( - matcher.isOptional(), "NameMatcher for GrpcKeyBuilders shouldn't be required"); + requiredMatch == null || !requiredMatch, + "requiredMatch shouldn't be specified for gRPC"); + NameMatcher matcher = new NameMatcher( + JsonUtil.getString(rawHeader, "key"), (List) rawHeader.get("names")); nameMatchers.add(matcher); } ExtraKeys extraKeys = ExtraKeys.DEFAULT; @@ -188,9 +216,21 @@ static GrpcKeyBuilder convert(Map keyBuilder) { if (constantKeys == null) { constantKeys = ImmutableMap.of(); } + checkUniqueKey(nameMatchers, constantKeys.keySet()); return new GrpcKeyBuilder(names, nameMatchers, extraKeys, constantKeys); } } + private static void checkUniqueKey(List nameMatchers, Set constantKeys) { + Set keys = new HashSet<>(constantKeys); + keys.addAll(EXTRA_KEY_NAMES); + for (NameMatcher nameMatcher : nameMatchers) { + keys.add(nameMatcher.getKey()); + } + if (keys.size() != nameMatchers.size() + constantKeys.size() + EXTRA_KEY_NAMES.size()) { + throw new IllegalArgumentException("keys in KeyBuilder must be unique"); + } + } + private RlsProtoConverters() {} } diff --git a/rls/src/main/java/io/grpc/rls/RlsProtoData.java b/rls/src/main/java/io/grpc/rls/RlsProtoData.java index 32dc81829b3..4709894833c 100644 --- a/rls/src/main/java/io/grpc/rls/RlsProtoData.java +++ b/rls/src/main/java/io/grpc/rls/RlsProtoData.java @@ -16,7 +16,6 @@ package io.grpc.rls; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -25,12 +24,8 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -142,66 +137,36 @@ public String toString() { @Immutable static final class RouteLookupConfig { - private static final long MAX_AGE_MILLIS = TimeUnit.MINUTES.toMillis(5); - private static final long MAX_CACHE_SIZE = 5 * 1024 * 1024; - private final ImmutableList grpcKeyBuilders; private final String lookupService; - private final long lookupServiceTimeoutInMillis; + private final long lookupServiceTimeoutInNanos; - private final long maxAgeInMillis; + private final long maxAgeInNanos; - private final long staleAgeInMillis; + private final long staleAgeInNanos; private final long cacheSizeBytes; - private final ImmutableList validTargets; - @Nullable private final String defaultTarget; RouteLookupConfig( List grpcKeyBuilders, String lookupService, - long lookupServiceTimeoutInMillis, - @Nullable Long maxAgeInMillis, - @Nullable Long staleAgeInMillis, + long lookupServiceTimeoutInNanos, + long maxAgeInNanos, + long staleAgeInNanos, long cacheSizeBytes, - List validTargets, @Nullable String defaultTarget) { - checkState( - !checkNotNull(grpcKeyBuilders, "grpcKeyBuilders").isEmpty(), - "must have at least one GrpcKeyBuilder"); - checkUniqueName(grpcKeyBuilders); this.grpcKeyBuilders = ImmutableList.copyOf(grpcKeyBuilders); - // TODO(creamsoup) also check if it is URI - checkState( - lookupService != null && !lookupService.isEmpty(), "lookupService must not be empty"); this.lookupService = lookupService; - checkState( - lookupServiceTimeoutInMillis > 0, "lookupServiceTimeoutInMillis should be positive"); - this.lookupServiceTimeoutInMillis = lookupServiceTimeoutInMillis; - if (maxAgeInMillis == null) { - checkState( - staleAgeInMillis == null, "To specify staleAgeInMillis, must have maxAgeInMillis"); - } - if (maxAgeInMillis == null || maxAgeInMillis == 0) { - maxAgeInMillis = MAX_AGE_MILLIS; - } - if (staleAgeInMillis == null || staleAgeInMillis == 0) { - staleAgeInMillis = MAX_AGE_MILLIS; - } - this.maxAgeInMillis = Math.min(maxAgeInMillis, MAX_AGE_MILLIS); - this.staleAgeInMillis = Math.min(staleAgeInMillis, this.maxAgeInMillis); - checkArgument(cacheSizeBytes > 0, "cacheSize must be positive"); - this.cacheSizeBytes = Math.min(cacheSizeBytes, MAX_CACHE_SIZE); - this.validTargets = ImmutableList.copyOf(checkNotNull(validTargets, "validTargets")); - if (defaultTarget != null && defaultTarget.isEmpty()) { - defaultTarget = null; - } + this.lookupServiceTimeoutInNanos = lookupServiceTimeoutInNanos; + this.maxAgeInNanos = maxAgeInNanos; + this.staleAgeInNanos = staleAgeInNanos; + this.cacheSizeBytes = cacheSizeBytes; this.defaultTarget = defaultTarget; } @@ -224,22 +189,22 @@ String getLookupService() { } /** Returns the timeout value for lookup service requests. */ - long getLookupServiceTimeoutInMillis() { - return lookupServiceTimeoutInMillis; + long getLookupServiceTimeoutInNanos() { + return lookupServiceTimeoutInNanos; } /** Returns the maximum age the result will be cached. */ - long getMaxAgeInMillis() { - return maxAgeInMillis; + long getMaxAgeInNanos() { + return maxAgeInNanos; } /** * Returns the time when an entry will be in a staled status. When cache is accessed whgen the * entry is in staled status, it will */ - long getStaleAgeInMillis() { - return staleAgeInMillis; + long getStaleAgeInNanos() { + return staleAgeInNanos; } /** @@ -252,15 +217,6 @@ long getCacheSizeBytes() { return cacheSizeBytes; } - /** - * Returns the list of all the possible targets that can be returned by the lookup service. If - * a target not on this list is returned, it will be treated the same as an RPC error from the - * RLS. - */ - ImmutableList getValidTargets() { - return validTargets; - } - /** * Returns the default target to use if needed. If nonempty (implies request processing * strategy SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR is set), it will be used if RLS returns an @@ -281,9 +237,9 @@ public boolean equals(Object o) { return false; } RouteLookupConfig that = (RouteLookupConfig) o; - return lookupServiceTimeoutInMillis == that.lookupServiceTimeoutInMillis - && maxAgeInMillis == that.maxAgeInMillis - && staleAgeInMillis == that.staleAgeInMillis + return lookupServiceTimeoutInNanos == that.lookupServiceTimeoutInNanos + && maxAgeInNanos == that.maxAgeInNanos + && staleAgeInNanos == that.staleAgeInNanos && cacheSizeBytes == that.cacheSizeBytes && Objects.equal(grpcKeyBuilders, that.grpcKeyBuilders) && Objects.equal(lookupService, that.lookupService) @@ -295,9 +251,9 @@ public int hashCode() { return Objects.hashCode( grpcKeyBuilders, lookupService, - lookupServiceTimeoutInMillis, - maxAgeInMillis, - staleAgeInMillis, + lookupServiceTimeoutInNanos, + maxAgeInNanos, + staleAgeInNanos, cacheSizeBytes, defaultTarget); } @@ -307,26 +263,15 @@ public String toString() { return MoreObjects.toStringHelper(this) .add("grpcKeyBuilders", grpcKeyBuilders) .add("lookupService", lookupService) - .add("lookupServiceTimeoutInMillis", lookupServiceTimeoutInMillis) - .add("maxAgeInMillis", maxAgeInMillis) - .add("staleAgeInMillis", staleAgeInMillis) + .add("lookupServiceTimeoutInNanos", lookupServiceTimeoutInNanos) + .add("maxAgeInNanos", maxAgeInNanos) + .add("staleAgeInNanos", staleAgeInNanos) .add("cacheSize", cacheSizeBytes) .add("defaultTarget", defaultTarget) .toString(); } } - private static void checkUniqueName(List grpcKeyBuilders) { - Set names = new HashSet<>(); - for (GrpcKeyBuilder grpcKeyBuilder : grpcKeyBuilders) { - int prevSize = names.size(); - names.addAll(grpcKeyBuilder.getNames()); - if (names.size() != prevSize + grpcKeyBuilder.getNames().size()) { - throw new IllegalStateException("Names in the GrpcKeyBuilders should be unique"); - } - } - } - /** * NameMatcher extract a key based on a given name (e.g. header name or query parameter name). * The name must match one of the names listed in the "name" field. If the "required_match" field @@ -339,12 +284,9 @@ static final class NameMatcher { private final ImmutableList names; - private final boolean optional; - - NameMatcher(String key, List names, @Nullable Boolean optional) { + NameMatcher(String key, List names) { this.key = checkNotNull(key, "key"); this.names = ImmutableList.copyOf(checkNotNull(names, "names")); - this.optional = optional != null ? optional : true; } /** The name that will be used in the RLS key_map to refer to this value. */ @@ -357,13 +299,6 @@ ImmutableList names() { return names; } - /** - * Indicates if this extraction optional. A key builder will still match if no value is found. - */ - boolean isOptional() { - return optional; - } - @Override public boolean equals(Object o) { if (this == o) { @@ -373,14 +308,13 @@ public boolean equals(Object o) { return false; } NameMatcher matcher = (NameMatcher) o; - return optional == matcher.optional - && java.util.Objects.equals(key, matcher.key) + return java.util.Objects.equals(key, matcher.key) && java.util.Objects.equals(names, matcher.names); } @Override public int hashCode() { - return java.util.Objects.hash(key, names, optional); + return java.util.Objects.hash(key, names); } @Override @@ -388,7 +322,6 @@ public String toString() { return MoreObjects.toStringHelper(this) .add("key", key) .add("names", names) - .add("optional", optional) .toString(); } } @@ -408,19 +341,11 @@ static final class GrpcKeyBuilder { Map constantKeys) { checkState(names != null && !names.isEmpty(), "names cannot be empty"); this.names = ImmutableList.copyOf(names); - checkUniqueKey(checkNotNull(headers, "headers")); this.headers = ImmutableList.copyOf(headers); this.extraKeys = checkNotNull(extraKeys, "extraKeys"); this.constantKeys = ImmutableMap.copyOf(checkNotNull(constantKeys, "constantKeys")); } - private static void checkUniqueKey(List headers) { - Set names = new HashSet<>(); - for (NameMatcher header : headers) { - checkState(names.add(header.key), "key in headers must be unique"); - } - } - /** * Returns names. To match, one of the given Name fields must match; the service and method * fields are specified as fixed strings. The service name is required and includes the proto @@ -486,17 +411,11 @@ static final class Name { private final String service; + @Nullable private final String method; - public Name(String service) { - this(service, "*"); - } - /** The primary constructor. */ - Name(String service, String method) { - checkState( - !checkNotNull(service, "service").isEmpty(), - "service must not be empty or null"); + Name(String service, @Nullable String method) { this.service = service; this.method = method; } @@ -505,6 +424,7 @@ String getService() { return service; } + @Nullable String getMethod() { return method; } diff --git a/rls/src/main/java/io/grpc/rls/RlsRequestFactory.java b/rls/src/main/java/io/grpc/rls/RlsRequestFactory.java index e181d64833d..d3aecabd034 100644 --- a/rls/src/main/java/io/grpc/rls/RlsRequestFactory.java +++ b/rls/src/main/java/io/grpc/rls/RlsRequestFactory.java @@ -21,8 +21,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import io.grpc.Metadata; -import io.grpc.Status; -import io.grpc.StatusRuntimeException; import io.grpc.rls.RlsProtoData.ExtraKeys; import io.grpc.rls.RlsProtoData.GrpcKeyBuilder; import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name; @@ -107,10 +105,6 @@ private Map createRequestHeaders( } if (value != null) { rlsRequestHeaders.put(nameMatcher.getKey(), value); - } else if (!nameMatcher.isOptional()) { - throw new StatusRuntimeException( - Status.INVALID_ARGUMENT.withDescription( - String.format("Missing mandatory metadata(%s) not found", nameMatcher.getKey()))); } } return rlsRequestHeaders; diff --git a/rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java b/rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java index aa64ec890b6..c8222a02b8a 100644 --- a/rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java +++ b/rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java @@ -210,7 +210,7 @@ public void get_noError_lifeCycle() throws Exception { assertThat(resp.hasData()).isTrue(); // cache hit for staled entry - fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.getStaleAgeInMillis(), TimeUnit.MILLISECONDS); + fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.getStaleAgeInNanos(), TimeUnit.NANOSECONDS); resp = getInSyncContext(routeLookupRequest); assertThat(resp.hasData()).isTrue(); @@ -226,7 +226,7 @@ public void get_noError_lifeCycle() throws Exception { assertThat(resp.hasData()).isTrue(); // existing cache expired - fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.getMaxAgeInMillis(), TimeUnit.MILLISECONDS); + fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.getMaxAgeInNanos(), TimeUnit.NANOSECONDS); resp = getInSyncContext(routeLookupRequest); @@ -423,16 +423,15 @@ private static RouteLookupConfig getRouteLookupConfig() { new GrpcKeyBuilder( ImmutableList.of(new Name("service1", "create")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("id", ImmutableList.of("X-Google-Id"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("id", ImmutableList.of("X-Google-Id"))), ExtraKeys.create("server", "service-key", "method-key"), ImmutableMap.of())), /* lookupService= */ "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toMillis(2), - /* maxAgeInMillis= */ TimeUnit.SECONDS.toMillis(300), - /* staleAgeInMillis= */ TimeUnit.SECONDS.toMillis(240), + /* lookupServiceTimeoutInNanos= */ TimeUnit.SECONDS.toNanos(2), + /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), + /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(240), /* cacheSizeBytes= */ 1000, - /* validTargets= */ ImmutableList.of("a valid target"), DEFAULT_TARGET); } diff --git a/rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java b/rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java index fba295f98f0..bf0bc47fcc4 100644 --- a/rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java +++ b/rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java @@ -420,11 +420,11 @@ private String getRlsConfigJsonStr() { + " }\n" + " ],\n" + " \"lookupService\": \"localhost:8972\",\n" - + " \"lookupServiceTimeout\": 2,\n" - + " \"maxAge\": 300,\n" - + " \"staleAge\": 240,\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"maxAge\": \"300s\",\n" + + " \"staleAge\": \"240s\",\n" + " \"validTargets\": [\"localhost:9001\", \"localhost:9002\"]," - + " \"cacheSizeBytes\": 1000,\n" + + " \"cacheSizeBytes\": \"1000\",\n" + " \"defaultTarget\": \"" + defaultTarget + "\",\n" + " \"requestProcessingStrategy\": \"SYNC_LOOKUP_DEFAULT_TARGET_ON_ERROR\"\n" + "}"; diff --git a/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java b/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java index bfb331e6cc8..5d1dcc1cadb 100644 --- a/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java +++ b/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java @@ -17,6 +17,7 @@ package io.grpc.rls; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; import com.google.common.base.Converter; import com.google.common.collect.ImmutableList; @@ -166,11 +167,11 @@ public void convert_jsonRlsConfig() throws IOException { + " }\n" + " ],\n" + " \"lookupService\": \"service1\",\n" - + " \"lookupServiceTimeout\": 2,\n" - + " \"maxAge\": 300,\n" - + " \"staleAge\": 240,\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"maxAge\": \"300s\",\n" + + " \"staleAge\": \"240s\",\n" + " \"validTargets\": [\"a valid target\"]," - + " \"cacheSizeBytes\": 1000,\n" + + " \"cacheSizeBytes\": \"1000\",\n" + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + "}"; @@ -180,29 +181,28 @@ public void convert_jsonRlsConfig() throws IOException { new GrpcKeyBuilder( ImmutableList.of(new Name("service1", "create")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("id", ImmutableList.of("X-Google-Id"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("id", ImmutableList.of("X-Google-Id"))), ExtraKeys.DEFAULT, ImmutableMap.of()), new GrpcKeyBuilder( - ImmutableList.of(new Name("service1")), + ImmutableList.of(new Name("service1", "*")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("password", ImmutableList.of("Password"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("password", ImmutableList.of("Password"))), ExtraKeys.DEFAULT, ImmutableMap.of()), new GrpcKeyBuilder( - ImmutableList.of(new Name("service3")), + ImmutableList.of(new Name("service3", "*")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent"))), ExtraKeys.create("host-key", "service-key", "method-key"), ImmutableMap.of("constKey1", "value1"))), /* lookupService= */ "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toMillis(2), - /* maxAgeInMillis= */ TimeUnit.SECONDS.toMillis(300), - /* staleAgeInMillis= */ TimeUnit.SECONDS.toMillis(240), + /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(2), + /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), + /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(240), /* cacheSizeBytes= */ 1000, - /* validTargets= */ ImmutableList.of("a valid target"), /* defaultTarget= */ "us_east_1.cloudbigtable.googleapis.com"); RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); @@ -211,4 +211,382 @@ public void convert_jsonRlsConfig() throws IOException { RouteLookupConfig converted = converter.convert(parsedJson); assertThat(converted).isEqualTo(expectedConfig); } + + @Test + public void convert_jsonRlsConfig_emptyKeyBuilders() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"maxAge\": \"300s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat().contains("must have at least one GrpcKeyBuilder"); + } + } + + @Test + public void convert_jsonRlsConfig_namesNotUnique() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\",\n" + + " \"method\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\",\n" + + " \"method\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"password\"," + + " \"names\": [\"Password\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service3\",\n" + + " \"method\": \"*\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ],\n" + + " \"extraKeys\": {\n" + + " \"host\": \"host-key\",\n" + + " \"service\": \"service-key\",\n" + + " \"method\": \"method-key\"\n" + + " }, \n" + + " \"constantKeys\": {\n" + + " \"constKey1\": \"value1\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"maxAge\": \"300s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat() + .contains("duplicate names in grpc_keybuilders: Name{service=service1, method=create}"); + } + } + + @Test + public void convert_jsonRlsConfig_defaultValues() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfig expectedConfig = + new RouteLookupConfig( + ImmutableList.of( + new GrpcKeyBuilder( + ImmutableList.of(new Name("service1", null)), + ImmutableList.of(), + ExtraKeys.DEFAULT, + ImmutableMap.of())), + /* lookupService= */ "service1", + /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(10), + /* maxAgeInNanos= */ TimeUnit.MINUTES.toNanos(5), + /* staleAgeInNanos= */ TimeUnit.MINUTES.toNanos(5), + /* cacheSizeBytes= */ 5 * 1024 * 1024, + /* defaultTarget= */ "us_east_1.cloudbigtable.googleapis.com"); + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + RouteLookupConfig converted = converter.convert(parsedJson); + assertThat(converted).isEqualTo(expectedConfig); + } + + @Test + public void convert_jsonRlsConfig_staleAgeCappedByMaxAge() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\",\n" + + " \"method\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"maxAge\": \"300s\",\n" + + " \"staleAge\": \"400s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfig expectedConfig = + new RouteLookupConfig( + ImmutableList.of( + new GrpcKeyBuilder( + ImmutableList.of(new Name("service1", "create")), + ImmutableList.of( + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("id", ImmutableList.of("X-Google-Id"))), + ExtraKeys.DEFAULT, + ImmutableMap.of())), + /* lookupService= */ "service1", + /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(2), + /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), + /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), + /* cacheSizeBytes= */ 1000, + /* defaultTarget= */ "us_east_1.cloudbigtable.googleapis.com"); + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + RouteLookupConfig converted = converter.convert(parsedJson); + assertThat(converted).isEqualTo(expectedConfig); + } + + @Test + public void convert_jsonRlsConfig_staleAgeGivenWithoutMaxAge() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\",\n" + + " \"method\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat().contains("to specify staleAge, must have maxAge"); + } + } + + @Test + public void convert_jsonRlsConfig_keyBuilderWithoutName() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat().contains("each keyBuilder must have at least one name"); + } + } + + @Test + public void convert_jsonRlsConfig_nameWithoutService() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"method\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"user\"," + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat().contains("service must not be empty or null"); + } + } + + @Test + public void convert_jsonRlsConfig_keysNotUnique() throws IOException { + String jsonStr = "{\n" + + " \"grpcKeyBuilders\": [\n" + + " {\n" + + " \"names\": [\n" + + " {\n" + + " \"service\": \"service1\"\n" + + " }\n" + + " ],\n" + + " \"headers\": [\n" + + " {\n" + + " \"key\": \"service\"," // duplicate to extra_keys + + " \"names\": [\"User\", \"Parent\"],\n" + + " \"optional\": true\n" + + " },\n" + + " {\n" + + " \"key\": \"id\"," + + " \"names\": [\"X-Google-Id\"],\n" + + " \"optional\": true\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"lookupService\": \"service1\",\n" + + " \"lookupServiceTimeout\": \"2s\",\n" + + " \"staleAge\": \"240s\",\n" + + " \"validTargets\": [\"a valid target\"]," + + " \"cacheSizeBytes\": \"1000\",\n" + + " \"defaultTarget\": \"us_east_1.cloudbigtable.googleapis.com\"\n" + + "}"; + + RouteLookupConfigConverter converter = new RouteLookupConfigConverter(); + @SuppressWarnings("unchecked") + Map parsedJson = (Map) JsonParser.parse(jsonStr); + try { + converter.convert(parsedJson); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessageThat().contains("keys in KeyBuilder must be unique"); + } + } } diff --git a/rls/src/test/java/io/grpc/rls/RlsProtoDataTest.java b/rls/src/test/java/io/grpc/rls/RlsProtoDataTest.java deleted file mode 100644 index 9cfb6c753fb..00000000000 --- a/rls/src/test/java/io/grpc/rls/RlsProtoDataTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2021 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.rls; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import io.grpc.rls.RlsProtoData.ExtraKeys; -import io.grpc.rls.RlsProtoData.GrpcKeyBuilder; -import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name; -import io.grpc.rls.RlsProtoData.NameMatcher; -import io.grpc.rls.RlsProtoData.RouteLookupConfig; -import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for {@link RlsProtoData}. */ -@RunWith(JUnit4.class) -public class RlsProtoDataTest { - @Test - public void maxCacheSize() { - RouteLookupConfig config = new RouteLookupConfig( - ImmutableList.of( - new GrpcKeyBuilder( - ImmutableList.of(new Name("service1", "create")), - ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("id", ImmutableList.of("X-Google-Id"), true)), - ExtraKeys.create("server", "service-key", "method-key"), - ImmutableMap.of())), - "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toMillis(2), - /* maxAgeInMillis= */ TimeUnit.SECONDS.toMillis(300), - /* staleAgeInMillis= */ TimeUnit.SECONDS.toMillis(240), - /* cacheSizeBytes= */ 20 * 1000 * 1000, - ImmutableList.of("a-valid-target"), - "default-target"); - assertThat(config.getCacheSizeBytes()).isEqualTo(5 * 1024 * 1024); - } -} diff --git a/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java b/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java index b0d197ff525..0d834601279 100644 --- a/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java +++ b/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java @@ -17,13 +17,10 @@ package io.grpc.rls; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.grpc.Metadata; -import io.grpc.Status.Code; -import io.grpc.StatusRuntimeException; import io.grpc.rls.RlsProtoData.ExtraKeys; import io.grpc.rls.RlsProtoData.GrpcKeyBuilder; import io.grpc.rls.RlsProtoData.GrpcKeyBuilder.Name; @@ -44,28 +41,27 @@ public class RlsRequestFactoryTest { new GrpcKeyBuilder( ImmutableList.of(new Name("com.google.service1", "Create")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("id", ImmutableList.of("X-Google-Id"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("id", ImmutableList.of("X-Google-Id"))), ExtraKeys.create("server-1", null, null), ImmutableMap.of("const-key-1", "const-value-1")), new GrpcKeyBuilder( - ImmutableList.of(new Name("com.google.service1")), + ImmutableList.of(new Name("com.google.service1", "*")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true), - new NameMatcher("password", ImmutableList.of("Password"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent")), + new NameMatcher("password", ImmutableList.of("Password"))), ExtraKeys.create(null, "service-2", null), ImmutableMap.of("const-key-2", "const-value-2")), new GrpcKeyBuilder( - ImmutableList.of(new Name("com.google.service2")), + ImmutableList.of(new Name("com.google.service2", "*")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), false), - new NameMatcher("password", ImmutableList.of("Password"), true)), + new NameMatcher("password", ImmutableList.of("Password"))), ExtraKeys.create(null, "service-3", "method-3"), ImmutableMap.of()), new GrpcKeyBuilder( - ImmutableList.of(new Name("com.google.service3")), + ImmutableList.of(new Name("com.google.service3", "*")), ImmutableList.of( - new NameMatcher("user", ImmutableList.of("User", "Parent"), true)), + new NameMatcher("user", ImmutableList.of("User", "Parent"))), ExtraKeys.create(null, null, null), ImmutableMap.of("const-key-4", "const-value-4"))), /* lookupService= */ "bigtable-rls.googleapis.com", @@ -73,7 +69,6 @@ public class RlsRequestFactoryTest { /* maxAgeInMillis= */ TimeUnit.SECONDS.toMillis(300), /* staleAgeInMillis= */ TimeUnit.SECONDS.toMillis(240), /* cacheSizeBytes= */ 1000, - /* validTargets= */ ImmutableList.of("a valid target"), /* defaultTarget= */ "us_east_1.cloudbigtable.googleapis.com"); private final RlsRequestFactory factory = new RlsRequestFactory( @@ -94,20 +89,6 @@ public void create_pathMatches() { "const-key-1", "const-value-1"); } - @Test - public void create_missingRequiredHeader() { - Metadata metadata = new Metadata(); - - try { - RouteLookupRequest unused = factory.create("com.google.service2", "Create", metadata); - fail(); - } catch (StatusRuntimeException e) { - assertThat(e.getStatus().getCode()).isEqualTo(Code.INVALID_ARGUMENT); - assertThat(e.getStatus().getDescription()) - .isEqualTo("Missing mandatory metadata(user) not found"); - } - } - @Test public void create_pathFallbackMatches() { Metadata metadata = new Metadata(); From 65c00cf24e9764335484614e3d41733e70c6d6df Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 30 Nov 2021 11:53:56 -0800 Subject: [PATCH 0005/1995] Start 1.44.0 development cycle (#8729) --- build.gradle | 2 +- .../src/test/golden/TestDeprecatedService.java.txt | 2 +- compiler/src/test/golden/TestService.java.txt | 2 +- .../src/testLite/golden/TestDeprecatedService.java.txt | 2 +- compiler/src/testLite/golden/TestService.java.txt | 2 +- core/src/main/java/io/grpc/internal/GrpcUtil.java | 2 +- examples/android/clientcache/app/build.gradle | 10 +++++----- examples/android/helloworld/app/build.gradle | 8 ++++---- examples/android/routeguide/app/build.gradle | 8 ++++---- examples/android/strictmode/app/build.gradle | 8 ++++---- examples/build.gradle | 2 +- examples/example-alts/build.gradle | 2 +- examples/example-gauth/build.gradle | 2 +- examples/example-gauth/pom.xml | 4 ++-- examples/example-hostname/build.gradle | 2 +- examples/example-hostname/pom.xml | 4 ++-- examples/example-jwt-auth/build.gradle | 2 +- examples/example-jwt-auth/pom.xml | 4 ++-- examples/example-tls/build.gradle | 2 +- examples/example-tls/pom.xml | 4 ++-- examples/example-xds/build.gradle | 2 +- examples/pom.xml | 4 ++-- 22 files changed, 40 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 9d9e991bca5..9aab8312c5c 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ subprojects { apply plugin: "net.ltgt.errorprone" group = "io.grpc" - version = "1.43.0-SNAPSHOT" // CURRENT_GRPC_VERSION + version = "1.44.0-SNAPSHOT" // CURRENT_GRPC_VERSION repositories { maven { // The google mirror is less flaky than mavenCentral() diff --git a/compiler/src/test/golden/TestDeprecatedService.java.txt b/compiler/src/test/golden/TestDeprecatedService.java.txt index 98dcbf87587..68d8e1172a3 100644 --- a/compiler/src/test/golden/TestDeprecatedService.java.txt +++ b/compiler/src/test/golden/TestDeprecatedService.java.txt @@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName; * */ @javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.43.0-SNAPSHOT)", + value = "by gRPC proto compiler (version 1.44.0-SNAPSHOT)", comments = "Source: grpc/testing/compiler/test.proto") @io.grpc.stub.annotations.GrpcGenerated @java.lang.Deprecated diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt index 49938bd9345..3c6cdc82b51 100644 --- a/compiler/src/test/golden/TestService.java.txt +++ b/compiler/src/test/golden/TestService.java.txt @@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName; * */ @javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.43.0-SNAPSHOT)", + value = "by gRPC proto compiler (version 1.44.0-SNAPSHOT)", comments = "Source: grpc/testing/compiler/test.proto") @io.grpc.stub.annotations.GrpcGenerated public final class TestServiceGrpc { diff --git a/compiler/src/testLite/golden/TestDeprecatedService.java.txt b/compiler/src/testLite/golden/TestDeprecatedService.java.txt index fdd980a554e..8dcafe51f24 100644 --- a/compiler/src/testLite/golden/TestDeprecatedService.java.txt +++ b/compiler/src/testLite/golden/TestDeprecatedService.java.txt @@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName; * */ @javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.43.0-SNAPSHOT)", + value = "by gRPC proto compiler (version 1.44.0-SNAPSHOT)", comments = "Source: grpc/testing/compiler/test.proto") @io.grpc.stub.annotations.GrpcGenerated @java.lang.Deprecated diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt index e13628ac66f..60ac085f920 100644 --- a/compiler/src/testLite/golden/TestService.java.txt +++ b/compiler/src/testLite/golden/TestService.java.txt @@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName; * */ @javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.43.0-SNAPSHOT)", + value = "by gRPC proto compiler (version 1.44.0-SNAPSHOT)", comments = "Source: grpc/testing/compiler/test.proto") @io.grpc.stub.annotations.GrpcGenerated public final class TestServiceGrpc { diff --git a/core/src/main/java/io/grpc/internal/GrpcUtil.java b/core/src/main/java/io/grpc/internal/GrpcUtil.java index 6a7b93baf06..635fab11c8f 100644 --- a/core/src/main/java/io/grpc/internal/GrpcUtil.java +++ b/core/src/main/java/io/grpc/internal/GrpcUtil.java @@ -205,7 +205,7 @@ public byte[] parseAsciiString(byte[] serialized) { public static final Splitter ACCEPT_ENCODING_SPLITTER = Splitter.on(',').trimResults(); - private static final String IMPLEMENTATION_VERSION = "1.43.0-SNAPSHOT"; // CURRENT_GRPC_VERSION + private static final String IMPLEMENTATION_VERSION = "1.44.0-SNAPSHOT"; // CURRENT_GRPC_VERSION /** * The default timeout in nanos for a keepalive ping request. diff --git a/examples/android/clientcache/app/build.gradle b/examples/android/clientcache/app/build.gradle index fbbcdd9b364..075f4fab117 100644 --- a/examples/android/clientcache/app/build.gradle +++ b/examples/android/clientcache/app/build.gradle @@ -34,7 +34,7 @@ android { protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } plugins { - grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } } generateProtoTasks { @@ -54,12 +54,12 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' // You need to build grpc-java to obtain these libraries below. - implementation 'io.grpc:grpc-okhttp:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-protobuf-lite:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-stub:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-okhttp:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-protobuf-lite:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-stub:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'org.apache.tomcat:annotations-api:6.0.53' testImplementation 'junit:junit:4.12' testImplementation 'com.google.truth:truth:1.0.1' - testImplementation 'io.grpc:grpc-testing:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + testImplementation 'io.grpc:grpc-testing:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/helloworld/app/build.gradle b/examples/android/helloworld/app/build.gradle index 0c71d91c0d2..e8655c09dd9 100644 --- a/examples/android/helloworld/app/build.gradle +++ b/examples/android/helloworld/app/build.gradle @@ -32,7 +32,7 @@ android { protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } plugins { - grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } } generateProtoTasks { @@ -52,8 +52,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' // You need to build grpc-java to obtain these libraries below. - implementation 'io.grpc:grpc-okhttp:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-protobuf-lite:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-stub:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-okhttp:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-protobuf-lite:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-stub:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'org.apache.tomcat:annotations-api:6.0.53' } diff --git a/examples/android/routeguide/app/build.gradle b/examples/android/routeguide/app/build.gradle index 09dc587850f..13df17021c8 100644 --- a/examples/android/routeguide/app/build.gradle +++ b/examples/android/routeguide/app/build.gradle @@ -32,7 +32,7 @@ android { protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } plugins { - grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } } generateProtoTasks { @@ -52,8 +52,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' // You need to build grpc-java to obtain these libraries below. - implementation 'io.grpc:grpc-okhttp:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-protobuf-lite:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-stub:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-okhttp:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-protobuf-lite:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-stub:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'org.apache.tomcat:annotations-api:6.0.53' } diff --git a/examples/android/strictmode/app/build.gradle b/examples/android/strictmode/app/build.gradle index 9fb69f3f690..b0bbc7a7268 100644 --- a/examples/android/strictmode/app/build.gradle +++ b/examples/android/strictmode/app/build.gradle @@ -33,7 +33,7 @@ android { protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } plugins { - grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } } generateProtoTasks { @@ -53,8 +53,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' // You need to build grpc-java to obtain these libraries below. - implementation 'io.grpc:grpc-okhttp:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-protobuf-lite:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION - implementation 'io.grpc:grpc-stub:1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-okhttp:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-protobuf-lite:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION + implementation 'io.grpc:grpc-stub:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'org.apache.tomcat:annotations-api:6.0.53' } diff --git a/examples/build.gradle b/examples/build.gradle index 4c88b826d38..03b43512a5c 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -22,7 +22,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protobufVersion = '3.17.2' def protocVersion = protobufVersion diff --git a/examples/example-alts/build.gradle b/examples/example-alts/build.gradle index a0d726f6768..6bb43394579 100644 --- a/examples/example-alts/build.gradle +++ b/examples/example-alts/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protocVersion = '3.17.2' dependencies { diff --git a/examples/example-gauth/build.gradle b/examples/example-gauth/build.gradle index 2558469feb3..fcfbab9d026 100644 --- a/examples/example-gauth/build.gradle +++ b/examples/example-gauth/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protobufVersion = '3.17.2' def protocVersion = protobufVersion diff --git a/examples/example-gauth/pom.xml b/examples/example-gauth/pom.xml index 67db6c7c9fb..7445b7b7ce7 100644 --- a/examples/example-gauth/pom.xml +++ b/examples/example-gauth/pom.xml @@ -6,13 +6,13 @@ jar - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT example-gauth https://github.com/grpc/grpc-java UTF-8 - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT 3.17.2 1.7 diff --git a/examples/example-hostname/build.gradle b/examples/example-hostname/build.gradle index 331d8309136..e6bb1d73846 100644 --- a/examples/example-hostname/build.gradle +++ b/examples/example-hostname/build.gradle @@ -21,7 +21,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protobufVersion = '3.17.2' dependencies { diff --git a/examples/example-hostname/pom.xml b/examples/example-hostname/pom.xml index d4625193bf8..71b2903e816 100644 --- a/examples/example-hostname/pom.xml +++ b/examples/example-hostname/pom.xml @@ -6,13 +6,13 @@ jar - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT example-hostname https://github.com/grpc/grpc-java UTF-8 - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT 3.17.2 1.7 diff --git a/examples/example-jwt-auth/build.gradle b/examples/example-jwt-auth/build.gradle index 94ae0610a21..881cc553645 100644 --- a/examples/example-jwt-auth/build.gradle +++ b/examples/example-jwt-auth/build.gradle @@ -22,7 +22,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protobufVersion = '3.17.2' def protocVersion = protobufVersion diff --git a/examples/example-jwt-auth/pom.xml b/examples/example-jwt-auth/pom.xml index 9ac3aefe34e..12724e4fbd1 100644 --- a/examples/example-jwt-auth/pom.xml +++ b/examples/example-jwt-auth/pom.xml @@ -7,13 +7,13 @@ jar - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT example-jwt-auth https://github.com/grpc/grpc-java UTF-8 - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT 3.17.2 3.17.2 diff --git a/examples/example-tls/build.gradle b/examples/example-tls/build.gradle index 8a8ceb371af..213034e10c2 100644 --- a/examples/example-tls/build.gradle +++ b/examples/example-tls/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def protocVersion = '3.17.2' dependencies { diff --git a/examples/example-tls/pom.xml b/examples/example-tls/pom.xml index 60d632bbb87..0eb097ee525 100644 --- a/examples/example-tls/pom.xml +++ b/examples/example-tls/pom.xml @@ -6,13 +6,13 @@ jar - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT example-tls https://github.com/grpc/grpc-java UTF-8 - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT 3.17.2 2.0.34.Final diff --git a/examples/example-xds/build.gradle b/examples/example-xds/build.gradle index d00beaa06bb..123adbcef8f 100644 --- a/examples/example-xds/build.gradle +++ b/examples/example-xds/build.gradle @@ -22,7 +22,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. -def grpcVersion = '1.43.0-SNAPSHOT' // CURRENT_GRPC_VERSION +def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def nettyTcNativeVersion = '2.0.31.Final' def protocVersion = '3.17.2' diff --git a/examples/pom.xml b/examples/pom.xml index 0704ce80d88..7546b58d763 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -6,13 +6,13 @@ jar - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT examples https://github.com/grpc/grpc-java UTF-8 - 1.43.0-SNAPSHOT + 1.44.0-SNAPSHOT 3.17.2 3.17.2 From 27b03c66a64aeae25f3fc867457b02e21ca81dab Mon Sep 17 00:00:00 2001 From: John Cormie Date: Tue, 30 Nov 2021 16:00:43 -0800 Subject: [PATCH 0006/1995] Send empty shutdown flags to avoid a binder memory leak (#8728) --- .../src/main/java/io/grpc/binder/internal/BinderTransport.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java b/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java index b3bc488b64a..8b41703af5c 100644 --- a/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java +++ b/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java @@ -345,6 +345,8 @@ private final void sendShutdownTransaction() { // Ignore. } Parcel parcel = Parcel.obtain(); + // Send empty flags to avoid a memory leak linked to empty parcels (b/207778694). + parcel.writeInt(0); try { outgoingBinder.transact(SHUTDOWN_TRANSPORT, parcel, null, IBinder.FLAG_ONEWAY); } catch (RemoteException re) { From 7aaa418ec71faeb761fd9146b1165e4eb28669fd Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 1 Dec 2021 15:02:13 -0800 Subject: [PATCH 0007/1995] rls: Fix RouteLookupConfig test arguments This PR fixes a few cosmetic violations of the ErrorProne patterns introduced in PR #8645: ParameterName, and TimeUnitMismatch. --- rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java | 6 +++--- rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java b/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java index 5d1dcc1cadb..958abea3926 100644 --- a/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java +++ b/rls/src/test/java/io/grpc/rls/RlsProtoConvertersTest.java @@ -199,7 +199,7 @@ public void convert_jsonRlsConfig() throws IOException { ExtraKeys.create("host-key", "service-key", "method-key"), ImmutableMap.of("constKey1", "value1"))), /* lookupService= */ "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(2), + /* lookupServiceTimeoutInNanos= */ TimeUnit.SECONDS.toNanos(2), /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(240), /* cacheSizeBytes= */ 1000, @@ -351,7 +351,7 @@ public void convert_jsonRlsConfig_defaultValues() throws IOException { ExtraKeys.DEFAULT, ImmutableMap.of())), /* lookupService= */ "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(10), + /* lookupServiceTimeoutInNanos= */ TimeUnit.SECONDS.toNanos(10), /* maxAgeInNanos= */ TimeUnit.MINUTES.toNanos(5), /* staleAgeInNanos= */ TimeUnit.MINUTES.toNanos(5), /* cacheSizeBytes= */ 5 * 1024 * 1024, @@ -409,7 +409,7 @@ public void convert_jsonRlsConfig_staleAgeCappedByMaxAge() throws IOException { ExtraKeys.DEFAULT, ImmutableMap.of())), /* lookupService= */ "service1", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toNanos(2), + /* lookupServiceTimeoutInNanos= */ TimeUnit.SECONDS.toNanos(2), /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), /* cacheSizeBytes= */ 1000, diff --git a/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java b/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java index 0d834601279..9b66944d787 100644 --- a/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java +++ b/rls/src/test/java/io/grpc/rls/RlsRequestFactoryTest.java @@ -65,9 +65,9 @@ public class RlsRequestFactoryTest { ExtraKeys.create(null, null, null), ImmutableMap.of("const-key-4", "const-value-4"))), /* lookupService= */ "bigtable-rls.googleapis.com", - /* lookupServiceTimeoutInMillis= */ TimeUnit.SECONDS.toMillis(2), - /* maxAgeInMillis= */ TimeUnit.SECONDS.toMillis(300), - /* staleAgeInMillis= */ TimeUnit.SECONDS.toMillis(240), + /* lookupServiceTimeoutInNanos= */ TimeUnit.SECONDS.toNanos(2), + /* maxAgeInNanos= */ TimeUnit.SECONDS.toNanos(300), + /* staleAgeInNanos= */ TimeUnit.SECONDS.toNanos(240), /* cacheSizeBytes= */ 1000, /* defaultTarget= */ "us_east_1.cloudbigtable.googleapis.com"); From 24330bccff2b0d0caf3fc4c27ccf3f11860773a7 Mon Sep 17 00:00:00 2001 From: apolcyn Date: Tue, 7 Dec 2021 13:29:29 -0800 Subject: [PATCH 0008/1995] Replace C2P resolver env var with experimental scheme suffix (#8744) Java analogue of grpc/grpc#28294 --- .../grpc/xds/GoogleCloudToProdNameResolverProvider.java | 9 ++------- .../xds/GoogleCloudToProdNameResolverProviderTest.java | 3 ++- .../io/grpc/xds/GoogleCloudToProdNameResolverTest.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolverProvider.java b/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolverProvider.java index be8324b93cf..e7f9cb45ff8 100644 --- a/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolverProvider.java +++ b/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolverProvider.java @@ -29,9 +29,7 @@ @Internal public final class GoogleCloudToProdNameResolverProvider extends NameResolverProvider { - private static final boolean enableC2PResolver = - Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_GOOGLE_C2P_RESOLVER")); - private static final String SCHEME = "google-c2p"; + private static final String SCHEME = "google-c2p-experimental"; @Override public NameResolver newNameResolver(URI targetUri, Args args) { @@ -50,10 +48,7 @@ public String getDefaultScheme() { @Override protected boolean isAvailable() { - if (enableC2PResolver) { - return true; - } - return false; + return true; } @Override diff --git a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverProviderTest.java b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverProviderTest.java index 372c8af8f41..cc6621028c8 100644 --- a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverProviderTest.java +++ b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverProviderTest.java @@ -73,7 +73,8 @@ NameResolverProvider.class, getClass().getClassLoader())) { @Test public void newNameResolver() { - assertThat(provider.newNameResolver(URI.create("google-c2p:///foo.googleapis.com"), args)) + assertThat(provider + .newNameResolver(URI.create("google-c2p-experimental:///foo.googleapis.com"), args)) .isInstanceOf(GoogleCloudToProdNameResolver.class); } } diff --git a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java index 421b2a1dd0a..58be7108405 100644 --- a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java +++ b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java @@ -69,7 +69,7 @@ public class GoogleCloudToProdNameResolverTest { @Rule public final MockitoRule mocks = MockitoJUnit.rule(); - private static final URI TARGET_URI = URI.create("google-c2p:///googleapis.com"); + private static final URI TARGET_URI = URI.create("google-c2p-experimental:///googleapis.com"); private static final String ZONE = "us-central1-a"; private static final int DEFAULT_PORT = 887; From e28145ab6afb92b68f18032f83ead26c1a37b2e6 Mon Sep 17 00:00:00 2001 From: Grant Oakley Date: Wed, 8 Dec 2021 14:39:42 -0800 Subject: [PATCH 0009/1995] Enclose all operations using obtained Parcels in try-finally blocks that will recycle the Parcel in the case that any exception is thrown. (#8733) --- .../grpc/binder/internal/BinderTransport.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java b/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java index 8b41703af5c..e07619dca33 100644 --- a/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java +++ b/binder/src/main/java/io/grpc/binder/internal/BinderTransport.java @@ -323,17 +323,18 @@ final void sendSetupTransaction() { @GuardedBy("this") final void sendSetupTransaction(IBinder iBinder) { Parcel parcel = Parcel.obtain(); - parcel.writeInt(WIRE_FORMAT_VERSION); - parcel.writeStrongBinder(incomingBinder); try { + parcel.writeInt(WIRE_FORMAT_VERSION); + parcel.writeStrongBinder(incomingBinder); if (!iBinder.transact(SETUP_TRANSPORT, parcel, null, IBinder.FLAG_ONEWAY)) { shutdownInternal( Status.UNAVAILABLE.withDescription("Failed sending SETUP_TRANSPORT transaction"), true); } } catch (RemoteException re) { shutdownInternal(statusFromRemoteException(re), true); + } finally { + parcel.recycle(); } - parcel.recycle(); } @GuardedBy("this") @@ -345,14 +346,15 @@ private final void sendShutdownTransaction() { // Ignore. } Parcel parcel = Parcel.obtain(); - // Send empty flags to avoid a memory leak linked to empty parcels (b/207778694). - parcel.writeInt(0); try { + // Send empty flags to avoid a memory leak linked to empty parcels (b/207778694). + parcel.writeInt(0); outgoingBinder.transact(SHUTDOWN_TRANSPORT, parcel, null, IBinder.FLAG_ONEWAY); } catch (RemoteException re) { // Ignore. + } finally { + parcel.recycle(); } - parcel.recycle(); } } @@ -363,8 +365,8 @@ protected synchronized void sendPing(int id) throws StatusException { throw Status.FAILED_PRECONDITION.withDescription("Transport not ready.").asException(); } else { Parcel parcel = Parcel.obtain(); - parcel.writeInt(id); try { + parcel.writeInt(id); outgoingBinder.transact(PING, parcel, null, IBinder.FLAG_ONEWAY); } catch (RemoteException re) { throw statusFromRemoteException(re).asException(); @@ -410,15 +412,16 @@ final void sendTransaction(int callId, Parcel parcel) throws StatusException { final void sendOutOfBandClose(int callId, Status status) { Parcel parcel = Parcel.obtain(); - parcel.writeInt(0); // Placeholder for flags. Will be filled in below. - int flags = TransactionUtils.writeStatus(parcel, status); - TransactionUtils.fillInFlags(parcel, flags | TransactionUtils.FLAG_OUT_OF_BAND_CLOSE); try { + parcel.writeInt(0); // Placeholder for flags. Will be filled in below. + int flags = TransactionUtils.writeStatus(parcel, status); + TransactionUtils.fillInFlags(parcel, flags | TransactionUtils.FLAG_OUT_OF_BAND_CLOSE); sendTransaction(callId, parcel); } catch (StatusException e) { logger.log(Level.WARNING, "Failed sending oob close transaction", e); + } finally { + parcel.recycle(); } - parcel.recycle(); } @Override @@ -507,16 +510,17 @@ private void sendAcknowledgeBytes(IBinder iBinder) { long n = numIncomingBytes.get(); acknowledgedIncomingBytes = n; Parcel parcel = Parcel.obtain(); - parcel.writeLong(n); try { + parcel.writeLong(n); if (!iBinder.transact(ACKNOWLEDGE_BYTES, parcel, null, IBinder.FLAG_ONEWAY)) { shutdownInternal( Status.UNAVAILABLE.withDescription("Failed sending ack bytes transaction"), true); } } catch (RemoteException re) { shutdownInternal(statusFromRemoteException(re), true); + } finally { + parcel.recycle(); } - parcel.recycle(); } @GuardedBy("this") @@ -909,3 +913,4 @@ private static Status statusFromRemoteException(RemoteException e) { return Status.INTERNAL.withCause(e); } } + From efd968bcbb9c34dc94493ed88dbf627a5552cebb Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 7 Dec 2021 16:18:46 -0800 Subject: [PATCH 0010/1995] Upgrade Protobuf to 3.19.1 and Guava to 30.1.1 Protobuf uses Guava 30.1.1, so I upgrade it at the same time. It also caused an update to rules_jvm_external and reworking the Bazel build. Protobuf no longer requires bind() so they were dropped. Although Protobuf's protobuf_deps() brings in rules_jvm_external, and so we don't need to define it ourselves, it seems better to define it directly and not depend on transitive deps since we use it directly. Protobuf now has support for maven_install() by exposing PROTOBUF_MAVEN_ARTIFACTS, which required reorganizing the WORKSPACE to use maven_install() after loading protobuf. Protobuf still doesn't define target overrides for itself so we still maintain those. When reorganizing the WORKSPACE I noticed http_archive should ideally be above io_grpc_grpc_java as most users will need it there, so I fixed that since there were lots of other load()-reordering already. --- COMPILING.md | 4 +-- WORKSPACE | 24 +++++++-------- build.gradle | 4 +-- buildscripts/make_dependencies.bat | 2 +- buildscripts/make_dependencies.sh | 2 +- examples/WORKSPACE | 30 +++++++++---------- examples/android/clientcache/app/build.gradle | 2 +- examples/android/helloworld/app/build.gradle | 2 +- examples/android/routeguide/app/build.gradle | 2 +- examples/android/strictmode/app/build.gradle | 2 +- examples/build.gradle | 2 +- examples/example-alts/build.gradle | 2 +- examples/example-gauth/build.gradle | 2 +- examples/example-gauth/pom.xml | 2 +- examples/example-hostname/build.gradle | 2 +- examples/example-hostname/pom.xml | 2 +- examples/example-jwt-auth/build.gradle | 2 +- examples/example-jwt-auth/pom.xml | 4 +-- examples/example-tls/build.gradle | 2 +- examples/example-tls/pom.xml | 2 +- examples/example-xds/build.gradle | 2 +- examples/pom.xml | 4 +-- repositories.bzl | 27 +++++------------ 23 files changed, 58 insertions(+), 71 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index 208f05e25cb..d065e702842 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -43,11 +43,11 @@ This section is only necessary if you are making changes to the code generation. Most users only need to use `skipCodegen=true` as discussed above. ### Build Protobuf -The codegen plugin is C++ code and requires protobuf 3.17.2 or later. +The codegen plugin is C++ code and requires protobuf 3.19.1 or later. For Linux, Mac and MinGW: ``` -$ PROTOBUF_VERSION=3.17.2 +$ PROTOBUF_VERSION=3.19.1 $ curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz $ tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz $ cd protobuf-$PROTOBUF_VERSION diff --git a/WORKSPACE b/WORKSPACE index dad4842a7a7..b6198573f28 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,17 +4,25 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_jvm_external", - sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", - strip_prefix = "rules_jvm_external-3.0", - url = "https://github.com/bazelbuild/rules_jvm_external/archive/3.0.zip", + sha256 = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca", + strip_prefix = "rules_jvm_external-4.2", + url = "https://github.com/bazelbuild/rules_jvm_external/archive/4.2.zip", ) load("@rules_jvm_external//:defs.bzl", "maven_install") load("//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS") load("//:repositories.bzl", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS") +load("//:repositories.bzl", "grpc_java_repositories") + +grpc_java_repositories() + +load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() maven_install( - artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS, + artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS + PROTOBUF_MAVEN_ARTIFACTS, generate_compat_repositories = True, override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS, repositories = [ @@ -25,11 +33,3 @@ maven_install( load("@maven//:compat.bzl", "compat_repositories") compat_repositories() - -load("//:repositories.bzl", "grpc_java_repositories") - -grpc_java_repositories() - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() diff --git a/build.gradle b/build.gradle index 9aab8312c5c..a852dec9276 100644 --- a/build.gradle +++ b/build.gradle @@ -55,9 +55,9 @@ subprojects { javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix" nettyVersion = '4.1.63.Final' - guavaVersion = '30.1-android' + guavaVersion = '30.1.1-android' googleauthVersion = '0.22.2' - protobufVersion = '3.17.2' + protobufVersion = '3.19.1' protocVersion = protobufVersion opencensusVersion = '0.28.0' autovalueVersion = '1.7.4' diff --git a/buildscripts/make_dependencies.bat b/buildscripts/make_dependencies.bat index 1622daaa16b..b8586e85832 100644 --- a/buildscripts/make_dependencies.bat +++ b/buildscripts/make_dependencies.bat @@ -1,4 +1,4 @@ -set PROTOBUF_VER=3.17.2 +set PROTOBUF_VER=3.19.1 set CMAKE_NAME=cmake-3.3.2-win32-x86 if not exist "protobuf-%PROTOBUF_VER%\cmake\build\Release\" ( diff --git a/buildscripts/make_dependencies.sh b/buildscripts/make_dependencies.sh index 927f1b4be28..7e132a91db0 100755 --- a/buildscripts/make_dependencies.sh +++ b/buildscripts/make_dependencies.sh @@ -3,7 +3,7 @@ # Build protoc set -evux -o pipefail -PROTOBUF_VERSION=3.17.2 +PROTOBUF_VERSION=3.19.1 # ARCH is x86_64 bit unless otherwise specified. ARCH="${ARCH:-x86_64}" diff --git a/examples/WORKSPACE b/examples/WORKSPACE index 36a002b4ee0..bd139ddd406 100644 --- a/examples/WORKSPACE +++ b/examples/WORKSPACE @@ -1,7 +1,9 @@ workspace(name = "examples") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + # For released versions, use release tag: -# http_repository( +# http_archive( # name = "io_grpc_grpc_java", # sha256 = "", # strip_prefix = "grpc-java-", @@ -12,24 +14,30 @@ local_repository( path = "..", ) -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - http_archive( name = "rules_jvm_external", - sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", - strip_prefix = "rules_jvm_external-3.0", - url = "https://github.com/bazelbuild/rules_jvm_external/archive/3.0.zip", + sha256 = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca", + strip_prefix = "rules_jvm_external-4.2", + url = "https://github.com/bazelbuild/rules_jvm_external/archive/4.2.zip", ) load("@rules_jvm_external//:defs.bzl", "maven_install") load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS") load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS") +load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories") + +grpc_java_repositories() + +load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() maven_install( artifacts = [ "com.google.api.grpc:grpc-google-cloud-pubsub-v1:0.1.24", "com.google.api.grpc:proto-google-cloud-pubsub-v1:0.1.24", - ] + IO_GRPC_GRPC_JAVA_ARTIFACTS, + ] + IO_GRPC_GRPC_JAVA_ARTIFACTS + PROTOBUF_MAVEN_ARTIFACTS, generate_compat_repositories = True, override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS, repositories = [ @@ -40,11 +48,3 @@ maven_install( load("@maven//:compat.bzl", "compat_repositories") compat_repositories() - -load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories") - -grpc_java_repositories() - -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() diff --git a/examples/android/clientcache/app/build.gradle b/examples/android/clientcache/app/build.gradle index 075f4fab117..260255a1773 100644 --- a/examples/android/clientcache/app/build.gradle +++ b/examples/android/clientcache/app/build.gradle @@ -32,7 +32,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/helloworld/app/build.gradle b/examples/android/helloworld/app/build.gradle index e8655c09dd9..458a33584ea 100644 --- a/examples/android/helloworld/app/build.gradle +++ b/examples/android/helloworld/app/build.gradle @@ -30,7 +30,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/routeguide/app/build.gradle b/examples/android/routeguide/app/build.gradle index 13df17021c8..fb3fe7e8f95 100644 --- a/examples/android/routeguide/app/build.gradle +++ b/examples/android/routeguide/app/build.gradle @@ -30,7 +30,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/strictmode/app/build.gradle b/examples/android/strictmode/app/build.gradle index b0bbc7a7268..9472151bceb 100644 --- a/examples/android/strictmode/app/build.gradle +++ b/examples/android/strictmode/app/build.gradle @@ -31,7 +31,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/build.gradle b/examples/build.gradle index 03b43512a5c..3fe5c439e6d 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.17.2' +def protobufVersion = '3.19.1' def protocVersion = protobufVersion dependencies { diff --git a/examples/example-alts/build.gradle b/examples/example-alts/build.gradle index 6bb43394579..7db8e672704 100644 --- a/examples/example-alts/build.gradle +++ b/examples/example-alts/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protocVersion = '3.17.2' +def protocVersion = '3.19.1' dependencies { // grpc-alts transitively depends on grpc-netty-shaded, grpc-protobuf, and grpc-stub diff --git a/examples/example-gauth/build.gradle b/examples/example-gauth/build.gradle index fcfbab9d026..2a581f2822f 100644 --- a/examples/example-gauth/build.gradle +++ b/examples/example-gauth/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.17.2' +def protobufVersion = '3.19.1' def protocVersion = protobufVersion diff --git a/examples/example-gauth/pom.xml b/examples/example-gauth/pom.xml index 7445b7b7ce7..765960c3bd3 100644 --- a/examples/example-gauth/pom.xml +++ b/examples/example-gauth/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.17.2 + 3.19.1 1.7 1.7 diff --git a/examples/example-hostname/build.gradle b/examples/example-hostname/build.gradle index e6bb1d73846..f18060097ea 100644 --- a/examples/example-hostname/build.gradle +++ b/examples/example-hostname/build.gradle @@ -22,7 +22,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.17.2' +def protobufVersion = '3.19.1' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/example-hostname/pom.xml b/examples/example-hostname/pom.xml index 71b2903e816..1ce2438e8de 100644 --- a/examples/example-hostname/pom.xml +++ b/examples/example-hostname/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.17.2 + 3.19.1 1.7 1.7 diff --git a/examples/example-jwt-auth/build.gradle b/examples/example-jwt-auth/build.gradle index 881cc553645..18f08658b69 100644 --- a/examples/example-jwt-auth/build.gradle +++ b/examples/example-jwt-auth/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.17.2' +def protobufVersion = '3.19.1' def protocVersion = protobufVersion dependencies { diff --git a/examples/example-jwt-auth/pom.xml b/examples/example-jwt-auth/pom.xml index 12724e4fbd1..9fc68fb40c1 100644 --- a/examples/example-jwt-auth/pom.xml +++ b/examples/example-jwt-auth/pom.xml @@ -14,8 +14,8 @@ UTF-8 1.44.0-SNAPSHOT - 3.17.2 - 3.17.2 + 3.19.1 + 3.19.1 1.7 1.7 diff --git a/examples/example-tls/build.gradle b/examples/example-tls/build.gradle index 213034e10c2..98b73eec9c7 100644 --- a/examples/example-tls/build.gradle +++ b/examples/example-tls/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protocVersion = '3.17.2' +def protocVersion = '3.19.1' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/example-tls/pom.xml b/examples/example-tls/pom.xml index 0eb097ee525..bcb6ecd47c0 100644 --- a/examples/example-tls/pom.xml +++ b/examples/example-tls/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.17.2 + 3.19.1 2.0.34.Final 1.7 diff --git a/examples/example-xds/build.gradle b/examples/example-xds/build.gradle index 123adbcef8f..f593a48050a 100644 --- a/examples/example-xds/build.gradle +++ b/examples/example-xds/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def nettyTcNativeVersion = '2.0.31.Final' -def protocVersion = '3.17.2' +def protocVersion = '3.19.1' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/pom.xml b/examples/pom.xml index 7546b58d763..ac45d452c68 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -13,8 +13,8 @@ UTF-8 1.44.0-SNAPSHOT - 3.17.2 - 3.17.2 + 3.19.1 + 3.19.1 1.7 1.7 diff --git a/repositories.bzl b/repositories.bzl index 3222e15ff65..712e34fded0 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -20,7 +20,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [ "com.google.auto.value:auto-value-annotations:1.7.4", "com.google.errorprone:error_prone_annotations:2.9.0", "com.google.guava:failureaccess:1.0.1", - "com.google.guava:guava:30.1-android", + "com.google.guava:guava:30.1.1-android", "com.google.j2objc:j2objc-annotations:1.3", "com.google.truth:truth:1.0.1", "com.squareup.okhttp:okhttp:2.7.4", @@ -92,37 +92,24 @@ def grpc_java_repositories(): if not native.existing_rule("io_grpc_grpc_proto"): io_grpc_grpc_proto() - native.bind( - name = "guava", - actual = "@com_google_guava_guava//jar", - ) - native.bind( - name = "gson", - actual = "@com_google_code_gson_gson//jar", - ) - native.bind( - name = "error_prone_annotations", - actual = "@com_google_errorprone_error_prone_annotations//jar", - ) - def com_google_protobuf(): # proto_library rules implicitly depend on @com_google_protobuf//:protoc, # which is the proto-compiler. # This statement defines the @com_google_protobuf repo. http_archive( name = "com_google_protobuf", - sha256 = "f6042eef01551cee4c663a11c3f429c06360a1f51daa9f4772bf3f13d24cde1f", - strip_prefix = "protobuf-3.17.2", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.2.zip"], + sha256 = "25f1292d4ea6666f460a2a30038eef121e6c3937ae0f61d610611dfb14b0bd32", + strip_prefix = "protobuf-3.19.1", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.zip"], ) def com_google_protobuf_javalite(): # java_lite_proto_library rules implicitly depend on @com_google_protobuf_javalite http_archive( name = "com_google_protobuf_javalite", - sha256 = "f6042eef01551cee4c663a11c3f429c06360a1f51daa9f4772bf3f13d24cde1f", - strip_prefix = "protobuf-3.17.2", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.2.zip"], + sha256 = "25f1292d4ea6666f460a2a30038eef121e6c3937ae0f61d610611dfb14b0bd32", + strip_prefix = "protobuf-3.19.1", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.zip"], ) def io_grpc_grpc_proto(): From 531db504ca9f84bdf6bcec6e06d202888abccd31 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 14 Dec 2021 17:55:48 -0800 Subject: [PATCH 0011/1995] core: fix race condition in idleTimer & ManagedChannel#enterIdle PR for Spikhalskiy/grpc-java@6d260b8 Hot fix of #8714 --- core/src/main/java/io/grpc/internal/ManagedChannelImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java index 2e079078fc7..601c7740ca4 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java @@ -349,6 +349,9 @@ private class IdleModeTimer implements Runnable { @Override public void run() { + if (lbHelper == null) { + return; + } enterIdleMode(); } } From 282a62e418e1e895e2f14c16f60c63d6294a9899 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Wed, 15 Dec 2021 10:27:01 -0800 Subject: [PATCH 0012/1995] Update README etc to reference 1.43.0 (#8760) --- README.md | 36 ++++++++++++------------ cronet/README.md | 2 +- documentation/android-channel-builder.md | 4 +-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d11c2850805..853b37e8c6a 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ For a guided tour, take a look at the [quick start guide](https://grpc.io/docs/languages/java/quickstart) or the more explanatory [gRPC basics](https://grpc.io/docs/languages/java/basics). -The [examples](https://github.com/grpc/grpc-java/tree/v1.42.1/examples) and the -[Android example](https://github.com/grpc/grpc-java/tree/v1.42.1/examples/android) +The [examples](https://github.com/grpc/grpc-java/tree/v1.43.0/examples) and the +[Android example](https://github.com/grpc/grpc-java/tree/v1.43.0/examples/android) are standalone projects that showcase the usage of gRPC. Download @@ -43,17 +43,17 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: io.grpc grpc-netty-shaded - 1.42.1 + 1.43.0 io.grpc grpc-protobuf - 1.42.1 + 1.43.0 io.grpc grpc-stub - 1.42.1 + 1.43.0 org.apache.tomcat @@ -65,23 +65,23 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: Or for Gradle with non-Android, add to your dependencies: ```gradle -implementation 'io.grpc:grpc-netty-shaded:1.42.1' -implementation 'io.grpc:grpc-protobuf:1.42.1' -implementation 'io.grpc:grpc-stub:1.42.1' +implementation 'io.grpc:grpc-netty-shaded:1.43.0' +implementation 'io.grpc:grpc-protobuf:1.43.0' +implementation 'io.grpc:grpc-stub:1.43.0' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+ ``` For Android client, use `grpc-okhttp` instead of `grpc-netty-shaded` and `grpc-protobuf-lite` instead of `grpc-protobuf`: ```gradle -implementation 'io.grpc:grpc-okhttp:1.42.1' -implementation 'io.grpc:grpc-protobuf-lite:1.42.1' -implementation 'io.grpc:grpc-stub:1.42.1' +implementation 'io.grpc:grpc-okhttp:1.43.0' +implementation 'io.grpc:grpc-protobuf-lite:1.43.0' +implementation 'io.grpc:grpc-stub:1.43.0' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+ ``` [the JARs]: -https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.42.1 +https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.43.0 Development snapshots are available in [Sonatypes's snapshot repository](https://oss.sonatype.org/content/repositories/snapshots/). @@ -111,9 +111,9 @@ For protobuf-based codegen integrated with the Maven build system, you can use protobuf-maven-plugin 0.6.1 - com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier} + com.google.protobuf:protoc:3.19.1:exe:${os.detected.classifier} grpc-java - io.grpc:protoc-gen-grpc-java:1.42.1:exe:${os.detected.classifier} + io.grpc:protoc-gen-grpc-java:1.43.0:exe:${os.detected.classifier} @@ -139,11 +139,11 @@ plugins { protobuf { protoc { - artifact = "com.google.protobuf:protoc:3.17.2" + artifact = "com.google.protobuf:protoc:3.19.1" } plugins { grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.42.1' + artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0' } } generateProtoTasks { @@ -172,11 +172,11 @@ plugins { protobuf { protoc { - artifact = "com.google.protobuf:protoc:3.17.2" + artifact = "com.google.protobuf:protoc:3.19.1" } plugins { grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.42.1' + artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0' } } generateProtoTasks { diff --git a/cronet/README.md b/cronet/README.md index a682c5bcee8..e7705acc3de 100644 --- a/cronet/README.md +++ b/cronet/README.md @@ -26,7 +26,7 @@ In your app module's `build.gradle` file, include a dependency on both `grpc-cro Google Play Services Client Library for Cronet ``` -implementation 'io.grpc:grpc-cronet:1.42.1' +implementation 'io.grpc:grpc-cronet:1.43.0' implementation 'com.google.android.gms:play-services-cronet:16.0.0' ``` diff --git a/documentation/android-channel-builder.md b/documentation/android-channel-builder.md index d9541c56623..3ebbf9522a4 100644 --- a/documentation/android-channel-builder.md +++ b/documentation/android-channel-builder.md @@ -36,8 +36,8 @@ In your `build.gradle` file, include a dependency on both `grpc-android` and `grpc-okhttp`: ``` -implementation 'io.grpc:grpc-android:1.42.1' -implementation 'io.grpc:grpc-okhttp:1.42.1' +implementation 'io.grpc:grpc-android:1.43.0' +implementation 'io.grpc:grpc-okhttp:1.43.0' ``` You also need permission to access the device's network state in your From d9eb30cd92faca201b5a1bff886102a10373722b Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 15 Dec 2021 14:03:36 -0800 Subject: [PATCH 0013/1995] Bump GSON to 2.8.9 --- build.gradle | 2 +- examples/pom.xml | 5 +++++ repositories.bzl | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index a852dec9276..e3dcad2a0de 100644 --- a/build.gradle +++ b/build.gradle @@ -148,7 +148,7 @@ subprojects { errorprone: "com.google.errorprone:error_prone_annotations:2.9.0", cronet_api: 'org.chromium.net:cronet-api:92.4515.131', cronet_embedded: 'org.chromium.net:cronet-embedded:92.4515.131', - gson: "com.google.code.gson:gson:2.8.6", + gson: "com.google.code.gson:gson:2.8.9", guava: "com.google.guava:guava:${guavaVersion}", javax_annotation: 'org.apache.tomcat:annotations-api:6.0.53', jsr305: 'com.google.code.findbugs:jsr305:3.0.2', diff --git a/examples/pom.xml b/examples/pom.xml index ac45d452c68..4a23872d05c 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -51,6 +51,11 @@ protobuf-java-util ${protobuf.version} + + com.google.code.gson + gson + 2.8.9 + org.apache.tomcat annotations-api diff --git a/repositories.bzl b/repositories.bzl index 712e34fded0..6e9caf9409d 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -15,7 +15,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [ "com.google.auth:google-auth-library-credentials:0.22.0", "com.google.auth:google-auth-library-oauth2-http:0.22.0", "com.google.code.findbugs:jsr305:3.0.2", - "com.google.code.gson:gson:jar:2.8.6", + "com.google.code.gson:gson:jar:2.8.9", "com.google.auto.value:auto-value:1.7.4", "com.google.auto.value:auto-value-annotations:1.7.4", "com.google.errorprone:error_prone_annotations:2.9.0", From 63756ec9514dbfd9d2ff496342b93f794b83ecc6 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Fri, 17 Dec 2021 07:36:00 -0800 Subject: [PATCH 0014/1995] core: remove unused method in AutoConfiguredLoadBalancer (#8769) The method added in #5821 seems not used now. --- .../io/grpc/internal/AutoConfiguredLoadBalancerFactory.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java b/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java index 037d49cb72f..01c48b9efcf 100644 --- a/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java +++ b/core/src/main/java/io/grpc/internal/AutoConfiguredLoadBalancerFactory.java @@ -96,10 +96,6 @@ public final class AutoConfiguredLoadBalancer { delegate = delegateProvider.newLoadBalancer(helper); } - public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) { - tryHandleResolvedAddresses(resolvedAddresses); - } - /** * Returns non-OK status if resolvedAddresses is empty and delegate lb requires address ({@link * LoadBalancer#canHandleEmptyAddressListFromNameResolution()} returns {@code false}). {@code From 042f9879d4c36aa4a4b04937c8f2e5775b851342 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Mon, 20 Dec 2021 09:46:25 -0800 Subject: [PATCH 0015/1995] all: remove deprecated StreamInfo.transportAttrs (#8768) APIs such as `StreamInfo.getTransportAttrs()` were [deprecated](https://github.com/grpc/grpc-java/commit/860e97d12ab46e184ac4448eeca8a45671de6462#diff-aa4049f54d6d5d462700e9221344184a37d2068b3ba7d715abd417b1df5bf883R114) since 1.41.0. Removing now. --- .../main/java/io/grpc/ClientStreamTracer.java | 39 +------------- .../test/java/io/grpc/CallOptionsTest.java | 2 +- .../io/grpc/census/CensusStatsModule.java | 2 +- .../io/grpc/census/CensusTracingModule.java | 2 +- .../main/java/io/grpc/internal/GrpcUtil.java | 53 +------------------ .../io/grpc/internal/RetriableStream.java | 2 +- .../java/io/grpc/ClientStreamTracerTest.java | 22 ++------ .../java/io/grpc/internal/GrpcUtilTest.java | 38 ------------- .../grpc/internal/ManagedChannelImplTest.java | 8 +-- .../grpc/grpclb/GrpclbClientLoadRecorder.java | 2 +- .../grpclb/TokenAttachingTracerFactory.java | 2 +- .../TokenAttachingTracerFactoryTest.java | 2 +- .../integration/AbstractInteropTest.java | 2 +- .../grpc/testing/integration/RetryTest.java | 4 +- .../io/grpc/xds/ClusterImplLoadBalancer.java | 2 +- .../java/io/grpc/xds/OrcaPerRequestUtil.java | 4 +- 16 files changed, 25 insertions(+), 161 deletions(-) diff --git a/api/src/main/java/io/grpc/ClientStreamTracer.java b/api/src/main/java/io/grpc/ClientStreamTracer.java index bb836ac82e1..53909f23740 100644 --- a/api/src/main/java/io/grpc/ClientStreamTracer.java +++ b/api/src/main/java/io/grpc/ClientStreamTracer.java @@ -81,10 +81,6 @@ public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata header } } - /** An abstract class for internal use only. */ - @Internal - public abstract static class InternalLimitedInfoFactory extends Factory {} - /** * Information about a stream. * @@ -95,32 +91,17 @@ public abstract static class InternalLimitedInfoFactory extends Factory {} */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2861") public static final class StreamInfo { - private final Attributes transportAttrs; private final CallOptions callOptions; private final int previousAttempts; private final boolean isTransparentRetry; StreamInfo( - Attributes transportAttrs, CallOptions callOptions, int previousAttempts, - boolean isTransparentRetry) { - this.transportAttrs = checkNotNull(transportAttrs, "transportAttrs"); + CallOptions callOptions, int previousAttempts, boolean isTransparentRetry) { this.callOptions = checkNotNull(callOptions, "callOptions"); this.previousAttempts = previousAttempts; this.isTransparentRetry = isTransparentRetry; } - /** - * Returns the attributes of the transport that this stream was created on. - * - * @deprecated Use {@link ClientStreamTracer#streamCreated(Attributes, Metadata)} to handle - * the transport Attributes instead. - */ - @Deprecated - @Grpc.TransportAttr - public Attributes getTransportAttrs() { - return transportAttrs; - } - /** * Returns the effective CallOptions of the call. */ @@ -154,7 +135,6 @@ public boolean isTransparentRetry() { public Builder toBuilder() { return new Builder() .setCallOptions(callOptions) - .setTransportAttrs(transportAttrs) .setPreviousAttempts(previousAttempts) .setIsTransparentRetry(isTransparentRetry); } @@ -171,7 +151,6 @@ public static Builder newBuilder() { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("transportAttrs", transportAttrs) .add("callOptions", callOptions) .add("previousAttempts", previousAttempts) .add("isTransparentRetry", isTransparentRetry) @@ -184,7 +163,6 @@ public String toString() { * @since 1.21.0 */ public static final class Builder { - private Attributes transportAttrs = Attributes.EMPTY; private CallOptions callOptions = CallOptions.DEFAULT; private int previousAttempts; private boolean isTransparentRetry; @@ -192,19 +170,6 @@ public static final class Builder { Builder() { } - /** - * Sets the attributes of the transport that this stream was created on. This field is - * optional. - * - * @deprecated Use {@link ClientStreamTracer#streamCreated(Attributes, Metadata)} to handle - * the transport Attributes instead. - */ - @Deprecated - public Builder setTransportAttrs(@Grpc.TransportAttr Attributes transportAttrs) { - this.transportAttrs = checkNotNull(transportAttrs, "transportAttrs cannot be null"); - return this; - } - /** * Sets the effective CallOptions of the call. This field is optional. */ @@ -237,7 +202,7 @@ public Builder setIsTransparentRetry(boolean isTransparentRetry) { * Builds a new StreamInfo. */ public StreamInfo build() { - return new StreamInfo(transportAttrs, callOptions, previousAttempts, isTransparentRetry); + return new StreamInfo(callOptions, previousAttempts, isTransparentRetry); } } } diff --git a/api/src/test/java/io/grpc/CallOptionsTest.java b/api/src/test/java/io/grpc/CallOptionsTest.java index 0bc0d357358..15e5163e860 100644 --- a/api/src/test/java/io/grpc/CallOptionsTest.java +++ b/api/src/test/java/io/grpc/CallOptionsTest.java @@ -272,7 +272,7 @@ public void increment(long period, TimeUnit unit) { } } - private static class FakeTracerFactory extends ClientStreamTracer.InternalLimitedInfoFactory { + private static class FakeTracerFactory extends ClientStreamTracer.Factory { final String name; FakeTracerFactory(String name) { diff --git a/census/src/main/java/io/grpc/census/CensusStatsModule.java b/census/src/main/java/io/grpc/census/CensusStatsModule.java index 487e49e5005..366be55de68 100644 --- a/census/src/main/java/io/grpc/census/CensusStatsModule.java +++ b/census/src/main/java/io/grpc/census/CensusStatsModule.java @@ -397,7 +397,7 @@ void recordFinishedAttempt() { @VisibleForTesting static final class CallAttemptsTracerFactory extends - ClientStreamTracer.InternalLimitedInfoFactory { + ClientStreamTracer.Factory { static final MeasureLong RETRIES_PER_CALL = Measure.MeasureLong.create( "grpc.io/client/retries_per_call", "Number of retries per call", "1"); diff --git a/census/src/main/java/io/grpc/census/CensusTracingModule.java b/census/src/main/java/io/grpc/census/CensusTracingModule.java index 08d5fe3ca97..5c635613f33 100644 --- a/census/src/main/java/io/grpc/census/CensusTracingModule.java +++ b/census/src/main/java/io/grpc/census/CensusTracingModule.java @@ -226,7 +226,7 @@ private static void recordMessageEvent( } @VisibleForTesting - final class CallAttemptsTracerFactory extends ClientStreamTracer.InternalLimitedInfoFactory { + final class CallAttemptsTracerFactory extends ClientStreamTracer.Factory { volatile int callEnded; private final boolean isSampledToLocalTracing; diff --git a/core/src/main/java/io/grpc/internal/GrpcUtil.java b/core/src/main/java/io/grpc/internal/GrpcUtil.java index 635fab11c8f..c997414eabe 100644 --- a/core/src/main/java/io/grpc/internal/GrpcUtil.java +++ b/core/src/main/java/io/grpc/internal/GrpcUtil.java @@ -27,10 +27,8 @@ import com.google.common.base.Supplier; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import io.grpc.Attributes; import io.grpc.CallOptions; import io.grpc.ClientStreamTracer; -import io.grpc.ClientStreamTracer.InternalLimitedInfoFactory; import io.grpc.ClientStreamTracer.StreamInfo; import io.grpc.InternalChannelz.SocketStats; import io.grpc.InternalLogId; @@ -725,7 +723,7 @@ public ClientStream newStream( ClientStreamTracer[] tracers) { StreamInfo info = StreamInfo.newBuilder().setCallOptions(callOptions).build(); ClientStreamTracer streamTracer = - newClientStreamTracer(streamTracerFactory, info, headers); + streamTracerFactory.newClientStreamTracer(info, headers); checkState(tracers[tracers.length - 1] == NOOP_TRACER, "lb tracer already assigned"); tracers[tracers.length - 1] = streamTracer; return transport.newStream(method, headers, callOptions, tracers); @@ -769,7 +767,7 @@ public static ClientStreamTracer[] getClientStreamTracers( .setIsTransparentRetry(isTransparentRetry) .build(); for (int i = 0; i < factories.size(); i++) { - tracers[i] = newClientStreamTracer(factories.get(i), streamInfo, headers); + tracers[i] = factories.get(i).newClientStreamTracer(streamInfo, headers); } // Reserved to be set later by the lb as per the API contract of ClientTransport.newStream(). // See also GrpcUtil.getTransportFromPickResult() @@ -777,53 +775,6 @@ public static ClientStreamTracer[] getClientStreamTracers( return tracers; } - // A util function for backward compatibility to support deprecated StreamInfo.getAttributes(). - @VisibleForTesting - static ClientStreamTracer newClientStreamTracer( - final ClientStreamTracer.Factory streamTracerFactory, final StreamInfo info, - final Metadata headers) { - ClientStreamTracer streamTracer; - if (streamTracerFactory instanceof InternalLimitedInfoFactory) { - streamTracer = streamTracerFactory.newClientStreamTracer(info, headers); - } else { - streamTracer = new ForwardingClientStreamTracer() { - final ClientStreamTracer noop = new ClientStreamTracer() {}; - volatile ClientStreamTracer delegate = noop; - - void maybeInit(StreamInfo info, Metadata headers) { - if (delegate != noop) { - return; - } - synchronized (this) { - if (delegate == noop) { - delegate = streamTracerFactory.newClientStreamTracer(info, headers); - } - } - } - - @Override - protected ClientStreamTracer delegate() { - return delegate; - } - - @SuppressWarnings("deprecation") - @Override - public void streamCreated(Attributes transportAttrs, Metadata headers) { - StreamInfo streamInfo = info.toBuilder().setTransportAttrs(transportAttrs).build(); - maybeInit(streamInfo, headers); - delegate().streamCreated(transportAttrs, headers); - } - - @Override - public void streamClosed(Status status) { - maybeInit(info, headers); - delegate().streamClosed(status); - } - }; - } - return streamTracer; - } - /** Quietly closes all messages in MessageProducer. */ static void closeQuietly(MessageProducer producer) { InputStream message; diff --git a/core/src/main/java/io/grpc/internal/RetriableStream.java b/core/src/main/java/io/grpc/internal/RetriableStream.java index 1fb8d3c43bd..4afdb3f750e 100644 --- a/core/src/main/java/io/grpc/internal/RetriableStream.java +++ b/core/src/main/java/io/grpc/internal/RetriableStream.java @@ -221,7 +221,7 @@ private Substream createSubstream(int previousAttemptCount, boolean isTransparen Substream sub = new Substream(previousAttemptCount); // one tracer per substream final ClientStreamTracer bufferSizeTracer = new BufferSizeTracer(sub); - ClientStreamTracer.Factory tracerFactory = new ClientStreamTracer.InternalLimitedInfoFactory() { + ClientStreamTracer.Factory tracerFactory = new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer( ClientStreamTracer.StreamInfo info, Metadata headers) { diff --git a/core/src/test/java/io/grpc/ClientStreamTracerTest.java b/core/src/test/java/io/grpc/ClientStreamTracerTest.java index df450adc630..5ddee77f5c0 100644 --- a/core/src/test/java/io/grpc/ClientStreamTracerTest.java +++ b/core/src/test/java/io/grpc/ClientStreamTracerTest.java @@ -27,48 +27,34 @@ /** Unit tests for the embedded classes in {@link ClientStreamTracer}. */ @RunWith(JUnit4.class) public class ClientStreamTracerTest { - private static final Attributes.Key TRANSPORT_ATTR_KEY = - Attributes.Key.create("transport-attr-key"); private final CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(1, MINUTES); - private final Attributes transportAttrs = - Attributes.newBuilder().set(TRANSPORT_ATTR_KEY, "value").build(); @Test - @SuppressWarnings("deprecation") // info.getTransportAttrs() public void streamInfo_empty() { StreamInfo info = StreamInfo.newBuilder().build(); assertThat(info.getCallOptions()).isSameInstanceAs(CallOptions.DEFAULT); - assertThat(info.getTransportAttrs()).isSameInstanceAs(Attributes.EMPTY); } @Test - @SuppressWarnings("deprecation") // info.getTransportAttrs() public void streamInfo_withInfo() { - StreamInfo info = StreamInfo.newBuilder() - .setCallOptions(callOptions).setTransportAttrs(transportAttrs).build(); + StreamInfo info = StreamInfo.newBuilder().setCallOptions(callOptions).build(); assertThat(info.getCallOptions()).isSameInstanceAs(callOptions); - assertThat(info.getTransportAttrs()).isSameInstanceAs(transportAttrs); } @Test - @SuppressWarnings("deprecation") // info.setTransportAttrs() public void streamInfo_noEquality() { - StreamInfo info1 = StreamInfo.newBuilder() - .setCallOptions(callOptions).setTransportAttrs(transportAttrs).build(); - StreamInfo info2 = StreamInfo.newBuilder() - .setCallOptions(callOptions).setTransportAttrs(transportAttrs).build(); + StreamInfo info1 = StreamInfo.newBuilder().setCallOptions(callOptions).build(); + StreamInfo info2 = StreamInfo.newBuilder().setCallOptions(callOptions).build(); assertThat(info1).isNotSameInstanceAs(info2); assertThat(info1).isNotEqualTo(info2); } @Test - @SuppressWarnings("deprecation") // info.getTransportAttrs() public void streamInfo_toBuilder() { StreamInfo info1 = StreamInfo.newBuilder() - .setCallOptions(callOptions).setTransportAttrs(transportAttrs).build(); + .setCallOptions(callOptions).build(); StreamInfo info2 = info1.toBuilder().build(); assertThat(info2.getCallOptions()).isSameInstanceAs(callOptions); - assertThat(info2.getTransportAttrs()).isSameInstanceAs(transportAttrs); } } diff --git a/core/src/test/java/io/grpc/internal/GrpcUtilTest.java b/core/src/test/java/io/grpc/internal/GrpcUtilTest.java index 6d2c21ddab8..7e3f6e7db4e 100644 --- a/core/src/test/java/io/grpc/internal/GrpcUtilTest.java +++ b/core/src/test/java/io/grpc/internal/GrpcUtilTest.java @@ -16,7 +16,6 @@ package io.grpc.internal; -import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -28,18 +27,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import io.grpc.Attributes; import io.grpc.CallOptions; import io.grpc.ClientStreamTracer; -import io.grpc.ClientStreamTracer.StreamInfo; import io.grpc.LoadBalancer.PickResult; import io.grpc.Metadata; import io.grpc.Status; import io.grpc.internal.ClientStreamListener.RpcProgress; import io.grpc.internal.GrpcUtil.Http2Error; import io.grpc.testing.TestMethodDescriptors; -import java.util.ArrayDeque; -import java.util.concurrent.atomic.AtomicReference; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -296,37 +291,4 @@ public void getTransportFromPickResult_dropPickResult_failFast() { verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class)); } - - @Test - public void clientStreamTracerFactoryBackwardCompatibility() { - final AtomicReference transportAttrsRef = new AtomicReference<>(); - final ClientStreamTracer mockTracer = mock(ClientStreamTracer.class); - final Metadata.Key key = Metadata.Key.of("fake-key", Metadata.ASCII_STRING_MARSHALLER); - final ArrayDeque tracers = new ArrayDeque<>(); - ClientStreamTracer.Factory oldFactoryImpl = new ClientStreamTracer.Factory() { - @SuppressWarnings("deprecation") - @Override - public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { - transportAttrsRef.set(info.getTransportAttrs()); - headers.put(key, "fake-value"); - tracers.offer(mockTracer); - return mockTracer; - } - }; - - StreamInfo info = - StreamInfo.newBuilder().setCallOptions(CallOptions.DEFAULT.withWaitForReady()).build(); - Metadata metadata = new Metadata(); - Attributes transAttrs = - Attributes.newBuilder().set(Attributes.Key.create("foo"), "bar").build(); - ClientStreamTracer tracer = GrpcUtil.newClientStreamTracer(oldFactoryImpl, info, metadata); - tracer.streamCreated(transAttrs, metadata); - assertThat(tracers.poll()).isSameInstanceAs(mockTracer); - assertThat(transportAttrsRef.get()).isEqualTo(transAttrs); - assertThat(metadata.get(key)).isEqualTo("fake-value"); - - tracer.streamClosed(Status.UNAVAILABLE); - // verify that newClientStreamTracer() is called no more than once - assertThat(tracers).isEmpty(); - } } diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java index 668411d7ecc..f47954e2215 100644 --- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java +++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java @@ -2447,13 +2447,13 @@ public void pickerReturnsStreamTracer_noDelay() { ClientStream mockStream = mock(ClientStream.class); final ClientStreamTracer tracer1 = new ClientStreamTracer() {}; final ClientStreamTracer tracer2 = new ClientStreamTracer() {}; - ClientStreamTracer.Factory factory1 = new ClientStreamTracer.InternalLimitedInfoFactory() { + ClientStreamTracer.Factory factory1 = new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return tracer1; } }; - ClientStreamTracer.Factory factory2 = new ClientStreamTracer.InternalLimitedInfoFactory() { + ClientStreamTracer.Factory factory2 = new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return tracer2; @@ -2491,13 +2491,13 @@ public void pickerReturnsStreamTracer_delayed() { ClientStream mockStream = mock(ClientStream.class); final ClientStreamTracer tracer1 = new ClientStreamTracer() {}; final ClientStreamTracer tracer2 = new ClientStreamTracer() {}; - ClientStreamTracer.Factory factory1 = new ClientStreamTracer.InternalLimitedInfoFactory() { + ClientStreamTracer.Factory factory1 = new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return tracer1; } }; - ClientStreamTracer.Factory factory2 = new ClientStreamTracer.InternalLimitedInfoFactory() { + ClientStreamTracer.Factory factory2 = new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return tracer2; diff --git a/grpclb/src/main/java/io/grpc/grpclb/GrpclbClientLoadRecorder.java b/grpclb/src/main/java/io/grpc/grpclb/GrpclbClientLoadRecorder.java index 75f2481254d..d27c485dc13 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/GrpclbClientLoadRecorder.java +++ b/grpclb/src/main/java/io/grpc/grpclb/GrpclbClientLoadRecorder.java @@ -37,7 +37,7 @@ * span of an LB stream with the remote load-balancer. */ @ThreadSafe -final class GrpclbClientLoadRecorder extends ClientStreamTracer.InternalLimitedInfoFactory { +final class GrpclbClientLoadRecorder extends ClientStreamTracer.Factory { private static final AtomicLongFieldUpdater callsStartedUpdater = AtomicLongFieldUpdater.newUpdater(GrpclbClientLoadRecorder.class, "callsStarted"); diff --git a/grpclb/src/main/java/io/grpc/grpclb/TokenAttachingTracerFactory.java b/grpclb/src/main/java/io/grpc/grpclb/TokenAttachingTracerFactory.java index 03e1447bb2c..c00d988aa5d 100644 --- a/grpclb/src/main/java/io/grpc/grpclb/TokenAttachingTracerFactory.java +++ b/grpclb/src/main/java/io/grpc/grpclb/TokenAttachingTracerFactory.java @@ -30,7 +30,7 @@ * Wraps a {@link ClientStreamTracer.Factory}, retrieves tokens from transport attributes and * attaches them to headers. This is only used in the PICK_FIRST mode. */ -final class TokenAttachingTracerFactory extends ClientStreamTracer.InternalLimitedInfoFactory { +final class TokenAttachingTracerFactory extends ClientStreamTracer.Factory { private static final ClientStreamTracer NOOP_TRACER = new ClientStreamTracer() {}; @Nullable diff --git a/grpclb/src/test/java/io/grpc/grpclb/TokenAttachingTracerFactoryTest.java b/grpclb/src/test/java/io/grpc/grpclb/TokenAttachingTracerFactoryTest.java index 29ded18d913..4787c8697cc 100644 --- a/grpclb/src/test/java/io/grpc/grpclb/TokenAttachingTracerFactoryTest.java +++ b/grpclb/src/test/java/io/grpc/grpclb/TokenAttachingTracerFactoryTest.java @@ -49,7 +49,7 @@ public void streamCreated(Attributes transportAttrs, Metadata headers) { private final ClientStreamTracer.Factory delegate = mock( ClientStreamTracer.Factory.class, delegatesTo( - new ClientStreamTracer.InternalLimitedInfoFactory() { + new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer( ClientStreamTracer.StreamInfo info, Metadata headers) { diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 698aa330ec6..8e107add3e3 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -302,7 +302,7 @@ final SocketAddress getListenAddress() { new LinkedBlockingQueue<>(); private final ClientStreamTracer.Factory clientStreamTracerFactory = - new ClientStreamTracer.InternalLimitedInfoFactory() { + new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer( ClientStreamTracer.StreamInfo info, Metadata headers) { diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/RetryTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/RetryTest.java index 045d54ea44e..80cf83b0939 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/RetryTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/RetryTest.java @@ -432,7 +432,7 @@ public void streamClosed(Status status) { } } - class CloseDelayedTracerFactory extends ClientStreamTracer.InternalLimitedInfoFactory { + class CloseDelayedTracerFactory extends ClientStreamTracer.Factory { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return new CloseDelayedTracer(); @@ -492,7 +492,7 @@ public void streamClosed(Status status) { } } - class TransparentRetryTracerFactory extends ClientStreamTracer.InternalLimitedInfoFactory { + class TransparentRetryTracerFactory extends ClientStreamTracer.Factory { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return new TransparentRetryTriggeringTracer(); diff --git a/xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java b/xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java index b4fc017d2d1..e9796267a85 100644 --- a/xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java +++ b/xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java @@ -336,7 +336,7 @@ public String toString() { } private static final class CountingStreamTracerFactory extends - ClientStreamTracer.InternalLimitedInfoFactory { + ClientStreamTracer.Factory { private ClusterLocalityStats stats; private final AtomicLong inFlights; @Nullable diff --git a/xds/src/main/java/io/grpc/xds/OrcaPerRequestUtil.java b/xds/src/main/java/io/grpc/xds/OrcaPerRequestUtil.java index 4b4cff92064..34589d77d07 100644 --- a/xds/src/main/java/io/grpc/xds/OrcaPerRequestUtil.java +++ b/xds/src/main/java/io/grpc/xds/OrcaPerRequestUtil.java @@ -37,7 +37,7 @@ abstract class OrcaPerRequestUtil { private static final ClientStreamTracer NOOP_CLIENT_STREAM_TRACER = new ClientStreamTracer() {}; private static final ClientStreamTracer.Factory NOOP_CLIENT_STREAM_TRACER_FACTORY = - new ClientStreamTracer.InternalLimitedInfoFactory() { + new ClientStreamTracer.Factory() { @Override public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata headers) { return NOOP_CLIENT_STREAM_TRACER; @@ -190,7 +190,7 @@ public interface OrcaPerRequestReportListener { */ @VisibleForTesting static final class OrcaReportingTracerFactory extends - ClientStreamTracer.InternalLimitedInfoFactory { + ClientStreamTracer.Factory { @VisibleForTesting static final Metadata.Key ORCA_ENDPOINT_LOAD_METRICS_KEY = From b244ba8d4cbbcca0362925b71f611f48d6c9f5f7 Mon Sep 17 00:00:00 2001 From: Mohan Li <67390330+mohanli-ml@users.noreply.github.com> Date: Mon, 20 Dec 2021 13:00:42 -0800 Subject: [PATCH 0016/1995] xds: add skipNetCmd flag to fallback test client (#8765) We are setting up fallback test based on TD. Currently the test client is compiled in google3, so we must run it in a container so that the client can have the GRTE dependency. However, container does not have `ip`, `iptables`, etc network command, so we plan to run the network command outside of the container. To do this, add a new flag `skipNetCmd` to skip network commands inside the test client. --- .../integration/GrpclbFallbackTestClient.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/GrpclbFallbackTestClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/GrpclbFallbackTestClient.java index e98f4c31d2a..52c9e8238b5 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/GrpclbFallbackTestClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/GrpclbFallbackTestClient.java @@ -74,6 +74,7 @@ public void run() { private String serverUri; private String customCredentialsType; private String testCase; + private Boolean skipNetCmd = false; private ManagedChannel channel; private TestServiceGrpc.TestServiceBlockingStub blockingStub; @@ -108,6 +109,8 @@ private void parseArgs(String[] args) { blackholeLbAndBackendAddrsCmd = value; } else if ("custom_credentials_type".equals(key)) { customCredentialsType = value; + } else if ("skip_net_cmd".equals(key)) { + skipNetCmd = Boolean.valueOf(value); } else { System.err.println("Unknown argument: " + key); usage = true; @@ -129,6 +132,10 @@ private void parseArgs(String[] args) { + "\n --blackhole_lb_and_backend_addrs_cmd Shell command used to make " + "LB and backend addresses black holed. Default: " + c.blackholeLbAndBackendAddrsCmd + + "\n --skip_net_cmd Skip unroute and blackhole " + + "shell command to allow setting the net config outside of the test " + + "client. Default: " + + c.skipNetCmd + "\n --test_case=TEST_CASE Test case to run. Valid options are:" + "\n fast_fallback_before_startup : fallback before LB connection" + "\n fast_fallback_after_startup : fallback after startup due to " @@ -172,9 +179,14 @@ private void tearDown() { } } - private static void runShellCmd(String cmd) throws Exception { + private void runShellCmd(String cmd) throws Exception { + if (skipNetCmd) { + logger.info("Skip net cmd because --skip_net_cmd is set to true"); + return; + } logger.info("Run shell command: " + cmd); - ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd); + // Do not use bash -c here as bash may not exist in a container + ProcessBuilder pb = new ProcessBuilder(cmd.split(" ")); pb.redirectErrorStream(true); Process process = pb.start(); logger.info("Shell command merged stdout and stderr: " @@ -211,7 +223,7 @@ private GrpclbRouteType doRpcAndGetPath(Deadline deadline) { private void waitForFallbackAndDoRpcs(Deadline fallbackDeadline) throws Exception { int fallbackRetryCount = 0; - boolean fellBack = false; + boolean fallBack = false; while (!fallbackDeadline.isExpired()) { GrpclbRouteType grpclbRouteType = doRpcAndGetPath( Deadline.after(1, TimeUnit.SECONDS)); @@ -222,14 +234,14 @@ private void waitForFallbackAndDoRpcs(Deadline fallbackDeadline) throws Exceptio if (grpclbRouteType == GrpclbRouteType.GRPCLB_ROUTE_TYPE_FALLBACK) { logger.info("Made one successful RPC to a fallback. Now expect the " + "same for the rest."); - fellBack = true; + fallBack = true; break; } else { logger.info("Retryable RPC failure on iteration: " + fallbackRetryCount); } fallbackRetryCount++; } - if (!fellBack) { + if (!fallBack) { throw new AssertionError("Didn't fall back within deadline"); } for (int i = 0; i < 30; i++) { From 86ca55483bbe2b2238aaa333fa1025dcd6292209 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 21 Dec 2021 15:18:52 -0800 Subject: [PATCH 0017/1995] Update README etc to reference 1.43.1 (#8775) --- README.md | 30 ++++++++++++------------ cronet/README.md | 2 +- documentation/android-channel-builder.md | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 853b37e8c6a..0e25ca28534 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ For a guided tour, take a look at the [quick start guide](https://grpc.io/docs/languages/java/quickstart) or the more explanatory [gRPC basics](https://grpc.io/docs/languages/java/basics). -The [examples](https://github.com/grpc/grpc-java/tree/v1.43.0/examples) and the -[Android example](https://github.com/grpc/grpc-java/tree/v1.43.0/examples/android) +The [examples](https://github.com/grpc/grpc-java/tree/v1.43.1/examples) and the +[Android example](https://github.com/grpc/grpc-java/tree/v1.43.1/examples/android) are standalone projects that showcase the usage of gRPC. Download @@ -43,17 +43,17 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: io.grpc grpc-netty-shaded - 1.43.0 + 1.43.1 io.grpc grpc-protobuf - 1.43.0 + 1.43.1 io.grpc grpc-stub - 1.43.0 + 1.43.1 org.apache.tomcat @@ -65,23 +65,23 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: Or for Gradle with non-Android, add to your dependencies: ```gradle -implementation 'io.grpc:grpc-netty-shaded:1.43.0' -implementation 'io.grpc:grpc-protobuf:1.43.0' -implementation 'io.grpc:grpc-stub:1.43.0' +implementation 'io.grpc:grpc-netty-shaded:1.43.1' +implementation 'io.grpc:grpc-protobuf:1.43.1' +implementation 'io.grpc:grpc-stub:1.43.1' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+ ``` For Android client, use `grpc-okhttp` instead of `grpc-netty-shaded` and `grpc-protobuf-lite` instead of `grpc-protobuf`: ```gradle -implementation 'io.grpc:grpc-okhttp:1.43.0' -implementation 'io.grpc:grpc-protobuf-lite:1.43.0' -implementation 'io.grpc:grpc-stub:1.43.0' +implementation 'io.grpc:grpc-okhttp:1.43.1' +implementation 'io.grpc:grpc-protobuf-lite:1.43.1' +implementation 'io.grpc:grpc-stub:1.43.1' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+ ``` [the JARs]: -https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.43.0 +https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.43.1 Development snapshots are available in [Sonatypes's snapshot repository](https://oss.sonatype.org/content/repositories/snapshots/). @@ -113,7 +113,7 @@ For protobuf-based codegen integrated with the Maven build system, you can use com.google.protobuf:protoc:3.19.1:exe:${os.detected.classifier} grpc-java - io.grpc:protoc-gen-grpc-java:1.43.0:exe:${os.detected.classifier} + io.grpc:protoc-gen-grpc-java:1.43.1:exe:${os.detected.classifier} @@ -143,7 +143,7 @@ protobuf { } plugins { grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0' + artifact = 'io.grpc:protoc-gen-grpc-java:1.43.1' } } generateProtoTasks { @@ -176,7 +176,7 @@ protobuf { } plugins { grpc { - artifact = 'io.grpc:protoc-gen-grpc-java:1.43.0' + artifact = 'io.grpc:protoc-gen-grpc-java:1.43.1' } } generateProtoTasks { diff --git a/cronet/README.md b/cronet/README.md index e7705acc3de..d53da56a8d7 100644 --- a/cronet/README.md +++ b/cronet/README.md @@ -26,7 +26,7 @@ In your app module's `build.gradle` file, include a dependency on both `grpc-cro Google Play Services Client Library for Cronet ``` -implementation 'io.grpc:grpc-cronet:1.43.0' +implementation 'io.grpc:grpc-cronet:1.43.1' implementation 'com.google.android.gms:play-services-cronet:16.0.0' ``` diff --git a/documentation/android-channel-builder.md b/documentation/android-channel-builder.md index 3ebbf9522a4..09c0bef179a 100644 --- a/documentation/android-channel-builder.md +++ b/documentation/android-channel-builder.md @@ -36,8 +36,8 @@ In your `build.gradle` file, include a dependency on both `grpc-android` and `grpc-okhttp`: ``` -implementation 'io.grpc:grpc-android:1.43.0' -implementation 'io.grpc:grpc-okhttp:1.43.0' +implementation 'io.grpc:grpc-android:1.43.1' +implementation 'io.grpc:grpc-okhttp:1.43.1' ``` You also need permission to access the device's network state in your From 80f1be03f0dc347125765bd9360848f221a7f174 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Tue, 21 Dec 2021 16:39:31 -0800 Subject: [PATCH 0018/1995] Use xds-test-server-5 as the GCE interop server (#8777) --- buildscripts/kokoro/xds.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildscripts/kokoro/xds.sh b/buildscripts/kokoro/xds.sh index c43438213c3..83ba7fc864f 100755 --- a/buildscripts/kokoro/xds.sh +++ b/buildscripts/kokoro/xds.sh @@ -31,7 +31,7 @@ JAVA_OPTS=-Djava.util.logging.config.file=grpc-java/buildscripts/xds_logging.pro --test_case="all,circuit_breaking,timeout,fault_injection,csds" \ --project_id=grpc-testing \ --project_num=830293263384 \ - --source_image=projects/grpc-testing/global/images/xds-test-server-4 \ + --source_image=projects/grpc-testing/global/images/xds-test-server-5 \ --path_to_server_binary=/java_server/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-server \ --gcp_suffix=$(date '+%s') \ --verbose \ From e474e3dc7ebc0f4ba0b97ddbec445f200a30ec6f Mon Sep 17 00:00:00 2001 From: sanjaypujare Date: Tue, 4 Jan 2022 13:01:02 -0800 Subject: [PATCH 0019/1995] buildscripts: always make sure we are using jdk8 (#8800) --- buildscripts/kokoro/unix.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildscripts/kokoro/unix.sh b/buildscripts/kokoro/unix.sh index 1de35827809..61d65324a07 100755 --- a/buildscripts/kokoro/unix.sh +++ b/buildscripts/kokoro/unix.sh @@ -24,6 +24,9 @@ fi cd $(dirname $0)/../.. # TODO(zpencer): always make sure we are using Oracle jdk8 +if [[ -f /usr/libexec/java_home ]]; then + JAVA_HOME=$(/usr/libexec/java_home -v"1.8.0") +fi # ARCH is x86_64 unless otherwise specified. ARCH="${ARCH:-x86_64}" From 24e345c06da7846053b8b3c86889e915160f34a4 Mon Sep 17 00:00:00 2001 From: Daniel Norberg Date: Tue, 4 Jan 2022 18:39:19 -0500 Subject: [PATCH 0020/1995] readme: grpc-netty-shaded runtime scope We should recommend runtime scope for grpc-netty-shaded. https://github.com/grpc/grpc-java/issues/8606#issuecomment-1004504316 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e25ca28534..610c637892b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: io.grpc grpc-netty-shaded 1.43.1 + runtime io.grpc @@ -65,7 +66,7 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`: Or for Gradle with non-Android, add to your dependencies: ```gradle -implementation 'io.grpc:grpc-netty-shaded:1.43.1' +runtimeOnly 'io.grpc:grpc-netty-shaded:1.43.1' implementation 'io.grpc:grpc-protobuf:1.43.1' implementation 'io.grpc:grpc-stub:1.43.1' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+ From 86b8b265ba5989d4b69e5015ba67c2db5e6954e7 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Wed, 5 Jan 2022 10:31:22 -0800 Subject: [PATCH 0021/1995] .github/workflows: publish test results for failed job The GitHub Actions Linux Testing only reports limited information (can not see full stacktrace, time consumed, or stderr from child threads) when unit tests fail. Adding a step to upload the test report to Artifacts if the test fails. If the test is successful, no artifacts will be uploaded. --- .github/workflows/testing.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ea883a77b04..609d0841494 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -53,6 +53,13 @@ jobs: - name: Build run: buildscripts/kokoro/unix.sh + - name: Post Failure Upload Test Reports to Artifacts + if: ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: Test Reports (JRE ${{ matrix.jre }}) + path: ./*/build/reports/tests/** + retention-days: 14 - name: Check for modified codegen run: test -z "$(git status --porcelain)" || (git status && echo Error Working directory is not clean. Forget to commit generated files? && false) From 80c3be0f80a9d961a66751bd85a086e382104cd5 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 6 Jan 2022 09:08:50 -0800 Subject: [PATCH 0022/1995] Bump protobuf to 3.19.2 --- COMPILING.md | 4 ++-- build.gradle | 2 +- buildscripts/make_dependencies.bat | 2 +- buildscripts/make_dependencies.sh | 2 +- examples/android/clientcache/app/build.gradle | 2 +- examples/android/helloworld/app/build.gradle | 2 +- examples/android/routeguide/app/build.gradle | 2 +- examples/android/strictmode/app/build.gradle | 2 +- examples/build.gradle | 2 +- examples/example-alts/build.gradle | 2 +- examples/example-gauth/build.gradle | 2 +- examples/example-gauth/pom.xml | 2 +- examples/example-hostname/build.gradle | 2 +- examples/example-hostname/pom.xml | 2 +- examples/example-jwt-auth/build.gradle | 2 +- examples/example-jwt-auth/pom.xml | 4 ++-- examples/example-tls/build.gradle | 2 +- examples/example-tls/pom.xml | 2 +- examples/example-xds/build.gradle | 2 +- examples/pom.xml | 4 ++-- repositories.bzl | 12 ++++++------ 21 files changed, 29 insertions(+), 29 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index d065e702842..3915c561db7 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -43,11 +43,11 @@ This section is only necessary if you are making changes to the code generation. Most users only need to use `skipCodegen=true` as discussed above. ### Build Protobuf -The codegen plugin is C++ code and requires protobuf 3.19.1 or later. +The codegen plugin is C++ code and requires protobuf 3.19.2 or later. For Linux, Mac and MinGW: ``` -$ PROTOBUF_VERSION=3.19.1 +$ PROTOBUF_VERSION=3.19.2 $ curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz $ tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz $ cd protobuf-$PROTOBUF_VERSION diff --git a/build.gradle b/build.gradle index e3dcad2a0de..f68125fa5d7 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ subprojects { nettyVersion = '4.1.63.Final' guavaVersion = '30.1.1-android' googleauthVersion = '0.22.2' - protobufVersion = '3.19.1' + protobufVersion = '3.19.2' protocVersion = protobufVersion opencensusVersion = '0.28.0' autovalueVersion = '1.7.4' diff --git a/buildscripts/make_dependencies.bat b/buildscripts/make_dependencies.bat index b8586e85832..18c6086adab 100644 --- a/buildscripts/make_dependencies.bat +++ b/buildscripts/make_dependencies.bat @@ -1,4 +1,4 @@ -set PROTOBUF_VER=3.19.1 +set PROTOBUF_VER=3.19.2 set CMAKE_NAME=cmake-3.3.2-win32-x86 if not exist "protobuf-%PROTOBUF_VER%\cmake\build\Release\" ( diff --git a/buildscripts/make_dependencies.sh b/buildscripts/make_dependencies.sh index 7e132a91db0..5e7561c4313 100755 --- a/buildscripts/make_dependencies.sh +++ b/buildscripts/make_dependencies.sh @@ -3,7 +3,7 @@ # Build protoc set -evux -o pipefail -PROTOBUF_VERSION=3.19.1 +PROTOBUF_VERSION=3.19.2 # ARCH is x86_64 bit unless otherwise specified. ARCH="${ARCH:-x86_64}" diff --git a/examples/android/clientcache/app/build.gradle b/examples/android/clientcache/app/build.gradle index 260255a1773..1b00d689488 100644 --- a/examples/android/clientcache/app/build.gradle +++ b/examples/android/clientcache/app/build.gradle @@ -32,7 +32,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.2' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/helloworld/app/build.gradle b/examples/android/helloworld/app/build.gradle index 458a33584ea..82c4abe7550 100644 --- a/examples/android/helloworld/app/build.gradle +++ b/examples/android/helloworld/app/build.gradle @@ -30,7 +30,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.2' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/routeguide/app/build.gradle b/examples/android/routeguide/app/build.gradle index fb3fe7e8f95..8e33ac40d39 100644 --- a/examples/android/routeguide/app/build.gradle +++ b/examples/android/routeguide/app/build.gradle @@ -30,7 +30,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.2' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/android/strictmode/app/build.gradle b/examples/android/strictmode/app/build.gradle index 9472151bceb..7b3de25c3f5 100644 --- a/examples/android/strictmode/app/build.gradle +++ b/examples/android/strictmode/app/build.gradle @@ -31,7 +31,7 @@ android { } protobuf { - protoc { artifact = 'com.google.protobuf:protoc:3.19.1' } + protoc { artifact = 'com.google.protobuf:protoc:3.19.2' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION } diff --git a/examples/build.gradle b/examples/build.gradle index 3fe5c439e6d..e95cfd2f33c 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.19.1' +def protobufVersion = '3.19.2' def protocVersion = protobufVersion dependencies { diff --git a/examples/example-alts/build.gradle b/examples/example-alts/build.gradle index 7db8e672704..2cc4ac5afc9 100644 --- a/examples/example-alts/build.gradle +++ b/examples/example-alts/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protocVersion = '3.19.1' +def protocVersion = '3.19.2' dependencies { // grpc-alts transitively depends on grpc-netty-shaded, grpc-protobuf, and grpc-stub diff --git a/examples/example-gauth/build.gradle b/examples/example-gauth/build.gradle index 2a581f2822f..db4baf1cd38 100644 --- a/examples/example-gauth/build.gradle +++ b/examples/example-gauth/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.19.1' +def protobufVersion = '3.19.2' def protocVersion = protobufVersion diff --git a/examples/example-gauth/pom.xml b/examples/example-gauth/pom.xml index 765960c3bd3..2ccd6654757 100644 --- a/examples/example-gauth/pom.xml +++ b/examples/example-gauth/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.19.1 + 3.19.2 1.7 1.7 diff --git a/examples/example-hostname/build.gradle b/examples/example-hostname/build.gradle index f18060097ea..e1476fe11f8 100644 --- a/examples/example-hostname/build.gradle +++ b/examples/example-hostname/build.gradle @@ -22,7 +22,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.19.1' +def protobufVersion = '3.19.2' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/example-hostname/pom.xml b/examples/example-hostname/pom.xml index 1ce2438e8de..31445d405de 100644 --- a/examples/example-hostname/pom.xml +++ b/examples/example-hostname/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.19.1 + 3.19.2 1.7 1.7 diff --git a/examples/example-jwt-auth/build.gradle b/examples/example-jwt-auth/build.gradle index 18f08658b69..c1470dd693e 100644 --- a/examples/example-jwt-auth/build.gradle +++ b/examples/example-jwt-auth/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protobufVersion = '3.19.1' +def protobufVersion = '3.19.2' def protocVersion = protobufVersion dependencies { diff --git a/examples/example-jwt-auth/pom.xml b/examples/example-jwt-auth/pom.xml index 9fc68fb40c1..f026be38467 100644 --- a/examples/example-jwt-auth/pom.xml +++ b/examples/example-jwt-auth/pom.xml @@ -14,8 +14,8 @@ UTF-8 1.44.0-SNAPSHOT - 3.19.1 - 3.19.1 + 3.19.2 + 3.19.2 1.7 1.7 diff --git a/examples/example-tls/build.gradle b/examples/example-tls/build.gradle index 98b73eec9c7..bd8d264b7f9 100644 --- a/examples/example-tls/build.gradle +++ b/examples/example-tls/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // Feel free to delete the comment at the next line. It is just for safely // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION -def protocVersion = '3.19.1' +def protocVersion = '3.19.2' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/example-tls/pom.xml b/examples/example-tls/pom.xml index bcb6ecd47c0..193e05fd812 100644 --- a/examples/example-tls/pom.xml +++ b/examples/example-tls/pom.xml @@ -13,7 +13,7 @@ UTF-8 1.44.0-SNAPSHOT - 3.19.1 + 3.19.2 2.0.34.Final 1.7 diff --git a/examples/example-xds/build.gradle b/examples/example-xds/build.gradle index f593a48050a..0ce7fbd56b5 100644 --- a/examples/example-xds/build.gradle +++ b/examples/example-xds/build.gradle @@ -24,7 +24,7 @@ targetCompatibility = 1.7 // updating the version in our release process. def grpcVersion = '1.44.0-SNAPSHOT' // CURRENT_GRPC_VERSION def nettyTcNativeVersion = '2.0.31.Final' -def protocVersion = '3.19.1' +def protocVersion = '3.19.2' dependencies { implementation "io.grpc:grpc-protobuf:${grpcVersion}" diff --git a/examples/pom.xml b/examples/pom.xml index 4a23872d05c..525fb616fa0 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -13,8 +13,8 @@ UTF-8 1.44.0-SNAPSHOT - 3.19.1 - 3.19.1 + 3.19.2 + 3.19.2 1.7 1.7 diff --git a/repositories.bzl b/repositories.bzl index 6e9caf9409d..e5e5ccb0a55 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -98,18 +98,18 @@ def com_google_protobuf(): # This statement defines the @com_google_protobuf repo. http_archive( name = "com_google_protobuf", - sha256 = "25f1292d4ea6666f460a2a30038eef121e6c3937ae0f61d610611dfb14b0bd32", - strip_prefix = "protobuf-3.19.1", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.zip"], + sha256 = "9ceef0daf7e8be16cd99ac759271eb08021b53b1c7b6edd399953a76390234cd", + strip_prefix = "protobuf-3.19.2", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.2.zip"], ) def com_google_protobuf_javalite(): # java_lite_proto_library rules implicitly depend on @com_google_protobuf_javalite http_archive( name = "com_google_protobuf_javalite", - sha256 = "25f1292d4ea6666f460a2a30038eef121e6c3937ae0f61d610611dfb14b0bd32", - strip_prefix = "protobuf-3.19.1", - urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.zip"], + sha256 = "9ceef0daf7e8be16cd99ac759271eb08021b53b1c7b6edd399953a76390234cd", + strip_prefix = "protobuf-3.19.2", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.2.zip"], ) def io_grpc_grpc_proto(): From b32d2d2de9766987e900ce0c098937f1ae24dc15 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Thu, 6 Jan 2022 10:22:57 -0800 Subject: [PATCH 0023/1995] xds: parse ClusterSpecifierPlugin from RouteConfiguration in xDS response Implement the xds Client section of go/grpc-rls-in-xds#heading=h.9kitavdfxxiw --- .../java/io/grpc/xds/ClientXdsClient.java | 107 +++++- .../io/grpc/xds/ClusterSpecifierPlugin.java | 12 + .../xds/ClusterSpecifierPluginRegistry.java | 7 +- ...teLookupServiceClusterSpecifierPlugin.java | 2 +- .../main/java/io/grpc/xds/VirtualHost.java | 33 +- .../io/grpc/xds/ClientXdsClientDataTest.java | 357 ++++++++++++++++-- .../ClusterSpecifierPluginRegistryTest.java | 2 +- ...okupServiceClusterSpecifierPluginTest.java | 6 +- 8 files changed, 469 insertions(+), 57 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/ClientXdsClient.java b/xds/src/main/java/io/grpc/xds/ClientXdsClient.java index 2b676553838..30c18cfe147 100644 --- a/xds/src/main/java/io/grpc/xds/ClientXdsClient.java +++ b/xds/src/main/java/io/grpc/xds/ClientXdsClient.java @@ -47,8 +47,10 @@ import io.envoyproxy.envoy.config.core.v3.SocketAddress; import io.envoyproxy.envoy.config.core.v3.SocketAddress.PortSpecifierCase; import io.envoyproxy.envoy.config.core.v3.TrafficDirection; +import io.envoyproxy.envoy.config.core.v3.TypedExtensionConfig; import io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment; import io.envoyproxy.envoy.config.listener.v3.Listener; +import io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin; import io.envoyproxy.envoy.config.route.v3.RetryPolicy.RetryBackOff; import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; import io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager; @@ -73,6 +75,8 @@ import io.grpc.xds.AbstractXdsClient.ResourceType; import io.grpc.xds.Bootstrapper.AuthorityInfo; import io.grpc.xds.Bootstrapper.ServerInfo; +import io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig; +import io.grpc.xds.ClusterSpecifierPlugin.PluginConfig; import io.grpc.xds.Endpoints.DropOverload; import io.grpc.xds.Endpoints.LbEndpoint; import io.grpc.xds.Endpoints.LocalityLbEndpoints; @@ -150,6 +154,10 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res static boolean enableRbac = Strings.isNullOrEmpty(System.getenv("GRPC_XDS_EXPERIMENTAL_RBAC")) || Boolean.parseBoolean(System.getenv("GRPC_XDS_EXPERIMENTAL_RBAC")); + @VisibleForTesting + static boolean enableRouteLookup = + !Strings.isNullOrEmpty(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB")) + && Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB")); private static final String TYPE_URL_HTTP_CONNECTION_MANAGER_V2 = "type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2" @@ -857,18 +865,8 @@ static io.grpc.xds.HttpConnectionManager parseHttpConnectionManager( // Parse inlined RouteConfiguration or RDS. if (proto.hasRouteConfig()) { - List virtualHosts = new ArrayList<>(); - for (io.envoyproxy.envoy.config.route.v3.VirtualHost virtualHostProto - : proto.getRouteConfig().getVirtualHostsList()) { - StructOrError virtualHost = - parseVirtualHost(virtualHostProto, filterRegistry, parseHttpFilter); - if (virtualHost.getErrorDetail() != null) { - throw new ResourceInvalidException( - "HttpConnectionManager contains invalid virtual host: " - + virtualHost.getErrorDetail()); - } - virtualHosts.add(virtualHost.getStruct()); - } + List virtualHosts = extractVirtualHosts( + proto.getRouteConfig(), filterRegistry, parseHttpFilter); return io.grpc.xds.HttpConnectionManager.forVirtualHosts( maxStreamDuration, virtualHosts, filterConfigs); } @@ -950,11 +948,12 @@ static StructOrError parseHttpFilter( private static StructOrError parseVirtualHost( io.envoyproxy.envoy.config.route.v3.VirtualHost proto, FilterRegistry filterRegistry, - boolean parseHttpFilter) { + boolean parseHttpFilter, Map pluginConfigMap) { String name = proto.getName(); List routes = new ArrayList<>(proto.getRoutesCount()); for (io.envoyproxy.envoy.config.route.v3.Route routeProto : proto.getRoutesList()) { - StructOrError route = parseRoute(routeProto, filterRegistry, parseHttpFilter); + StructOrError route = parseRoute( + routeProto, filterRegistry, parseHttpFilter, pluginConfigMap); if (route == null) { continue; } @@ -1039,7 +1038,7 @@ static StructOrError> parseOverrideFilterConfigs( @Nullable static StructOrError parseRoute( io.envoyproxy.envoy.config.route.v3.Route proto, FilterRegistry filterRegistry, - boolean parseHttpFilter) { + boolean parseHttpFilter, Map pluginConfigMap) { StructOrError routeMatch = parseRouteMatch(proto.getMatch()); if (routeMatch == null) { return null; @@ -1065,7 +1064,7 @@ static StructOrError parseRoute( switch (proto.getActionCase()) { case ROUTE: StructOrError routeAction = - parseRouteAction(proto.getRoute(), filterRegistry, parseHttpFilter); + parseRouteAction(proto.getRoute(), filterRegistry, parseHttpFilter, pluginConfigMap); if (routeAction == null) { return null; } @@ -1218,7 +1217,7 @@ static StructOrError parseHeaderMatcher( @Nullable static StructOrError parseRouteAction( io.envoyproxy.envoy.config.route.v3.RouteAction proto, FilterRegistry filterRegistry, - boolean parseHttpFilter) { + boolean parseHttpFilter, Map pluginConfigMap) { Long timeoutNano = null; if (proto.hasMaxStreamDuration()) { io.envoyproxy.envoy.config.route.v3.RouteAction.MaxStreamDuration maxStreamDuration @@ -1297,6 +1296,20 @@ static StructOrError parseRouteAction( // TODO(chengyuanzhang): validate if the sum of weights equals to total weight. return StructOrError.fromStruct(RouteAction.forWeightedClusters( weightedClusters, hashPolicies, timeoutNano, retryPolicy)); + case CLUSTER_SPECIFIER_PLUGIN: + if (enableRouteLookup) { + String pluginName = proto.getClusterSpecifierPlugin(); + PluginConfig pluginConfig = pluginConfigMap.get(pluginName); + if (pluginConfig == null) { + return StructOrError.fromError( + "ClusterSpecifierPlugin for [" + pluginName + "] not found"); + } + NamedPluginConfig namedPluginConfig = NamedPluginConfig.create(pluginName, pluginConfig); + return StructOrError.fromStruct(RouteAction.forClusterSpecifierPlugin( + namedPluginConfig, hashPolicies, timeoutNano, retryPolicy)); + } else { + return StructOrError.fromError("Support for ClusterSpecifierPlugin not enabled"); + } case CLUSTERSPECIFIER_NOT_SET: default: return StructOrError.fromError( @@ -1432,18 +1445,74 @@ public void handleRdsResponse( private static RdsUpdate processRouteConfiguration( RouteConfiguration routeConfig, FilterRegistry filterRegistry, boolean parseHttpFilter) throws ResourceInvalidException { + return new RdsUpdate(extractVirtualHosts(routeConfig, filterRegistry, parseHttpFilter)); + } + + private static List extractVirtualHosts( + RouteConfiguration routeConfig, FilterRegistry filterRegistry, boolean parseHttpFilter) + throws ResourceInvalidException { + Map pluginConfigMap = new HashMap<>(); + if (enableRouteLookup) { + List 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 virtualHosts = new ArrayList<>(routeConfig.getVirtualHostsCount()); for (io.envoyproxy.envoy.config.route.v3.VirtualHost virtualHostProto : routeConfig.getVirtualHostsList()) { StructOrError virtualHost = - parseVirtualHost(virtualHostProto, filterRegistry, parseHttpFilter); + parseVirtualHost(virtualHostProto, filterRegistry, parseHttpFilter, pluginConfigMap); if (virtualHost.getErrorDetail() != null) { throw new ResourceInvalidException( "RouteConfiguration contains invalid virtual host: " + virtualHost.getErrorDetail()); } virtualHosts.add(virtualHost.getStruct()); } - return new RdsUpdate(virtualHosts); + return virtualHosts; + } + + private static PluginConfig parseClusterSpecifierPlugin(ClusterSpecifierPlugin pluginProto) + throws ResourceInvalidException { + return parseClusterSpecifierPlugin( + pluginProto, ClusterSpecifierPluginRegistry.getDefaultRegistry()); + } + + @VisibleForTesting + static PluginConfig parseClusterSpecifierPlugin( + ClusterSpecifierPlugin pluginProto, ClusterSpecifierPluginRegistry registry) + throws ResourceInvalidException { + TypedExtensionConfig extension = pluginProto.getExtension(); + String pluginName = extension.getName(); + Any anyConfig = extension.getTypedConfig(); + String typeUrl = anyConfig.getTypeUrl(); + Message rawConfig = anyConfig; + if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA) || typeUrl.equals(TYPE_URL_TYPED_STRUCT)) { + try { + TypedStruct typedStruct = unpackCompatibleType( + anyConfig, TypedStruct.class, TYPE_URL_TYPED_STRUCT_UDPA, TYPE_URL_TYPED_STRUCT); + typeUrl = typedStruct.getTypeUrl(); + rawConfig = typedStruct.getValue(); + } catch (InvalidProtocolBufferException e) { + throw new ResourceInvalidException( + "ClusterSpecifierPlugin [" + pluginName + "] contains invalid proto", e); + } + } + io.grpc.xds.ClusterSpecifierPlugin plugin = registry.get(typeUrl); + if (plugin == null) { + throw new ResourceInvalidException("Unsupported ClusterSpecifierPlugin type: " + typeUrl); + } + ConfigOrError pluginConfigOrError = plugin.parsePlugin(rawConfig); + if (pluginConfigOrError.errorDetail != null) { + throw new ResourceInvalidException(pluginConfigOrError.errorDetail); + } + return pluginConfigOrError.config; } @Override diff --git a/xds/src/main/java/io/grpc/xds/ClusterSpecifierPlugin.java b/xds/src/main/java/io/grpc/xds/ClusterSpecifierPlugin.java index 44de67b8295..1a0d4a82c28 100644 --- a/xds/src/main/java/io/grpc/xds/ClusterSpecifierPlugin.java +++ b/xds/src/main/java/io/grpc/xds/ClusterSpecifierPlugin.java @@ -16,6 +16,7 @@ package io.grpc.xds; +import com.google.auto.value.AutoValue; import com.google.protobuf.Message; /** @@ -35,4 +36,15 @@ interface ClusterSpecifierPlugin { interface PluginConfig { String typeUrl(); } + + @AutoValue + abstract class NamedPluginConfig { + abstract String name(); + + abstract PluginConfig config(); + + static NamedPluginConfig create(String name, PluginConfig config) { + return new AutoValue_ClusterSpecifierPlugin_NamedPluginConfig(name, config); + } + } } diff --git a/xds/src/main/java/io/grpc/xds/ClusterSpecifierPluginRegistry.java b/xds/src/main/java/io/grpc/xds/ClusterSpecifierPluginRegistry.java index cf7b4cf523d..b81ee96b319 100644 --- a/xds/src/main/java/io/grpc/xds/ClusterSpecifierPluginRegistry.java +++ b/xds/src/main/java/io/grpc/xds/ClusterSpecifierPluginRegistry.java @@ -16,6 +16,7 @@ package io.grpc.xds; +import com.google.common.annotations.VisibleForTesting; import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; @@ -34,11 +35,13 @@ static synchronized ClusterSpecifierPluginRegistry getDefaultRegistry() { return instance; } - private static ClusterSpecifierPluginRegistry newRegistry() { + @VisibleForTesting + static ClusterSpecifierPluginRegistry newRegistry() { return new ClusterSpecifierPluginRegistry(); } - private ClusterSpecifierPluginRegistry register(ClusterSpecifierPlugin... plugins) { + @VisibleForTesting + ClusterSpecifierPluginRegistry register(ClusterSpecifierPlugin... plugins) { for (ClusterSpecifierPlugin plugin : plugins) { for (String typeUrl : plugin.typeUrls()) { supportedPlugins.put(typeUrl, plugin); diff --git a/xds/src/main/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPlugin.java b/xds/src/main/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPlugin.java index 64464f03737..3f843758eeb 100644 --- a/xds/src/main/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPlugin.java +++ b/xds/src/main/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPlugin.java @@ -33,7 +33,7 @@ final class RouteLookupServiceClusterSpecifierPlugin implements ClusterSpecifier new RouteLookupServiceClusterSpecifierPlugin(); private static final String TYPE_URL = - "type.googleapis.com/grpc.lookup.v1.RouteLookupConfig"; + "type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier"; private RouteLookupServiceClusterSpecifierPlugin() {} diff --git a/xds/src/main/java/io/grpc/xds/VirtualHost.java b/xds/src/main/java/io/grpc/xds/VirtualHost.java index 24f66dd8934..d9f93dd3a07 100644 --- a/xds/src/main/java/io/grpc/xds/VirtualHost.java +++ b/xds/src/main/java/io/grpc/xds/VirtualHost.java @@ -26,6 +26,7 @@ import com.google.protobuf.Duration; import com.google.re2j.Pattern; import io.grpc.Status.Code; +import io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig; import io.grpc.xds.Filter.FilterConfig; import io.grpc.xds.internal.Matchers.FractionMatcher; import io.grpc.xds.internal.Matchers.HeaderMatcher; @@ -34,7 +35,7 @@ import java.util.Map; import javax.annotation.Nullable; -/** Reprsents an upstream virtual host. */ +/** Represents an upstream virtual host. */ @AutoValue abstract class VirtualHost { // The canonical name of this virtual host. @@ -159,6 +160,9 @@ abstract static class RouteAction { @Nullable abstract ImmutableList weightedClusters(); + @Nullable + abstract NamedPluginConfig namedClusterSpecifierPluginConfig(); + @Nullable abstract RetryPolicy retryPolicy(); @@ -166,7 +170,7 @@ static RouteAction forCluster( String cluster, List hashPolicies, @Nullable Long timeoutNano, @Nullable RetryPolicy retryPolicy) { checkNotNull(cluster, "cluster"); - return RouteAction.create(hashPolicies, timeoutNano, cluster, null, retryPolicy); + return RouteAction.create(hashPolicies, timeoutNano, cluster, null, null, retryPolicy); } static RouteAction forWeightedClusters( @@ -174,15 +178,32 @@ static RouteAction forWeightedClusters( @Nullable Long timeoutNano, @Nullable RetryPolicy retryPolicy) { checkNotNull(weightedClusters, "weightedClusters"); checkArgument(!weightedClusters.isEmpty(), "empty cluster list"); - return RouteAction.create(hashPolicies, timeoutNano, null, weightedClusters, retryPolicy); + return RouteAction.create( + hashPolicies, timeoutNano, null, weightedClusters, null, retryPolicy); + } + + static RouteAction forClusterSpecifierPlugin( + NamedPluginConfig namedConfig, + List hashPolicies, + @Nullable Long timeoutNano, + @Nullable RetryPolicy retryPolicy) { + checkNotNull(namedConfig, "namedConfig"); + return RouteAction.create(hashPolicies, timeoutNano, null, null, namedConfig, retryPolicy); } - private static RouteAction create(List hashPolicies, @Nullable Long timeoutNano, - @Nullable String cluster, @Nullable List weightedClusters, + private static RouteAction create( + List hashPolicies, + @Nullable Long timeoutNano, + @Nullable String cluster, + @Nullable List weightedClusters, + @Nullable NamedPluginConfig namedConfig, @Nullable RetryPolicy retryPolicy) { return new AutoValue_VirtualHost_Route_RouteAction( - ImmutableList.copyOf(hashPolicies), timeoutNano, cluster, + ImmutableList.copyOf(hashPolicies), + timeoutNano, + cluster, weightedClusters == null ? null : ImmutableList.copyOf(weightedClusters), + namedConfig, retryPolicy); } diff --git a/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java b/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java index e14d6db45ac..44b36b9c5c5 100644 --- a/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java +++ b/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java @@ -18,9 +18,10 @@ import static com.google.common.truth.Truth.assertThat; -import com.github.xds.type.v3.TypedStruct; +import com.github.udpa.udpa.type.v1.TypedStruct; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.protobuf.Any; import com.google.protobuf.BoolValue; import com.google.protobuf.InvalidProtocolBufferException; @@ -72,6 +73,7 @@ import io.envoyproxy.envoy.config.route.v3.RouteAction.HashPolicy.Header; import io.envoyproxy.envoy.config.route.v3.RouteAction.HashPolicy.QueryParameter; import io.envoyproxy.envoy.config.route.v3.RouteAction.MaxStreamDuration; +import io.envoyproxy.envoy.config.route.v3.RouteConfiguration; import io.envoyproxy.envoy.config.route.v3.WeightedCluster; import io.envoyproxy.envoy.extensions.filters.common.fault.v3.FaultDelay; import io.envoyproxy.envoy.extensions.filters.http.fault.v3.FaultAbort; @@ -102,12 +104,20 @@ import io.grpc.InsecureChannelCredentials; import io.grpc.LoadBalancer; import io.grpc.Status.Code; +import io.grpc.lookup.v1.GrpcKeyBuilder; +import io.grpc.lookup.v1.GrpcKeyBuilder.Name; +import io.grpc.lookup.v1.NameMatcher; +import io.grpc.lookup.v1.RouteLookupClusterSpecifier; +import io.grpc.lookup.v1.RouteLookupConfig; import io.grpc.xds.Bootstrapper.ServerInfo; import io.grpc.xds.ClientXdsClient.ResourceInvalidException; import io.grpc.xds.ClientXdsClient.StructOrError; +import io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig; +import io.grpc.xds.ClusterSpecifierPlugin.PluginConfig; import io.grpc.xds.Endpoints.LbEndpoint; import io.grpc.xds.Endpoints.LocalityLbEndpoints; import io.grpc.xds.Filter.FilterConfig; +import io.grpc.xds.RouteLookupServiceClusterSpecifierPlugin.RlsPluginConfig; import io.grpc.xds.VirtualHost.Route; import io.grpc.xds.VirtualHost.Route.RouteAction; import io.grpc.xds.VirtualHost.Route.RouteAction.ClusterWeight; @@ -145,6 +155,7 @@ public class ClientXdsClientDataTest { private final FilterRegistry filterRegistry = FilterRegistry.getDefaultRegistry(); private boolean originalEnableRetry; private boolean originalEnableRbac; + private boolean originalEnableRouteLookup; @Before public void setUp() { @@ -152,12 +163,15 @@ public void setUp() { assertThat(originalEnableRetry).isTrue(); originalEnableRbac = ClientXdsClient.enableRbac; assertThat(originalEnableRbac).isTrue(); + originalEnableRouteLookup = ClientXdsClient.enableRouteLookup; + assertThat(originalEnableRouteLookup).isFalse(); } @After public void tearDown() { ClientXdsClient.enableRetry = originalEnableRetry; ClientXdsClient.enableRbac = originalEnableRbac; + ClientXdsClient.enableRouteLookup = originalEnableRouteLookup; } @Test @@ -172,7 +186,8 @@ public void parseRoute_withRouteAction() { io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() .setCluster("cluster-foo")) .build(); - StructOrError struct = ClientXdsClient.parseRoute(proto, filterRegistry, false); + StructOrError struct = ClientXdsClient.parseRoute( + proto, filterRegistry, false, ImmutableMap.of()); assertThat(struct.getErrorDetail()).isNull(); assertThat(struct.getStruct()) .isEqualTo( @@ -194,7 +209,8 @@ public void parseRoute_withNonForwardingAction() { .setPath("/service/method")) .setNonForwardingAction(NonForwardingAction.getDefaultInstance()) .build(); - StructOrError struct = ClientXdsClient.parseRoute(proto, filterRegistry, false); + StructOrError struct = ClientXdsClient.parseRoute( + proto, filterRegistry, false, ImmutableMap.of()); assertThat(struct.getStruct()) .isEqualTo( Route.forNonForwardingAction( @@ -212,7 +228,8 @@ public void parseRoute_withUnsupportedActionTypes() { .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPath("")) .setRedirect(RedirectAction.getDefaultInstance()) .build(); - res = ClientXdsClient.parseRoute(redirectRoute, filterRegistry, false); + res = ClientXdsClient.parseRoute( + redirectRoute, filterRegistry, false, ImmutableMap.of()); assertThat(res.getStruct()).isNull(); assertThat(res.getErrorDetail()) .isEqualTo("Route [route-blade] with unknown action type: REDIRECT"); @@ -223,7 +240,8 @@ public void parseRoute_withUnsupportedActionTypes() { .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPath("")) .setDirectResponse(DirectResponseAction.getDefaultInstance()) .build(); - res = ClientXdsClient.parseRoute(directResponseRoute, filterRegistry, false); + res = ClientXdsClient.parseRoute( + directResponseRoute, filterRegistry, false, ImmutableMap.of()); assertThat(res.getStruct()).isNull(); assertThat(res.getErrorDetail()) .isEqualTo("Route [route-blade] with unknown action type: DIRECT_RESPONSE"); @@ -234,7 +252,8 @@ public void parseRoute_withUnsupportedActionTypes() { .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPath("")) .setFilterAction(FilterAction.getDefaultInstance()) .build(); - res = ClientXdsClient.parseRoute(filterRoute, filterRegistry, false); + res = ClientXdsClient.parseRoute( + filterRoute, filterRegistry, false, ImmutableMap.of()); assertThat(res.getStruct()).isNull(); assertThat(res.getErrorDetail()) .isEqualTo("Route [route-blade] with unknown action type: FILTER_ACTION"); @@ -255,7 +274,9 @@ public void parseRoute_skipRouteWithUnsupportedMatcher() { io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() .setCluster("cluster-foo")) .build(); - assertThat(ClientXdsClient.parseRoute(proto, filterRegistry, false)).isNull(); + assertThat(ClientXdsClient.parseRoute( + proto, filterRegistry, false, ImmutableMap.of())) + .isNull(); } @Test @@ -270,7 +291,9 @@ public void parseRoute_skipRouteWithUnsupportedAction() { io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() .setClusterHeader("cluster header")) // cluster_header action not supported .build(); - assertThat(ClientXdsClient.parseRoute(proto, filterRegistry, false)).isNull(); + assertThat(ClientXdsClient.parseRoute( + proto, filterRegistry, false, ImmutableMap.of())) + .isNull(); } @Test @@ -456,7 +479,8 @@ public void parseRouteAction_withCluster() { .setCluster("cluster-foo") .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()).isNull(); assertThat(struct.getStruct().cluster()).isEqualTo("cluster-foo"); assertThat(struct.getStruct().weightedClusters()).isNull(); @@ -479,7 +503,8 @@ public void parseRouteAction_withWeightedCluster() { .setWeight(UInt32Value.newBuilder().setValue(70)))) .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()).isNull(); assertThat(struct.getStruct().cluster()).isNull(); assertThat(struct.getStruct().weightedClusters()).containsExactly( @@ -498,7 +523,8 @@ public void parseRouteAction_withTimeoutByGrpcTimeoutHeaderMax() { .setMaxStreamDuration(Durations.fromMillis(20L))) .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().timeoutNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L)); } @@ -512,7 +538,8 @@ public void parseRouteAction_withTimeoutByMaxStreamDuration() { .setMaxStreamDuration(Durations.fromSeconds(5L))) .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().timeoutNano()).isEqualTo(TimeUnit.SECONDS.toNanos(5L)); } @@ -523,7 +550,8 @@ public void parseRouteAction_withTimeoutUnset() { .setCluster("cluster-foo") .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().timeoutNano()).isNull(); } @@ -545,7 +573,8 @@ public void parseRouteAction_withRetryPolicy() { .setRetryPolicy(builder.build()) .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); RouteAction.RetryPolicy retryPolicy = struct.getStruct().retryPolicy(); assertThat(retryPolicy.maxAttempts()).isEqualTo(4); assertThat(retryPolicy.initialBackoff()).isEqualTo(Durations.fromMillis(500)); @@ -568,7 +597,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder.build()) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().retryPolicy()).isNotNull(); assertThat(struct.getStruct().retryPolicy().retryableStatusCodes()).isEmpty(); @@ -580,7 +610,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()).isEqualTo("No base_interval specified in retry_backoff"); // max_interval unset @@ -589,7 +620,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); retryPolicy = struct.getStruct().retryPolicy(); assertThat(retryPolicy.maxBackoff()).isEqualTo(Durations.fromMillis(500 * 10)); @@ -599,7 +631,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()) .isEqualTo("base_interval in retry_backoff must be positive"); @@ -611,7 +644,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()) .isEqualTo("max_interval in retry_backoff cannot be less than base_interval"); @@ -623,7 +657,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getErrorDetail()) .isEqualTo("max_interval in retry_backoff cannot be less than base_interval"); @@ -635,7 +670,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().retryPolicy().initialBackoff()) .isEqualTo(Durations.fromMillis(1)); assertThat(struct.getStruct().retryPolicy().maxBackoff()) @@ -650,7 +686,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); retryPolicy = struct.getStruct().retryPolicy(); assertThat(retryPolicy.initialBackoff()).isEqualTo(Durations.fromMillis(25)); assertThat(retryPolicy.maxBackoff()).isEqualTo(Durations.fromMillis(250)); @@ -668,7 +705,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().retryPolicy().retryableStatusCodes()) .containsExactly(Code.CANCELLED); @@ -685,7 +723,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().retryPolicy().retryableStatusCodes()) .containsExactly(Code.CANCELLED); @@ -702,7 +741,8 @@ public void parseRouteAction_withRetryPolicy() { .setCluster("cluster-foo") .setRetryPolicy(builder) .build(); - struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + struct = ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); assertThat(struct.getStruct().retryPolicy().retryableStatusCodes()) .containsExactly(Code.CANCELLED); } @@ -739,7 +779,8 @@ public void parseRouteAction_withHashPolicies() { QueryParameter.newBuilder().setName("param"))) // unsupported .build(); StructOrError struct = - ClientXdsClient.parseRouteAction(proto, filterRegistry, false); + ClientXdsClient.parseRouteAction(proto, filterRegistry, false, + ImmutableMap.of()); List policies = struct.getStruct().hashPolicies(); assertThat(policies).hasSize(2); assertThat(policies.get(0).type()).isEqualTo(HashPolicy.Type.HEADER); @@ -1339,6 +1380,270 @@ public void parseHttpConnectionManager_emptyFilters() throws ResourceInvalidExce true /* does not matter */); } + @Test + public void parseHttpConnectionManager_clusterSpecifierPlugin() throws Exception { + ClientXdsClient.enableRouteLookup = true; + RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder() + .addGrpcKeybuilders( + GrpcKeyBuilder.newBuilder() + .addNames(Name.newBuilder().setService("service1")) + .addNames(Name.newBuilder().setService("service2")) + .addHeaders( + NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))) + .setLookupService("rls-cbt.googleapis.com") + .setLookupServiceTimeout(Durations.fromMillis(1234)) + .setCacheSizeBytes(5000) + .addValidTargets("valid-target") + .build(); + RouteLookupClusterSpecifier specifier = + RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build(); + TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder() + .setName("rls-plugin-1") + .setTypedConfig(Any.pack(specifier)) + .build(); + io.envoyproxy.envoy.config.route.v3.Route route = + io.envoyproxy.envoy.config.route.v3.Route.newBuilder() + .setName("route-1") + .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")) + .setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() + .setClusterSpecifierPlugin("rls-plugin-1")) + .build(); + HttpConnectionManager hcm = + HttpConnectionManager.newBuilder() + .setRouteConfig( + RouteConfiguration.newBuilder() + .addClusterSpecifierPlugins( + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(typedExtensionConfig) + .build()) + .addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder() + .setName("virtual-host-1") + .addRoutes(route))) + .build(); + + io.grpc.xds.HttpConnectionManager parsedHcm = ClientXdsClient.parseHttpConnectionManager( + hcm, new HashSet(), filterRegistry, false /* parseHttpFilter */, + true /* does not matter */); + + VirtualHost virtualHost = Iterables.getOnlyElement(parsedHcm.virtualHosts()); + Route parsedRoute = Iterables.getOnlyElement(virtualHost.routes()); + NamedPluginConfig namedPluginConfig = + parsedRoute.routeAction().namedClusterSpecifierPluginConfig(); + assertThat(namedPluginConfig.name()).isEqualTo("rls-plugin-1"); + assertThat(namedPluginConfig.config()).isInstanceOf(RlsPluginConfig.class); + } + + @Test + public void parseHttpConnectionManager_duplicatePluginName() throws Exception { + ClientXdsClient.enableRouteLookup = true; + RouteLookupConfig routeLookupConfig1 = RouteLookupConfig.newBuilder() + .addGrpcKeybuilders( + GrpcKeyBuilder.newBuilder() + .addNames(Name.newBuilder().setService("service1")) + .addNames(Name.newBuilder().setService("service2")) + .addHeaders( + NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))) + .setLookupService("rls-cbt.googleapis.com") + .setLookupServiceTimeout(Durations.fromMillis(1234)) + .setCacheSizeBytes(5000) + .addValidTargets("valid-target") + .build(); + RouteLookupClusterSpecifier specifier1 = + RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig1).build(); + RouteLookupConfig routeLookupConfig2 = RouteLookupConfig.newBuilder() + .addGrpcKeybuilders( + GrpcKeyBuilder.newBuilder() + .addNames(Name.newBuilder().setService("service3")) + .addHeaders( + NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))) + .setLookupService("rls-cbt.googleapis.com") + .setLookupServiceTimeout(Durations.fromMillis(1234)) + .setCacheSizeBytes(5000) + .addValidTargets("valid-target") + .build(); + RouteLookupClusterSpecifier specifier2 = + RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig2).build(); + TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder() + .setName("rls-plugin-1") + .setTypedConfig(Any.pack(specifier1)) + .build(); + TypedExtensionConfig typedExtensionConfig2 = TypedExtensionConfig.newBuilder() + .setName("rls-plugin-1") + .setTypedConfig(Any.pack(specifier2)) + .build(); + io.envoyproxy.envoy.config.route.v3.Route route = + io.envoyproxy.envoy.config.route.v3.Route.newBuilder() + .setName("route-1") + .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")) + .setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() + .setClusterSpecifierPlugin("rls-plugin-1")) + .build(); + HttpConnectionManager hcm = + HttpConnectionManager.newBuilder() + .setRouteConfig( + RouteConfiguration.newBuilder() + .addClusterSpecifierPlugins( + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(typedExtensionConfig) + .build()) + .addClusterSpecifierPlugins( + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(typedExtensionConfig2) + .build()) + .addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder() + .setName("virtual-host-1") + .addRoutes(route))) + .build(); + + thrown.expect(ResourceInvalidException.class); + thrown.expectMessage("Multiple ClusterSpecifierPlugins with the same name: rls-plugin-1"); + + ClientXdsClient.parseHttpConnectionManager( + hcm, new HashSet(), filterRegistry, false /* parseHttpFilter */, + true /* does not matter */); + } + + @Test + public void parseHttpConnectionManager_pluginNameNotFound() throws Exception { + ClientXdsClient.enableRouteLookup = true; + RouteLookupConfig routeLookupConfig = RouteLookupConfig.newBuilder() + .addGrpcKeybuilders( + GrpcKeyBuilder.newBuilder() + .addNames(Name.newBuilder().setService("service1")) + .addNames(Name.newBuilder().setService("service2")) + .addHeaders( + NameMatcher.newBuilder().setKey("key1").addNames("v1").setRequiredMatch(true))) + .setLookupService("rls-cbt.googleapis.com") + .setLookupServiceTimeout(Durations.fromMillis(1234)) + .setCacheSizeBytes(5000) + .addValidTargets("valid-target") + .build(); + RouteLookupClusterSpecifier specifier = + RouteLookupClusterSpecifier.newBuilder().setRouteLookupConfig(routeLookupConfig).build(); + TypedExtensionConfig typedExtensionConfig = TypedExtensionConfig.newBuilder() + .setName("rls-plugin-1") + .setTypedConfig(Any.pack(specifier)) + .build(); + io.envoyproxy.envoy.config.route.v3.Route route = + io.envoyproxy.envoy.config.route.v3.Route.newBuilder() + .setName("route-1") + .setMatch(io.envoyproxy.envoy.config.route.v3.RouteMatch.newBuilder().setPrefix("")) + .setRoute(io.envoyproxy.envoy.config.route.v3.RouteAction.newBuilder() + .setClusterSpecifierPlugin("invalid-plugin-name")) + .build(); + HttpConnectionManager hcm = + HttpConnectionManager.newBuilder() + .setRouteConfig( + RouteConfiguration.newBuilder() + .addClusterSpecifierPlugins( + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(typedExtensionConfig) + .build()) + .addVirtualHosts(io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder() + .setName("virtual-host-1") + .addRoutes(route))) + .build(); + + thrown.expect(ResourceInvalidException.class); + thrown.expectMessage("ClusterSpecifierPlugin for [invalid-plugin-name] not found"); + + ClientXdsClient.parseHttpConnectionManager( + hcm, new HashSet(), filterRegistry, false /* parseHttpFilter */, + true /* does not matter */); + } + + @Test + public void parseClusterSpecifierPlugin_typedStructInTypedExtension() throws Exception { + class TestPluginConfig implements PluginConfig { + @Override + public String typeUrl() { + return "type.googleapis.com/google.protobuf.Empty"; + } + } + + ClusterSpecifierPluginRegistry registry = ClusterSpecifierPluginRegistry.newRegistry(); + registry.register(new ClusterSpecifierPlugin() { + @Override + public String[] typeUrls() { + return new String[] { + "type.googleapis.com/google.protobuf.Empty", + }; + } + + @Override + public ConfigOrError parsePlugin(Message rawProtoMessage) { + return ConfigOrError.fromConfig(new TestPluginConfig()); + } + }); + + TypedStruct typedStruct = TypedStruct.newBuilder() + .setTypeUrl("type.googleapis.com/google.protobuf.Empty") + .setValue(Struct.newBuilder()) + .build(); + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin pluginProto = + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(TypedExtensionConfig.newBuilder() + .setTypedConfig(Any.pack(typedStruct))) + .build(); + + PluginConfig pluginConfig = ClientXdsClient.parseClusterSpecifierPlugin(pluginProto, registry); + assertThat(pluginConfig).isInstanceOf(TestPluginConfig.class); + } + + @Test + public void parseClusterSpecifierPlugin_v3TypedStructInTypedExtension() throws Exception { + class TestPluginConfig implements PluginConfig { + @Override + public String typeUrl() { + return "type.googleapis.com/google.protobuf.Empty"; + } + } + + ClusterSpecifierPluginRegistry registry = ClusterSpecifierPluginRegistry.newRegistry(); + registry.register(new ClusterSpecifierPlugin() { + @Override + public String[] typeUrls() { + return new String[] { + "type.googleapis.com/google.protobuf.Empty", + }; + } + + @Override + public ConfigOrError parsePlugin(Message rawProtoMessage) { + return ConfigOrError.fromConfig(new TestPluginConfig()); + } + }); + + com.github.xds.type.v3.TypedStruct typedStruct = com.github.xds.type.v3.TypedStruct.newBuilder() + .setTypeUrl("type.googleapis.com/google.protobuf.Empty") + .setValue(Struct.newBuilder()) + .build(); + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin pluginProto = + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(TypedExtensionConfig.newBuilder() + .setTypedConfig(Any.pack(typedStruct))) + .build(); + + PluginConfig pluginConfig = ClientXdsClient.parseClusterSpecifierPlugin(pluginProto, registry); + assertThat(pluginConfig).isInstanceOf(TestPluginConfig.class); + } + + @Test + public void parseClusterSpecifierPlugin_unregisteredPlugin() throws Exception { + ClusterSpecifierPluginRegistry registry = ClusterSpecifierPluginRegistry.newRegistry(); + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin pluginProto = + io.envoyproxy.envoy.config.route.v3.ClusterSpecifierPlugin.newBuilder() + .setExtension(TypedExtensionConfig.newBuilder() + .setTypedConfig(Any.pack(StringValue.of("unregistered")))) + .build(); + + thrown.expect(ResourceInvalidException.class); + thrown.expectMessage( + "Unsupported ClusterSpecifierPlugin type: type.googleapis.com/google.protobuf.StringValue"); + + ClientXdsClient.parseClusterSpecifierPlugin(pluginProto, registry); + } + @Test public void parseCluster_ringHashLbPolicy_defaultLbConfig() throws ResourceInvalidException { Cluster cluster = Cluster.newBuilder() diff --git a/xds/src/test/java/io/grpc/xds/ClusterSpecifierPluginRegistryTest.java b/xds/src/test/java/io/grpc/xds/ClusterSpecifierPluginRegistryTest.java index 7f04a2a7f39..27ad72a7683 100644 --- a/xds/src/test/java/io/grpc/xds/ClusterSpecifierPluginRegistryTest.java +++ b/xds/src/test/java/io/grpc/xds/ClusterSpecifierPluginRegistryTest.java @@ -28,7 +28,7 @@ public class ClusterSpecifierPluginRegistryTest { @Test public void pluginsInGlobaalInstance() { assertThat(ClusterSpecifierPluginRegistry.getDefaultRegistry() - .get("type.googleapis.com/grpc.lookup.v1.RouteLookupConfig")) + .get("type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier")) .isEqualTo(RouteLookupServiceClusterSpecifierPlugin.INSTANCE); } } diff --git a/xds/src/test/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPluginTest.java b/xds/src/test/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPluginTest.java index f8d1c2ef7c0..c883a9d257d 100644 --- a/xds/src/test/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPluginTest.java +++ b/xds/src/test/java/io/grpc/xds/RouteLookupServiceClusterSpecifierPluginTest.java @@ -62,7 +62,8 @@ public void parseConfigWithAllFieldsGiven() { RlsPluginConfig config = RouteLookupServiceClusterSpecifierPlugin.INSTANCE.parsePlugin(Any.pack(specifier)) .config; - assertThat(config.typeUrl()).isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupConfig"); + assertThat(config.typeUrl()) + .isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier"); assertThat(config.config()).isEqualTo( ImmutableMap.builder() .put( @@ -110,7 +111,8 @@ public void parseConfigWithOptionalFieldsUnspecified() { RlsPluginConfig config = RouteLookupServiceClusterSpecifierPlugin.INSTANCE.parsePlugin(Any.pack(specifier)) .config; - assertThat(config.typeUrl()).isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupConfig"); + assertThat(config.typeUrl()) + .isEqualTo("type.googleapis.com/grpc.lookup.v1.RouteLookupClusterSpecifier"); assertThat(config.config()).isEqualTo( ImmutableMap.builder() .put( From 6f223920a6c6c8d8014c528c5abdac984b14dd15 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Wed, 5 Jan 2022 16:03:52 -0800 Subject: [PATCH 0024/1995] xds: Rename parseCluster() back to processCluster() for consistency This is to keep names of the top-level process* functions called from handle*Response functions, and returning *Update resources consistent: - `handleLdsResponse()` -> `LdsUpdate processClientSideListener()` `LdsUpdate processServerSideListener()` - `handleCdsResponse()` -> `CdsUpdate processCluster()` - `handleRdsResponse()` -> `RdsUpdate processRouteConfiguration()` - `handleEdsResponse()` -> `EdsUpdate processClusterLoadAssignment()` For some reason, processCluster() was renamed to parseCluster() in fa4b980e0. --- xds/src/main/java/io/grpc/xds/ClientXdsClient.java | 5 +++-- .../test/java/io/grpc/xds/ClientXdsClientDataTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/ClientXdsClient.java b/xds/src/main/java/io/grpc/xds/ClientXdsClient.java index 30c18cfe147..222191ad55b 100644 --- a/xds/src/main/java/io/grpc/xds/ClientXdsClient.java +++ b/xds/src/main/java/io/grpc/xds/ClientXdsClient.java @@ -1554,7 +1554,8 @@ public void handleCdsResponse( if (getBootstrapInfo() != null && getBootstrapInfo().certProviders() != null) { certProviderInstances = getBootstrapInfo().certProviders().keySet(); } - cdsUpdate = parseCluster(cluster, retainedEdsResources, certProviderInstances, serverInfo); + cdsUpdate = + processCluster(cluster, retainedEdsResources, certProviderInstances, serverInfo); } catch (ResourceInvalidException e) { errors.add( "CDS response Cluster '" + clusterName + "' validation error: " + e.getMessage()); @@ -1572,7 +1573,7 @@ public void handleCdsResponse( } @VisibleForTesting - static CdsUpdate parseCluster(Cluster cluster, Set retainedEdsResources, + static CdsUpdate processCluster(Cluster cluster, Set retainedEdsResources, Set certProviderInstances, ServerInfo serverInfo) throws ResourceInvalidException { StructOrError structOrError; diff --git a/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java b/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java index 44b36b9c5c5..940d96fd10e 100644 --- a/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java +++ b/xds/src/test/java/io/grpc/xds/ClientXdsClientDataTest.java @@ -1658,7 +1658,7 @@ public void parseCluster_ringHashLbPolicy_defaultLbConfig() throws ResourceInval .setLbPolicy(LbPolicy.RING_HASH) .build(); - CdsUpdate update = ClientXdsClient.parseCluster( + CdsUpdate update = ClientXdsClient.processCluster( cluster, new HashSet(), null, LRS_SERVER_INFO); assertThat(update.lbPolicy()).isEqualTo(CdsUpdate.LbPolicy.RING_HASH); assertThat(update.minRingSize()) @@ -1686,7 +1686,7 @@ public void parseCluster_transportSocketMatches_exception() throws ResourceInval thrown.expect(ResourceInvalidException.class); thrown.expectMessage( "Cluster cluster-foo.googleapis.com: transport-socket-matches not supported."); - ClientXdsClient.parseCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); + ClientXdsClient.processCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); } @Test @@ -1711,7 +1711,7 @@ public void parseCluster_ringHashLbPolicy_invalidRingSizeConfig_minGreaterThanMa thrown.expect(ResourceInvalidException.class); thrown.expectMessage("Cluster cluster-foo.googleapis.com: invalid ring_hash_lb_config"); - ClientXdsClient.parseCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); + ClientXdsClient.processCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); } @Test @@ -1738,7 +1738,7 @@ public void parseCluster_ringHashLbPolicy_invalidRingSizeConfig_tooLargeRingSize thrown.expect(ResourceInvalidException.class); thrown.expectMessage("Cluster cluster-foo.googleapis.com: invalid ring_hash_lb_config"); - ClientXdsClient.parseCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); + ClientXdsClient.processCluster(cluster, new HashSet(), null, LRS_SERVER_INFO); } @Test From 3ad4d9bfb7f7407ec0b9637ee1de508051192676 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Fri, 7 Jan 2022 08:13:32 -0800 Subject: [PATCH 0025/1995] all: clean up code related to android api level less than 19 --- .../integrationtest/InteropInstrumentationTest.java | 8 -------- api/build.gradle | 2 +- auth/build.gradle | 2 +- context/build.gradle | 2 +- core/build.gradle | 2 +- .../main/java/io/grpc/internal/ProxyDetectorImpl.java | 9 +-------- okhttp/build.gradle | 2 +- protobuf-lite/build.gradle | 2 +- stub/build.gradle | 2 +- 9 files changed, 8 insertions(+), 23 deletions(-) diff --git a/android-interop-testing/src/androidTest/java/io/grpc/android/integrationtest/InteropInstrumentationTest.java b/android-interop-testing/src/androidTest/java/io/grpc/android/integrationtest/InteropInstrumentationTest.java index e6a2c85fda5..abcf9e08593 100644 --- a/android-interop-testing/src/androidTest/java/io/grpc/android/integrationtest/InteropInstrumentationTest.java +++ b/android-interop-testing/src/androidTest/java/io/grpc/android/integrationtest/InteropInstrumentationTest.java @@ -20,7 +20,6 @@ import android.util.Log; import androidx.test.InstrumentationRegistry; -import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import com.google.android.gms.common.GooglePlayServicesNotAvailableException; import com.google.android.gms.common.GooglePlayServicesRepairableException; @@ -30,7 +29,6 @@ import java.io.InputStream; import java.util.concurrent.TimeUnit; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,12 +44,6 @@ public class InteropInstrumentationTest { private boolean useTestCa; private String testCase; - // Ensures Looper is initialized for tests running on API level 15. Otherwise instantiating an - // AsyncTask throws an exception. - @Rule - public ActivityTestRule activityRule = - new ActivityTestRule(TesterActivity.class); - @Before public void setUp() throws Exception { host = InstrumentationRegistry.getArguments().getString("server_host", "10.0.2.2"); diff --git a/api/build.gradle b/api/build.gradle index a959fed4ea9..fa58c96ef8a 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -25,7 +25,7 @@ dependencies { jmh project(':grpc-core') signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } javadoc { diff --git a/auth/build.gradle b/auth/build.gradle index 233de359b49..791402fce59 100644 --- a/auth/build.gradle +++ b/auth/build.gradle @@ -14,5 +14,5 @@ dependencies { testImplementation project(':grpc-testing'), libraries.google_auth_oauth2_http signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } diff --git a/context/build.gradle b/context/build.gradle index 4512cc56f0a..909a7472b1e 100644 --- a/context/build.gradle +++ b/context/build.gradle @@ -15,5 +15,5 @@ dependencies { exclude group: 'junit', module: 'junit' } signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } diff --git a/core/build.gradle b/core/build.gradle index 14cfbb70497..e62ae8a804b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -43,7 +43,7 @@ dependencies { jmh project(':grpc-testing') signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } javadoc { diff --git a/core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java b/core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java index 3e7dd010e22..0cc1dd3aaca 100644 --- a/core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java +++ b/core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java @@ -202,14 +202,7 @@ public ProxiedSocketAddress proxyFor(SocketAddress targetServerAddress) throws I private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IOException { URI uri; - String host; - try { - host = GrpcUtil.getHost(targetAddr); - } catch (Throwable t) { - // Workaround for Android API levels < 19 if getHostName causes a NetworkOnMainThreadException - log.log(Level.WARNING, "Failed to get host for proxy lookup, proceeding without proxy", t); - return null; - } + String host = GrpcUtil.getHost(targetAddr); try { uri = new URI( diff --git a/okhttp/build.gradle b/okhttp/build.gradle index 999f21e7c10..3271118feda 100644 --- a/okhttp/build.gradle +++ b/okhttp/build.gradle @@ -22,7 +22,7 @@ dependencies { project(':grpc-testing'), project(':grpc-netty') signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } project.sourceSets { diff --git a/protobuf-lite/build.gradle b/protobuf-lite/build.gradle index 7b58309c414..75cca43f0e6 100644 --- a/protobuf-lite/build.gradle +++ b/protobuf-lite/build.gradle @@ -18,7 +18,7 @@ dependencies { testImplementation project(':grpc-core') signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } compileTestJava { diff --git a/stub/build.gradle b/stub/build.gradle index 2b5a6a4edb6..7d8040a87c2 100644 --- a/stub/build.gradle +++ b/stub/build.gradle @@ -14,7 +14,7 @@ dependencies { testImplementation libraries.truth, project(':grpc-testing') signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" + signature "net.sf.androidscents.signature:android-api-level-19:4.4.2_r4@signature" } javadoc { From 5ae6f9ca2597fef96ce0cbe0957250d6b08be4bd Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Fri, 7 Jan 2022 09:52:26 -0800 Subject: [PATCH 0026/1995] all: Upgrade Android plugin to 4.2.0 - bump android plugin version to 4.2.0 - migrate deprecated android.support dependencies to androidx dependencies - bump `targetSdkVersion` to 29 - temporarily ignore lint error for 'MissingClass' due to #8799 - run android CIs with `-Pandroid.useAndroidX=true -Pandroid.enableJetifier=true` flags - android examples are still using android.support dependencies, will not be updated in this PR. --- COMPILING.md | 1 + android-interop-testing/build.gradle | 17 ++++++++++------- .../src/main/AndroidManifest.xml | 2 +- .../android/integrationtest/TesterActivity.java | 2 +- .../TesterOkHttpChannelBuilder.java | 2 +- buildscripts/kokoro/android-interop.sh | 8 +++++--- buildscripts/kokoro/android.sh | 7 +++++-- buildscripts/kokoro/linux_artifacts.sh | 10 +++++++--- settings.gradle | 4 ++-- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/COMPILING.md b/COMPILING.md index 3915c561db7..aef4cf61b66 100644 --- a/COMPILING.md +++ b/COMPILING.md @@ -15,6 +15,7 @@ Some parts of grpc-java depend on Android. Since many Java developers don't have the Android SDK installed and don't need to run or modify the Android components, the build can skip it. To skip, create the file `/gradle.properties` and add `skipAndroid=true`. +Otherwise, create the file `/gradle.properties` and add `android.useAndroidX=true`. Then, to build, run: ``` diff --git a/android-interop-testing/build.gradle b/android-interop-testing/build.gradle index 8f1c0849e9e..b18d84e2625 100644 --- a/android-interop-testing/build.gradle +++ b/android-interop-testing/build.gradle @@ -29,12 +29,12 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - compileSdkVersion 26 + compileSdkVersion 29 defaultConfig { applicationId "io.grpc.android.integrationtest" minSdkVersion 19 - targetSdkVersion 26 + targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -47,14 +47,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { disable 'InvalidPackage', 'HardcodedText' } + lintOptions { + disable 'InvalidPackage', 'HardcodedText', + 'MissingClass' // https://github.com/grpc/grpc-java/issues/8799 + } } dependencies { - implementation 'com.android.support:appcompat-v7:26.1.0' - implementation 'com.android.support:multidex:1.0.3' - implementation 'com.android.support:support-annotations:26.1.0' - implementation 'com.google.android.gms:play-services-base:16.1.0' + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'androidx.multidex:multidex:2.0.0' + implementation libraries.androidx_annotation + implementation 'com.google.android.gms:play-services-base:18.0.1' implementation project(':grpc-auth'), project(':grpc-census'), diff --git a/android-interop-testing/src/main/AndroidManifest.xml b/android-interop-testing/src/main/AndroidManifest.xml index 2e1e2c696d8..d9ce28630e0 100644 --- a/android-interop-testing/src/main/AndroidManifest.xml +++ b/android-interop-testing/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/Base.V7.Theme.AppCompat.Light" - android:name="android.support.multidex.MultiDexApplication" > + android:name="androidx.multidex.MultiDexApplication" > diff --git a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterActivity.java b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterActivity.java index 004950e7380..d4358ddf945 100644 --- a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterActivity.java +++ b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterActivity.java @@ -19,7 +19,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; import android.view.View; @@ -28,6 +27,7 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; import com.google.android.gms.security.ProviderInstaller; import io.grpc.ManagedChannel; import java.io.InputStream; diff --git a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterOkHttpChannelBuilder.java b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterOkHttpChannelBuilder.java index f4d8f5abcdc..a663378dbf3 100644 --- a/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterOkHttpChannelBuilder.java +++ b/android-interop-testing/src/main/java/io/grpc/android/integrationtest/TesterOkHttpChannelBuilder.java @@ -16,7 +16,7 @@ package io.grpc.android.integrationtest; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import io.grpc.ChannelCredentials; import io.grpc.Grpc; import io.grpc.InsecureChannelCredentials; diff --git a/buildscripts/kokoro/android-interop.sh b/buildscripts/kokoro/android-interop.sh index 50523c8e88e..3046d9bb9e8 100755 --- a/buildscripts/kokoro/android-interop.sh +++ b/buildscripts/kokoro/android-interop.sh @@ -21,10 +21,12 @@ echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3" # Proto deps buildscripts/make_dependencies.sh +GRADLE_FLAGS="-Pandroid.useAndroidX=true" + # Build and run interop instrumentation tests on Firebase Test Lab cd android-interop-testing -../gradlew assembleDebug -../gradlew assembleDebugAndroidTest +../gradlew assembleDebug $GRADLE_FLAGS +../gradlew assembleDebugAndroidTest $GRADLE_FLAGS gcloud firebase test android run \ --type instrumentation \ --app build/outputs/apk/debug/grpc-android-interop-testing-debug.apk \ @@ -41,7 +43,7 @@ gcloud firebase test android run \ # Build and run binderchannel instrumentation tests on Firebase Test Lab cd ../binder -../gradlew assembleDebugAndroidTest +../gradlew assembleDebugAndroidTest $GRADLE_FLAGS gcloud firebase test android run \ --type instrumentation \ --app ../android-interop-testing/build/outputs/apk/debug/grpc-android-interop-testing-debug.apk \ diff --git a/buildscripts/kokoro/android.sh b/buildscripts/kokoro/android.sh index 7b9e7f53885..9318138182e 100755 --- a/buildscripts/kokoro/android.sh +++ b/buildscripts/kokoro/android.sh @@ -28,13 +28,16 @@ echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3" # Proto deps buildscripts/make_dependencies.sh +GRADLE_FLAGS="-Pandroid.useAndroidX=true" + ./gradlew \ :grpc-android-interop-testing:build \ :grpc-android:build \ :grpc-cronet:build \ :grpc-binder:build \ assembleAndroidTest \ - publishToMavenLocal + publishToMavenLocal \ + $GRADLE_FLAGS if [[ ! -z $(git status --porcelain) ]]; then git status @@ -89,7 +92,7 @@ cd $BASE_DIR/github/grpc-java ./gradlew clean git checkout HEAD^ ./gradlew --stop # use a new daemon to build the previous commit -./gradlew publishToMavenLocal +./gradlew publishToMavenLocal $GRADLE_FLAGS cd examples/android/helloworld/ ../../gradlew build diff --git a/buildscripts/kokoro/linux_artifacts.sh b/buildscripts/kokoro/linux_artifacts.sh index c4386b94e07..b4551843c6a 100755 --- a/buildscripts/kokoro/linux_artifacts.sh +++ b/buildscripts/kokoro/linux_artifacts.sh @@ -14,25 +14,29 @@ readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" # use --include-build for its grpc-core dependency echo y | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;28.0.3" LOCAL_MVN_TEMP=$(mktemp -d) +GRADLE_FLAGS="-Pandroid.useAndroidX=true" pushd "$GRPC_JAVA_DIR/android" ../gradlew publish \ -Dorg.gradle.parallel=false \ -PskipCodegen=true \ - -PrepositoryDir="$LOCAL_MVN_TEMP" + -PrepositoryDir="$LOCAL_MVN_TEMP" \ + $GRADLE_FLAGS popd pushd "$GRPC_JAVA_DIR/cronet" ../gradlew publish \ -Dorg.gradle.parallel=false \ -PskipCodegen=true \ - -PrepositoryDir="$LOCAL_MVN_TEMP" + -PrepositoryDir="$LOCAL_MVN_TEMP" \ + $GRADLE_FLAGS popd pushd "$GRPC_JAVA_DIR/binder" ../gradlew publish \ -Dorg.gradle.parallel=false \ -PskipCodegen=true \ - -PrepositoryDir="$LOCAL_MVN_TEMP" + -PrepositoryDir="$LOCAL_MVN_TEMP" \ + $GRADLE_FLAGS popd readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}" diff --git a/settings.gradle b/settings.gradle index 114d9af3c91..a09ee35ade4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ pluginManagement { plugins { - id "com.android.application" version "3.5.0" - id "com.android.library" version "3.5.0" + id "com.android.application" version "4.2.0" + id "com.android.library" version "4.2.0" id "com.github.johnrengelman.shadow" version "6.1.0" id "com.github.kt3k.coveralls" version "2.10.2" id "com.google.osdetector" version "1.6.2" From d44de5069df2ef485f19895707868754474f2745 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 7 Jan 2022 09:54:50 -0800 Subject: [PATCH 0027/1995] Bump to Gradle 6.9 and update plugins These changes make the build compatible with Gradle 7, except for Android which requires plugin updates. I removed animalsniffer from binder because it did nothing (as there were no signatures) and it was failing after setting toolVersion. It failed because animalsniffer is only compatible with java plugin. After this change I put the withId(animalsniffer) loading inside the withId(java) to avoid a plugin ordering failure. That made it safe again for binder to load animalsniffer, but it is still best to remove the plugin from binder as it is misleading. I did not upgrade Android plugin versions as newer versions (even 3.6) require dealing with androidx (#8421). --- all/build.gradle | 4 +- api/build.gradle | 2 +- benchmarks/build.gradle | 12 ++--- binder/build.gradle | 1 - build.gradle | 20 +++++--- context/build.gradle | 2 +- core/build.gradle | 2 +- examples/android/clientcache/build.gradle | 2 +- examples/android/helloworld/build.gradle | 2 +- examples/android/routeguide/build.gradle | 2 +- examples/android/strictmode/build.gradle | 2 +- examples/build.gradle | 46 +++++++++---------- examples/example-alts/build.gradle | 8 ++-- examples/example-gauth/build.gradle | 4 +- examples/example-jwt-auth/build.gradle | 8 ++-- examples/example-tls/build.gradle | 8 ++-- examples/example-xds/build.gradle | 8 ++-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- interop-testing/build.gradle | 18 ++++---- netty/build.gradle | 2 +- settings.gradle | 16 +++---- 22 files changed, 89 insertions(+), 84 deletions(-) diff --git a/all/build.gradle b/all/build.gradle index bfc9ad0e66f..ede0b03c27e 100644 --- a/all/build.gradle +++ b/all/build.gradle @@ -63,8 +63,8 @@ task jacocoMerge(type: JacocoMerge) { jacocoTestReport { dependsOn(jacocoMerge) reports { - xml.enabled = true - html.enabled = true + xml.required = true + html.required = true } subprojects.each { subproject -> diff --git a/api/build.gradle b/api/build.gradle index fa58c96ef8a..1348e49ad60 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -2,7 +2,7 @@ plugins { id "java-library" id "maven-publish" - id "me.champeau.gradle.jmh" + id "me.champeau.jmh" id "ru.vyarus.animalsniffer" } diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index ec071137e0c..48b9030714f 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -4,7 +4,7 @@ plugins { id "maven-publish" id "com.google.protobuf" - id "me.champeau.gradle.jmh" + id "me.champeau.jmh" } description = "grpc Benchmarks" @@ -13,7 +13,7 @@ startScripts.enabled = false run.enabled = false jmh { - jvmArgs = "-server -Xms2g -Xmx2g" + jvmArgs = ["-server", "-Xms2g", "-Xmx2g"] } configurations { @@ -55,7 +55,7 @@ def vmArgs = [ ] task qps_client(type: CreateStartScripts) { - mainClassName = "io.grpc.benchmarks.qps.AsyncClient" + mainClass = "io.grpc.benchmarks.qps.AsyncClient" applicationName = "qps_client" defaultJvmOpts = vmArgs outputDir = new File(project.buildDir, 'tmp/scripts/' + name) @@ -63,7 +63,7 @@ task qps_client(type: CreateStartScripts) { } task openloop_client(type: CreateStartScripts) { - mainClassName = "io.grpc.benchmarks.qps.OpenLoopClient" + mainClass = "io.grpc.benchmarks.qps.OpenLoopClient" applicationName = "openloop_client" defaultJvmOpts = vmArgs outputDir = new File(project.buildDir, 'tmp/scripts/' + name) @@ -71,14 +71,14 @@ task openloop_client(type: CreateStartScripts) { } task qps_server(type: CreateStartScripts) { - mainClassName = "io.grpc.benchmarks.qps.AsyncServer" + mainClass = "io.grpc.benchmarks.qps.AsyncServer" applicationName = "qps_server" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task benchmark_worker(type: CreateStartScripts) { - mainClassName = "io.grpc.benchmarks.driver.LoadWorker" + mainClass = "io.grpc.benchmarks.driver.LoadWorker" applicationName = "benchmark_worker" defaultJvmOpts = vmArgs outputDir = new File(project.buildDir, 'tmp/scripts/' + name) diff --git a/binder/build.gradle b/binder/build.gradle index 04f8444ff01..fa9d0d8cee9 100644 --- a/binder/build.gradle +++ b/binder/build.gradle @@ -1,7 +1,6 @@ plugins { id "maven-publish" id "com.android.library" - id "ru.vyarus.animalsniffer" id "digital.wup.android-maven-publish" } diff --git a/build.gradle b/build.gradle index f68125fa5d7..84b281bc945 100644 --- a/build.gradle +++ b/build.gradle @@ -224,8 +224,6 @@ subprojects { } } - jacoco { toolVersion = "0.8.2" } - checkstyle { configDirectory = file("$rootDir/buildscripts") toolVersion = "6.17" @@ -320,6 +318,14 @@ subprojects { options.errorprone.check("UnnecessaryAnonymousClass", CheckSeverity.OFF) options.errorprone.check("PreferJavaTimeOverload", CheckSeverity.OFF) } + + plugins.withId("ru.vyarus.animalsniffer") { + // Only available after java plugin has loaded + animalsniffer { + // Breaks on upgrade: https://github.com/mojohaus/animal-sniffer/issues/131 + toolVersion = '1.18' + } + } } plugins.withId("java-library") { @@ -335,13 +341,13 @@ subprojects { } } - plugins.withId("me.champeau.gradle.jmh") { - dependencies { - jmh 'org.openjdk.jmh:jmh-core:1.19', - 'org.openjdk.jmh:jmh-generator-bytecode:1.19' - } + plugins.withId("me.champeau.jmh") { // invoke jmh on a single benchmark class like so: // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh + compileJmhJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } jmh { warmupIterations = 10 iterations = 10 diff --git a/context/build.gradle b/context/build.gradle index 909a7472b1e..35ad0566bb6 100644 --- a/context/build.gradle +++ b/context/build.gradle @@ -3,7 +3,7 @@ plugins { id "maven-publish" id "me.champeau.gradle.japicmp" - id "me.champeau.gradle.jmh" + id "me.champeau.jmh" id "ru.vyarus.animalsniffer" } diff --git a/core/build.gradle b/core/build.gradle index e62ae8a804b..ed8e5400765 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -9,7 +9,7 @@ plugins { id "maven-publish" id "me.champeau.gradle.japicmp" - id "me.champeau.gradle.jmh" + id "me.champeau.jmh" id "ru.vyarus.animalsniffer" } diff --git a/examples/android/clientcache/build.gradle b/examples/android/clientcache/build.gradle index 0c3acd3f47f..0c3cae44980 100644 --- a/examples/android/clientcache/build.gradle +++ b/examples/android/clientcache/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.17" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/examples/android/helloworld/build.gradle b/examples/android/helloworld/build.gradle index 0c3acd3f47f..0c3cae44980 100644 --- a/examples/android/helloworld/build.gradle +++ b/examples/android/helloworld/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.17" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/examples/android/routeguide/build.gradle b/examples/android/routeguide/build.gradle index c8958fb8abb..09d5b19589a 100644 --- a/examples/android/routeguide/build.gradle +++ b/examples/android/routeguide/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.17" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/examples/android/strictmode/build.gradle b/examples/android/strictmode/build.gradle index 0c3acd3f47f..0c3cae44980 100644 --- a/examples/android/strictmode/build.gradle +++ b/examples/android/strictmode/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' - classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.17" + classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/examples/build.gradle b/examples/build.gradle index e95cfd2f33c..45648d4af85 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -2,7 +2,7 @@ plugins { // Provide convenience executables for trying out the examples. id 'application' // ASSUMES GRADLE 5.6 OR HIGHER. Use plugin version 0.8.10 with earlier gradle versions - id 'com.google.protobuf' version '0.8.17' + id 'com.google.protobuf' version '0.8.18' // Generate IntelliJ IDEA's .idea & .iml project files id 'idea' } @@ -64,79 +64,79 @@ sourceSets { startScripts.enabled = false task routeGuideServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.routeguide.RouteGuideServer' + mainClass = 'io.grpc.examples.routeguide.RouteGuideServer' applicationName = 'route-guide-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task routeGuideClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.routeguide.RouteGuideClient' + mainClass = 'io.grpc.examples.routeguide.RouteGuideClient' applicationName = 'route-guide-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task helloWorldServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworld.HelloWorldServer' + mainClass = 'io.grpc.examples.helloworld.HelloWorldServer' applicationName = 'hello-world-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task helloWorldClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworld.HelloWorldClient' + mainClass = 'io.grpc.examples.helloworld.HelloWorldClient' applicationName = 'hello-world-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task retryingHelloWorldServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.retrying.RetryingHelloWorldServer' + mainClass = 'io.grpc.examples.retrying.RetryingHelloWorldServer' applicationName = 'retrying-hello-world-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task retryingHelloWorldClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.retrying.RetryingHelloWorldClient' + mainClass = 'io.grpc.examples.retrying.RetryingHelloWorldClient' applicationName = 'retrying-hello-world-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task hedgingHelloWorldServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.hedging.HedgingHelloWorldServer' + mainClass = 'io.grpc.examples.hedging.HedgingHelloWorldServer' applicationName = 'hedging-hello-world-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task hedgingHelloWorldClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.hedging.HedgingHelloWorldClient' + mainClass = 'io.grpc.examples.hedging.HedgingHelloWorldClient' applicationName = 'hedging-hello-world-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task compressingHelloWorldClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.experimental.CompressingHelloWorldClient' + mainClass = 'io.grpc.examples.experimental.CompressingHelloWorldClient' applicationName = 'compressing-hello-world-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task manualFlowControlClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.manualflowcontrol.ManualFlowControlClient' + mainClass = 'io.grpc.examples.manualflowcontrol.ManualFlowControlClient' applicationName = 'manual-flow-control-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task manualFlowControlServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.manualflowcontrol.ManualFlowControlServer' + mainClass = 'io.grpc.examples.manualflowcontrol.ManualFlowControlServer' applicationName = 'manual-flow-control-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/example-alts/build.gradle b/examples/example-alts/build.gradle index 2cc4ac5afc9..de4e11fd916 100644 --- a/examples/example-alts/build.gradle +++ b/examples/example-alts/build.gradle @@ -56,16 +56,16 @@ startScripts.enabled = false task helloWorldAltsServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.alts.HelloWorldAltsServer' + mainClass = 'io.grpc.examples.alts.HelloWorldAltsServer' applicationName = 'hello-world-alts-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task helloWorldAltsClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.alts.HelloWorldAltsClient' + mainClass = 'io.grpc.examples.alts.HelloWorldAltsClient' applicationName = 'hello-world-alts-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/example-gauth/build.gradle b/examples/example-gauth/build.gradle index db4baf1cd38..fdde6e01aff 100644 --- a/examples/example-gauth/build.gradle +++ b/examples/example-gauth/build.gradle @@ -61,9 +61,9 @@ sourceSets { startScripts.enabled = false task googleAuthClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.googleAuth.GoogleAuthClient' + mainClass = 'io.grpc.examples.googleAuth.GoogleAuthClient' applicationName = 'google-auth-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/example-jwt-auth/build.gradle b/examples/example-jwt-auth/build.gradle index c1470dd693e..8f962a2ffc8 100644 --- a/examples/example-jwt-auth/build.gradle +++ b/examples/example-jwt-auth/build.gradle @@ -64,16 +64,16 @@ sourceSets { startScripts.enabled = false task hellowWorldJwtAuthServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.jwtauth.AuthServer' + mainClass = 'io.grpc.examples.jwtauth.AuthServer' applicationName = 'auth-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task hellowWorldJwtAuthClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.jwtauth.AuthClient' + mainClass = 'io.grpc.examples.jwtauth.AuthClient' applicationName = 'auth-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/example-tls/build.gradle b/examples/example-tls/build.gradle index bd8d264b7f9..b3b8372e1c4 100644 --- a/examples/example-tls/build.gradle +++ b/examples/example-tls/build.gradle @@ -56,16 +56,16 @@ sourceSets { startScripts.enabled = false task helloWorldTlsServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldServerTls' + mainClass = 'io.grpc.examples.helloworldtls.HelloWorldServerTls' applicationName = 'hello-world-tls-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task helloWorldTlsClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworldtls.HelloWorldClientTls' + mainClass = 'io.grpc.examples.helloworldtls.HelloWorldClientTls' applicationName = 'hello-world-tls-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/example-xds/build.gradle b/examples/example-xds/build.gradle index 0ce7fbd56b5..2d35f5c40d9 100644 --- a/examples/example-xds/build.gradle +++ b/examples/example-xds/build.gradle @@ -49,16 +49,16 @@ protobuf { startScripts.enabled = false task xdsHelloWorldClient(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworldxds.XdsHelloWorldClient' + mainClass = 'io.grpc.examples.helloworldxds.XdsHelloWorldClient' applicationName = 'xds-hello-world-client' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task xdsHelloWorldServer(type: CreateStartScripts) { - mainClassName = 'io.grpc.examples.helloworldxds.XdsHelloWorldServer' + mainClass = 'io.grpc.examples.helloworldxds.XdsHelloWorldServer' applicationName = 'xds-hello-world-server' - outputDir = new File(project.buildDir, 'tmp') + outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties index 4d9ca164914..3ab0b725efc 100644 --- a/examples/gradle/wrapper/gradle-wrapper.properties +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca164914..3ab0b725efc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/interop-testing/build.gradle b/interop-testing/build.gradle index 944c0daab81..3790479f03f 100644 --- a/interop-testing/build.gradle +++ b/interop-testing/build.gradle @@ -68,7 +68,7 @@ test { // Note that OkHttp currently only supports ALPN, so OpenSSL version >= 1.0.2 is required. task test_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.TestServiceClient" + mainClass = "io.grpc.testing.integration.TestServiceClient" applicationName = "test-client" defaultJvmOpts = [ "-javaagent:JAVAAGENT_APP_HOME" + configurations.alpnagent.singleFile.name @@ -82,21 +82,21 @@ task test_client(type: CreateStartScripts) { } task test_server(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.TestServiceServer" + mainClass = "io.grpc.testing.integration.TestServiceServer" applicationName = "test-server" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task reconnect_test_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.ReconnectTestClient" + mainClass = "io.grpc.testing.integration.ReconnectTestClient" applicationName = "reconnect-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task stresstest_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.StressTestClient" + mainClass = "io.grpc.testing.integration.StressTestClient" applicationName = "stresstest-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath @@ -107,14 +107,14 @@ task stresstest_client(type: CreateStartScripts) { } task http2_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.Http2Client" + mainClass = "io.grpc.testing.integration.Http2Client" applicationName = "http2-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task grpclb_long_lived_affinity_test_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.GrpclbLongLivedAffinityTestClient" + mainClass = "io.grpc.testing.integration.GrpclbLongLivedAffinityTestClient" applicationName = "grpclb-long-lived-affinity-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath @@ -124,7 +124,7 @@ task grpclb_long_lived_affinity_test_client(type: CreateStartScripts) { } task grpclb_fallback_test_client (type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.GrpclbFallbackTestClient" + mainClass = "io.grpc.testing.integration.GrpclbFallbackTestClient" applicationName = "grpclb-fallback-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath @@ -134,14 +134,14 @@ task grpclb_fallback_test_client (type: CreateStartScripts) { } task xds_test_client(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.XdsTestClient" + mainClass = "io.grpc.testing.integration.XdsTestClient" applicationName = "xds-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath } task xds_test_server(type: CreateStartScripts) { - mainClassName = "io.grpc.testing.integration.XdsTestServer" + mainClass = "io.grpc.testing.integration.XdsTestServer" applicationName = "xds-test-server" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) classpath = startScripts.classpath diff --git a/netty/build.gradle b/netty/build.gradle index 00726940cde..5fdc8f20f08 100644 --- a/netty/build.gradle +++ b/netty/build.gradle @@ -3,7 +3,7 @@ plugins { id "maven-publish" id "me.champeau.gradle.japicmp" - id "me.champeau.gradle.jmh" + id "me.champeau.jmh" id "ru.vyarus.animalsniffer" } diff --git a/settings.gradle b/settings.gradle index a09ee35ade4..086a2312137 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,14 +3,14 @@ pluginManagement { id "com.android.application" version "4.2.0" id "com.android.library" version "4.2.0" id "com.github.johnrengelman.shadow" version "6.1.0" - id "com.github.kt3k.coveralls" version "2.10.2" - id "com.google.osdetector" version "1.6.2" - id "com.google.protobuf" version "0.8.17" - id "digital.wup.android-maven-publish" version "3.6.2" - id "me.champeau.gradle.japicmp" version "0.2.5" - id "me.champeau.gradle.jmh" version "0.5.2" - id "net.ltgt.errorprone" version "1.3.0" - id "ru.vyarus.animalsniffer" version "1.5.2" + id "com.github.kt3k.coveralls" version "2.12.0" + id "com.google.osdetector" version "1.7.0" + id "com.google.protobuf" version "0.8.18" + id "digital.wup.android-maven-publish" version "3.6.3" + id "me.champeau.gradle.japicmp" version "0.3.0" + id "me.champeau.jmh" version "0.6.6" + id "net.ltgt.errorprone" version "2.0.2" + id "ru.vyarus.animalsniffer" version "1.5.4" } resolutionStrategy { eachPlugin { From 23a2202efa89ebee83f296e36d01e35cc9489d98 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Fri, 7 Jan 2022 16:22:30 -0500 Subject: [PATCH 0028/1995] xds: Rename ring_hash LB Policy to ring_hash_experimental (#8776) Ring hash can only be used from within xds currently, because that's the only way to get a hash assigned to RPCs which is required for it to function. So it should be using the _experimental suffix like the other only-used-from-xds policies. --- xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java | 2 +- .../java/io/grpc/xds/ClusterResolverLoadBalancer.java | 8 ++++---- .../io/grpc/xds/ClusterResolverLoadBalancerProvider.java | 2 +- .../java/io/grpc/xds/RingHashLoadBalancerProvider.java | 4 ++-- xds/src/main/java/io/grpc/xds/XdsClient.java | 4 ++-- xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java | 4 ++-- .../test/java/io/grpc/xds/ClientXdsClientTestBase.java | 4 ++-- xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java | 4 ++-- xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java | 4 ++-- .../java/io/grpc/xds/ClusterResolverLoadBalancerTest.java | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java b/xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java index 396292a2392..7735199134f 100644 --- a/xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java +++ b/xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java @@ -187,7 +187,7 @@ private void handleClusterDiscovered() { LoadBalancerProvider lbProvider = null; Object lbConfig = null; if (root.result.lbPolicy() == LbPolicy.RING_HASH) { - lbProvider = lbRegistry.getProvider("ring_hash"); + lbProvider = lbRegistry.getProvider("ring_hash_experimental"); lbConfig = new RingHashConfig(root.result.minRingSize(), root.result.maxRingSize()); } if (lbProvider == null) { diff --git a/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java b/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java index f4fcabcb21f..e4800cf668c 100644 --- a/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java +++ b/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java @@ -672,7 +672,7 @@ private static PriorityChildConfig generateDnsBasedPriorityChildConfig( * Generates configs to be used in the priority LB policy for priorities in an EDS cluster. * *

priority LB -> cluster_impl LB (one per priority) -> (weighted_target LB - * -> round_robin (one per locality)) / ring_hash + * -> round_robin (one per locality)) / ring_hash_experimental */ private static Map generateEdsBasedPriorityChildConfigs( String cluster, @Nullable String edsServiceName, @Nullable ServerInfo lrsServerInfo, @@ -687,9 +687,9 @@ private static Map generateEdsBasedPriorityChildCon // created. If the endpoint-level LB policy is round_robin, it creates a two-level LB // hierarchy: a locality-level LB policy that balances load according to locality weights // followed by an endpoint-level LB policy that simply rounds robin the endpoints within - // the locality. If the endpoint-level LB policy is ring_hash, it creates a unified LB - // policy that balances load by weighing the product of each endpoint's weight and the - // weight of the locality it belongs to. + // the locality. If the endpoint-level LB policy is ring_hash_experimental, it creates + // a unified LB policy that balances load by weighing the product of each endpoint's weight + // and the weight of the locality it belongs to. if (endpointLbPolicy.getProvider().getPolicyName().equals("round_robin")) { Map localityWeights = prioritizedLocalityWeights.get(priority); Map targets = new HashMap<>(); diff --git a/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java b/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java index 551c2c296fc..4aaf0dcadde 100644 --- a/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java +++ b/xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java @@ -68,7 +68,7 @@ public LoadBalancer newLoadBalancer(Helper helper) { static final class ClusterResolverConfig { // Ordered list of clusters to be resolved. final List discoveryMechanisms; - // Endpoint-level load balancing policy with config (round_robin or ring_hash). + // Endpoint-level load balancing policy with config (round_robin or ring_hash_experimental). final PolicySelection lbPolicy; ClusterResolverConfig(List discoveryMechanisms, PolicySelection lbPolicy) { diff --git a/xds/src/main/java/io/grpc/xds/RingHashLoadBalancerProvider.java b/xds/src/main/java/io/grpc/xds/RingHashLoadBalancerProvider.java index 102a18000a9..0df4c8c2984 100644 --- a/xds/src/main/java/io/grpc/xds/RingHashLoadBalancerProvider.java +++ b/xds/src/main/java/io/grpc/xds/RingHashLoadBalancerProvider.java @@ -29,7 +29,7 @@ import java.util.Map; /** - * The provider for the "ring_hash" balancing policy. + * The provider for the "ring_hash_experimental" balancing policy. */ @Internal public final class RingHashLoadBalancerProvider extends LoadBalancerProvider { @@ -66,7 +66,7 @@ public int getPriority() { @Override public String getPolicyName() { - return "ring_hash"; + return "ring_hash_experimental"; } @Override diff --git a/xds/src/main/java/io/grpc/xds/XdsClient.java b/xds/src/main/java/io/grpc/xds/XdsClient.java index 65d4d67c427..024500253a3 100644 --- a/xds/src/main/java/io/grpc/xds/XdsClient.java +++ b/xds/src/main/java/io/grpc/xds/XdsClient.java @@ -113,10 +113,10 @@ abstract static class CdsUpdate implements ResourceUpdate { // Endpoint-level load balancing policy. abstract LbPolicy lbPolicy(); - // Only valid if lbPolicy is "ring_hash". + // Only valid if lbPolicy is "ring_hash_experimental". abstract long minRingSize(); - // Only valid if lbPolicy is "ring_hash". + // Only valid if lbPolicy is "ring_hash_experimental". abstract long maxRingSize(); // Alternative resource name to be used in EDS requests. diff --git a/xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java b/xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java index 388fc6a8b20..7664660d4c6 100644 --- a/xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java +++ b/xds/src/test/java/io/grpc/xds/CdsLoadBalancer2Test.java @@ -120,7 +120,7 @@ public void setUp() { when(helper.getSynchronizationContext()).thenReturn(syncContext); lbRegistry.register(new FakeLoadBalancerProvider(CLUSTER_RESOLVER_POLICY_NAME)); lbRegistry.register(new FakeLoadBalancerProvider("round_robin")); - lbRegistry.register(new FakeLoadBalancerProvider("ring_hash")); + lbRegistry.register(new FakeLoadBalancerProvider("ring_hash_experimental")); loadBalancer = new CdsLoadBalancer2(helper, lbRegistry); loadBalancer.handleResolvedAddresses( ResolvedAddresses.newBuilder() @@ -283,7 +283,7 @@ public void discoverAggregateCluster() { assertDiscoveryMechanism(childLbConfig.discoveryMechanisms.get(2), cluster4, DiscoveryMechanism.Type.EDS, null, null, LRS_SERVER_INFO, 300L, null); assertThat(childLbConfig.lbPolicy.getProvider().getPolicyName()) - .isEqualTo("ring_hash"); // dominated by top-level cluster's config + .isEqualTo("ring_hash_experimental"); // dominated by top-level cluster's config assertThat(((RingHashConfig) childLbConfig.lbPolicy.getConfig()).minRingSize).isEqualTo(100L); assertThat(((RingHashConfig) childLbConfig.lbPolicy.getConfig()).maxRingSize).isEqualTo(1000L); } diff --git a/xds/src/test/java/io/grpc/xds/ClientXdsClientTestBase.java b/xds/src/test/java/io/grpc/xds/ClientXdsClientTestBase.java index 6fdf5e1b811..42cf9baa1d9 100644 --- a/xds/src/test/java/io/grpc/xds/ClientXdsClientTestBase.java +++ b/xds/src/test/java/io/grpc/xds/ClientXdsClientTestBase.java @@ -1483,8 +1483,8 @@ public void cdsResourceFound_ringHashLbPolicy() { DiscoveryRpcCall call = startResourceWatcher(CDS, CDS_RESOURCE, cdsResourceWatcher); Message ringHashConfig = mf.buildRingHashLbConfig("xx_hash", 10L, 100L); Any clusterRingHash = Any.pack( - mf.buildEdsCluster(CDS_RESOURCE, null, "ring_hash", ringHashConfig, false, null, - "envoy.transport_sockets.tls", null + mf.buildEdsCluster(CDS_RESOURCE, null, "ring_hash_experimental", ringHashConfig, false, + null, "envoy.transport_sockets.tls", null )); call.sendResponse(ResourceType.CDS, clusterRingHash, VERSION_1, "0000"); diff --git a/xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java b/xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java index 1a69b6fc650..be28f07b73c 100644 --- a/xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java +++ b/xds/src/test/java/io/grpc/xds/ClientXdsClientV2Test.java @@ -438,7 +438,7 @@ protected Message buildAggregateCluster(String clusterName, String lbPolicy, Cluster.Builder builder = Cluster.newBuilder().setName(clusterName).setClusterType(type); if (lbPolicy.equals("round_robin")) { builder.setLbPolicy(LbPolicy.ROUND_ROBIN); - } else if (lbPolicy.equals("ring_hash")) { + } else if (lbPolicy.equals("ring_hash_experimental")) { builder.setLbPolicy(LbPolicy.RING_HASH); builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig); } else { @@ -454,7 +454,7 @@ private Cluster.Builder initClusterBuilder(String clusterName, String lbPolicy, builder.setName(clusterName); if (lbPolicy.equals("round_robin")) { builder.setLbPolicy(LbPolicy.ROUND_ROBIN); - } else if (lbPolicy.equals("ring_hash")) { + } else if (lbPolicy.equals("ring_hash_experimental")) { builder.setLbPolicy(LbPolicy.RING_HASH); builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig); } else { diff --git a/xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java b/xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java index 6df36e1c31e..69e75292778 100644 --- a/xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java +++ b/xds/src/test/java/io/grpc/xds/ClientXdsClientV3Test.java @@ -494,7 +494,7 @@ protected Message buildAggregateCluster(String clusterName, String lbPolicy, Cluster.Builder builder = Cluster.newBuilder().setName(clusterName).setClusterType(type); if (lbPolicy.equals("round_robin")) { builder.setLbPolicy(LbPolicy.ROUND_ROBIN); - } else if (lbPolicy.equals("ring_hash")) { + } else if (lbPolicy.equals("ring_hash_experimental")) { builder.setLbPolicy(LbPolicy.RING_HASH); builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig); } else { @@ -511,7 +511,7 @@ private Cluster.Builder initClusterBuilder(String clusterName, String lbPolicy, builder.setName(clusterName); if (lbPolicy.equals("round_robin")) { builder.setLbPolicy(LbPolicy.ROUND_ROBIN); - } else if (lbPolicy.equals("ring_hash")) { + } else if (lbPolicy.equals("ring_hash_experimental")) { builder.setLbPolicy(LbPolicy.RING_HASH); builder.setRingHashLbConfig((RingHashLbConfig) ringHashLbConfig); } else { diff --git a/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java b/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java index ccc1975265d..a85f476ed4b 100644 --- a/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java +++ b/xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java @@ -135,7 +135,7 @@ public void uncaughtException(Thread t, Throwable e) { private final PolicySelection roundRobin = new PolicySelection(new FakeLoadBalancerProvider("round_robin"), null); private final PolicySelection ringHash = new PolicySelection( - new FakeLoadBalancerProvider("ring_hash"), new RingHashConfig(10L, 100L)); + new FakeLoadBalancerProvider("ring_hash_experimental"), new RingHashConfig(10L, 100L)); private final List childBalancers = new ArrayList<>(); private final List resolvers = new ArrayList<>(); private final FakeXdsClient xdsClient = new FakeXdsClient(); @@ -260,7 +260,7 @@ public void edsClustersWithRingHashEndpointLbPolicy() { ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig(); assertClusterImplConfig(clusterImplConfig, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L, - tlsContext, Collections.emptyList(), "ring_hash"); + tlsContext, Collections.emptyList(), "ring_hash_experimental"); RingHashConfig ringHashConfig = (RingHashConfig) clusterImplConfig.childPolicy.getConfig(); assertThat(ringHashConfig.minRingSize).isEqualTo(10L); From a74a3ad83498a3a939d863790670914b3ebd6776 Mon Sep 17 00:00:00 2001 From: Jintao Date: Sat, 8 Jan 2022 07:03:14 +0800 Subject: [PATCH 0029/1995] use charset from StandardCharsets instead of 'Charset.forName' (#8779) Co-authored-by: Penn (Dapeng) Zhang --- api/src/jmh/java/io/grpc/StatusBenchmark.java | 8 ++++---- api/src/main/java/io/grpc/DecompressorRegistry.java | 4 ++-- api/src/main/java/io/grpc/InternalMetadata.java | 3 ++- api/src/test/java/io/grpc/StatusTest.java | 4 +++- .../main/java/io/grpc/internal/ClientCallImpl.java | 4 ++-- core/src/main/java/io/grpc/internal/GrpcUtil.java | 3 ++- .../main/java/io/grpc/cronet/CronetClientStream.java | 10 +++++----- .../java/io/grpc/cronet/CronetClientStreamTest.java | 12 ++++++------ .../io/grpc/examples/advanced/JsonMarshaller.java | 3 ++- .../io/grpc/examples/routeguide/RouteGuideUtil.java | 4 ++-- .../grpc/testing/integration/TestServiceClient.java | 3 ++- .../io/grpc/testing/integration/CompressionTest.java | 4 ++-- .../java/io/grpc/okhttp/OkHttpClientStreamTest.java | 4 ++-- .../main/java/io/grpc/okhttp/internal/Util.java | 3 ++- .../io/grpc/protobuf/services/BinlogHelperTest.java | 3 ++- 15 files changed, 40 insertions(+), 32 deletions(-) diff --git a/api/src/jmh/java/io/grpc/StatusBenchmark.java b/api/src/jmh/java/io/grpc/StatusBenchmark.java index e3f087c6204..846682c3298 100644 --- a/api/src/jmh/java/io/grpc/StatusBenchmark.java +++ b/api/src/jmh/java/io/grpc/StatusBenchmark.java @@ -16,7 +16,7 @@ package io.grpc; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -57,7 +57,7 @@ public byte[] messageEncodeEscape() { @OutputTimeUnit(TimeUnit.NANOSECONDS) public String messageDecodePlain() { return Status.MESSAGE_KEY.parseBytes( - "Unexpected RST in stream".getBytes(Charset.forName("US-ASCII"))); + "Unexpected RST in stream".getBytes(StandardCharsets.US_ASCII)); } /** @@ -68,7 +68,7 @@ public String messageDecodePlain() { @OutputTimeUnit(TimeUnit.NANOSECONDS) public String messageDecodeEscape() { return Status.MESSAGE_KEY.parseBytes( - "Some Error%10Wasabi and Horseradish are the same".getBytes(Charset.forName("US-ASCII"))); + "Some Error%10Wasabi and Horseradish are the same".getBytes(StandardCharsets.US_ASCII)); } /** @@ -88,7 +88,7 @@ public byte[] codeEncode() { @BenchmarkMode(Mode.SampleTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public Status codeDecode() { - return Status.CODE_KEY.parseBytes("15".getBytes(Charset.forName("US-ASCII"))); + return Status.CODE_KEY.parseBytes("15".getBytes(StandardCharsets.US_ASCII)); } } diff --git a/api/src/main/java/io/grpc/DecompressorRegistry.java b/api/src/main/java/io/grpc/DecompressorRegistry.java index ea0433d8d0a..b2669d3c0fc 100644 --- a/api/src/main/java/io/grpc/DecompressorRegistry.java +++ b/api/src/main/java/io/grpc/DecompressorRegistry.java @@ -20,7 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Joiner; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; @@ -85,7 +85,7 @@ private DecompressorRegistry(Decompressor d, boolean advertised, DecompressorReg decompressors = Collections.unmodifiableMap(newDecompressors); advertisedDecompressors = ACCEPT_ENCODING_JOINER.join(getAdvertisedMessageEncodings()) - .getBytes(Charset.forName("US-ASCII")); + .getBytes(StandardCharsets.US_ASCII); } private DecompressorRegistry() { diff --git a/api/src/main/java/io/grpc/InternalMetadata.java b/api/src/main/java/io/grpc/InternalMetadata.java index 2823882952f..cb98ad752b2 100644 --- a/api/src/main/java/io/grpc/InternalMetadata.java +++ b/api/src/main/java/io/grpc/InternalMetadata.java @@ -20,6 +20,7 @@ import io.grpc.Metadata.AsciiMarshaller; import io.grpc.Metadata.BinaryStreamMarshaller; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * Internal {@link Metadata} accessor. This is intended for use by io.grpc.internal, and the @@ -42,7 +43,7 @@ public interface TrustedAsciiMarshaller extends Metadata.TrustedAsciiMarshall * Copy of StandardCharsets, which is only available on Java 1.7 and above. */ @Internal - public static final Charset US_ASCII = Charset.forName("US-ASCII"); + public static final Charset US_ASCII = StandardCharsets.US_ASCII; /** * An instance of base64 encoder that omits padding. diff --git a/api/src/test/java/io/grpc/StatusTest.java b/api/src/test/java/io/grpc/StatusTest.java index 9abeba436f7..aca5dc8ee66 100644 --- a/api/src/test/java/io/grpc/StatusTest.java +++ b/api/src/test/java/io/grpc/StatusTest.java @@ -21,6 +21,8 @@ import io.grpc.Status.Code; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -28,7 +30,7 @@ /** Unit tests for {@link Status}. */ @RunWith(JUnit4.class) public class StatusTest { - private final Charset ascii = Charset.forName("US-ASCII"); + private final Charset ascii = StandardCharsets.US_ASCII; @Test public void verifyExceptionMessage() { diff --git a/core/src/main/java/io/grpc/internal/ClientCallImpl.java b/core/src/main/java/io/grpc/internal/ClientCallImpl.java index db1a992b968..e60f9e54b47 100644 --- a/core/src/main/java/io/grpc/internal/ClientCallImpl.java +++ b/core/src/main/java/io/grpc/internal/ClientCallImpl.java @@ -53,7 +53,7 @@ import io.perfmark.PerfMark; import io.perfmark.Tag; import java.io.InputStream; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; @@ -71,7 +71,7 @@ final class ClientCallImpl extends ClientCall { private static final Logger log = Logger.getLogger(ClientCallImpl.class.getName()); private static final byte[] FULL_STREAM_DECOMPRESSION_ENCODINGS - = "gzip".getBytes(Charset.forName("US-ASCII")); + = "gzip".getBytes(StandardCharsets.US_ASCII); private final MethodDescriptor method; private final Tag tag; diff --git a/core/src/main/java/io/grpc/internal/GrpcUtil.java b/core/src/main/java/io/grpc/internal/GrpcUtil.java index c997414eabe..bce1a0f1503 100644 --- a/core/src/main/java/io/grpc/internal/GrpcUtil.java +++ b/core/src/main/java/io/grpc/internal/GrpcUtil.java @@ -55,6 +55,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; import java.util.concurrent.Executor; @@ -75,7 +76,7 @@ public final class GrpcUtil { private static final Logger log = Logger.getLogger(GrpcUtil.class.getName()); - public static final Charset US_ASCII = Charset.forName("US-ASCII"); + public static final Charset US_ASCII = StandardCharsets.US_ASCII; /** * {@link io.grpc.Metadata.Key} for the timeout header. diff --git a/cronet/src/main/java/io/grpc/cronet/CronetClientStream.java b/cronet/src/main/java/io/grpc/cronet/CronetClientStream.java index d44b716146e..7329ed08c5d 100644 --- a/cronet/src/main/java/io/grpc/cronet/CronetClientStream.java +++ b/cronet/src/main/java/io/grpc/cronet/CronetClientStream.java @@ -44,7 +44,7 @@ import java.lang.reflect.Method; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -408,10 +408,10 @@ private void setGrpcHeaders(BidirectionalStream.Builder builder) { // String and byte array. byte[][] serializedHeaders = TransportFrameUtil.toHttp2Headers(headers); for (int i = 0; i < serializedHeaders.length; i += 2) { - String key = new String(serializedHeaders[i], Charset.forName("UTF-8")); + String key = new String(serializedHeaders[i], StandardCharsets.UTF_8); // TODO(ericgribkoff): log an error or throw an exception if (isApplicationHeader(key)) { - String value = new String(serializedHeaders[i + 1], Charset.forName("UTF-8")); + String value = new String(serializedHeaders[i + 1], StandardCharsets.UTF_8); builder.addHeader(key, value); } } @@ -588,8 +588,8 @@ private void reportHeaders(List> headers, boolean endO byte[][] headerValues = new byte[headerList.size()][]; for (int i = 0; i < headerList.size(); i += 2) { - headerValues[i] = headerList.get(i).getBytes(Charset.forName("UTF-8")); - headerValues[i + 1] = headerList.get(i + 1).getBytes(Charset.forName("UTF-8")); + headerValues[i] = headerList.get(i).getBytes(StandardCharsets.UTF_8); + headerValues[i + 1] = headerList.get(i + 1).getBytes(StandardCharsets.UTF_8); } Metadata metadata = InternalMetadata.newMetadata(TransportFrameUtil.toRawSerializedHeaders(headerValues)); diff --git a/cronet/src/test/java/io/grpc/cronet/CronetClientStreamTest.java b/cronet/src/test/java/io/grpc/cronet/CronetClientStreamTest.java index 48ce71c493f..9b63601d717 100644 --- a/cronet/src/test/java/io/grpc/cronet/CronetClientStreamTest.java +++ b/cronet/src/test/java/io/grpc/cronet/CronetClientStreamTest.java @@ -46,7 +46,7 @@ import java.io.ByteArrayInputStream; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -168,7 +168,7 @@ public void write() { for (int i = 0; i < 5; ++i) { requests[i] = new String("request" + String.valueOf(i)); buffers[i] = allocator.allocate(requests[i].length()); - buffers[i].write(requests[i].getBytes(Charset.forName("UTF-8")), 0, requests[i].length()); + buffers[i].write(requests[i].getBytes(StandardCharsets.UTF_8), 0, requests[i].length()); // The 3rd and 5th writeFrame calls have flush=true. clientStream.abstractClientStreamSink().writeFrame(buffers[i], false, i == 2 || i == 4, 1); } @@ -261,7 +261,7 @@ public void read() { callback.onReadCompleted( cronetStream, info, - createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))), + createMessageFrame(new String("response1").getBytes(StandardCharsets.UTF_8)), false); // Haven't request any message, so no callback is called here. verify(clientListener, times(0)).messagesAvailable(isA(MessageProducer.class)); @@ -293,7 +293,7 @@ public void streamSucceeded() { CronetWritableBufferAllocator allocator = new CronetWritableBufferAllocator(); String request = new String("request"); WritableBuffer writableBuffer = allocator.allocate(request.length()); - writableBuffer.write(request.getBytes(Charset.forName("UTF-8")), 0, request.length()); + writableBuffer.write(request.getBytes(StandardCharsets.UTF_8), 0, request.length()); clientStream.abstractClientStreamSink().writeFrame(writableBuffer, false, true, 1); ArgumentCaptor bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class); verify(cronetStream, times(1)).write(bufferCaptor.capture(), isA(Boolean.class)); @@ -312,7 +312,7 @@ public void streamSucceeded() { callback.onReadCompleted( cronetStream, info, - createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))), + createMessageFrame(new String("response").getBytes(StandardCharsets.UTF_8)), false); verify(clientListener, times(1)).messagesAvailable(isA(MessageProducer.class)); verify(cronetStream, times(2)).read(isA(ByteBuffer.class)); @@ -688,7 +688,7 @@ public void getUnaryRequest() { .newBidirectionalStreamBuilder( isA(String.class), isA(BidirectionalStream.Callback.class), isA(Executor.class)); - byte[] msg = "request".getBytes(Charset.forName("UTF-8")); + byte[] msg = "request".getBytes(StandardCharsets.UTF_8); stream.writeMessage(new ByteArrayInputStream(msg)); // We still haven't built the stream or sent anything. verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class)); diff --git a/examples/src/main/java/io/grpc/examples/advanced/JsonMarshaller.java b/examples/src/main/java/io/grpc/examples/advanced/JsonMarshaller.java index 8b3068cc009..fbe3fa50afc 100644 --- a/examples/src/main/java/io/grpc/examples/advanced/JsonMarshaller.java +++ b/examples/src/main/java/io/grpc/examples/advanced/JsonMarshaller.java @@ -30,6 +30,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * A {@link Marshaller} for JSON. This marshals in the Protobuf 3 format described here: @@ -58,7 +59,7 @@ public static Marshaller jsonMarshaller(final T defaultIn public static Marshaller jsonMarshaller( final T defaultInstance, final Parser parser, final Printer printer) { - final Charset charset = Charset.forName("UTF-8"); + final Charset charset = StandardCharsets.UTF_8; return new Marshaller() { @Override diff --git a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java index 6e49492da06..0794674091f 100644 --- a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java +++ b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideUtil.java @@ -22,7 +22,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.List; /** @@ -58,7 +58,7 @@ public static URL getDefaultFeaturesFile() { public static List parseFeatures(URL file) throws IOException { InputStream input = file.openStream(); try { - Reader reader = new InputStreamReader(input, Charset.forName("UTF-8")); + Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8); try { FeatureDatabase.Builder database = FeatureDatabase.newBuilder(); JsonFormat.parser().merge(reader, database); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index 914db12e5a8..8ac50419d5f 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -40,6 +40,7 @@ import java.io.File; import java.io.FileInputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; @@ -50,7 +51,7 @@ */ public class TestServiceClient { - private static final Charset UTF_8 = Charset.forName("UTF-8"); + private static final Charset UTF_8 = StandardCharsets.UTF_8; /** * The main application allowing this client to be launched from the command line. diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java index 208eb40c438..fdd3ac63011 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/CompressionTest.java @@ -52,7 +52,7 @@ import io.grpc.testing.integration.Messages.SimpleResponse; import io.grpc.testing.integration.TestServiceGrpc.TestServiceBlockingStub; import io.grpc.testing.integration.TransportCompressionTest.Fzip; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -312,6 +312,6 @@ public void onHeaders(Metadata headers) { } private static void assertEqualsString(String expected, byte[] actual) { - assertEquals(expected, new String(actual, Charset.forName("US-ASCII"))); + assertEquals(expected, new String(actual, StandardCharsets.US_ASCII)); } } diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientStreamTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientStreamTest.java index 99a9159eab0..46a49463e5f 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientStreamTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientStreamTest.java @@ -42,7 +42,7 @@ import io.grpc.okhttp.internal.framed.Header; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; @@ -243,7 +243,7 @@ public void getUnaryRequest() throws IOException { eq(false), eq(false), eq(3), eq(0), headersCaptor.capture()); verify(transport, times(0)).streamReadyToStart(isA(OkHttpClientStream.class)); - byte[] msg = "request".getBytes(Charset.forName("UTF-8")); + byte[] msg = "request".getBytes(StandardCharsets.UTF_8); stream.writeMessage(new ByteArrayInputStream(msg)); stream.halfClose(); verify(transport).streamReadyToStart(eq(stream)); diff --git a/okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/Util.java b/okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/Util.java index 556d849c705..a961c605656 100644 --- a/okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/Util.java +++ b/okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/Util.java @@ -27,6 +27,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -47,7 +48,7 @@ public final class Util { public static final String[] EMPTY_STRING_ARRAY = new String[0]; /** A cheap and type-safe constant for the UTF-8 Charset. */ - public static final Charset UTF_8 = Charset.forName("UTF-8"); + public static final Charset UTF_8 = StandardCharsets.UTF_8; private Util() { } diff --git a/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java b/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java index 37e503ccd41..23022192be3 100644 --- a/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java +++ b/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java @@ -80,6 +80,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -94,7 +95,7 @@ /** Tests for {@link BinlogHelper}. */ @RunWith(JUnit4.class) public final class BinlogHelperTest { - private static final Charset US_ASCII = Charset.forName("US-ASCII"); + private static final Charset US_ASCII = StandardCharsets.US_ASCII; private static final BinlogHelper HEADER_FULL = new Builder().header(Integer.MAX_VALUE).build(); private static final BinlogHelper HEADER_256 = new Builder().header(256).build(); private static final BinlogHelper MSG_FULL = new Builder().msg(Integer.MAX_VALUE).build(); From d7f951a9d8a259682b786b711cd7431834a283cd Mon Sep 17 00:00:00 2001 From: sanjaypujare Date: Fri, 7 Jan 2022 15:34:59 -0800 Subject: [PATCH 0030/1995] all: update netty to 4.1.72.Final and tcnative to 2.0.46.Final (#8780) --- SECURITY.md | 3 ++- build.gradle | 4 ++-- buildscripts/kokoro/macos.cfg | 1 + .../java/io/grpc/netty/NettyTestUtil.java | 4 +++- .../grpc/netty/ProtocolNegotiatorsTest.java | 14 ++++++++++- repositories.bzl | 24 +++++++++---------- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index df9061eab8f..44efbe8d42e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -409,7 +409,8 @@ grpc-netty version | netty-handler version | netty-tcnative-boringssl-static ver 1.29.x-1.31.x | 4.1.48.Final | 2.0.30.Final 1.32.x-1.34.x | 4.1.51.Final | 2.0.31.Final 1.35.x-1.41.x | 4.1.52.Final | 2.0.34.Final -1.42.x- | 4.1.63.Final | 2.0.38.Final +1.42.x-1.43.x | 4.1.63.Final | 2.0.38.Final +1.44.x | 4.1.72.Final | 2.0.46.Final _(grpc-netty-shaded avoids issues with keeping these versions in sync.)_ diff --git a/build.gradle b/build.gradle index 84b281bc945..fa281a3a0d9 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ subprojects { protocPluginBaseName = 'protoc-gen-grpc-java' javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix" - nettyVersion = '4.1.63.Final' + nettyVersion = '4.1.72.Final' guavaVersion = '30.1.1-android' googleauthVersion = '0.22.2' protobufVersion = '3.19.2' @@ -176,7 +176,7 @@ subprojects { // SECURITY.md (multiple occurrences) // examples/example-tls/build.gradle // examples/example-tls/pom.xml - netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.38.Final', + netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.46.Final', conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:2.5.1', re2j: 'com.google.re2j:re2j:1.5', diff --git a/buildscripts/kokoro/macos.cfg b/buildscripts/kokoro/macos.cfg index 310e1130416..a6bf290d1ec 100644 --- a/buildscripts/kokoro/macos.cfg +++ b/buildscripts/kokoro/macos.cfg @@ -15,6 +15,7 @@ env_vars { # We always build mvn artifacts. action { define_artifacts { + regex: "github/grpc-java/**/build/reports/**" regex: "github/grpc-java/mvn-artifacts/**" } } diff --git a/netty/src/test/java/io/grpc/netty/NettyTestUtil.java b/netty/src/test/java/io/grpc/netty/NettyTestUtil.java index d030f53d118..802a6efcd58 100644 --- a/netty/src/test/java/io/grpc/netty/NettyTestUtil.java +++ b/netty/src/test/java/io/grpc/netty/NettyTestUtil.java @@ -67,7 +67,9 @@ public Executor getObject() { inUse = true; return new Executor() { @Override - public void execute(Runnable var1) { } + public void execute(Runnable var1) { + var1.run(); + } }; } diff --git a/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java b/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java index d333d1cc8c6..ca1ccde101c 100644 --- a/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java +++ b/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java @@ -48,6 +48,7 @@ import io.grpc.ServerCredentials; import io.grpc.ServerStreamTracer; import io.grpc.Status; +import io.grpc.StatusException; import io.grpc.StatusRuntimeException; import io.grpc.TlsChannelCredentials; import io.grpc.TlsServerCredentials; @@ -132,6 +133,7 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; +import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManagerFactory; import org.junit.After; @@ -415,7 +417,17 @@ public void from_tls_clientAuthRequire_noClientCert() throws Exception { .trustManager(caCert) .build(); Status status = expectFailedHandshake(channelCreds, serverCreds); - assertThat(status.getDescription()).isEqualTo("ssl exception"); + assertEquals(Status.Code.UNAVAILABLE, status.getCode()); + StatusException sre = status.asException(); + // because of netty/netty#11604 we need to check for both TLSv1.2 and v1.3 behaviors + if (sre.getCause() instanceof SSLHandshakeException) { + assertThat(sre).hasCauseThat().isInstanceOf(SSLHandshakeException.class); + assertThat(sre).hasCauseThat().hasMessageThat().contains("SSLV3_ALERT_HANDSHAKE_FAILURE"); + } else { + // Client cert verification is after handshake in TLSv1.3 + assertThat(sre).hasCauseThat().hasCauseThat().isInstanceOf(SSLException.class); + assertThat(sre).hasCauseThat().hasMessageThat().contains("CERTIFICATE_REQUIRED"); + } } @Test diff --git a/repositories.bzl b/repositories.bzl index e5e5ccb0a55..8ad5f109e6f 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -25,18 +25,18 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [ "com.google.truth:truth:1.0.1", "com.squareup.okhttp:okhttp:2.7.4", "com.squareup.okio:okio:1.17.5", - "io.netty:netty-buffer:4.1.63.Final", - "io.netty:netty-codec-http2:4.1.63.Final", - "io.netty:netty-codec-http:4.1.63.Final", - "io.netty:netty-codec-socks:4.1.63.Final", - "io.netty:netty-codec:4.1.63.Final", - "io.netty:netty-common:4.1.63.Final", - "io.netty:netty-handler-proxy:4.1.63.Final", - "io.netty:netty-handler:4.1.63.Final", - "io.netty:netty-resolver:4.1.63.Final", - "io.netty:netty-tcnative-boringssl-static:2.0.38.Final", - "io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.63.Final", - "io.netty:netty-transport:4.1.63.Final", + "io.netty:netty-buffer:4.1.72.Final", + "io.netty:netty-codec-http2:4.1.72.Final", + "io.netty:netty-codec-http:4.1.72.Final", + "io.netty:netty-codec-socks:4.1.72.Final", + "io.netty:netty-codec:4.1.72.Final", + "io.netty:netty-common:4.1.72.Final", + "io.netty:netty-handler-proxy:4.1.72.Final", + "io.netty:netty-handler:4.1.72.Final", + "io.netty:netty-resolver:4.1.72.Final", + "io.netty:netty-tcnative-boringssl-static:2.0.46.Final", + "io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.72.Final", + "io.netty:netty-transport:4.1.72.Final", "io.opencensus:opencensus-api:0.24.0", "io.opencensus:opencensus-contrib-grpc-metrics:0.24.0", "io.perfmark:perfmark-api:0.23.0", From e0dca93c6a96e1aa5bcb09d3f410f36da97bd4ce Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 10 Jan 2022 10:28:42 -0800 Subject: [PATCH 0031/1995] Bump to Gradle 7.3.3 Android Gradle plugin bumped to 4.2.0 in examples, for Gradle 7 compat and to match main build. Jib 3 changed default base image away from distroless, but we do want to use distroless. --- examples/android/clientcache/app/build.gradle | 4 +- examples/android/clientcache/build.gradle | 2 +- examples/android/helloworld/app/build.gradle | 4 +- examples/android/helloworld/build.gradle | 2 +- examples/android/routeguide/app/build.gradle | 4 +- examples/android/routeguide/build.gradle | 2 +- examples/android/strictmode/app/build.gradle | 4 +- examples/android/strictmode/build.gradle | 2 +- examples/example-hostname/build.gradle | 3 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- examples/gradlew | 282 +++++++++++------- examples/gradlew.bat | 43 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 282 +++++++++++------- gradlew.bat | 43 +-- settings.gradle | 2 +- 16 files changed, 409 insertions(+), 274 deletions(-) diff --git a/examples/android/clientcache/app/build.gradle b/examples/android/clientcache/app/build.gradle index 1b00d689488..a71611df7a5 100644 --- a/examples/android/clientcache/app/build.gradle +++ b/examples/android/clientcache/app/build.gradle @@ -6,12 +6,12 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { applicationId "io.grpc.clientcacheexample" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 29 multiDexEnabled true versionCode 1 versionName "1.0" diff --git a/examples/android/clientcache/build.gradle b/examples/android/clientcache/build.gradle index 0c3cae44980..8a94a30191e 100644 --- a/examples/android/clientcache/build.gradle +++ b/examples/android/clientcache/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.2.0' classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong diff --git a/examples/android/helloworld/app/build.gradle b/examples/android/helloworld/app/build.gradle index 82c4abe7550..cc84e9bcc5c 100644 --- a/examples/android/helloworld/app/build.gradle +++ b/examples/android/helloworld/app/build.gradle @@ -6,12 +6,12 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { applicationId "io.grpc.helloworldexample" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 1 versionName "1.0" } diff --git a/examples/android/helloworld/build.gradle b/examples/android/helloworld/build.gradle index 0c3cae44980..8a94a30191e 100644 --- a/examples/android/helloworld/build.gradle +++ b/examples/android/helloworld/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.2.0' classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong diff --git a/examples/android/routeguide/app/build.gradle b/examples/android/routeguide/app/build.gradle index 8e33ac40d39..5a43416a5fb 100644 --- a/examples/android/routeguide/app/build.gradle +++ b/examples/android/routeguide/app/build.gradle @@ -6,12 +6,12 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { applicationId "io.grpc.routeguideexample" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 1 versionName "1.0" } diff --git a/examples/android/routeguide/build.gradle b/examples/android/routeguide/build.gradle index 09d5b19589a..b1083bb867a 100644 --- a/examples/android/routeguide/build.gradle +++ b/examples/android/routeguide/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.2.0' classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong diff --git a/examples/android/strictmode/app/build.gradle b/examples/android/strictmode/app/build.gradle index 7b3de25c3f5..ad74597ed27 100644 --- a/examples/android/strictmode/app/build.gradle +++ b/examples/android/strictmode/app/build.gradle @@ -6,13 +6,13 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { applicationId "io.grpc.strictmodehelloworldexample" // API level 28 is required for StrictMode penaltyListener minSdkVersion 28 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" } diff --git a/examples/android/strictmode/build.gradle b/examples/android/strictmode/build.gradle index 0c3cae44980..8a94a30191e 100644 --- a/examples/android/strictmode/build.gradle +++ b/examples/android/strictmode/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.2.0' classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.18" // NOTE: Do not place your application dependencies here; they belong diff --git a/examples/example-hostname/build.gradle b/examples/example-hostname/build.gradle index e1476fe11f8..f40528e56ea 100644 --- a/examples/example-hostname/build.gradle +++ b/examples/example-hostname/build.gradle @@ -3,7 +3,7 @@ plugins { id 'java' id "com.google.protobuf" version "0.8.17" - id 'com.google.cloud.tools.jib' version '2.7.0' // For releasing to Docker Hub + id 'com.google.cloud.tools.jib' version '3.1.4' // For releasing to Docker Hub } repositories { @@ -56,6 +56,7 @@ mainClassName = 'io.grpc.examples.hostname.HostnameServer' // For releasing to Docker Hub jib { + from.image = "gcr.io/distroless/java:8" container.ports = ['50051'] outputPaths { tar = 'build/example-hostname.tar' diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties index 3ab0b725efc..2e6e5897b52 100644 --- a/examples/gradle/wrapper/gradle-wrapper.properties +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/gradlew b/examples/gradlew index cccdd3d517f..1b6c787337f 100755 --- a/examples/gradlew +++ b/examples/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/examples/gradlew.bat b/examples/gradlew.bat index e95643d6a2c..ac1b06f9382 100644 --- a/examples/gradlew.bat +++ b/examples/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3ab0b725efc..2e6e5897b52 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d517f..1b6c787337f 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d6a2c..ac1b06f9382 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 086a2312137..d60cddcbbac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { plugins { id "com.android.application" version "4.2.0" id "com.android.library" version "4.2.0" - id "com.github.johnrengelman.shadow" version "6.1.0" + id "com.github.johnrengelman.shadow" version "7.1.2" id "com.github.kt3k.coveralls" version "2.12.0" id "com.google.osdetector" version "1.7.0" id "com.google.protobuf" version "0.8.18" From 9e8375850b8b9709a040930ad686851f0eb25c94 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 10 Jan 2022 14:59:19 -0800 Subject: [PATCH 0032/1995] build.gradle: Add missing dependsOn for generated code sync When messing with error prone for another commit, Gradle started producing a clear warning the dependsOn was missing. But the warning was not reliable. However, even when no warning was printed it is clear the task was broken. --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index fa281a3a0d9..149ade4ae02 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { } import net.ltgt.gradle.errorprone.CheckSeverity +import org.gradle.util.GUtil subprojects { apply plugin: "checkstyle" @@ -97,6 +98,11 @@ subprojects { def syncTask = project.tasks.register("syncGeneratedSources${variantOrSourceSet}", Sync) { from "$buildDir/generated/source/proto/${variantOrSourceSet}/grpc" into "$generatedSourcePath/${variantOrSourceSet}/grpc" + String source = GUtil.toCamelCase(variantOrSourceSet) + if (source == "Main") { + source = "" + } + dependsOn "generate${source}Proto" } syncGeneratedSources.dependsOn syncTask From 56e9321d8a082f7f8a438cfa57a612d40c730219 Mon Sep 17 00:00:00 2001 From: sanjaypujare Date: Tue, 11 Jan 2022 09:12:46 -0800 Subject: [PATCH 0033/1995] android-interop-testing: add the linter error message ignore annotation in the source xml file (#8821) --- .../src/main/res/layout/activity_tester.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android-interop-testing/src/main/res/layout/activity_tester.xml b/android-interop-testing/src/main/res/layout/activity_tester.xml index f1339330227..9c511cab8da 100644 --- a/android-interop-testing/src/main/res/layout/activity_tester.xml +++ b/android-interop-testing/src/main/res/layout/activity_tester.xml @@ -46,6 +46,7 @@ android:layout_height="wrap_content" android:onClick="startEmptyUnary" android:text="Empty Unary" + tools:ignore="OnClick" />