Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 237759a

Browse files
feat: Enable REST transport for most of Java and Go clients (#22)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: googleapis/googleapis@8a251f5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9
1 parent 29d588e commit 237759a

File tree

123 files changed

+9948
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+9948
-11
lines changed

google-cloud-gke-backup/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<groupId>com.google.api</groupId>
5959
<artifactId>gax-grpc</artifactId>
6060
</dependency>
61+
<dependency>
62+
<groupId>com.google.api</groupId>
63+
<artifactId>gax-httpjson</artifactId>
64+
</dependency>
6165
<dependency>
6266
<groupId>org.threeten</groupId>
6367
<artifactId>threetenbp</artifactId>
@@ -77,12 +81,24 @@
7781
<scope>test</scope>
7882
</dependency>
7983
<!-- Need testing utility classes for generated gRPC clients tests -->
84+
<dependency>
85+
<groupId>com.google.api</groupId>
86+
<artifactId>gax</artifactId>
87+
<classifier>testlib</classifier>
88+
<scope>test</scope>
89+
</dependency>
8090
<dependency>
8191
<groupId>com.google.api</groupId>
8292
<artifactId>gax-grpc</artifactId>
8393
<classifier>testlib</classifier>
8494
<scope>test</scope>
8595
</dependency>
96+
<dependency>
97+
<groupId>com.google.api</groupId>
98+
<artifactId>gax-httpjson</artifactId>
99+
<classifier>testlib</classifier>
100+
<scope>test</scope>
101+
</dependency>
86102
</dependencies>
87103

88104
<profiles>

google-cloud-gke-backup/src/main/java/com/google/cloud/gkebackup/v1/BackupForGKEClient.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.api.core.ApiFuture;
2020
import com.google.api.core.ApiFutures;
2121
import com.google.api.gax.core.BackgroundResource;
22+
import com.google.api.gax.httpjson.longrunning.OperationsClient;
2223
import com.google.api.gax.longrunning.OperationFuture;
2324
import com.google.api.gax.paging.AbstractFixedSizeCollection;
2425
import com.google.api.gax.paging.AbstractPage;
@@ -30,7 +31,6 @@
3031
import com.google.cloud.gkebackup.v1.stub.BackupForGKEStubSettings;
3132
import com.google.common.util.concurrent.MoreExecutors;
3233
import com.google.longrunning.Operation;
33-
import com.google.longrunning.OperationsClient;
3434
import com.google.protobuf.Empty;
3535
import com.google.protobuf.FieldMask;
3636
import java.io.IOException;
@@ -103,13 +103,28 @@
103103
* BackupForGKEClient backupForGKEClient = BackupForGKEClient.create(backupForGKESettings);
104104
* }</pre>
105105
*
106+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
107+
* the wire:
108+
*
109+
* <pre>{@code
110+
* // This snippet has been automatically generated for illustrative purposes only.
111+
* // It may require modifications to work in your environment.
112+
* BackupForGKESettings backupForGKESettings =
113+
* BackupForGKESettings.newBuilder()
114+
* .setTransportChannelProvider(
115+
* BackupForGKESettings.defaultHttpJsonTransportProviderBuilder().build())
116+
* .build();
117+
* BackupForGKEClient backupForGKEClient = BackupForGKEClient.create(backupForGKESettings);
118+
* }</pre>
119+
*
106120
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
107121
*/
108122
@Generated("by gapic-generator-java")
109123
public class BackupForGKEClient implements BackgroundResource {
110124
private final BackupForGKESettings settings;
111125
private final BackupForGKEStub stub;
112-
private final OperationsClient operationsClient;
126+
private final OperationsClient httpJsonOperationsClient;
127+
private final com.google.longrunning.OperationsClient operationsClient;
113128

114129
/** Constructs an instance of BackupForGKEClient with default settings. */
115130
public static final BackupForGKEClient create() throws IOException {
@@ -140,13 +155,17 @@ public static final BackupForGKEClient create(BackupForGKEStub stub) {
140155
protected BackupForGKEClient(BackupForGKESettings settings) throws IOException {
141156
this.settings = settings;
142157
this.stub = ((BackupForGKEStubSettings) settings.getStubSettings()).createStub();
143-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
158+
this.operationsClient =
159+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
160+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
144161
}
145162

146163
protected BackupForGKEClient(BackupForGKEStub stub) {
147164
this.settings = null;
148165
this.stub = stub;
149-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
166+
this.operationsClient =
167+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
168+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
150169
}
151170

152171
public final BackupForGKESettings getSettings() {
@@ -161,10 +180,18 @@ public BackupForGKEStub getStub() {
161180
* Returns the OperationsClient that can be used to query the status of a long-running operation
162181
* returned by another API method call.
163182
*/
164-
public final OperationsClient getOperationsClient() {
183+
public final com.google.longrunning.OperationsClient getOperationsClient() {
165184
return operationsClient;
166185
}
167186

187+
/**
188+
* Returns the OperationsClient that can be used to query the status of a long-running operation
189+
* returned by another API method call.
190+
*/
191+
public final OperationsClient getHttpJsonOperationsClient() {
192+
return httpJsonOperationsClient;
193+
}
194+
168195
// AUTO-GENERATED DOCUMENTATION AND METHOD.
169196
/**
170197
* Creates a new BackupPlan in a given location.

google-cloud-gke-backup/src/main/java/com/google/cloud/gkebackup/v1/BackupForGKESettings.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.api.gax.core.GoogleCredentialsProvider;
2929
import com.google.api.gax.core.InstantiatingExecutorProvider;
3030
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
31+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
3132
import com.google.api.gax.rpc.ApiClientHeaderProvider;
3233
import com.google.api.gax.rpc.ClientContext;
3334
import com.google.api.gax.rpc.ClientSettings;
@@ -305,11 +306,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
305306
return BackupForGKEStubSettings.defaultCredentialsProviderBuilder();
306307
}
307308

308-
/** Returns a builder for the default ChannelProvider for this service. */
309+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
309310
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
310311
return BackupForGKEStubSettings.defaultGrpcTransportProviderBuilder();
311312
}
312313

314+
/** Returns a builder for the default REST ChannelProvider for this service. */
315+
@BetaApi
316+
public static InstantiatingHttpJsonChannelProvider.Builder
317+
defaultHttpJsonTransportProviderBuilder() {
318+
return BackupForGKEStubSettings.defaultHttpJsonTransportProviderBuilder();
319+
}
320+
313321
public static TransportChannelProvider defaultTransportChannelProvider() {
314322
return BackupForGKEStubSettings.defaultTransportChannelProvider();
315323
}
@@ -319,11 +327,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
319327
return BackupForGKEStubSettings.defaultApiClientHeaderProviderBuilder();
320328
}
321329

322-
/** Returns a new builder for this class. */
330+
/** Returns a new gRPC builder for this class. */
323331
public static Builder newBuilder() {
324332
return Builder.createDefault();
325333
}
326334

335+
/** Returns a new REST builder for this class. */
336+
@BetaApi
337+
public static Builder newHttpJsonBuilder() {
338+
return Builder.createHttpJsonDefault();
339+
}
340+
327341
/** Returns a new builder for this class. */
328342
public static Builder newBuilder(ClientContext clientContext) {
329343
return new Builder(clientContext);
@@ -361,6 +375,11 @@ private static Builder createDefault() {
361375
return new Builder(BackupForGKEStubSettings.newBuilder());
362376
}
363377

378+
@BetaApi
379+
private static Builder createHttpJsonDefault() {
380+
return new Builder(BackupForGKEStubSettings.newHttpJsonBuilder());
381+
}
382+
364383
public BackupForGKEStubSettings.Builder getStubSettingsBuilder() {
365384
return ((BackupForGKEStubSettings.Builder) getStubSettings());
366385
}

google-cloud-gke-backup/src/main/java/com/google/cloud/gkebackup/v1/stub/BackupForGKEStub.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@
7878
public abstract class BackupForGKEStub implements BackgroundResource {
7979

8080
public OperationsStub getOperationsStub() {
81-
throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
81+
return null;
82+
}
83+
84+
public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
85+
return null;
8286
}
8387

8488
public OperationCallable<CreateBackupPlanRequest, BackupPlan, OperationMetadata>

google-cloud-gke-backup/src/main/java/com/google/cloud/gkebackup/v1/stub/BackupForGKEStubSettings.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import com.google.api.gax.grpc.GrpcTransportChannel;
3434
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
3535
import com.google.api.gax.grpc.ProtoOperationTransformers;
36+
import com.google.api.gax.httpjson.GaxHttpJsonProperties;
37+
import com.google.api.gax.httpjson.HttpJsonTransportChannel;
38+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
3639
import com.google.api.gax.longrunning.OperationSnapshot;
3740
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
3841
import com.google.api.gax.retrying.RetrySettings;
@@ -748,6 +751,11 @@ public BackupForGKEStub createStub() throws IOException {
748751
.equals(GrpcTransportChannel.getGrpcTransportName())) {
749752
return GrpcBackupForGKEStub.create(this);
750753
}
754+
if (getTransportChannelProvider()
755+
.getTransportName()
756+
.equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
757+
return HttpJsonBackupForGKEStub.create(this);
758+
}
751759
throw new UnsupportedOperationException(
752760
String.format(
753761
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -780,30 +788,56 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
780788
.setUseJwtAccessWithScope(true);
781789
}
782790

783-
/** Returns a builder for the default ChannelProvider for this service. */
791+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
784792
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
785793
return InstantiatingGrpcChannelProvider.newBuilder()
786794
.setMaxInboundMessageSize(Integer.MAX_VALUE);
787795
}
788796

797+
/** Returns a builder for the default REST ChannelProvider for this service. */
798+
@BetaApi
799+
public static InstantiatingHttpJsonChannelProvider.Builder
800+
defaultHttpJsonTransportProviderBuilder() {
801+
return InstantiatingHttpJsonChannelProvider.newBuilder();
802+
}
803+
789804
public static TransportChannelProvider defaultTransportChannelProvider() {
790805
return defaultGrpcTransportProviderBuilder().build();
791806
}
792807

793808
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
794-
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
809+
public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
795810
return ApiClientHeaderProvider.newBuilder()
796811
.setGeneratedLibToken(
797812
"gapic", GaxProperties.getLibraryVersion(BackupForGKEStubSettings.class))
798813
.setTransportToken(
799814
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
800815
}
801816

802-
/** Returns a new builder for this class. */
817+
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
818+
public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
819+
return ApiClientHeaderProvider.newBuilder()
820+
.setGeneratedLibToken(
821+
"gapic", GaxProperties.getLibraryVersion(BackupForGKEStubSettings.class))
822+
.setTransportToken(
823+
GaxHttpJsonProperties.getHttpJsonTokenName(),
824+
GaxHttpJsonProperties.getHttpJsonVersion());
825+
}
826+
827+
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
828+
return BackupForGKEStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
829+
}
830+
831+
/** Returns a new gRPC builder for this class. */
803832
public static Builder newBuilder() {
804833
return Builder.createDefault();
805834
}
806835

836+
/** Returns a new REST builder for this class. */
837+
public static Builder newHttpJsonBuilder() {
838+
return Builder.createHttpJsonDefault();
839+
}
840+
807841
/** Returns a new builder for this class. */
808842
public static Builder newBuilder(ClientContext clientContext) {
809843
return new Builder(clientContext);
@@ -1149,6 +1183,19 @@ private static Builder createDefault() {
11491183
return initDefaults(builder);
11501184
}
11511185

1186+
private static Builder createHttpJsonDefault() {
1187+
Builder builder = new Builder(((ClientContext) null));
1188+
1189+
builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
1190+
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
1191+
builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
1192+
builder.setEndpoint(getDefaultEndpoint());
1193+
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
1194+
builder.setSwitchToMtlsEndpointAllowed(true);
1195+
1196+
return initDefaults(builder);
1197+
}
1198+
11521199
private static Builder initDefaults(Builder builder) {
11531200
builder
11541201
.createBackupPlanSettings()

0 commit comments

Comments
 (0)