Skip to content

Commit d716e91

Browse files
committed
Merge branch 'main' into PR #2663 to update
2 parents 7b114e1 + 5c4a2c7 commit d716e91

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/GaxBasicChannelProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.internal.compat;
1717

18+
import com.google.api.core.ApiFunction;
1819
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
1920
import com.google.auth.Credentials;
2021
import com.google.bigtable.v2.FeatureFlags;
@@ -32,11 +33,15 @@
3233
import javax.annotation.Nullable;
3334

3435
public class GaxBasicChannelProvider implements ChannelProvider {
36+
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
3537
private final InstantiatingGrpcChannelProvider inner;
3638
private final @Nullable CallCredentials credentials;
3739

40+
@SuppressWarnings("rawtypes")
3841
public GaxBasicChannelProvider(
3942
InstantiatingGrpcChannelProvider inner, @Nullable Credentials credentials) {
43+
this.channelConfigurator =
44+
Optional.ofNullable(inner.toBuilder().getChannelConfigurator()).orElse(b -> b);
4045
this.inner = inner.toBuilder().setAttemptDirectPath(false).build();
4146
this.credentials = Optional.ofNullable(credentials).map(MoreCallCredentials::from).orElse(null);
4247
}
@@ -56,6 +61,7 @@ public ManagedChannelBuilder<?> newChannelBuilder() {
5661
if (credentials != null) {
5762
builder.intercept(new CredInterceptor(credentials));
5863
}
64+
builder = channelConfigurator.apply(builder);
5965
return builder;
6066
} catch (IOException e) {
6167
throw new RuntimeException("Gax channel provider failed to provide a channel builder", e);

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/GaxDirectAccessChannelProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.internal.compat;
1717

18+
import com.google.api.core.ApiFunction;
1819
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
1920
import com.google.auth.Credentials;
2021
import com.google.bigtable.v2.FeatureFlags;
@@ -26,6 +27,10 @@
2627

2728
public class GaxDirectAccessChannelProvider implements ChannelProvider {
2829
private final InstantiatingGrpcChannelProvider inner;
30+
31+
@SuppressWarnings("rawtypes")
32+
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
33+
2934
private final Optional<ChannelProvider> fallback;
3035

3136
public static ChannelProvider create(
@@ -67,6 +72,9 @@ private GaxDirectAccessChannelProvider(
6772
@SuppressWarnings("unused") @Nullable Credentials credentials,
6873
Optional<ChannelProvider> fallback) {
6974
this.inner = directAccessProvider;
75+
this.channelConfigurator =
76+
Optional.ofNullable(directAccessProvider.toBuilder().getChannelConfigurator())
77+
.orElse(b -> b);
7078
this.fallback = fallback;
7179
}
7280

@@ -81,7 +89,7 @@ public FeatureFlags updateFeatureFlags(FeatureFlags featureFlags) {
8189
@Override
8290
public ManagedChannelBuilder<?> newChannelBuilder() {
8391
try {
84-
return inner.createChannelBuilder();
92+
return channelConfigurator.apply(inner.createChannelBuilder());
8593
} catch (IOException e) {
8694
throw new RuntimeException("Gax channel provider failed to provide a channel builder", e);
8795
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/ops/DivertingUnaryCallable.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import io.grpc.StatusRuntimeException;
3535
import java.time.Duration;
3636
import java.util.concurrent.CompletableFuture;
37+
import java.util.concurrent.CompletionException;
38+
import java.util.concurrent.ExecutionException;
3739
import java.util.concurrent.ThreadLocalRandom;
3840

3941
/** A callable to fork traffic between classic and session based operations. */
@@ -110,15 +112,25 @@ private boolean useExperimental(ReqT req) {
110112
}
111113

112114
ApiException translateException(Throwable e) {
115+
Throwable cause = e;
116+
while (cause instanceof CompletionException || cause instanceof ExecutionException) {
117+
if (cause.getCause() != null) {
118+
cause = cause.getCause();
119+
} else {
120+
break;
121+
}
122+
}
123+
113124
Status.Code code = Status.Code.UNKNOWN;
114125

115-
if (e instanceof StatusRuntimeException) {
116-
code = ((StatusRuntimeException) e).getStatus().getCode();
126+
if (cause instanceof StatusRuntimeException) {
127+
code = ((StatusRuntimeException) cause).getStatus().getCode();
117128
}
118-
if (e instanceof StatusException) {
119-
code = ((StatusException) e).getStatus().getCode();
129+
if (cause instanceof StatusException) {
130+
code = ((StatusException) cause).getStatus().getCode();
120131
}
121132

122-
return ApiExceptionFactory.createException(e.getMessage(), e, GrpcStatusCode.of(code), false);
133+
return ApiExceptionFactory.createException(
134+
cause.getMessage(), e, GrpcStatusCode.of(code), false);
123135
}
124136
}

0 commit comments

Comments
 (0)