Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

feat: Enable REST transport for most of Java and Go clients #237

Merged
merged 13 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file:
If you are using Gradle without BOM, add this to your dependencies

```Groovy
implementation 'com.google.cloud:google-cloud-gkehub:1.1.2'
implementation 'com.google.cloud:google-cloud-gkehub:1.2.0'
```

If you are using SBT, add this to your dependencies

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-gkehub" % "1.1.2"
libraryDependencies += "com.google.cloud" % "google-cloud-gkehub" % "1.2.0"
```

## Authentication
Expand Down
16 changes: 16 additions & 0 deletions google-cloud-gkehub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-httpjson</artifactId>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
Expand Down Expand Up @@ -113,12 +117,24 @@
<scope>test</scope>
</dependency>
<!-- Need testing utility classes for generated gRPC clients tests -->
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-httpjson</artifactId>
<classifier>testlib</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.httpjson.longrunning.OperationsClient;
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
Expand All @@ -31,7 +31,6 @@
import com.google.cloud.gkehub.v1.stub.GkeHubStubSettings;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.longrunning.Operation;
import com.google.longrunning.OperationsClient;
import com.google.protobuf.Empty;
import com.google.protobuf.FieldMask;
import java.io.IOException;
Expand Down Expand Up @@ -116,13 +115,28 @@
* GkeHubClient gkeHubClient = GkeHubClient.create(gkeHubSettings);
* }</pre>
*
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
* the wire:
*
* <pre>{@code
* // This snippet has been automatically generated for illustrative purposes only.
* // It may require modifications to work in your environment.
* GkeHubSettings gkeHubSettings =
* GkeHubSettings.newBuilder()
* .setTransportChannelProvider(
* GkeHubSettings.defaultHttpJsonTransportProviderBuilder().build())
* .build();
* GkeHubClient gkeHubClient = GkeHubClient.create(gkeHubSettings);
* }</pre>
*
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
public class GkeHubClient implements BackgroundResource {
private final GkeHubSettings settings;
private final GkeHubStub stub;
private final OperationsClient operationsClient;
private final OperationsClient httpJsonOperationsClient;
private final com.google.longrunning.OperationsClient operationsClient;

/** Constructs an instance of GkeHubClient with default settings. */
public static final GkeHubClient create() throws IOException {
Expand All @@ -141,7 +155,6 @@ public static final GkeHubClient create(GkeHubSettings settings) throws IOExcept
* Constructs an instance of GkeHubClient, using the given stub for making calls. This is for
* advanced usage - prefer using create(GkeHubSettings).
*/
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public static final GkeHubClient create(GkeHubStub stub) {
return new GkeHubClient(stub);
}
Expand All @@ -153,21 +166,23 @@ public static final GkeHubClient create(GkeHubStub stub) {
protected GkeHubClient(GkeHubSettings settings) throws IOException {
this.settings = settings;
this.stub = ((GkeHubStubSettings) settings.getStubSettings()).createStub();
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
this.operationsClient =
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
protected GkeHubClient(GkeHubStub stub) {
this.settings = null;
this.stub = stub;
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
this.operationsClient =
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}

public final GkeHubSettings getSettings() {
return settings;
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public GkeHubStub getStub() {
return stub;
}
Expand All @@ -176,10 +191,18 @@ public GkeHubStub getStub() {
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
public final OperationsClient getOperationsClient() {
public final com.google.longrunning.OperationsClient getOperationsClient() {
return operationsClient;
}

/**
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
public final OperationsClient getHttpJsonOperationsClient() {
return httpJsonOperationsClient;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Lists Memberships in a given project and location.
Expand Down Expand Up @@ -318,7 +341,7 @@ public final ListMembershipsPagedResponse listMemberships(ListMembershipsRequest
* .build();
* while (true) {
* ListMembershipsResponse response = gkeHubClient.listMembershipsCallable().call(request);
* for (Membership element : response.getResponsesList()) {
* for (Membership element : response.getResourcesList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
Expand Down Expand Up @@ -473,7 +496,7 @@ public final ListFeaturesPagedResponse listFeatures(ListFeaturesRequest request)
* .build();
* while (true) {
* ListFeaturesResponse response = gkeHubClient.listFeaturesCallable().call(request);
* for (Feature element : response.getResponsesList()) {
* for (Feature element : response.getResourcesList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
Expand Down Expand Up @@ -193,11 +194,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return GkeHubStubSettings.defaultCredentialsProviderBuilder();
}

/** Returns a builder for the default ChannelProvider for this service. */
/** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return GkeHubStubSettings.defaultGrpcTransportProviderBuilder();
}

/** Returns a builder for the default REST ChannelProvider for this service. */
@BetaApi
public static InstantiatingHttpJsonChannelProvider.Builder
defaultHttpJsonTransportProviderBuilder() {
return GkeHubStubSettings.defaultHttpJsonTransportProviderBuilder();
}

public static TransportChannelProvider defaultTransportChannelProvider() {
return GkeHubStubSettings.defaultTransportChannelProvider();
}
Expand All @@ -207,11 +215,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return GkeHubStubSettings.defaultApiClientHeaderProviderBuilder();
}

/** Returns a new builder for this class. */
/** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}

/** Returns a new REST builder for this class. */
@BetaApi
public static Builder newHttpJsonBuilder() {
return Builder.createHttpJsonDefault();
}

/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
Expand Down Expand Up @@ -249,6 +263,11 @@ private static Builder createDefault() {
return new Builder(GkeHubStubSettings.newBuilder());
}

@BetaApi
private static Builder createHttpJsonDefault() {
return new Builder(GkeHubStubSettings.newHttpJsonBuilder());
}

public GkeHubStubSettings.Builder getStubSettingsBuilder() {
return ((GkeHubStubSettings.Builder) getStubSettings());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
public abstract class GkeHubStub implements BackgroundResource {

public OperationsStub getOperationsStub() {
throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
return null;
}

public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
return null;
}

public UnaryCallable<ListMembershipsRequest, ListMembershipsPagedResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.ProtoOperationTransformers;
import com.google.api.gax.httpjson.GaxHttpJsonProperties;
import com.google.api.gax.httpjson.HttpJsonTransportChannel;
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
Expand Down Expand Up @@ -345,13 +348,17 @@ public UnaryCallSettings<UpdateFeatureRequest, Operation> updateFeatureSettings(
return generateConnectManifestSettings;
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public GkeHubStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcGkeHubStub.create(this);
}
if (getTransportChannelProvider()
.getTransportName()
.equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
return HttpJsonGkeHubStub.create(this);
}
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
Expand Down Expand Up @@ -384,29 +391,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
.setUseJwtAccessWithScope(true);
}

/** Returns a builder for the default ChannelProvider for this service. */
/** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}

/** Returns a builder for the default REST ChannelProvider for this service. */
@BetaApi
public static InstantiatingHttpJsonChannelProvider.Builder
defaultHttpJsonTransportProviderBuilder() {
return InstantiatingHttpJsonChannelProvider.newBuilder();
}

public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}

@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(GkeHubStubSettings.class))
.setTransportToken(
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}

/** Returns a new builder for this class. */
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(GkeHubStubSettings.class))
.setTransportToken(
GaxHttpJsonProperties.getHttpJsonTokenName(),
GaxHttpJsonProperties.getHttpJsonVersion());
}

public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
return GkeHubStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
}

/** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}

/** Returns a new REST builder for this class. */
public static Builder newHttpJsonBuilder() {
return Builder.createHttpJsonDefault();
}

/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
Expand Down Expand Up @@ -597,6 +629,19 @@ private static Builder createDefault() {
return initDefaults(builder);
}

private static Builder createHttpJsonDefault() {
Builder builder = new Builder(((ClientContext) null));

builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);

return initDefaults(builder);
}

private static Builder initDefaults(Builder builder) {
builder
.listMembershipsSettings()
Expand Down
Loading