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: Remove setting the default endpoint in StubSettings #2348

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,6 +52,9 @@ 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 @@ -1007,6 +1007,7 @@ 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 @@ -1020,6 +1021,45 @@ 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 @@ -1465,6 +1505,7 @@ private List<MethodDefinition> createNestedClassMethods(
nestedClassMethods.addAll(
createNestedClassSettingsBuilderGetterMethods(
nestedMethodSettingsMemberVarExprs, nestedDeprecatedSettingVarNames));
nestedClassMethods.add(createGetEndpointMethod());
nestedClassMethods.add(createNestedClassBuildMethod(service, typeStore));
return nestedClassMethods;
}
Expand Down Expand Up @@ -1895,14 +1936,6 @@ protected MethodDefinition createNestedClassCreateDefaultMethod(
.setMethodName("build")
.build())
.build());

bodyExprs.add(
MethodInvocationExpr.builder()
.setExprReferenceExpr(builderVarExpr)
.setMethodName("setEndpoint")
.setArguments(
MethodInvocationExpr.builder().setMethodName("getDefaultEndpoint").build())
.build());
bodyExprs.add(
MethodInvocationExpr.builder()
.setExprReferenceExpr(builderVarExpr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ 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 @@ -235,7 +244,6 @@ public class DeprecatedServiceStubSettings extends StubSettings<DeprecatedServic
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -286,6 +294,15 @@ 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,6 +285,15 @@ 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 @@ -484,7 +493,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -630,6 +638,15 @@ 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 @@ -422,6 +422,15 @@ 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 @@ -626,7 +635,6 @@ public class LoggingServiceV2StubSettings extends StubSettings<LoggingServiceV2S
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -732,6 +740,15 @@ 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 @@ -431,6 +431,15 @@ 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 @@ -667,7 +676,6 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -804,6 +812,15 @@ 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,6 +301,15 @@ 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 @@ -512,7 +521,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand All @@ -525,7 +533,6 @@ public class EchoStubSettings extends StubSettings<EchoStubSettings> {
builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -691,6 +698,15 @@ 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,6 +99,15 @@ 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 @@ -231,7 +240,6 @@ public class WickedStubSettings extends StubSettings<WickedStubSettings> {
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -277,6 +285,15 @@ 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,6 +131,15 @@ 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 @@ -302,7 +311,6 @@ public class ComplianceStubSettings extends StubSettings<ComplianceStubSettings>
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

Expand Down Expand Up @@ -410,6 +418,15 @@ 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 @@ -153,7 +153,7 @@ public final String getUniverseDomain() {
return universeDomain;
}

public final String getEndpoint() {
public String getEndpoint() {
return endpoint;
}

Expand Down
Loading
Loading