• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.workflows.v1beta.stub;
18 
19 import static com.google.cloud.workflows.v1beta.WorkflowsClient.ListWorkflowsPagedResponse;
20 
21 import com.google.api.core.BetaApi;
22 import com.google.api.gax.core.BackgroundResource;
23 import com.google.api.gax.core.BackgroundResourceAggregation;
24 import com.google.api.gax.grpc.GrpcCallSettings;
25 import com.google.api.gax.grpc.GrpcStubCallableFactory;
26 import com.google.api.gax.rpc.ClientContext;
27 import com.google.api.gax.rpc.OperationCallable;
28 import com.google.api.gax.rpc.UnaryCallable;
29 import com.google.cloud.workflows.v1beta.CreateWorkflowRequest;
30 import com.google.cloud.workflows.v1beta.DeleteWorkflowRequest;
31 import com.google.cloud.workflows.v1beta.GetWorkflowRequest;
32 import com.google.cloud.workflows.v1beta.ListWorkflowsRequest;
33 import com.google.cloud.workflows.v1beta.ListWorkflowsResponse;
34 import com.google.cloud.workflows.v1beta.OperationMetadata;
35 import com.google.cloud.workflows.v1beta.UpdateWorkflowRequest;
36 import com.google.cloud.workflows.v1beta.Workflow;
37 import com.google.common.collect.ImmutableMap;
38 import com.google.longrunning.Operation;
39 import com.google.longrunning.stub.GrpcOperationsStub;
40 import com.google.protobuf.Empty;
41 import io.grpc.MethodDescriptor;
42 import io.grpc.protobuf.ProtoUtils;
43 import java.io.IOException;
44 import java.util.concurrent.TimeUnit;
45 import javax.annotation.Generated;
46 
47 // AUTO-GENERATED DOCUMENTATION AND CLASS.
48 /**
49  * gRPC stub implementation for the Workflows service API.
50  *
51  * <p>This class is for advanced usage and reflects the underlying API directly.
52  */
53 @BetaApi
54 @Generated("by gapic-generator-java")
55 public class GrpcWorkflowsStub extends WorkflowsStub {
56   private static final MethodDescriptor<ListWorkflowsRequest, ListWorkflowsResponse>
57       listWorkflowsMethodDescriptor =
58           MethodDescriptor.<ListWorkflowsRequest, ListWorkflowsResponse>newBuilder()
59               .setType(MethodDescriptor.MethodType.UNARY)
60               .setFullMethodName("google.cloud.workflows.v1beta.Workflows/ListWorkflows")
61               .setRequestMarshaller(
62                   ProtoUtils.marshaller(ListWorkflowsRequest.getDefaultInstance()))
63               .setResponseMarshaller(
64                   ProtoUtils.marshaller(ListWorkflowsResponse.getDefaultInstance()))
65               .build();
66 
67   private static final MethodDescriptor<GetWorkflowRequest, Workflow> getWorkflowMethodDescriptor =
68       MethodDescriptor.<GetWorkflowRequest, Workflow>newBuilder()
69           .setType(MethodDescriptor.MethodType.UNARY)
70           .setFullMethodName("google.cloud.workflows.v1beta.Workflows/GetWorkflow")
71           .setRequestMarshaller(ProtoUtils.marshaller(GetWorkflowRequest.getDefaultInstance()))
72           .setResponseMarshaller(ProtoUtils.marshaller(Workflow.getDefaultInstance()))
73           .build();
74 
75   private static final MethodDescriptor<CreateWorkflowRequest, Operation>
76       createWorkflowMethodDescriptor =
77           MethodDescriptor.<CreateWorkflowRequest, Operation>newBuilder()
78               .setType(MethodDescriptor.MethodType.UNARY)
79               .setFullMethodName("google.cloud.workflows.v1beta.Workflows/CreateWorkflow")
80               .setRequestMarshaller(
81                   ProtoUtils.marshaller(CreateWorkflowRequest.getDefaultInstance()))
82               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
83               .build();
84 
85   private static final MethodDescriptor<DeleteWorkflowRequest, Operation>
86       deleteWorkflowMethodDescriptor =
87           MethodDescriptor.<DeleteWorkflowRequest, Operation>newBuilder()
88               .setType(MethodDescriptor.MethodType.UNARY)
89               .setFullMethodName("google.cloud.workflows.v1beta.Workflows/DeleteWorkflow")
90               .setRequestMarshaller(
91                   ProtoUtils.marshaller(DeleteWorkflowRequest.getDefaultInstance()))
92               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
93               .build();
94 
95   private static final MethodDescriptor<UpdateWorkflowRequest, Operation>
96       updateWorkflowMethodDescriptor =
97           MethodDescriptor.<UpdateWorkflowRequest, Operation>newBuilder()
98               .setType(MethodDescriptor.MethodType.UNARY)
99               .setFullMethodName("google.cloud.workflows.v1beta.Workflows/UpdateWorkflow")
100               .setRequestMarshaller(
101                   ProtoUtils.marshaller(UpdateWorkflowRequest.getDefaultInstance()))
102               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
103               .build();
104 
105   private final UnaryCallable<ListWorkflowsRequest, ListWorkflowsResponse> listWorkflowsCallable;
106   private final UnaryCallable<ListWorkflowsRequest, ListWorkflowsPagedResponse>
107       listWorkflowsPagedCallable;
108   private final UnaryCallable<GetWorkflowRequest, Workflow> getWorkflowCallable;
109   private final UnaryCallable<CreateWorkflowRequest, Operation> createWorkflowCallable;
110   private final OperationCallable<CreateWorkflowRequest, Workflow, OperationMetadata>
111       createWorkflowOperationCallable;
112   private final UnaryCallable<DeleteWorkflowRequest, Operation> deleteWorkflowCallable;
113   private final OperationCallable<DeleteWorkflowRequest, Empty, OperationMetadata>
114       deleteWorkflowOperationCallable;
115   private final UnaryCallable<UpdateWorkflowRequest, Operation> updateWorkflowCallable;
116   private final OperationCallable<UpdateWorkflowRequest, Workflow, OperationMetadata>
117       updateWorkflowOperationCallable;
118 
119   private final BackgroundResource backgroundResources;
120   private final GrpcOperationsStub operationsStub;
121   private final GrpcStubCallableFactory callableFactory;
122 
create(WorkflowsStubSettings settings)123   public static final GrpcWorkflowsStub create(WorkflowsStubSettings settings) throws IOException {
124     return new GrpcWorkflowsStub(settings, ClientContext.create(settings));
125   }
126 
create(ClientContext clientContext)127   public static final GrpcWorkflowsStub create(ClientContext clientContext) throws IOException {
128     return new GrpcWorkflowsStub(WorkflowsStubSettings.newBuilder().build(), clientContext);
129   }
130 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)131   public static final GrpcWorkflowsStub create(
132       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
133     return new GrpcWorkflowsStub(
134         WorkflowsStubSettings.newBuilder().build(), clientContext, callableFactory);
135   }
136 
137   /**
138    * Constructs an instance of GrpcWorkflowsStub, using the given settings. This is protected so
139    * that it is easy to make a subclass, but otherwise, the static factory methods should be
140    * preferred.
141    */
GrpcWorkflowsStub(WorkflowsStubSettings settings, ClientContext clientContext)142   protected GrpcWorkflowsStub(WorkflowsStubSettings settings, ClientContext clientContext)
143       throws IOException {
144     this(settings, clientContext, new GrpcWorkflowsCallableFactory());
145   }
146 
147   /**
148    * Constructs an instance of GrpcWorkflowsStub, using the given settings. This is protected so
149    * that it is easy to make a subclass, but otherwise, the static factory methods should be
150    * preferred.
151    */
GrpcWorkflowsStub( WorkflowsStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)152   protected GrpcWorkflowsStub(
153       WorkflowsStubSettings settings,
154       ClientContext clientContext,
155       GrpcStubCallableFactory callableFactory)
156       throws IOException {
157     this.callableFactory = callableFactory;
158     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
159 
160     GrpcCallSettings<ListWorkflowsRequest, ListWorkflowsResponse> listWorkflowsTransportSettings =
161         GrpcCallSettings.<ListWorkflowsRequest, ListWorkflowsResponse>newBuilder()
162             .setMethodDescriptor(listWorkflowsMethodDescriptor)
163             .setParamsExtractor(
164                 request -> {
165                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
166                   params.put("parent", String.valueOf(request.getParent()));
167                   return params.build();
168                 })
169             .build();
170     GrpcCallSettings<GetWorkflowRequest, Workflow> getWorkflowTransportSettings =
171         GrpcCallSettings.<GetWorkflowRequest, Workflow>newBuilder()
172             .setMethodDescriptor(getWorkflowMethodDescriptor)
173             .setParamsExtractor(
174                 request -> {
175                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
176                   params.put("name", String.valueOf(request.getName()));
177                   return params.build();
178                 })
179             .build();
180     GrpcCallSettings<CreateWorkflowRequest, Operation> createWorkflowTransportSettings =
181         GrpcCallSettings.<CreateWorkflowRequest, Operation>newBuilder()
182             .setMethodDescriptor(createWorkflowMethodDescriptor)
183             .setParamsExtractor(
184                 request -> {
185                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
186                   params.put("parent", String.valueOf(request.getParent()));
187                   return params.build();
188                 })
189             .build();
190     GrpcCallSettings<DeleteWorkflowRequest, Operation> deleteWorkflowTransportSettings =
191         GrpcCallSettings.<DeleteWorkflowRequest, Operation>newBuilder()
192             .setMethodDescriptor(deleteWorkflowMethodDescriptor)
193             .setParamsExtractor(
194                 request -> {
195                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
196                   params.put("name", String.valueOf(request.getName()));
197                   return params.build();
198                 })
199             .build();
200     GrpcCallSettings<UpdateWorkflowRequest, Operation> updateWorkflowTransportSettings =
201         GrpcCallSettings.<UpdateWorkflowRequest, Operation>newBuilder()
202             .setMethodDescriptor(updateWorkflowMethodDescriptor)
203             .setParamsExtractor(
204                 request -> {
205                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
206                   params.put("workflow.name", String.valueOf(request.getWorkflow().getName()));
207                   return params.build();
208                 })
209             .build();
210 
211     this.listWorkflowsCallable =
212         callableFactory.createUnaryCallable(
213             listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext);
214     this.listWorkflowsPagedCallable =
215         callableFactory.createPagedCallable(
216             listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext);
217     this.getWorkflowCallable =
218         callableFactory.createUnaryCallable(
219             getWorkflowTransportSettings, settings.getWorkflowSettings(), clientContext);
220     this.createWorkflowCallable =
221         callableFactory.createUnaryCallable(
222             createWorkflowTransportSettings, settings.createWorkflowSettings(), clientContext);
223     this.createWorkflowOperationCallable =
224         callableFactory.createOperationCallable(
225             createWorkflowTransportSettings,
226             settings.createWorkflowOperationSettings(),
227             clientContext,
228             operationsStub);
229     this.deleteWorkflowCallable =
230         callableFactory.createUnaryCallable(
231             deleteWorkflowTransportSettings, settings.deleteWorkflowSettings(), clientContext);
232     this.deleteWorkflowOperationCallable =
233         callableFactory.createOperationCallable(
234             deleteWorkflowTransportSettings,
235             settings.deleteWorkflowOperationSettings(),
236             clientContext,
237             operationsStub);
238     this.updateWorkflowCallable =
239         callableFactory.createUnaryCallable(
240             updateWorkflowTransportSettings, settings.updateWorkflowSettings(), clientContext);
241     this.updateWorkflowOperationCallable =
242         callableFactory.createOperationCallable(
243             updateWorkflowTransportSettings,
244             settings.updateWorkflowOperationSettings(),
245             clientContext,
246             operationsStub);
247 
248     this.backgroundResources =
249         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
250   }
251 
getOperationsStub()252   public GrpcOperationsStub getOperationsStub() {
253     return operationsStub;
254   }
255 
256   @Override
listWorkflowsCallable()257   public UnaryCallable<ListWorkflowsRequest, ListWorkflowsResponse> listWorkflowsCallable() {
258     return listWorkflowsCallable;
259   }
260 
261   @Override
262   public UnaryCallable<ListWorkflowsRequest, ListWorkflowsPagedResponse>
listWorkflowsPagedCallable()263       listWorkflowsPagedCallable() {
264     return listWorkflowsPagedCallable;
265   }
266 
267   @Override
getWorkflowCallable()268   public UnaryCallable<GetWorkflowRequest, Workflow> getWorkflowCallable() {
269     return getWorkflowCallable;
270   }
271 
272   @Override
createWorkflowCallable()273   public UnaryCallable<CreateWorkflowRequest, Operation> createWorkflowCallable() {
274     return createWorkflowCallable;
275   }
276 
277   @Override
278   public OperationCallable<CreateWorkflowRequest, Workflow, OperationMetadata>
createWorkflowOperationCallable()279       createWorkflowOperationCallable() {
280     return createWorkflowOperationCallable;
281   }
282 
283   @Override
deleteWorkflowCallable()284   public UnaryCallable<DeleteWorkflowRequest, Operation> deleteWorkflowCallable() {
285     return deleteWorkflowCallable;
286   }
287 
288   @Override
289   public OperationCallable<DeleteWorkflowRequest, Empty, OperationMetadata>
deleteWorkflowOperationCallable()290       deleteWorkflowOperationCallable() {
291     return deleteWorkflowOperationCallable;
292   }
293 
294   @Override
updateWorkflowCallable()295   public UnaryCallable<UpdateWorkflowRequest, Operation> updateWorkflowCallable() {
296     return updateWorkflowCallable;
297   }
298 
299   @Override
300   public OperationCallable<UpdateWorkflowRequest, Workflow, OperationMetadata>
updateWorkflowOperationCallable()301       updateWorkflowOperationCallable() {
302     return updateWorkflowOperationCallable;
303   }
304 
305   @Override
close()306   public final void close() {
307     try {
308       backgroundResources.close();
309     } catch (RuntimeException e) {
310       throw e;
311     } catch (Exception e) {
312       throw new IllegalStateException("Failed to close resource", e);
313     }
314   }
315 
316   @Override
shutdown()317   public void shutdown() {
318     backgroundResources.shutdown();
319   }
320 
321   @Override
isShutdown()322   public boolean isShutdown() {
323     return backgroundResources.isShutdown();
324   }
325 
326   @Override
isTerminated()327   public boolean isTerminated() {
328     return backgroundResources.isTerminated();
329   }
330 
331   @Override
shutdownNow()332   public void shutdownNow() {
333     backgroundResources.shutdownNow();
334   }
335 
336   @Override
awaitTermination(long duration, TimeUnit unit)337   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
338     return backgroundResources.awaitTermination(duration, unit);
339   }
340 }
341