8000 mark endpoint as Obsolete. · rmehta19/sdk-platform-java@926faca · GitHub
[go: up one dir, main page]

Skip to content

Commit 926faca

Browse files
committed
mark endpoint as Obsolete.
1 parent fb3d608 commit 926faca

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private static String getSystemProductName() {
421421
// Universe Domain configuration is currently only supported in the GDU
422422
@VisibleForTesting
423423
boolean canUseDirectPathWithUniverseDomain() {
424-
return endpoint.contains(Credentials.GOOGLE_DEFAULT_UNIVERSE);
424+
return endpointContext.resolvedEndpoint().contains(Credentials.GOOGLE_DEFAULT_UNIVERSE);
425425
}
426426

427427
@VisibleForTesting
@@ -542,20 +542,13 @@ private ManagedChannel createSingleChannel() throws IOException {
542542
GrpcMetadataHandlerInterceptor metadataHandlerInterceptor =
543543
new GrpcMetadataHandlerInterceptor();
544544

545-
int colon = endpoint.lastIndexOf(':');
545+
int colon = endpointContext.resolvedEndpoint().lastIndexOf(':');
546546
if (colon < 0) {
547-
throw new IllegalStateException("invalid endpoint - should have been validated: " + endpoint);
548-
}
549-
int port = Integer.parseInt(endpoint.substring(colon + 1));
550-
String serviceAddress = endpoint.substring(0, colon);
551-
552-
int mtlsColon = endpointContext.mtlsEndpoint().lastIndexOf(':');
553-
if (mtlsColon < 0) {
554547
throw new IllegalStateException(
555-
"invalid mtlsEndpoint - should have been validated: " + endpointContext.mtlsEndpoint());
548+
"invalid endpoint - should have been validated: " + endpointContext.resolvedEndpoint());
556549
}
557-
int mtlsPort = Integer.parseInt(endpointContext.mtlsEndpoint().substring(mtlsColon + 1));
558-
String mtlsServiceAddress = endpointContext.mtlsEndpoint().substring(0, mtlsColon);
550+
int port = Integer.parseInt(endpointContext.resolvedEndpoint().substring(colon + 1));
551+
String serviceAddress = endpointContext.resolvedEndpoint().substring(0, colon);
559552

560553
ManagedChannelBuilder<?> builder;
561554

@@ -589,7 +582,7 @@ private ManagedChannel createSingleChannel() throws IOException {
589582
}
590583
if (channelCredentials != null) {
591584
// Create the channel using channel credentials created via DCA.
592-
builder = Grpc.newChannelBuilder(endpoint, channelCredentials);
585+
builder = Grpc.newChannelBuilder(endpointContext.resolvedEndpoint(), channelCredentials);
593586
} else {
594587
// Could not create channel credentials via DCA. In accordance with
595588
// https://google.aip.dev/auth/4115, if credentials not available through
@@ -599,7 +592,7 @@ private ManagedChannel createSingleChannel() throws IOException {
599592
}
600593
if (channelCredentials != null) {
601594
// Create the channel using S2A-secured channel credentials.
602-
builder = Grpc.newChannelBuilder(mtlsServiceAddress, channelCredentials);
595+
builder = Grpc.newChannelBuilder(endpointContext.mtlsEndpoint(), channelCredentials);
603596
} else {
604597
// Use default if we cannot initialize channel credentials via DCA or S2A.
605598
builder = ManagedChannelBuilder.forAddress(serviceAddress, port);

gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686

8787
class InstantiatingGrpcChannelProviderTest extends AbstractMtlsTransportChannelTest {
8888
private static final String DEFAULT_ENDPOINT = "test.googleapis.com:443";
89-
private static final String DEFAULT_MTLS_ENDPOINT = "test.mtls.googleapis.com:443";
9089
private static final String API_KEY_HEADER_VALUE = "fake_api_key_2";
9190
private static final String API_KEY_AUTH_HEADER_KEY = "x-goog-api-key";
9291
private static String originalOSName;
@@ -206,7 +205,7 @@ void testWithPoolSize() throws IOException {
206205
executor.shutdown();
207206
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
208207
Mockito.when(endpointContext.useS2A()).thenReturn(false);
209-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
208+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
210209
TransportChannelProvider provider =
211210
InstantiatingGrpcChannelProvider.newBuilder()
212211
.build()
@@ -274,7 +273,7 @@ private void testWithInterceptors(int numChannels) throws Exception {
274273

275274
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
276275
Mockito.when(endpointContext.useS2A()).thenReturn(false);
277-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
276+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
278277

279278
InstantiatingGrpcChannelProvider channelProvider =
280279
InstantiatingGrpcChannelProvider.newBuilder()
@@ -312,7 +311,7 @@ void testChannelConfigurator() throws IOException {
312311

313312
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
314313
Mockito.when(endpointContext.useS2A()).thenReturn(false);
315-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
314+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
316315

317316
// Invoke the provider
318317
InstantiatingGrpcChannelProvider.newBuilder()
@@ -338,7 +337,7 @@ void testWithGCECredentials() throws IOException {
338337

339338
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
340339
Mockito.when(endpointContext.useS2A()).thenReturn(false);
341-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
340+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
342341

343342
TransportChannelProvider provider =
344343
InstantiatingGrpcChannelProvider.newBuilder()
@@ -424,7 +423,7 @@ void testWithNonGCECredentials() throws IOException {
424423

425424
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
426425
Mockito.when(endpointContext.useS2A()).thenReturn(false);
427-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
426+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
428427

429428
TransportChannelProvider provider =
430429
InstantiatingGrpcChannelProvider.newBuilder()
@@ -457,7 +456,7 @@ void testWithDirectPathDisabled() throws IOException {
457456

458457
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
459458
Mockito.when(endpointContext.useS2A()).thenReturn(false);
460-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
459+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
461460

462461
TransportChannelProvider provider =
463462
InstantiatingGrpcChannelProvider.newBuilder()
@@ -490,7 +489,7 @@ void testWithNoDirectPathFlagSet() throws IOException {
490489

491490
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
492491
Mockito.when(endpointContext.useS2A()).thenReturn(false);
493-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
492+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
494493

495494
TransportChannelProvider provider =
496495
InstantiatingGrpcChannelProvider.newBuilder()
@@ -515,7 +514,7 @@ void testWithIPv6Address() throws IOException {
515514

< 10000 code>516515
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
517516
Mockito.when(endpointContext.useS2A()).thenReturn(false);
518-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
517+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
519518

520519
TransportChannelProvider provider =
521520
InstantiatingGrpcChannelProvider.newBuilder()
@@ -535,7 +534,7 @@ void testWithIPv6Address() throws IOException {
535534
void testWithPrimeChannel() throws IOException {
536535
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
537536
Mockito.when(endpointContext.useS2A()).thenReturn(false);
538-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
537+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
539538
// create channelProvider with different pool sizes to verify ChannelPrimer is called the
540539
// correct number of times
541540
for (int poolSize = 1; poolSize < 5; poolSize++) {
@@ -669,7 +668,7 @@ private void createAndCloseTransportChannel(InstantiatingGrpcChannelProvider pro
669668
InstantiatingGrpcChannelProvider.LOG.addHandler(logHandler);
670669
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
671670
Mockito.when(endpointContext.useS2A()).thenReturn(false);
672-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
671+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
673672
InstantiatingGrpcChannelProvider provider =
674673
createChannelProviderBuilderForDirectPathLogTests()
675674
.setAttemptDirectPathXds()
@@ -717,7 +716,7 @@ void testLogDirectPathMisconfigWrongCredential() throws Exception {
717716
InstantiatingGrpcChannelProvider.LOG.addHandler(logHandler);
718717
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
719718
Mockito.when(endpointContext.useS2A()).thenReturn(false);
720-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
719+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
721720
InstantiatingGrpcChannelProvider provider =
722721
InstantiatingGrpcChannelProvider.newBuilder()
723722
.setAttemptDirectPathXds()
@@ -746,7 +745,7 @@ void testLogDirectPathMisconfigNotOnGCE() throws Exception {
746745
InstantiatingGrpcChannelProvider.LOG.addHandler(logHandler);
747746
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
748747
Mockito.when(endpointContext.useS2A()).thenReturn(false);
749-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
748+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
750749
InstantiatingGrpcChannelProvider provider =
751750
InstantiatingGrpcChannelProvider.newBuilder()
752751
.setAttemptDirectPathXds()
@@ -780,7 +779,7 @@ public void canUseDirectPath_happyPath() throws IOException {
780779
InstantiatingGrpcChannelProvider.DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))
781780
.thenReturn("false");
782781
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
783-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
782+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
784783
InstantiatingGrpcChannelProvider.Builder builder =
785784
InstantiatingGrpcChannelProvider.newBuilder()
786785
.setAttemptDirectPath(true)
@@ -809,7 +808,7 @@ public void canUseDirectPath_directPathEnvVarDisabled() throws IOException {
809808
.thenReturn("true");
810809
EndpointContext endpointContext = Mockito.mock(EndpointContext.class);
811810
Mockito.when(endpointContext.useS2A()).thenReturn(false);
812-
Mockito.when(endpointContext.mtlsEndpoint()).thenReturn(DEFAULT_MTLS_ENDPOINT);
811+
Mockito.when(endpointContext.resolvedEndpoint()).thenReturn(DEFAULT_ENDPOINT);
813812
InstantiatingGrpcChannelProvider.Builder builder =
814813
InstantiatingGrpcChannelProvider.newBuilder()
815814
.setAttemptDirectPath(true)

gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private HttpJsonTransportChannel createChannel() throws IOException, GeneralSecu
197197
// the channel will use a default executor for the calls.
198198
ManagedHttpJsonChannel channel =
199199
ManagedHttpJsonChannel.newBuilder()
200-
.setEndpoint(endpoint)
200+
.setEndpoint(endpointContext.resolvedEndpoint())
201201
.setExecutor(executor)
202202
.setHttpTransport(httpTransportToUse)
203203
.build();

gax-java/gax/src/main/java/com/google/api/gax/rpc/TransportChannelProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.google.api.core.BetaApi;
3333
import com.google.api.core.InternalExtensionOnly;
34+
import com.google.api.core.ObsoleteApi;
3435
import com.google.auth.Credentials;
3536
import java.io.IOException;
3637
import java.util.Map;
@@ -88,13 +89,15 @@ public interface TransportChannelProvider {
8889
TransportChannelProvider withHeaders(Map<String, String> headers);
8990

9091
/** True if the TransportProvider has no endpoint set. */
92+
@ObsoleteApi("Use endpointContext.resolvedEndpoint() instead")
9193
boolean needsEndpoint();
9294

9395
/**
9496
* Sets the endpoint to use when constructing a new {@link TransportChannel}.
9597
*
9698
* <p>This method should only be called if {@link #needsEndpoint()} returns true.
9799
*/
100+
@ObsoleteApi("Use endpointContext.resolvedEndpoint() instead")
98101
TransportChannelProvider withEndpoint(String endpoint);
99102

100103
/** Sets the {@link EndpointContext} when constructing a new {@link TransportChannel}. */

0 commit comments

Comments
 (0)
0