Skip to content

Commit 4942bc1

Browse files
lqiu96blakeli0
andauthored
feat: Client/StubSettings' getEndpoint() returns the resolved endpoint (#2440)
## Changes - Client|StubSettings `getEndpoint()` will now return the fully resolved endpoint - Client|StubSettings `getUniverseDomain()` will not return the fully resolved universe domain - Remove the generated `getEndpoint()` method in the {Client}StubSettings class. The call to `getEndpoint()` will now always hit the parent StubSettings and return the fully resolved endpoint. --------- Co-authored-by: Blake Li <[email protected]>
1 parent 8312706 commit 4942bc1

File tree

44 files changed

+569
-752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+569
-752
lines changed

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public class SettingsCommentComposer {
5252
private static final String CLASS_HEADER_DEFAULTS_RETRIES_DESCRIPTION =
5353
"Retries are configured for idempotent methods but not for non-idempotent methods.";
5454

55-
public static final CommentStatement GET_ENDPOINT_COMMENT =
56-
toSimpleComment(
57-
"Returns the endpoint set by the user or the the service's default endpoint.");
5855
public static final CommentStatement DEFAULT_SCOPES_COMMENT =
5956
toSimpleComment("The default scopes of the service.");
6057

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java

-41
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ private List<MethodDefinition> createClassMethods(
999999
javaMethods.addAll(
10001000
createMethodSettingsGetterMethods(methodSettingsMemberVarExprs, deprecatedSettingVarNames));
10011001
javaMethods.add(createCreateStubMethod(service, typeStore));
1002-
javaMethods.add(createGetEndpointMethod());
10031002
javaMethods.addAll(createDefaultHelperAndGetterMethods(service, typeStore));
10041003
javaMethods.addAll(
10051004
createNewBuilderMethods(
@@ -1013,45 +1012,6 @@ private List<MethodDefinition> createClassMethods(
10131012
return javaMethods;
10141013
}
10151014

1016-
// Helper method to create the getEndpoint method in the ServiceStubSettings class
1017-
private MethodDefinition createGetEndpointMethod() {
1018-
Expr getEndpointExpr =
1019-
MethodInvocationExpr.builder()
1020-
.setMethodName("getEndpoint")
1021-
.setExprReferenceExpr(
1022-
ValueExpr.withValue(
1023-
SuperObjectValue.withType(
1024-
TypeNode.withReference(ConcreteReference.withClazz(StubSettings.class)))))
1025-
.setReturnType(TypeNode.STRING)
1026-
.build();
1027-
Expr isNotNullCheck =
1028-
RelationalOperationExpr.notEqualToWithExprs(getEndpointExpr, ValueExpr.createNullExpr());
1029-
1030-
IfStatement ifStatement =
1031-
IfStatement.builder()
1032-
.setConditionExpr(isNotNullCheck)
1033-
.setBody(ImmutableList.of(ExprStatement.withExpr(ReturnExpr.withExpr(getEndpointExpr))))
1034-
.build();
1035-
1036-
Expr getDefaultEndpointExpr =
1037-
MethodInvocationExpr.builder()
1038-
.setMethodName("getDefaultEndpoint")
1039-
.setReturnType(TypeNode.STRING)
1040-
.build();
1041-
ReturnExpr returnExpr = ReturnExpr.withExpr(getDefaultEndpointExpr);
1042-
1043-
return MethodDefinition.builder()
1044-
.setHeaderCommentStatements(SettingsCommentComposer.GET_ENDPOINT_COMMENT)
1045-
.setScope(ScopeNode.PUBLIC)
1046-
.setIsStatic(false)
1047-
.setAnnotations(ImmutableList.of(AnnotationNode.OVERRIDE))
1048-
.setReturnType(TypeNode.STRING)
1049-
.setName("getEndpoint")
1050-
.setBody(ImmutableList.of(ifStatement))
1051-
.setReturnExpr(returnExpr)
1052-
.build();
1053-
}
1054-
10551015
private static List<MethodDefinition> createMethodSettingsGetterMethods(
10561016
Map<String, VariableExpr> methodSettingsMemberVarExprs,
10571017
final Set<String> deprecatedSettingVarNames) {
@@ -1497,7 +1457,6 @@ private List<MethodDefinition> createNestedClassMethods(
14971457
nestedClassMethods.addAll(
14981458
createNestedClassSettingsBuilderGetterMethods(
14991459
nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames));
1500-
nestedClassMethods.add(createGetEndpointMethod());
15011460
nestedClassMethods.add(createNestedClassBuildMethod(service, typeStore));
15021461
return nestedClassMethods;
15031462
}

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/DeprecatedServiceStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
101101
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
102102
}
103103

104-
/** Returns the endpoint set by the user or the the service's default endpoint. */
105-
@Override
106-
public String getEndpoint() {
107-
if (super.getEndpoint() != null) {
108-
return super.getEndpoint();
109-
}
110-
return getDefaultEndpoint();
111-
}
112-
113104
/** Returns a builder for the default ExecutorProvider for this service. */
114105
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
115106
return InstantiatingExecutorProvider.newBuilder();
@@ -292,15 +283,6 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
292283
return slowFibonacciSettings;
293284
}
294285

295-
/** Returns the endpoint set by the user or the the service's default endpoint. */
296-
@Override
297-
public String getEndpoint() {
298-
if (super.getEndpoint() != null) {
299-
return super.getEndpoint();
300-
}
301-
return getDefaultEndpoint();
302-
}
303-
304286
@Override
305287
public DeprecatedServiceStubSettings build() throws IOException {
306288
return new DeprecatedServiceStubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
285285
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
286286
}
287287

288-
/** Returns the endpoint set by the user or the the service's default endpoint. */
289-
@Override
290-
public String getEndpoint() {
291-
if (super.getEndpoint() != null) {
292-
return super.getEndpoint();
293-
}
294-
return getDefaultEndpoint();
295-
}
296-
297288
/** Returns a builder for the default ExecutorProvider for this service. */
298289
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
299290
return InstantiatingExecutorProvider.newBuilder();
@@ -635,15 +626,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
635626
return collideNameSettings;
636627
}
637628

638-
/** Returns the endpoint set by the user or the the service's default endpoint. */
639-
@Override
640-
public String getEndpoint() {
641-
if (super.getEndpoint() != null) {
642-
return super.getEndpoint();
643-
}
644-
return getDefaultEndpoint();
645-
}
646-
647629
@Override
648630
public EchoStubSettings build() throws IOException {
649631
return new EchoStubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/LoggingServiceV2StubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,6 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
421421
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
422422
}
423423

424-
/** Returns the endpoint set by the user or the the service's default endpoint. */
425-
@Override
426-
public String getEndpoint() {
427-
if (super.getEndpoint() != null) {
428-
return super.getEndpoint();
429-
}
430-
return getDefaultEndpoint();
431-
}
432-
433424
/** Returns the default service name. */
434425
@Override
435426
public String getServiceName() {
@@ -738,15 +729,6 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
738729
return tailLogEntriesSettings;
739730
}
740731

741-
/** Returns the endpoint set by the user or the the service's default endpoint. */
742-
@Override
743-
public String getEndpoint() {
744-
if (super.getEndpoint() != null) {
745-
return super.getEndpoint();
746-
}
747-
return getDefaultEndpoint();
748-
}
749-
750732
@Override
751733
public LoggingServiceV2StubSettings build() throws IOException {
752734
return new LoggingServiceV2StubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/PublisherStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,6 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
430430
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
431431
}
432432

433-
/** Returns the endpoint set by the user or the the service's default endpoint. */
434-
@Override
435-
public String getEndpoint() {
436-
if (super.getEndpoint() != null) {
437-
return super.getEndpoint();
438-
}
439-
return getDefaultEndpoint();
440-
}
441-
442433
/** Returns the default service name. */
443434
@Override
444435
public String getServiceName() {
@@ -810,15 +801,6 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
810801
return detachSubscriptionSettings;
811802
}
812803

813-
/** Returns the endpoint set by the user or the the service's default endpoint. */
814-
@Override
815-
public String getEndpoint() {
816-
if (super.getEndpoint() != null) {
817-
return super.getEndpoint();
818-
}
819-
return getDefaultEndpoint();
820-
}
821-
822804
@Override
823805
public PublisherStubSettings build() throws IOException {
824806
return new PublisherStubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
301301
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
302302
}
303303

304-
/** Returns the endpoint set by the user or the the service's default endpoint. */
305-
@Override
306-
public String getEndpoint() {
307-
if (super.getEndpoint() != null) {
308-
return super.getEndpoint();
309-
}
310-
return getDefaultEndpoint();
311-
}
312-
313304
/** Returns a builder for the default ExecutorProvider for this service. */
314305
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
315306
return InstantiatingExecutorProvider.newBuilder();
@@ -694,15 +685,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
694685
return updateCaseSettings;
695686
}
696687

697-
/** Returns the endpoint set by the user or the the service's default endpoint. */
698-
@Override
699-
public String getEndpoint() {
700-
if (super.getEndpoint() != null) {
701-
return super.getEndpoint();
702-
}
703-
return getDefaultEndpoint();
704-
}
705-
706688
@Override
707689
public EchoStubSettings build() throws IOException {
708690
return new EchoStubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/WickedStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ public class WickedStubSettings extends StubSettings<WickedStubSettings> {
9999
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
100100
}
101101

102-
/** Returns the endpoint set by the user or the the service's default endpoint. */
103-
@Override
104-
public String getEndpoint() {
105-
if (super.getEndpoint() != null) {
106-
return super.getEndpoint();
107-
}
108-
return getDefaultEndpoint();
109-
}
110-
111102
/** Returns a builder for the default ExecutorProvider for this service. */
112103
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
113104
return InstantiatingExecutorProvider.newBuilder();
@@ -284,15 +275,6 @@ public class WickedStubSettings extends StubSettings<WickedStubSettings> {
284275
return persuadeEvilPlanSettings;
285276
}
286277

287-
/** Returns the endpoint set by the user or the the service's default endpoint. */
288-
@Override
289-
public String getEndpoint() {
290-
if (super.getEndpoint() != null) {
291-
return super.getEndpoint();
292-
}
293-
return getDefaultEndpoint();
294-
}
295-
296278
@Override
297279
public WickedStubSettings build() throws IOException {
298280
return new WickedStubSettings(this);

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/ComplianceStubSettings.golden

-18
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>
131131
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
132132
}
133133

134-
/** Returns the endpoint set by the user or the the service's default endpoint. */
135-
@Override
136-
public String getEndpoint() {
137-
if (super.getEndpoint() != null) {
138-
return super.getEndpoint();
139-
}
140-
return getDefaultEndpoint();
141-
}
142-
143134
/** Returns a builder for the default ExecutorProvider for this service. */
144135
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
145136
return InstantiatingExecutorProvider.newBuilder();
@@ -417,15 +408,6 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>
417408
return verifyEnumSettings;
418409
}
419410

420-
/** Returns the endpoint set by the user or the the service's default endpoint. */
421-
@Override
422-
public String getEndpoint() {
423-
if (super.getEndpoint() != null) {
424-
return super.getEndpoint();
425-
}
426-
return getDefaultEndpoint();
427-
}
428-
429411
@Override
430412
public ComplianceStubSettings build() throws IOException {
431413
return new ComplianceStubSettings(this);

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private GrpcCallContext(
140140
ApiCallContextOptions options,
141141
@Nullable RetrySettings retrySettings,
142142
@Nullable Set<StatusCode.Code> retryableCodes,
143-
EndpointContext endpointContext) {
143+
@Nullable EndpointContext endpointContext) {
144144
this.channel = channel;
145145
this.credentials = credentials;
146146
this.callOptions = Preconditions.checkNotNull(callOptions);
@@ -152,7 +152,14 @@ private GrpcCallContext(
152152
this.options = Preconditions.checkNotNull(options);
153153
this.retrySettings = retrySettings;
154154
this.retryableCodes = retryableCodes == null ? null : ImmutableSet.copyOf(retryableCodes);
155-
this.endpointContext = endpointContext;
155+
// Attempt to create an empty, non-functioning EndpointContext by default. The client will have
156+
// a valid EndpointContext with user configurations after the client has been initialized.
157+
try {
158+
this.endpointContext =
159+
endpointContext == null ? EndpointContext.newBuilder().build() : endpointContext;
160+
} catch (IOException ex) {
161+
throw new RuntimeException(ex);
162+
}
156163
}
157164

158165
/**

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private HttpJsonCallContext(
121121
ApiTracer tracer,
122122
RetrySettings defaultRetrySettings,
123123
Set<StatusCode.Code> defaultRetryableCodes,
124-
EndpointContext endpointContext) {
124+
@Nullable EndpointContext endpointContext) {
125125
this.channel = channel;
126126
this.callOptions = callOptions;
127127
this.timeout = timeout;
@@ -133,7 +133,14 @@ private HttpJsonCallContext(
133133
this.retrySettings = defaultRetrySettings;
134134
this.retryableCodes =
135135
defaultRetryableCodes == null ? null : ImmutableSet.copyOf(defaultRetryableCodes);
136-
this.endpointContext = endpointContext;
136+
// Attempt to create an empty, non-functioning EndpointContext by default. The client will have
137+
// a valid EndpointContext with user configurations after the client has been initialized.
138+
try {
139+
this.endpointContext =
140+
endpointContext == null ? EndpointContext.newBuilder().build() : endpointContext;
141+
} catch (IOException ex) {
142+
throw new RuntimeException(ex);
143+
}
137144
}
138145

139146
/**

gax-java/gax/clirr-ignored-differences.xml

+5
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@
4242
<className>com/google/api/gax/rpc/ApiCallContext</className>
4343
<method>* validateUniverseDomain()</method>
4444
</difference>
45+
<difference>
46+
<differenceType>7009</differenceType>
47+
<className>com/google/api/gax/rpc/StubSettings</className>
48+
<method>* getServiceName()</method>
49+
</difference>
4550
</differences>

0 commit comments

Comments
 (0)