• 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.dataproc.v1.stub;
18 
19 import static com.google.cloud.dataproc.v1.JobControllerClient.ListJobsPagedResponse;
20 
21 import com.google.api.gax.core.BackgroundResource;
22 import com.google.api.gax.core.BackgroundResourceAggregation;
23 import com.google.api.gax.grpc.GrpcCallSettings;
24 import com.google.api.gax.grpc.GrpcStubCallableFactory;
25 import com.google.api.gax.rpc.ClientContext;
26 import com.google.api.gax.rpc.OperationCallable;
27 import com.google.api.gax.rpc.UnaryCallable;
28 import com.google.cloud.dataproc.v1.CancelJobRequest;
29 import com.google.cloud.dataproc.v1.DeleteJobRequest;
30 import com.google.cloud.dataproc.v1.GetJobRequest;
31 import com.google.cloud.dataproc.v1.Job;
32 import com.google.cloud.dataproc.v1.JobMetadata;
33 import com.google.cloud.dataproc.v1.ListJobsRequest;
34 import com.google.cloud.dataproc.v1.ListJobsResponse;
35 import com.google.cloud.dataproc.v1.SubmitJobRequest;
36 import com.google.cloud.dataproc.v1.UpdateJobRequest;
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 JobController service API.
50  *
51  * <p>This class is for advanced usage and reflects the underlying API directly.
52  */
53 @Generated("by gapic-generator-java")
54 public class GrpcJobControllerStub extends JobControllerStub {
55   private static final MethodDescriptor<SubmitJobRequest, Job> submitJobMethodDescriptor =
56       MethodDescriptor.<SubmitJobRequest, Job>newBuilder()
57           .setType(MethodDescriptor.MethodType.UNARY)
58           .setFullMethodName("google.cloud.dataproc.v1.JobController/SubmitJob")
59           .setRequestMarshaller(ProtoUtils.marshaller(SubmitJobRequest.getDefaultInstance()))
60           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
61           .build();
62 
63   private static final MethodDescriptor<SubmitJobRequest, Operation>
64       submitJobAsOperationMethodDescriptor =
65           MethodDescriptor.<SubmitJobRequest, Operation>newBuilder()
66               .setType(MethodDescriptor.MethodType.UNARY)
67               .setFullMethodName("google.cloud.dataproc.v1.JobController/SubmitJobAsOperation")
68               .setRequestMarshaller(ProtoUtils.marshaller(SubmitJobRequest.getDefaultInstance()))
69               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
70               .build();
71 
72   private static final MethodDescriptor<GetJobRequest, Job> getJobMethodDescriptor =
73       MethodDescriptor.<GetJobRequest, Job>newBuilder()
74           .setType(MethodDescriptor.MethodType.UNARY)
75           .setFullMethodName("google.cloud.dataproc.v1.JobController/GetJob")
76           .setRequestMarshaller(ProtoUtils.marshaller(GetJobRequest.getDefaultInstance()))
77           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
78           .build();
79 
80   private static final MethodDescriptor<ListJobsRequest, ListJobsResponse>
81       listJobsMethodDescriptor =
82           MethodDescriptor.<ListJobsRequest, ListJobsResponse>newBuilder()
83               .setType(MethodDescriptor.MethodType.UNARY)
84               .setFullMethodName("google.cloud.dataproc.v1.JobController/ListJobs")
85               .setRequestMarshaller(ProtoUtils.marshaller(ListJobsRequest.getDefaultInstance()))
86               .setResponseMarshaller(ProtoUtils.marshaller(ListJobsResponse.getDefaultInstance()))
87               .build();
88 
89   private static final MethodDescriptor<UpdateJobRequest, Job> updateJobMethodDescriptor =
90       MethodDescriptor.<UpdateJobRequest, Job>newBuilder()
91           .setType(MethodDescriptor.MethodType.UNARY)
92           .setFullMethodName("google.cloud.dataproc.v1.JobController/UpdateJob")
93           .setRequestMarshaller(ProtoUtils.marshaller(UpdateJobRequest.getDefaultInstance()))
94           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
95           .build();
96 
97   private static final MethodDescriptor<CancelJobRequest, Job> cancelJobMethodDescriptor =
98       MethodDescriptor.<CancelJobRequest, Job>newBuilder()
99           .setType(MethodDescriptor.MethodType.UNARY)
100           .setFullMethodName("google.cloud.dataproc.v1.JobController/CancelJob")
101           .setRequestMarshaller(ProtoUtils.marshaller(CancelJobRequest.getDefaultInstance()))
102           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
103           .build();
104 
105   private static final MethodDescriptor<DeleteJobRequest, Empty> deleteJobMethodDescriptor =
106       MethodDescriptor.<DeleteJobRequest, Empty>newBuilder()
107           .setType(MethodDescriptor.MethodType.UNARY)
108           .setFullMethodName("google.cloud.dataproc.v1.JobController/DeleteJob")
109           .setRequestMarshaller(ProtoUtils.marshaller(DeleteJobRequest.getDefaultInstance()))
110           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
111           .build();
112 
113   private final UnaryCallable<SubmitJobRequest, Job> submitJobCallable;
114   private final UnaryCallable<SubmitJobRequest, Operation> submitJobAsOperationCallable;
115   private final OperationCallable<SubmitJobRequest, Job, JobMetadata>
116       submitJobAsOperationOperationCallable;
117   private final UnaryCallable<GetJobRequest, Job> getJobCallable;
118   private final UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable;
119   private final UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable;
120   private final UnaryCallable<UpdateJobRequest, Job> updateJobCallable;
121   private final UnaryCallable<CancelJobRequest, Job> cancelJobCallable;
122   private final UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable;
123 
124   private final BackgroundResource backgroundResources;
125   private final GrpcOperationsStub operationsStub;
126   private final GrpcStubCallableFactory callableFactory;
127 
create(JobControllerStubSettings settings)128   public static final GrpcJobControllerStub create(JobControllerStubSettings settings)
129       throws IOException {
130     return new GrpcJobControllerStub(settings, ClientContext.create(settings));
131   }
132 
create(ClientContext clientContext)133   public static final GrpcJobControllerStub create(ClientContext clientContext) throws IOException {
134     return new GrpcJobControllerStub(JobControllerStubSettings.newBuilder().build(), clientContext);
135   }
136 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)137   public static final GrpcJobControllerStub create(
138       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
139     return new GrpcJobControllerStub(
140         JobControllerStubSettings.newBuilder().build(), clientContext, callableFactory);
141   }
142 
143   /**
144    * Constructs an instance of GrpcJobControllerStub, using the given settings. This is protected so
145    * that it is easy to make a subclass, but otherwise, the static factory methods should be
146    * preferred.
147    */
GrpcJobControllerStub(JobControllerStubSettings settings, ClientContext clientContext)148   protected GrpcJobControllerStub(JobControllerStubSettings settings, ClientContext clientContext)
149       throws IOException {
150     this(settings, clientContext, new GrpcJobControllerCallableFactory());
151   }
152 
153   /**
154    * Constructs an instance of GrpcJobControllerStub, using the given settings. This is protected so
155    * that it is easy to make a subclass, but otherwise, the static factory methods should be
156    * preferred.
157    */
GrpcJobControllerStub( JobControllerStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)158   protected GrpcJobControllerStub(
159       JobControllerStubSettings settings,
160       ClientContext clientContext,
161       GrpcStubCallableFactory callableFactory)
162       throws IOException {
163     this.callableFactory = callableFactory;
164     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
165 
166     GrpcCallSettings<SubmitJobRequest, Job> submitJobTransportSettings =
167         GrpcCallSettings.<SubmitJobRequest, Job>newBuilder()
168             .setMethodDescriptor(submitJobMethodDescriptor)
169             .setParamsExtractor(
170                 request -> {
171                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
172                   params.put("project_id", String.valueOf(request.getProjectId()));
173                   params.put("region", String.valueOf(request.getRegion()));
174                   return params.build();
175                 })
176             .build();
177     GrpcCallSettings<SubmitJobRequest, Operation> submitJobAsOperationTransportSettings =
178         GrpcCallSettings.<SubmitJobRequest, Operation>newBuilder()
179             .setMethodDescriptor(submitJobAsOperationMethodDescriptor)
180             .setParamsExtractor(
181                 request -> {
182                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
183                   params.put("project_id", String.valueOf(request.getProjectId()));
184                   params.put("region", String.valueOf(request.getRegion()));
185                   return params.build();
186                 })
187             .build();
188     GrpcCallSettings<GetJobRequest, Job> getJobTransportSettings =
189         GrpcCallSettings.<GetJobRequest, Job>newBuilder()
190             .setMethodDescriptor(getJobMethodDescriptor)
191             .setParamsExtractor(
192                 request -> {
193                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
194                   params.put("job_id", String.valueOf(request.getJobId()));
195                   params.put("project_id", String.valueOf(request.getProjectId()));
196                   params.put("region", String.valueOf(request.getRegion()));
197                   return params.build();
198                 })
199             .build();
200     GrpcCallSettings<ListJobsRequest, ListJobsResponse> listJobsTransportSettings =
201         GrpcCallSettings.<ListJobsRequest, ListJobsResponse>newBuilder()
202             .setMethodDescriptor(listJobsMethodDescriptor)
203             .setParamsExtractor(
204                 request -> {
205                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
206                   params.put("project_id", String.valueOf(request.getProjectId()));
207                   params.put("region", String.valueOf(request.getRegion()));
208                   return params.build();
209                 })
210             .build();
211     GrpcCallSettings<UpdateJobRequest, Job> updateJobTransportSettings =
212         GrpcCallSettings.<UpdateJobRequest, Job>newBuilder()
213             .setMethodDescriptor(updateJobMethodDescriptor)
214             .setParamsExtractor(
215                 request -> {
216                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
217                   params.put("job_id", String.valueOf(request.getJobId()));
218                   params.put("project_id", String.valueOf(request.getProjectId()));
219                   params.put("region", String.valueOf(request.getRegion()));
220                   return params.build();
221                 })
222             .build();
223     GrpcCallSettings<CancelJobRequest, Job> cancelJobTransportSettings =
224         GrpcCallSettings.<CancelJobRequest, Job>newBuilder()
225             .setMethodDescriptor(cancelJobMethodDescriptor)
226             .setParamsExtractor(
227                 request -> {
228                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
229                   params.put("job_id", String.valueOf(request.getJobId()));
230                   params.put("project_id", String.valueOf(request.getProjectId()));
231                   params.put("region", String.valueOf(request.getRegion()));
232                   return params.build();
233                 })
234             .build();
235     GrpcCallSettings<DeleteJobRequest, Empty> deleteJobTransportSettings =
236         GrpcCallSettings.<DeleteJobRequest, Empty>newBuilder()
237             .setMethodDescriptor(deleteJobMethodDescriptor)
238             .setParamsExtractor(
239                 request -> {
240                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
241                   params.put("job_id", String.valueOf(request.getJobId()));
242                   params.put("project_id", String.valueOf(request.getProjectId()));
243                   params.put("region", String.valueOf(request.getRegion()));
244                   return params.build();
245                 })
246             .build();
247 
248     this.submitJobCallable =
249         callableFactory.createUnaryCallable(
250             submitJobTransportSettings, settings.submitJobSettings(), clientContext);
251     this.submitJobAsOperationCallable =
252         callableFactory.createUnaryCallable(
253             submitJobAsOperationTransportSettings,
254             settings.submitJobAsOperationSettings(),
255             clientContext);
256     this.submitJobAsOperationOperationCallable =
257         callableFactory.createOperationCallable(
258             submitJobAsOperationTransportSettings,
259             settings.submitJobAsOperationOperationSettings(),
260             clientContext,
261             operationsStub);
262     this.getJobCallable =
263         callableFactory.createUnaryCallable(
264             getJobTransportSettings, settings.getJobSettings(), clientContext);
265     this.listJobsCallable =
266         callableFactory.createUnaryCallable(
267             listJobsTransportSettings, settings.listJobsSettings(), clientContext);
268     this.listJobsPagedCallable =
269         callableFactory.createPagedCallable(
270             listJobsTransportSettings, settings.listJobsSettings(), clientContext);
271     this.updateJobCallable =
272         callableFactory.createUnaryCallable(
273             updateJobTransportSettings, settings.updateJobSettings(), clientContext);
274     this.cancelJobCallable =
275         callableFactory.createUnaryCallable(
276             cancelJobTransportSettings, settings.cancelJobSettings(), clientContext);
277     this.deleteJobCallable =
278         callableFactory.createUnaryCallable(
279             deleteJobTransportSettings, settings.deleteJobSettings(), clientContext);
280 
281     this.backgroundResources =
282         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
283   }
284 
getOperationsStub()285   public GrpcOperationsStub getOperationsStub() {
286     return operationsStub;
287   }
288 
289   @Override
submitJobCallable()290   public UnaryCallable<SubmitJobRequest, Job> submitJobCallable() {
291     return submitJobCallable;
292   }
293 
294   @Override
submitJobAsOperationCallable()295   public UnaryCallable<SubmitJobRequest, Operation> submitJobAsOperationCallable() {
296     return submitJobAsOperationCallable;
297   }
298 
299   @Override
300   public OperationCallable<SubmitJobRequest, Job, JobMetadata>
submitJobAsOperationOperationCallable()301       submitJobAsOperationOperationCallable() {
302     return submitJobAsOperationOperationCallable;
303   }
304 
305   @Override
getJobCallable()306   public UnaryCallable<GetJobRequest, Job> getJobCallable() {
307     return getJobCallable;
308   }
309 
310   @Override
listJobsCallable()311   public UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable() {
312     return listJobsCallable;
313   }
314 
315   @Override
listJobsPagedCallable()316   public UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable() {
317     return listJobsPagedCallable;
318   }
319 
320   @Override
updateJobCallable()321   public UnaryCallable<UpdateJobRequest, Job> updateJobCallable() {
322     return updateJobCallable;
323   }
324 
325   @Override
cancelJobCallable()326   public UnaryCallable<CancelJobRequest, Job> cancelJobCallable() {
327     return cancelJobCallable;
328   }
329 
330   @Override
deleteJobCallable()331   public UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable() {
332     return deleteJobCallable;
333   }
334 
335   @Override
close()336   public final void close() {
337     try {
338       backgroundResources.close();
339     } catch (RuntimeException e) {
340       throw e;
341     } catch (Exception e) {
342       throw new IllegalStateException("Failed to close resource", e);
343     }
344   }
345 
346   @Override
shutdown()347   public void shutdown() {
348     backgroundResources.shutdown();
349   }
350 
351   @Override
isShutdown()352   public boolean isShutdown() {
353     return backgroundResources.isShutdown();
354   }
355 
356   @Override
isTerminated()357   public boolean isTerminated() {
358     return backgroundResources.isTerminated();
359   }
360 
361   @Override
shutdownNow()362   public void shutdownNow() {
363     backgroundResources.shutdownNow();
364   }
365 
366   @Override
awaitTermination(long duration, TimeUnit unit)367   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
368     return backgroundResources.awaitTermination(duration, unit);
369   }
370 }
371