This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
/
HttpJsonOperationsStub.java
369 lines (339 loc) · 16.4 KB
/
HttpJsonOperationsStub.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
* Copyright 2021 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.api.gax.httpjson.longrunning.stub;
import com.google.api.client.http.HttpMethods;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.httpjson.ApiMethodDescriptor;
import com.google.api.gax.httpjson.HttpJsonCallSettings;
import com.google.api.gax.httpjson.HttpJsonLongRunningClient;
import com.google.api.gax.httpjson.HttpJsonOperationSnapshot;
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
import com.google.api.gax.httpjson.ProtoMessageResponseParser;
import com.google.api.gax.httpjson.ProtoRestSerializer;
import com.google.api.gax.httpjson.longrunning.OperationsClient.ListOperationsPagedResponse;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.LongRunningClient;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.longrunning.CancelOperationRequest;
import com.google.longrunning.DeleteOperationRequest;
import com.google.longrunning.GetOperationRequest;
import com.google.longrunning.ListOperationsRequest;
import com.google.longrunning.ListOperationsResponse;
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* REST stub implementation for the Operations service API.
*
* <p>This class is for advanced usage and reflects the underlying API directly.
*/
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public class HttpJsonOperationsStub extends OperationsStub {
private static final ApiMethodDescriptor<ListOperationsRequest, ListOperationsResponse>
listOperationsMethodDescriptor =
ApiMethodDescriptor.<ListOperationsRequest, ListOperationsResponse>newBuilder()
.setFullMethodName("google.longrunning.Operations/ListOperations")
.setHttpMethod(HttpMethods.GET)
.setRequestFormatter(
ProtoMessageRequestFormatter.<ListOperationsRequest>newBuilder()
.setPath(
"/v1/{name=operations}",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<ListOperationsRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map<String, List<String>> fields = new HashMap<>();
ProtoRestSerializer<ListOperationsRequest> serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.<ListOperationsResponse>newBuilder()
.setDefaultInstance(ListOperationsResponse.getDefaultInstance())
.build())
.build();
private static final ApiMethodDescriptor<GetOperationRequest, Operation>
getOperationMethodDescriptor =
ApiMethodDescriptor.<GetOperationRequest, Operation>newBuilder()
.setFullMethodName("google.longrunning.Operations/GetOperation")
.setHttpMethod(HttpMethods.GET)
.setRequestFormatter(
ProtoMessageRequestFormatter.<GetOperationRequest>newBuilder()
.setPath(
"/v1/{name=operations/**}",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<GetOperationRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(request -> new HashMap<>())
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.<Operation>newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.build())
.setOperationSnapshotFactory(
(request, response) -> HttpJsonOperationSnapshot.create(response))
.setPollingRequestFactory(
compoundOperationId ->
GetOperationRequest.newBuilder().setName(compoundOperationId).build())
.build();
private static final ApiMethodDescriptor<DeleteOperationRequest, Empty>
deleteOperationMethodDescriptor =
ApiMethodDescriptor.<DeleteOperationRequest, Empty>newBuilder()
.setFullMethodName("google.longrunning.Operations/DeleteOperation")
.setHttpMethod(HttpMethods.DELETE)
.setRequestFormatter(
ProtoMessageRequestFormatter.<DeleteOperationRequest>newBuilder()
.setPath(
"/v1/{name=operations/**}",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<DeleteOperationRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(request -> new HashMap<>())
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.<Empty>newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.build())
.build();
private static final ApiMethodDescriptor<CancelOperationRequest, Empty>
cancelOperationMethodDescriptor =
ApiMethodDescriptor.<CancelOperationRequest, Empty>newBuilder()
.setFullMethodName("google.longrunning.Operations/CancelOperation")
.setHttpMethod(HttpMethods.POST)
.setRequestFormatter(
ProtoMessageRequestFormatter.<CancelOperationRequest>newBuilder()
.setPath(
"/v1/{name=operations/**}:cancel",
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<CancelOperationRequest> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(request -> new HashMap<>())
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.<Empty>newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.build())
.build();
private final UnaryCallable<ListOperationsRequest, ListOperationsResponse> listOperationsCallable;
private final UnaryCallable<ListOperationsRequest, ListOperationsPagedResponse>
listOperationsPagedCallable;
private final UnaryCallable<GetOperationRequest, Operation> getOperationCallable;
private final UnaryCallable<DeleteOperationRequest, Empty> deleteOperationCallable;
private final UnaryCallable<CancelOperationRequest, Empty> cancelOperationCallable;
private final LongRunningClient longRunningClient;
private final BackgroundResource backgroundResources;
private final HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonOperationsStub create(OperationsStubSettings settings)
throws IOException {
return new HttpJsonOperationsStub(settings, ClientContext.create(settings));
}
public static final HttpJsonOperationsStub create(ClientContext clientContext)
throws IOException {
return new HttpJsonOperationsStub(OperationsStubSettings.newBuilder().build(), clientContext);
}
public static final HttpJsonOperationsStub create(
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
return new HttpJsonOperationsStub(
OperationsStubSettings.newBuilder().build(),
clientContext,
callableFactory,
TypeRegistry.getEmptyTypeRegistry());
}
public static final HttpJsonOperationsStub create(
ClientContext clientContext,
HttpJsonStubCallableFactory callableFactory,
TypeRegistry typeRegistry)
throws IOException {
return new HttpJsonOperationsStub(
OperationsStubSettings.newBuilder().build(), clientContext, callableFactory, typeRegistry);
}
/**
* Constructs an instance of HttpJsonOperationsStub, using the given settings. This is protected
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
* preferred.
*/
protected HttpJsonOperationsStub(OperationsStubSettings settings, ClientContext clientContext)
throws IOException {
this(
settings,
clientContext,
new HttpJsonOperationsCallableFactory(),
TypeRegistry.getEmptyTypeRegistry());
}
/**
* Constructs an instance of HttpJsonOperationsStub, using the given settings. This is protected
* so that it is easy to make a subclass, but otherwise, the static factory methods should be
* preferred.
*/
protected HttpJsonOperationsStub(
OperationsStubSettings settings,
ClientContext clientContext,
HttpJsonStubCallableFactory callableFactory,
TypeRegistry typeRegistry)
throws IOException {
this.callableFactory = callableFactory;
HttpJsonCallSettings<ListOperationsRequest, ListOperationsResponse>
listOperationsTransportSettings =
HttpJsonCallSettings.<ListOperationsRequest, ListOperationsResponse>newBuilder()
.setMethodDescriptor(listOperationsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
HttpJsonCallSettings<GetOperationRequest, Operation> getOperationTransportSettings =
HttpJsonCallSettings.<GetOperationRequest, Operation>newBuilder()
.setMethodDescriptor(getOperationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
HttpJsonCallSettings<DeleteOperationRequest, Empty> deleteOperationTransportSettings =
HttpJsonCallSettings.<DeleteOperationRequest, Empty>newBuilder()
.setMethodDescriptor(deleteOperationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
HttpJsonCallSettings<CancelOperationRequest, Empty> cancelOperationTransportSettings =
HttpJsonCallSettings.<CancelOperationRequest, Empty>newBuilder()
.setMethodDescriptor(cancelOperationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.build();
listOperationsCallable =
callableFactory.createUnaryCallable(
listOperationsTransportSettings, settings.listOperationsSettings(), clientContext);
listOperationsPagedCallable =
callableFactory.createPagedCallable(
listOperationsTransportSettings, settings.listOperationsSettings(), clientContext);
getOperationCallable =
callableFactory.createUnaryCallable(
getOperationTransportSettings, settings.getOperationSettings(), clientContext);
deleteOperationCallable =
callableFactory.createUnaryCallable(
deleteOperationTransportSettings, settings.deleteOperationSettings(), clientContext);
cancelOperationCallable =
callableFactory.createUnaryCallable(
cancelOperationTransportSettings, settings.cancelOperationSettings(), clientContext);
longRunningClient =
new HttpJsonLongRunningClient<>(
getOperationCallable,
getOperationMethodDescriptor.getOperationSnapshotFactory(),
getOperationMethodDescriptor.getPollingRequestFactory());
backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
@InternalApi
public static List<ApiMethodDescriptor> getMethodDescriptors() {
List<ApiMethodDescriptor> methodDescriptors = new ArrayList<>();
methodDescriptors.add(listOperationsMethodDescriptor);
methodDescriptors.add(getOperationMethodDescriptor);
methodDescriptors.add(deleteOperationMethodDescriptor);
methodDescriptors.add(cancelOperationMethodDescriptor);
return methodDescriptors;
}
@Override
public UnaryCallable<ListOperationsRequest, ListOperationsResponse> listOperationsCallable() {
return listOperationsCallable;
}
@Override
public UnaryCallable<ListOperationsRequest, ListOperationsPagedResponse>
listOperationsPagedCallable() {
return listOperationsPagedCallable;
}
@Override
public UnaryCallable<GetOperationRequest, Operation> getOperationCallable() {
return getOperationCallable;
}
@Override
public UnaryCallable<DeleteOperationRequest, Empty> deleteOperationCallable() {
return deleteOperationCallable;
}
@Override
public UnaryCallable<CancelOperationRequest, Empty> cancelOperationCallable() {
return cancelOperationCallable;
}
@Override
public LongRunningClient longRunningClient() {
return longRunningClient;
}
@Override
public final void close() {
shutdown();
}
@Override
public void shutdown() {
backgroundResources.shutdown();
}
@Override
public boolean isShutdown() {
return backgroundResources.isShutdown();
}
@Override
public boolean isTerminated() {
return backgroundResources.isTerminated();
}
@Override
public void shutdownNow() {
backgroundResources.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return backgroundResources.awaitTermination(duration, unit);
}
}