Skip to content

Commit

Permalink
feat: Client/StubSettings' getEndpoint() returns the resolved endpoint (
Browse files Browse the repository at this point in the history
#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 <blakeli@google.com>
lqiu96 and blakeli0 authored Apr 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8312706 commit 4942bc1
Showing 44 changed files with 569 additions and 752 deletions.
Original file line number Diff line number Diff line change
@@ -52,9 +52,6 @@ public class SettingsCommentComposer {
private static final String CLASS_HEADER_DEFAULTS_RETRIES_DESCRIPTION =
"Retries are configured for idempotent methods but not for non-idempotent methods.";

public static final CommentStatement GET_ENDPOINT_COMMENT =
toSimpleComment(
"Returns the endpoint set by the user or the the service's default endpoint.");
public static final CommentStatement DEFAULT_SCOPES_COMMENT =
toSimpleComment("The default scopes of the service.");

Original file line number Diff line number Diff line change
@@ -999,7 +999,6 @@ private List<MethodDefinition> createClassMethods(
javaMethods.addAll(
createMethodSettingsGetterMethods(methodSettingsMemberVarExprs, deprecatedSettingVarNames));
javaMethods.add(createCreateStubMethod(service, typeStore));
javaMethods.add(createGetEndpointMethod());
javaMethods.addAll(createDefaultHelperAndGetterMethods(service, typeStore));
javaMethods.addAll(
createNewBuilderMethods(
@@ -1013,45 +1012,6 @@ private List<MethodDefinition> createClassMethods(
return javaMethods;
}

// Helper method to create the getEndpoint method in the ServiceStubSettings class
private MethodDefinition createGetEndpointMethod() {
Expr getEndpointExpr =
MethodInvocationExpr.builder()
.setMethodName("getEndpoint")
.setExprReferenceExpr(
ValueExpr.withValue(
SuperObjectValue.withType(
TypeNode.withReference(ConcreteReference.withClazz(StubSettings.class)))))
.setReturnType(TypeNode.STRING)
.build();
Expr isNotNullCheck =
RelationalOperationExpr.notEqualToWithExprs(getEndpointExpr, ValueExpr.createNullExpr());

IfStatement ifStatement =
IfStatement.builder()
.setConditionExpr(isNotNullCheck)
.setBody(ImmutableList.of(ExprStatement.withExpr(ReturnExpr.withExpr(getEndpointExpr))))
.build();

Expr getDefaultEndpointExpr =
MethodInvocationExpr.builder()
.setMethodName("getDefaultEndpoint")
.setReturnType(TypeNode.STRING)
.build();
ReturnExpr returnExpr = ReturnExpr.withExpr(getDefaultEndpointExpr);

return MethodDefinition.builder()
.setHeaderCommentStatements(SettingsCommentComposer.GET_ENDPOINT_COMMENT)
.setScope(ScopeNode.PUBLIC)
.setIsStatic(false)
.setAnnotations(ImmutableList.of(AnnotationNode.OVERRIDE))
.setReturnType(TypeNode.STRING)
.setName("getEndpoint")
.setBody(ImmutableList.of(ifStatement))
.setReturnExpr(returnExpr)
.build();
}

private static List<MethodDefinition> createMethodSettingsGetterMethods(
Map<String, VariableExpr> methodSettingsMemberVarExprs,
final Set<String> deprecatedSettingVarNames) {
@@ -1497,7 +1457,6 @@ private List<MethodDefinition> createNestedClassMethods(
nestedClassMethods.addAll(
createNestedClassSettingsBuilderGetterMethods(
nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames));
nestedClassMethods.add(createGetEndpointMethod());
nestedClassMethods.add(createNestedClassBuildMethod(service, typeStore));
return nestedClassMethods;
}
Original file line number Diff line number Diff line change
@@ -101,15 +101,6 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
@@ -292,15 +283,6 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
return slowFibonacciSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public DeprecatedServiceStubSettings build() throws IOException {
return new DeprecatedServiceStubSettings(this);
Original file line number Diff line number Diff line change
@@ -285,15 +285,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
@@ -635,15 +626,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
return collideNameSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public EchoStubSettings build() throws IOException {
return new EchoStubSettings(this);
Original file line number Diff line number Diff line change
@@ -421,15 +421,6 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns the default service name. */
@Override
public String getServiceName() {
@@ -738,15 +729,6 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
return tailLogEntriesSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public LoggingServiceV2StubSettings build() throws IOException {
return new LoggingServiceV2StubSettings(this);
Original file line number Diff line number Diff line change
@@ -430,15 +430,6 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns the default service name. */
@Override
public String getServiceName() {
@@ -810,15 +801,6 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
return detachSubscriptionSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public PublisherStubSettings build() throws IOException {
return new PublisherStubSettings(this);
Original file line number Diff line number Diff line change
@@ -301,15 +301,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
@@ -694,15 +685,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
return updateCaseSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public EchoStubSettings build() throws IOException {
return new EchoStubSettings(this);
Original file line number Diff line number Diff line change
@@ -99,15 +99,6 @@ public class WickedStubSettings extends StubSettings<WickedStubSettings> {
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
@@ -284,15 +275,6 @@ public class WickedStubSettings extends StubSettings<WickedStubSettings> {
return persuadeEvilPlanSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public WickedStubSettings build() throws IOException {
return new WickedStubSettings(this);
Original file line number Diff line number Diff line change
@@ -131,15 +131,6 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
@@ -417,15 +408,6 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>
return verifyEnumSettings;
}

/** Returns the endpoint set by the user or the the service's default endpoint. */
@Override
public String getEndpoint() {
if (super.getEndpoint() != null) {
return super.getEndpoint();
}
return getDefaultEndpoint();
}

@Override
public ComplianceStubSettings build() throws IOException {
return new ComplianceStubSettings(this);
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ private GrpcCallContext(
ApiCallContextOptions options,
@Nullable RetrySettings retrySettings,
@Nullable Set<StatusCode.Code> retryableCodes,
EndpointContext endpointContext) {
@Nullable EndpointContext endpointContext) {
this.channel = channel;
this.credentials = credentials;
this.callOptions = Preconditions.checkNotNull(callOptions);
@@ -152,7 +152,14 @@ private GrpcCallContext(
this.options = Preconditions.checkNotNull(options);
this.retrySettings = retrySettings;
this.retryableCodes = retryableCodes == null ? null : ImmutableSet.copyOf(retryableCodes);
this.endpointContext = endpointContext;
// Attempt to create an empty, non-functioning EndpointContext by default. The client will have
// a valid EndpointContext with user configurations after the client has been initialized.
try {
this.endpointContext =
endpointContext == null ? EndpointContext.newBuilder().build() : endpointContext;
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

/**
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ private HttpJsonCallContext(
ApiTracer tracer,
RetrySettings defaultRetrySettings,
Set<StatusCode.Code> defaultRetryableCodes,
EndpointContext endpointContext) {
@Nullable EndpointContext endpointContext) {
this.channel = channel;
this.callOptions = callOptions;
this.timeout = timeout;
@@ -133,7 +133,14 @@ private HttpJsonCallContext(
this.retrySettings = defaultRetrySettings;
this.retryableCodes =
defaultRetryableCodes == null ? null : ImmutableSet.copyOf(defaultRetryableCodes);
this.endpointContext = endpointContext;
// Attempt to create an empty, non-functioning EndpointContext by default. The client will have
// a valid EndpointContext with user configurations after the client has been initialized.
try {
this.endpointContext =
endpointContext == null ? EndpointContext.newBuilder().build() : endpointContext;
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

/**
5 changes: 5 additions & 0 deletions gax-java/gax/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
@@ -42,4 +42,9 @@
<className>com/google/api/gax/rpc/ApiCallContext</className>
<method>* validateUniverseDomain()</method>
</difference>
<difference>
<differenceType>7009</differenceType>
<className>com/google/api/gax/rpc/StubSettings</className>
<method>* getServiceName()</method>
</difference>
</differences>
Loading

0 comments on commit 4942bc1

Please sign in to comment.