Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Client/StubSettings' getEndpoint() returns the resolved endpoint #2440

Merged
merged 39 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ab57eb4
chore: Update the tests
lqiu96 Feb 5, 2024
8ec9ad0
chore: Add serviceName to StubSettings
lqiu96 Feb 6, 2024
2f3e49a
chore: Add clirr checks
lqiu96 Feb 6, 2024
0b1a6f1
chore: Add static getDefaultServiceName
lqiu96 Feb 6, 2024
8700542
Merge branch 'main' into getEndpoint_returnsResolvedEndpoint
lqiu96 Mar 19, 2024
18b32cc
chore: Build default EndpointContext in CallContext
lqiu96 Mar 20, 2024
015b714
chore: Update ITEndpointContext
lqiu96 Mar 20, 2024
6924835
Merge branch 'main' into getEndpoint_returnsResolvedEndpoint
lqiu96 Mar 20, 2024
d192f54
chore: Set getDefaultServiceName as private scope
lqiu96 Mar 20, 2024
ef2d11a
chore: Add javadoc comments
lqiu96 Mar 20, 2024
1542146
chore: Add comments for building the EndpointContext
lqiu96 Mar 20, 2024
d078f78
chore: Add docs for InternalApi
lqiu96 Mar 20, 2024
a51d579
chore: Fix docs for Showcase ITs
lqiu96 Mar 20, 2024
c156716
chore: Remove setter from ClientSettings.Builder
lqiu96 Mar 20, 2024
55b69e3
chore: Fix docs
lqiu96 Mar 20, 2024
030db51
chore: Refactor EndpointContext builder
lqiu96 Mar 21, 2024
4953001
chore: Remove getDefaultServiceName()
lqiu96 Mar 21, 2024
1ff4136
chore: Update ITEndpointContext
lqiu96 Mar 21, 2024
42be513
chore: Update javadoc and comments
lqiu96 Mar 21, 2024
18fb9ab
chore: Remove @Nullable annotation from getServiceName
lqiu96 Mar 21, 2024
c5887ac
chore: Fix broken tests
lqiu96 Mar 25, 2024
1decba9
Merge branch 'main' into getEndpoint_returnsResolvedEndpoint
lqiu96 Mar 25, 2024
0d789ba
chore: Address PR comments
lqiu96 Mar 26, 2024
633425d
Merge branch 'main' into getEndpoint_returnsResolvedEndpoint
lqiu96 Mar 26, 2024
c2271b8
chore: Update javadocs for ITEndpointContext
lqiu96 Mar 26, 2024
9294b7b
chore: Remove clirr file
lqiu96 Mar 26, 2024
12aa005
chore: Update javadocs
lqiu96 Mar 26, 2024
ed76b75
chore: Remove unused fields
lqiu96 Mar 26, 2024
594d1ed
chore: Update the javadocs
lqiu96 Mar 27, 2024
626f891
chore: Update toString()
lqiu96 Mar 27, 2024
47efcb7
chore: Pass EndpointContext between StubSettings and ClientContext
lqiu96 Mar 27, 2024
15fe528
chore: Set StubSettings builder values to original configs
lqiu96 Mar 27, 2024
3ee2a38
Update showcase/gapic-showcase/src/test/java/com/google/showcase/v1be…
lqiu96 Apr 2, 2024
42880ea
chore: Address PR comments
lqiu96 Apr 2, 2024
07be497
chore: Add UniverseDomainCredentials wrapper
lqiu96 Apr 2, 2024
2c84dd3
chore: Add javadocs
lqiu96 Apr 2, 2024
ecda13d
chore: Fix clirr issue
lqiu96 Apr 2, 2024
565885b
chore: Refactor tests
lqiu96 Apr 2, 2024
6a0c1d9
Merge branch 'main' into getEndpoint_returnsResolvedEndpoint
lqiu96 Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -1497,7 +1457,6 @@ private List<MethodDefinition> createNestedClassMethods(
nestedClassMethods.addAll(
createNestedClassSettingsBuilderGetterMethods(
nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames));
nestedClassMethods.add(createGetEndpointMethod());
nestedClassMethods.add(createNestedClassBuildMethod(service, typeStore));
return nestedClassMethods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions gax-java/gax/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading