-
Notifications
You must be signed in to change notification settings - Fork 61
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: Add Universe Domain to Java-Core #2329
Conversation
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Show resolved
Hide resolved
@@ -767,4 +794,40 @@ public String getClientLibToken() { | |||
public String getQuotaProjectId() { | |||
return quotaProjectId; | |||
} | |||
|
|||
/** Returns the resolved endpoint for the Service to connect to Google Cloud */ | |||
public String getResolvedEndpoint(String serviceName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think host
in java-core is basically endpoint
in Gax without the port, based on the value of DEFAULT_HOST. So we should either rename this to getResolvedHost
and remove the port concatenation in formatEndpoint
, or return host:port
if host
is specified.
Can you please verify the format of host
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the format of host is intended to be scheme://host:port
. For gRPC, the channel is expecting something in format of domain:port
and httpjson is open to anything valid.
I see that the handwritten libraries handle these inside their own codebase:
- Storage gRPC (strips the scheme and adds a port if missing): https://github.com/googleapis/java-storage/blob/2b5b27eac3279db815b36b252830d0905ade0665/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java#L163-L170
- Storage HttpJson (sets it directly): https://github.com/googleapis/java-storage/blob/2b5b27eac3279db815b36b252830d0905ade0665/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java#L143
- Spanner (enforces that a port exists): https://github.com/googleapis/java-spanner/blob/21f5eba7d46c9011803accf0aaf87e6072066419/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java#L1469-L1471
- Bigquery (sets it directly): https://github.com/googleapis/java-bigquery/blob/7a1bbd2d33e71644d83c42b71c67bac099882a4a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java#L108
I think it should be that the gRPC clients use getResolvedEndpoint()
and expect something in the format host:port
. Apiary clients (httpjson) will use getResolvedApiaryEndpoint()
and that will return the just the host.
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
if (universeDomain != null && universeDomain.isEmpty()) { | ||
throw new IllegalArgumentException("Universe Domain cannot be empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt it's wrong a method that "Returns the resolved endpoint for the Service to connect to Google Cloud" works only when universeDomain
is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a required check. If universedomain is set as ""
, we must error out. If universeDomain is null, the resolvedUniverseDomain will be googleapis.com
. Otherwise, the resolvedUniverseDomain will be whatever is inputted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misunderstood the meaning of the code. Added suggested edits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then how about setting the requirement in setUniverseDomain
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense. Guidance for temporary Apiary is to use whatever is passed in as the universe domain. The empty check is for handwritten and gapics. I'll ask about the empty string check, but it shouldn't be blocking for this.
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the | ||
* future. Returns the host to be used as the rootUrl. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe rootUrl is not a generic term but specific to our code. Can you add a link to rootUrl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will add.
/** | ||
* Returns the resolved host for the Service to connect to Google Cloud | ||
* | ||
* <p>The resolved host will be in `https://www.{serviceName}.{resolvedUniverseDomain}/` format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you add a reference about adding "www." (Javadoc's @see
annotation)? I checked www.speech.googleapis.com
but it (the DNS entry) does not exist.
suztomo@suztomo2:~$ ping www.speech.googleapis.com
ping: www.speech.googleapis.com: Name or service not known
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a link to DEFAULT_HOST
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for cloudkms.googleapis.com
not sure why there is an issue for speech.googleapis.com
java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please resolve outstanding comments before merging.
|
|
* href="https://github.com/googleapis/sdk-platform-java/blob/097964f24fa1989bc74b4807a253f0be4e9dd1ea/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L85">DEFAULT_HOST</a> | ||
*/ | ||
@InternalApi | ||
public String getResolvedHost(String serviceName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling it as host is itchy. Fine but ensure to explain this to library owners.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URL.html#getHost()
* feat: Add Java-Core Universe Domain changes * chore: Move validate universe domain logic to ServiceOptions * chore: Add javadocs * chore: Add tests * chore: Fix lint issues * chore: Add project id to tests * chore: Fix format issues * chore: Address PR comments * chore: Update Apiary to return rootHostUrl * chore: Use Google Auth Library v1.21.0 * chore: Add tests for normalizeEndpoint() * chore: Address PR comments * chore: Address PR comments * chore: Fix comments * chore: Address PR comments * chore: Address PR comments * chore: Add links * chore: Add format to match DEFAULT_HOST * chore: Fix failing tests * chore: Update javadocs * chore: Remove www. prefix
Google Auth Library v1.21.0 has been released.
ServiceOptions exposes Getters and Setters for Universe Domain. There is a helper method to resolve the endpoint and to validate the universe domain.