Skip to content

Commit

Permalink
Merge branch 'main' into renovate/google-api-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
alicejli authored May 2, 2024
2 parents fbba58e + 5bb9770 commit 667dea5
Show file tree
Hide file tree
Showing 16 changed files with 1,159 additions and 105 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
on:
push:
branches:
- main
pull_request:

workflow_dispatch:
name: verify_library_generation
jobs:
should-run-library-generation-tests:
Expand All @@ -20,8 +16,12 @@ jobs:
shell: bash
run: |
set -ex
# Checkout a detached head, and then fetch the base ref to populate the detached head.
git checkout "${base_ref}"
git fetch --no-tags --prune origin +${base_ref}:refs/remotes/origin/${base_ref}
# Checkout a detached head, and then fetch the head ref to populate the detached head.
git checkout "${head_ref}"
git fetch --no-tags --prune origin +${head_ref}:refs/remotes/origin/${head_ref}
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
if [[ ${changed_directories} =~ "library_generation/" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ private GrpcCallContext(
this.retryableCodes = retryableCodes == null ? null : ImmutableSet.copyOf(retryableCodes);
// 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);
}
this.endpointContext =
endpointContext == null ? EndpointContext.getDefaultInstance() : endpointContext;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,8 @@ private HttpJsonCallContext(
defaultRetryableCodes == null ? null : ImmutableSet.copyOf(defaultRetryableCodes);
// 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);
}
this.endpointContext =
endpointContext == null ? EndpointContext.getDefaultInstance() : endpointContext;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,20 @@ public abstract class ClientContext {

/** Create a new ClientContext with default values */
public static Builder newBuilder() {
try {
return new AutoValue_ClientContext.Builder()
.setBackgroundResources(Collections.<BackgroundResource>emptyList())
.setExecutor(Executors.newScheduledThreadPool(0))
.setHeaders(Collections.<String, String>emptyMap())
.setInternalHeaders(Collections.<String, String>emptyMap())
.setClock(NanoClock.getDefaultClock())
.setStreamWatchdog(null)
.setStreamWatchdogCheckInterval(Duration.ZERO)
.setTracerFactory(BaseApiTracerFactory.getInstance())
.setQuotaProjectId(null)
.setGdchApiAudience(null)
// Attempt to create an empty, non-functioning EndpointContext by default. This is
// not exposed to the user via getters/setters.
.setEndpointContext(EndpointContext.newBuilder().build());
} catch (IOException e) {
throw new RuntimeException(e);
}
return new AutoValue_ClientContext.Builder()
.setBackgroundResources(Collections.<BackgroundResource>emptyList())
.setExecutor(Executors.newScheduledThreadPool(0))
.setHeaders(Collections.<String, String>emptyMap())
.setInternalHeaders(Collections.<String, String>emptyMap())
.setClock(NanoClock.getDefaultClock())
.setStreamWatchdog(null)
.setStreamWatchdogCheckInterval(Duration.ZERO)
.setTracerFactory(BaseApiTracerFactory.getInstance())
.setQuotaProjectId(null)
.setGdchApiAudience(null)
// Attempt to create an empty, non-functioning EndpointContext by default. This is
// not exposed to the user via getters/setters.
.setEndpointContext(EndpointContext.getDefaultInstance());
}

public abstract Builder toBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,28 @@
@InternalApi
@AutoValue
public abstract class EndpointContext {

private static final EndpointContext INSTANCE;

// static block initialization for exception handling
static {
try {
INSTANCE = EndpointContext.newBuilder().setServiceName("").build();
} catch (IOException e) {
throw new RuntimeException("Unable to create a default empty EndpointContext", e);
}
}

public static final String GOOGLE_CLOUD_UNIVERSE_DOMAIN = "GOOGLE_CLOUD_UNIVERSE_DOMAIN";
public static final String INVALID_UNIVERSE_DOMAIN_ERROR_TEMPLATE =
"The configured universe domain (%s) does not match the universe domain found in the credentials (%s). If you haven't configured the universe domain explicitly, `googleapis.com` is the default.";
public static final String UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE =
"Unable to retrieve the Universe Domain from the Credentials.";

public static EndpointContext getDefaultInstance() {
return INSTANCE;
}

/**
* ServiceName is host URI for Google Cloud Services. It follows the format of
* `{ServiceName}.googleapis.com`. For example, speech.googleapis.com would have a ServiceName of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public abstract static class Builder<
@Nonnull private ApiTracerFactory tracerFactory;
private boolean deprecatedExecutorProviderSet;
private String universeDomain;
private final EndpointContext endpointContext;

/**
* Indicate when creating transport whether it is allowed to use mTLS endpoint instead of the
Expand Down Expand Up @@ -300,6 +301,9 @@ protected Builder(StubSettings settings) {
this.switchToMtlsEndpointAllowed =
settings.getEndpointContext().switchToMtlsEndpointAllowed();
this.universeDomain = settings.getEndpointContext().universeDomain();
// Store the EndpointContext that was already created. This is used to return the state
// of the EndpointContext prior to any new modifications
this.endpointContext = settings.getEndpointContext();
}

/** Get Quota Project ID from Client Context * */
Expand Down Expand Up @@ -327,16 +331,22 @@ protected Builder(ClientContext clientContext) {
this.headerProvider = new NoHeaderProvider();
this.internalHeaderProvider = new NoHeaderProvider();
this.clock = NanoClock.getDefaultClock();
this.clientSettingsEndpoint = null;
this.transportChannelProviderEndpoint = null;
this.mtlsEndpoint = null;
this.quotaProjectId = null;
this.streamWatchdogProvider = InstantiatingWatchdogProvider.create();
this.streamWatchdogCheckInterval = Duration.ofSeconds(10);
this.tracerFactory = BaseApiTracerFactory.getInstance();
this.deprecatedExecutorProviderSet = false;
this.gdchApiAudience = null;

this.clientSettingsEndpoint = null;
this.transportChannelProviderEndpoint = null;
this.mtlsEndpoint = null;
this.switchToMtlsEndpointAllowed = false;
this.universeDomain = null;
// 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.
this.endpointContext = EndpointContext.getDefaultInstance();
} else {
ExecutorProvider fixedExecutorProvider =
FixedExecutorProvider.create(clientContext.getExecutor());
Expand Down Expand Up @@ -365,6 +375,9 @@ protected Builder(ClientContext clientContext) {
this.switchToMtlsEndpointAllowed =
clientContext.getEndpointContext().switchToMtlsEndpointAllowed();
this.universeDomain = clientContext.getEndpointContext().universeDomain();
// Store the EndpointContext that was already created. This is used to return the state
// of the EndpointContext prior to any new modifications
this.endpointContext = clientContext.getEndpointContext();
}
}

Expand Down Expand Up @@ -584,8 +597,19 @@ public ApiClock getClock() {
return clock;
}

/**
* @return the resolved endpoint when the Builder was created. If invoked after
* `StubSettings.newBuilder()` is called, it will return the clientSettingsEndpoint value.
* If other parameters are then set in the builder, the resolved endpoint is not
* automatically updated. The resolved endpoint will only be recomputed when the
* StubSettings is built again.
*/
public String getEndpoint() {
return clientSettingsEndpoint;
// For the `StubSettings.newBuilder()` case
if (endpointContext.equals(EndpointContext.getDefaultInstance())) {
return clientSettingsEndpoint;
}
return endpointContext.resolvedEndpoint();
}

public String getMtlsEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -88,12 +87,8 @@ private FakeCallContext(
this.tracer = tracer;
this.retrySettings = retrySettings;
this.retryableCodes = retryableCodes == null ? null : ImmutableSet.copyOf(retryableCodes);
try {
this.endpointContext =
endpointContext == null ? EndpointContext.newBuilder().build() : endpointContext;
} catch (IOException e) {
throw new RuntimeException(e);
}
this.endpointContext =
endpointContext == null ? EndpointContext.getDefaultInstance() : endpointContext;
}

public static FakeCallContext createDefault() {
Expand Down
6 changes: 3 additions & 3 deletions java-common-protos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file:
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
<version>2.37.1</version>
<version>2.38.0</version>
</dependency>
```

If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.api.grpc:proto-google-common-protos:2.37.1'
implementation 'com.google.api.grpc:proto-google-common-protos:2.38.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % "2.37.1"
libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % "2.38.0"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand All @@ -91,8 +89,6 @@ public boolean hasAmountMicros() {
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand Down Expand Up @@ -554,8 +550,6 @@ public Builder mergeFrom(
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand All @@ -573,8 +567,6 @@ public boolean hasAmountMicros() {
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand All @@ -592,8 +584,6 @@ public long getAmountMicros() {
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand All @@ -615,8 +605,6 @@ public Builder setAmountMicros(long value) {
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public interface PriceOrBuilder
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand All @@ -47,8 +45,6 @@ public interface PriceOrBuilder
* The price represented as a number in micros (1 million micros is an
* equivalent to one's currency standard unit, for example, 1 USD = 1000000
* micros).
* This field can also be set as infinity by setting to -1.
* This field only support -1 and positive value.
* </pre>
*
* <code>optional int64 amount_micros = 1;</code>
Expand Down
Loading

0 comments on commit 667dea5

Please sign in to comment.