• 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.compute.v1;
18 
19 import com.google.api.core.ApiFuture;
20 import com.google.api.core.ApiFutures;
21 import com.google.api.core.BetaApi;
22 import com.google.api.gax.core.BackgroundResource;
23 import com.google.api.gax.longrunning.OperationFuture;
24 import com.google.api.gax.paging.AbstractFixedSizeCollection;
25 import com.google.api.gax.paging.AbstractPage;
26 import com.google.api.gax.paging.AbstractPagedListResponse;
27 import com.google.api.gax.rpc.OperationCallable;
28 import com.google.api.gax.rpc.PageContext;
29 import com.google.api.gax.rpc.UnaryCallable;
30 import com.google.cloud.compute.v1.stub.TargetInstancesStub;
31 import com.google.cloud.compute.v1.stub.TargetInstancesStubSettings;
32 import com.google.common.util.concurrent.MoreExecutors;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.concurrent.TimeUnit;
37 import javax.annotation.Generated;
38 
39 // AUTO-GENERATED DOCUMENTATION AND CLASS.
40 /**
41  * Service Description: The TargetInstances API.
42  *
43  * <p>This class provides the ability to make remote calls to the backing service through method
44  * calls that map to API methods. Sample code to get started:
45  *
46  * <pre>{@code
47  * // This snippet has been automatically generated and should be regarded as a code template only.
48  * // It will require modifications to work:
49  * // - It may require correct/in-range values for request initialization.
50  * // - It may require specifying regional endpoints when creating the service client as shown in
51  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
52  * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
53  *   String project = "project-309310695";
54  *   String zone = "zone3744684";
55  *   String targetInstance = "targetInstance-1036957370";
56  *   TargetInstance response = targetInstancesClient.get(project, zone, targetInstance);
57  * }
58  * }</pre>
59  *
60  * <p>Note: close() needs to be called on the TargetInstancesClient object to clean up resources
61  * such as threads. In the example above, try-with-resources is used, which automatically calls
62  * close().
63  *
64  * <p>The surface of this class includes several types of Java methods for each of the API's
65  * methods:
66  *
67  * <ol>
68  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
69  *       converted into function parameters. It may be the case that not all fields are available as
70  *       parameters, and not every API method will have a flattened method entry point.
71  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
72  *       which must be constructed before the call. Not every API method will have a request object
73  *       method.
74  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
75  *       callable object, which can be used to initiate calls to the service.
76  * </ol>
77  *
78  * <p>See the individual methods for example code.
79  *
80  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
81  * these names, this class includes a format method for each type of name, and additionally a parse
82  * method to extract the individual identifiers contained within names that are returned.
83  *
84  * <p>This class can be customized by passing in a custom instance of TargetInstancesSettings to
85  * create(). For example:
86  *
87  * <p>To customize credentials:
88  *
89  * <pre>{@code
90  * // This snippet has been automatically generated and should be regarded as a code template only.
91  * // It will require modifications to work:
92  * // - It may require correct/in-range values for request initialization.
93  * // - It may require specifying regional endpoints when creating the service client as shown in
94  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
95  * TargetInstancesSettings targetInstancesSettings =
96  *     TargetInstancesSettings.newBuilder()
97  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
98  *         .build();
99  * TargetInstancesClient targetInstancesClient =
100  *     TargetInstancesClient.create(targetInstancesSettings);
101  * }</pre>
102  *
103  * <p>To customize the endpoint:
104  *
105  * <pre>{@code
106  * // This snippet has been automatically generated and should be regarded as a code template only.
107  * // It will require modifications to work:
108  * // - It may require correct/in-range values for request initialization.
109  * // - It may require specifying regional endpoints when creating the service client as shown in
110  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
111  * TargetInstancesSettings targetInstancesSettings =
112  *     TargetInstancesSettings.newBuilder().setEndpoint(myEndpoint).build();
113  * TargetInstancesClient targetInstancesClient =
114  *     TargetInstancesClient.create(targetInstancesSettings);
115  * }</pre>
116  *
117  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
118  */
119 @Generated("by gapic-generator-java")
120 public class TargetInstancesClient implements BackgroundResource {
121   private final TargetInstancesSettings settings;
122   private final TargetInstancesStub stub;
123 
124   /** Constructs an instance of TargetInstancesClient with default settings. */
create()125   public static final TargetInstancesClient create() throws IOException {
126     return create(TargetInstancesSettings.newBuilder().build());
127   }
128 
129   /**
130    * Constructs an instance of TargetInstancesClient, using the given settings. The channels are
131    * created based on the settings passed in, or defaults for any settings that are not set.
132    */
create(TargetInstancesSettings settings)133   public static final TargetInstancesClient create(TargetInstancesSettings settings)
134       throws IOException {
135     return new TargetInstancesClient(settings);
136   }
137 
138   /**
139    * Constructs an instance of TargetInstancesClient, using the given stub for making calls. This is
140    * for advanced usage - prefer using create(TargetInstancesSettings).
141    */
create(TargetInstancesStub stub)142   public static final TargetInstancesClient create(TargetInstancesStub stub) {
143     return new TargetInstancesClient(stub);
144   }
145 
146   /**
147    * Constructs an instance of TargetInstancesClient, using the given settings. This is protected so
148    * that it is easy to make a subclass, but otherwise, the static factory methods should be
149    * preferred.
150    */
TargetInstancesClient(TargetInstancesSettings settings)151   protected TargetInstancesClient(TargetInstancesSettings settings) throws IOException {
152     this.settings = settings;
153     this.stub = ((TargetInstancesStubSettings) settings.getStubSettings()).createStub();
154   }
155 
TargetInstancesClient(TargetInstancesStub stub)156   protected TargetInstancesClient(TargetInstancesStub stub) {
157     this.settings = null;
158     this.stub = stub;
159   }
160 
getSettings()161   public final TargetInstancesSettings getSettings() {
162     return settings;
163   }
164 
getStub()165   public TargetInstancesStub getStub() {
166     return stub;
167   }
168 
169   // AUTO-GENERATED DOCUMENTATION AND METHOD.
170   /**
171    * Retrieves an aggregated list of target instances.
172    *
173    * <p>Sample code:
174    *
175    * <pre>{@code
176    * // This snippet has been automatically generated and should be regarded as a code template only.
177    * // It will require modifications to work:
178    * // - It may require correct/in-range values for request initialization.
179    * // - It may require specifying regional endpoints when creating the service client as shown in
180    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
181    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
182    *   String project = "project-309310695";
183    *   for (Map.Entry<String, TargetInstancesScopedList> element :
184    *       targetInstancesClient.aggregatedList(project).iterateAll()) {
185    *     // doThingsWith(element);
186    *   }
187    * }
188    * }</pre>
189    *
190    * @param project Project ID for this request.
191    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
192    */
aggregatedList(String project)193   public final AggregatedListPagedResponse aggregatedList(String project) {
194     AggregatedListTargetInstancesRequest request =
195         AggregatedListTargetInstancesRequest.newBuilder().setProject(project).build();
196     return aggregatedList(request);
197   }
198 
199   // AUTO-GENERATED DOCUMENTATION AND METHOD.
200   /**
201    * Retrieves an aggregated list of target instances.
202    *
203    * <p>Sample code:
204    *
205    * <pre>{@code
206    * // This snippet has been automatically generated and should be regarded as a code template only.
207    * // It will require modifications to work:
208    * // - It may require correct/in-range values for request initialization.
209    * // - It may require specifying regional endpoints when creating the service client as shown in
210    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
211    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
212    *   AggregatedListTargetInstancesRequest request =
213    *       AggregatedListTargetInstancesRequest.newBuilder()
214    *           .setFilter("filter-1274492040")
215    *           .setIncludeAllScopes(true)
216    *           .setMaxResults(1128457243)
217    *           .setOrderBy("orderBy-1207110587")
218    *           .setPageToken("pageToken873572522")
219    *           .setProject("project-309310695")
220    *           .setReturnPartialSuccess(true)
221    *           .build();
222    *   for (Map.Entry<String, TargetInstancesScopedList> element :
223    *       targetInstancesClient.aggregatedList(request).iterateAll()) {
224    *     // doThingsWith(element);
225    *   }
226    * }
227    * }</pre>
228    *
229    * @param request The request object containing all of the parameters for the API call.
230    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
231    */
aggregatedList( AggregatedListTargetInstancesRequest request)232   public final AggregatedListPagedResponse aggregatedList(
233       AggregatedListTargetInstancesRequest request) {
234     return aggregatedListPagedCallable().call(request);
235   }
236 
237   // AUTO-GENERATED DOCUMENTATION AND METHOD.
238   /**
239    * Retrieves an aggregated list of target instances.
240    *
241    * <p>Sample code:
242    *
243    * <pre>{@code
244    * // This snippet has been automatically generated and should be regarded as a code template only.
245    * // It will require modifications to work:
246    * // - It may require correct/in-range values for request initialization.
247    * // - It may require specifying regional endpoints when creating the service client as shown in
248    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
249    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
250    *   AggregatedListTargetInstancesRequest request =
251    *       AggregatedListTargetInstancesRequest.newBuilder()
252    *           .setFilter("filter-1274492040")
253    *           .setIncludeAllScopes(true)
254    *           .setMaxResults(1128457243)
255    *           .setOrderBy("orderBy-1207110587")
256    *           .setPageToken("pageToken873572522")
257    *           .setProject("project-309310695")
258    *           .setReturnPartialSuccess(true)
259    *           .build();
260    *   ApiFuture<Map.Entry<String, TargetInstancesScopedList>> future =
261    *       targetInstancesClient.aggregatedListPagedCallable().futureCall(request);
262    *   // Do something.
263    *   for (Map.Entry<String, TargetInstancesScopedList> element : future.get().iterateAll()) {
264    *     // doThingsWith(element);
265    *   }
266    * }
267    * }</pre>
268    */
269   public final UnaryCallable<AggregatedListTargetInstancesRequest, AggregatedListPagedResponse>
aggregatedListPagedCallable()270       aggregatedListPagedCallable() {
271     return stub.aggregatedListPagedCallable();
272   }
273 
274   // AUTO-GENERATED DOCUMENTATION AND METHOD.
275   /**
276    * Retrieves an aggregated list of target instances.
277    *
278    * <p>Sample code:
279    *
280    * <pre>{@code
281    * // This snippet has been automatically generated and should be regarded as a code template only.
282    * // It will require modifications to work:
283    * // - It may require correct/in-range values for request initialization.
284    * // - It may require specifying regional endpoints when creating the service client as shown in
285    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
286    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
287    *   AggregatedListTargetInstancesRequest request =
288    *       AggregatedListTargetInstancesRequest.newBuilder()
289    *           .setFilter("filter-1274492040")
290    *           .setIncludeAllScopes(true)
291    *           .setMaxResults(1128457243)
292    *           .setOrderBy("orderBy-1207110587")
293    *           .setPageToken("pageToken873572522")
294    *           .setProject("project-309310695")
295    *           .setReturnPartialSuccess(true)
296    *           .build();
297    *   while (true) {
298    *     TargetInstanceAggregatedList response =
299    *         targetInstancesClient.aggregatedListCallable().call(request);
300    *     for (Map.Entry<String, TargetInstancesScopedList> element : response.getItemsList()) {
301    *       // doThingsWith(element);
302    *     }
303    *     String nextPageToken = response.getNextPageToken();
304    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
305    *       request = request.toBuilder().setPageToken(nextPageToken).build();
306    *     } else {
307    *       break;
308    *     }
309    *   }
310    * }
311    * }</pre>
312    */
313   public final UnaryCallable<AggregatedListTargetInstancesRequest, TargetInstanceAggregatedList>
aggregatedListCallable()314       aggregatedListCallable() {
315     return stub.aggregatedListCallable();
316   }
317 
318   // AUTO-GENERATED DOCUMENTATION AND METHOD.
319   /**
320    * Deletes the specified TargetInstance resource.
321    *
322    * <p>Sample code:
323    *
324    * <pre>{@code
325    * // This snippet has been automatically generated and should be regarded as a code template only.
326    * // It will require modifications to work:
327    * // - It may require correct/in-range values for request initialization.
328    * // - It may require specifying regional endpoints when creating the service client as shown in
329    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
330    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
331    *   String project = "project-309310695";
332    *   String zone = "zone3744684";
333    *   String targetInstance = "targetInstance-1036957370";
334    *   Operation response = targetInstancesClient.deleteAsync(project, zone, targetInstance).get();
335    * }
336    * }</pre>
337    *
338    * @param project Project ID for this request.
339    * @param zone Name of the zone scoping this request.
340    * @param targetInstance Name of the TargetInstance resource to delete.
341    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
342    */
deleteAsync( String project, String zone, String targetInstance)343   public final OperationFuture<Operation, Operation> deleteAsync(
344       String project, String zone, String targetInstance) {
345     DeleteTargetInstanceRequest request =
346         DeleteTargetInstanceRequest.newBuilder()
347             .setProject(project)
348             .setZone(zone)
349             .setTargetInstance(targetInstance)
350             .build();
351     return deleteAsync(request);
352   }
353 
354   // AUTO-GENERATED DOCUMENTATION AND METHOD.
355   /**
356    * Deletes the specified TargetInstance resource.
357    *
358    * <p>Sample code:
359    *
360    * <pre>{@code
361    * // This snippet has been automatically generated and should be regarded as a code template only.
362    * // It will require modifications to work:
363    * // - It may require correct/in-range values for request initialization.
364    * // - It may require specifying regional endpoints when creating the service client as shown in
365    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
366    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
367    *   DeleteTargetInstanceRequest request =
368    *       DeleteTargetInstanceRequest.newBuilder()
369    *           .setProject("project-309310695")
370    *           .setRequestId("requestId693933066")
371    *           .setTargetInstance("targetInstance-1036957370")
372    *           .setZone("zone3744684")
373    *           .build();
374    *   Operation response = targetInstancesClient.deleteAsync(request).get();
375    * }
376    * }</pre>
377    *
378    * @param request The request object containing all of the parameters for the API call.
379    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
380    */
381   @BetaApi(
382       "The surface for long-running operations is not stable yet and may change in the future.")
deleteAsync( DeleteTargetInstanceRequest request)383   public final OperationFuture<Operation, Operation> deleteAsync(
384       DeleteTargetInstanceRequest request) {
385     return deleteOperationCallable().futureCall(request);
386   }
387 
388   // AUTO-GENERATED DOCUMENTATION AND METHOD.
389   /**
390    * Deletes the specified TargetInstance resource.
391    *
392    * <p>Sample code:
393    *
394    * <pre>{@code
395    * // This snippet has been automatically generated and should be regarded as a code template only.
396    * // It will require modifications to work:
397    * // - It may require correct/in-range values for request initialization.
398    * // - It may require specifying regional endpoints when creating the service client as shown in
399    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
400    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
401    *   DeleteTargetInstanceRequest request =
402    *       DeleteTargetInstanceRequest.newBuilder()
403    *           .setProject("project-309310695")
404    *           .setRequestId("requestId693933066")
405    *           .setTargetInstance("targetInstance-1036957370")
406    *           .setZone("zone3744684")
407    *           .build();
408    *   OperationFuture<Operation, Operation> future =
409    *       targetInstancesClient.deleteOperationCallable().futureCall(request);
410    *   // Do something.
411    *   Operation response = future.get();
412    * }
413    * }</pre>
414    */
415   public final OperationCallable<DeleteTargetInstanceRequest, Operation, Operation>
deleteOperationCallable()416       deleteOperationCallable() {
417     return stub.deleteOperationCallable();
418   }
419 
420   // AUTO-GENERATED DOCUMENTATION AND METHOD.
421   /**
422    * Deletes the specified TargetInstance resource.
423    *
424    * <p>Sample code:
425    *
426    * <pre>{@code
427    * // This snippet has been automatically generated and should be regarded as a code template only.
428    * // It will require modifications to work:
429    * // - It may require correct/in-range values for request initialization.
430    * // - It may require specifying regional endpoints when creating the service client as shown in
431    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
432    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
433    *   DeleteTargetInstanceRequest request =
434    *       DeleteTargetInstanceRequest.newBuilder()
435    *           .setProject("project-309310695")
436    *           .setRequestId("requestId693933066")
437    *           .setTargetInstance("targetInstance-1036957370")
438    *           .setZone("zone3744684")
439    *           .build();
440    *   ApiFuture<Operation> future = targetInstancesClient.deleteCallable().futureCall(request);
441    *   // Do something.
442    *   Operation response = future.get();
443    * }
444    * }</pre>
445    */
deleteCallable()446   public final UnaryCallable<DeleteTargetInstanceRequest, Operation> deleteCallable() {
447     return stub.deleteCallable();
448   }
449 
450   // AUTO-GENERATED DOCUMENTATION AND METHOD.
451   /**
452    * Returns the specified TargetInstance resource.
453    *
454    * <p>Sample code:
455    *
456    * <pre>{@code
457    * // This snippet has been automatically generated and should be regarded as a code template only.
458    * // It will require modifications to work:
459    * // - It may require correct/in-range values for request initialization.
460    * // - It may require specifying regional endpoints when creating the service client as shown in
461    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
462    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
463    *   String project = "project-309310695";
464    *   String zone = "zone3744684";
465    *   String targetInstance = "targetInstance-1036957370";
466    *   TargetInstance response = targetInstancesClient.get(project, zone, targetInstance);
467    * }
468    * }</pre>
469    *
470    * @param project Project ID for this request.
471    * @param zone Name of the zone scoping this request.
472    * @param targetInstance Name of the TargetInstance resource to return.
473    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
474    */
get(String project, String zone, String targetInstance)475   public final TargetInstance get(String project, String zone, String targetInstance) {
476     GetTargetInstanceRequest request =
477         GetTargetInstanceRequest.newBuilder()
478             .setProject(project)
479             .setZone(zone)
480             .setTargetInstance(targetInstance)
481             .build();
482     return get(request);
483   }
484 
485   // AUTO-GENERATED DOCUMENTATION AND METHOD.
486   /**
487    * Returns the specified TargetInstance resource.
488    *
489    * <p>Sample code:
490    *
491    * <pre>{@code
492    * // This snippet has been automatically generated and should be regarded as a code template only.
493    * // It will require modifications to work:
494    * // - It may require correct/in-range values for request initialization.
495    * // - It may require specifying regional endpoints when creating the service client as shown in
496    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
497    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
498    *   GetTargetInstanceRequest request =
499    *       GetTargetInstanceRequest.newBuilder()
500    *           .setProject("project-309310695")
501    *           .setTargetInstance("targetInstance-1036957370")
502    *           .setZone("zone3744684")
503    *           .build();
504    *   TargetInstance response = targetInstancesClient.get(request);
505    * }
506    * }</pre>
507    *
508    * @param request The request object containing all of the parameters for the API call.
509    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
510    */
get(GetTargetInstanceRequest request)511   public final TargetInstance get(GetTargetInstanceRequest request) {
512     return getCallable().call(request);
513   }
514 
515   // AUTO-GENERATED DOCUMENTATION AND METHOD.
516   /**
517    * Returns the specified TargetInstance resource.
518    *
519    * <p>Sample code:
520    *
521    * <pre>{@code
522    * // This snippet has been automatically generated and should be regarded as a code template only.
523    * // It will require modifications to work:
524    * // - It may require correct/in-range values for request initialization.
525    * // - It may require specifying regional endpoints when creating the service client as shown in
526    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
527    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
528    *   GetTargetInstanceRequest request =
529    *       GetTargetInstanceRequest.newBuilder()
530    *           .setProject("project-309310695")
531    *           .setTargetInstance("targetInstance-1036957370")
532    *           .setZone("zone3744684")
533    *           .build();
534    *   ApiFuture<TargetInstance> future = targetInstancesClient.getCallable().futureCall(request);
535    *   // Do something.
536    *   TargetInstance response = future.get();
537    * }
538    * }</pre>
539    */
getCallable()540   public final UnaryCallable<GetTargetInstanceRequest, TargetInstance> getCallable() {
541     return stub.getCallable();
542   }
543 
544   // AUTO-GENERATED DOCUMENTATION AND METHOD.
545   /**
546    * Creates a TargetInstance resource in the specified project and zone using the data included in
547    * the request.
548    *
549    * <p>Sample code:
550    *
551    * <pre>{@code
552    * // This snippet has been automatically generated and should be regarded as a code template only.
553    * // It will require modifications to work:
554    * // - It may require correct/in-range values for request initialization.
555    * // - It may require specifying regional endpoints when creating the service client as shown in
556    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
557    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
558    *   String project = "project-309310695";
559    *   String zone = "zone3744684";
560    *   TargetInstance targetInstanceResource = TargetInstance.newBuilder().build();
561    *   Operation response =
562    *       targetInstancesClient.insertAsync(project, zone, targetInstanceResource).get();
563    * }
564    * }</pre>
565    *
566    * @param project Project ID for this request.
567    * @param zone Name of the zone scoping this request.
568    * @param targetInstanceResource The body resource for this request
569    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
570    */
insertAsync( String project, String zone, TargetInstance targetInstanceResource)571   public final OperationFuture<Operation, Operation> insertAsync(
572       String project, String zone, TargetInstance targetInstanceResource) {
573     InsertTargetInstanceRequest request =
574         InsertTargetInstanceRequest.newBuilder()
575             .setProject(project)
576             .setZone(zone)
577             .setTargetInstanceResource(targetInstanceResource)
578             .build();
579     return insertAsync(request);
580   }
581 
582   // AUTO-GENERATED DOCUMENTATION AND METHOD.
583   /**
584    * Creates a TargetInstance resource in the specified project and zone using the data included in
585    * the request.
586    *
587    * <p>Sample code:
588    *
589    * <pre>{@code
590    * // This snippet has been automatically generated and should be regarded as a code template only.
591    * // It will require modifications to work:
592    * // - It may require correct/in-range values for request initialization.
593    * // - It may require specifying regional endpoints when creating the service client as shown in
594    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
595    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
596    *   InsertTargetInstanceRequest request =
597    *       InsertTargetInstanceRequest.newBuilder()
598    *           .setProject("project-309310695")
599    *           .setRequestId("requestId693933066")
600    *           .setTargetInstanceResource(TargetInstance.newBuilder().build())
601    *           .setZone("zone3744684")
602    *           .build();
603    *   Operation response = targetInstancesClient.insertAsync(request).get();
604    * }
605    * }</pre>
606    *
607    * @param request The request object containing all of the parameters for the API call.
608    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
609    */
610   @BetaApi(
611       "The surface for long-running operations is not stable yet and may change in the future.")
insertAsync( InsertTargetInstanceRequest request)612   public final OperationFuture<Operation, Operation> insertAsync(
613       InsertTargetInstanceRequest request) {
614     return insertOperationCallable().futureCall(request);
615   }
616 
617   // AUTO-GENERATED DOCUMENTATION AND METHOD.
618   /**
619    * Creates a TargetInstance resource in the specified project and zone using the data included in
620    * the request.
621    *
622    * <p>Sample code:
623    *
624    * <pre>{@code
625    * // This snippet has been automatically generated and should be regarded as a code template only.
626    * // It will require modifications to work:
627    * // - It may require correct/in-range values for request initialization.
628    * // - It may require specifying regional endpoints when creating the service client as shown in
629    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
630    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
631    *   InsertTargetInstanceRequest request =
632    *       InsertTargetInstanceRequest.newBuilder()
633    *           .setProject("project-309310695")
634    *           .setRequestId("requestId693933066")
635    *           .setTargetInstanceResource(TargetInstance.newBuilder().build())
636    *           .setZone("zone3744684")
637    *           .build();
638    *   OperationFuture<Operation, Operation> future =
639    *       targetInstancesClient.insertOperationCallable().futureCall(request);
640    *   // Do something.
641    *   Operation response = future.get();
642    * }
643    * }</pre>
644    */
645   public final OperationCallable<InsertTargetInstanceRequest, Operation, Operation>
insertOperationCallable()646       insertOperationCallable() {
647     return stub.insertOperationCallable();
648   }
649 
650   // AUTO-GENERATED DOCUMENTATION AND METHOD.
651   /**
652    * Creates a TargetInstance resource in the specified project and zone using the data included in
653    * the request.
654    *
655    * <p>Sample code:
656    *
657    * <pre>{@code
658    * // This snippet has been automatically generated and should be regarded as a code template only.
659    * // It will require modifications to work:
660    * // - It may require correct/in-range values for request initialization.
661    * // - It may require specifying regional endpoints when creating the service client as shown in
662    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
663    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
664    *   InsertTargetInstanceRequest request =
665    *       InsertTargetInstanceRequest.newBuilder()
666    *           .setProject("project-309310695")
667    *           .setRequestId("requestId693933066")
668    *           .setTargetInstanceResource(TargetInstance.newBuilder().build())
669    *           .setZone("zone3744684")
670    *           .build();
671    *   ApiFuture<Operation> future = targetInstancesClient.insertCallable().futureCall(request);
672    *   // Do something.
673    *   Operation response = future.get();
674    * }
675    * }</pre>
676    */
insertCallable()677   public final UnaryCallable<InsertTargetInstanceRequest, Operation> insertCallable() {
678     return stub.insertCallable();
679   }
680 
681   // AUTO-GENERATED DOCUMENTATION AND METHOD.
682   /**
683    * Retrieves a list of TargetInstance resources available to the specified project and zone.
684    *
685    * <p>Sample code:
686    *
687    * <pre>{@code
688    * // This snippet has been automatically generated and should be regarded as a code template only.
689    * // It will require modifications to work:
690    * // - It may require correct/in-range values for request initialization.
691    * // - It may require specifying regional endpoints when creating the service client as shown in
692    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
693    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
694    *   String project = "project-309310695";
695    *   String zone = "zone3744684";
696    *   for (TargetInstance element : targetInstancesClient.list(project, zone).iterateAll()) {
697    *     // doThingsWith(element);
698    *   }
699    * }
700    * }</pre>
701    *
702    * @param project Project ID for this request.
703    * @param zone Name of the zone scoping this request.
704    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
705    */
list(String project, String zone)706   public final ListPagedResponse list(String project, String zone) {
707     ListTargetInstancesRequest request =
708         ListTargetInstancesRequest.newBuilder().setProject(project).setZone(zone).build();
709     return list(request);
710   }
711 
712   // AUTO-GENERATED DOCUMENTATION AND METHOD.
713   /**
714    * Retrieves a list of TargetInstance resources available to the specified project and zone.
715    *
716    * <p>Sample code:
717    *
718    * <pre>{@code
719    * // This snippet has been automatically generated and should be regarded as a code template only.
720    * // It will require modifications to work:
721    * // - It may require correct/in-range values for request initialization.
722    * // - It may require specifying regional endpoints when creating the service client as shown in
723    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
724    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
725    *   ListTargetInstancesRequest request =
726    *       ListTargetInstancesRequest.newBuilder()
727    *           .setFilter("filter-1274492040")
728    *           .setMaxResults(1128457243)
729    *           .setOrderBy("orderBy-1207110587")
730    *           .setPageToken("pageToken873572522")
731    *           .setProject("project-309310695")
732    *           .setReturnPartialSuccess(true)
733    *           .setZone("zone3744684")
734    *           .build();
735    *   for (TargetInstance element : targetInstancesClient.list(request).iterateAll()) {
736    *     // doThingsWith(element);
737    *   }
738    * }
739    * }</pre>
740    *
741    * @param request The request object containing all of the parameters for the API call.
742    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
743    */
list(ListTargetInstancesRequest request)744   public final ListPagedResponse list(ListTargetInstancesRequest request) {
745     return listPagedCallable().call(request);
746   }
747 
748   // AUTO-GENERATED DOCUMENTATION AND METHOD.
749   /**
750    * Retrieves a list of TargetInstance resources available to the specified project and zone.
751    *
752    * <p>Sample code:
753    *
754    * <pre>{@code
755    * // This snippet has been automatically generated and should be regarded as a code template only.
756    * // It will require modifications to work:
757    * // - It may require correct/in-range values for request initialization.
758    * // - It may require specifying regional endpoints when creating the service client as shown in
759    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
760    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
761    *   ListTargetInstancesRequest request =
762    *       ListTargetInstancesRequest.newBuilder()
763    *           .setFilter("filter-1274492040")
764    *           .setMaxResults(1128457243)
765    *           .setOrderBy("orderBy-1207110587")
766    *           .setPageToken("pageToken873572522")
767    *           .setProject("project-309310695")
768    *           .setReturnPartialSuccess(true)
769    *           .setZone("zone3744684")
770    *           .build();
771    *   ApiFuture<TargetInstance> future =
772    *       targetInstancesClient.listPagedCallable().futureCall(request);
773    *   // Do something.
774    *   for (TargetInstance element : future.get().iterateAll()) {
775    *     // doThingsWith(element);
776    *   }
777    * }
778    * }</pre>
779    */
listPagedCallable()780   public final UnaryCallable<ListTargetInstancesRequest, ListPagedResponse> listPagedCallable() {
781     return stub.listPagedCallable();
782   }
783 
784   // AUTO-GENERATED DOCUMENTATION AND METHOD.
785   /**
786    * Retrieves a list of TargetInstance resources available to the specified project and zone.
787    *
788    * <p>Sample code:
789    *
790    * <pre>{@code
791    * // This snippet has been automatically generated and should be regarded as a code template only.
792    * // It will require modifications to work:
793    * // - It may require correct/in-range values for request initialization.
794    * // - It may require specifying regional endpoints when creating the service client as shown in
795    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
796    * try (TargetInstancesClient targetInstancesClient = TargetInstancesClient.create()) {
797    *   ListTargetInstancesRequest request =
798    *       ListTargetInstancesRequest.newBuilder()
799    *           .setFilter("filter-1274492040")
800    *           .setMaxResults(1128457243)
801    *           .setOrderBy("orderBy-1207110587")
802    *           .setPageToken("pageToken873572522")
803    *           .setProject("project-309310695")
804    *           .setReturnPartialSuccess(true)
805    *           .setZone("zone3744684")
806    *           .build();
807    *   while (true) {
808    *     TargetInstanceList response = targetInstancesClient.listCallable().call(request);
809    *     for (TargetInstance element : response.getItemsList()) {
810    *       // doThingsWith(element);
811    *     }
812    *     String nextPageToken = response.getNextPageToken();
813    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
814    *       request = request.toBuilder().setPageToken(nextPageToken).build();
815    *     } else {
816    *       break;
817    *     }
818    *   }
819    * }
820    * }</pre>
821    */
listCallable()822   public final UnaryCallable<ListTargetInstancesRequest, TargetInstanceList> listCallable() {
823     return stub.listCallable();
824   }
825 
826   @Override
close()827   public final void close() {
828     stub.close();
829   }
830 
831   @Override
shutdown()832   public void shutdown() {
833     stub.shutdown();
834   }
835 
836   @Override
isShutdown()837   public boolean isShutdown() {
838     return stub.isShutdown();
839   }
840 
841   @Override
isTerminated()842   public boolean isTerminated() {
843     return stub.isTerminated();
844   }
845 
846   @Override
shutdownNow()847   public void shutdownNow() {
848     stub.shutdownNow();
849   }
850 
851   @Override
awaitTermination(long duration, TimeUnit unit)852   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
853     return stub.awaitTermination(duration, unit);
854   }
855 
856   public static class AggregatedListPagedResponse
857       extends AbstractPagedListResponse<
858           AggregatedListTargetInstancesRequest,
859           TargetInstanceAggregatedList,
860           Map.Entry<String, TargetInstancesScopedList>,
861           AggregatedListPage,
862           AggregatedListFixedSizeCollection> {
863 
createAsync( PageContext< AggregatedListTargetInstancesRequest, TargetInstanceAggregatedList, Map.Entry<String, TargetInstancesScopedList>> context, ApiFuture<TargetInstanceAggregatedList> futureResponse)864     public static ApiFuture<AggregatedListPagedResponse> createAsync(
865         PageContext<
866                 AggregatedListTargetInstancesRequest,
867                 TargetInstanceAggregatedList,
868                 Map.Entry<String, TargetInstancesScopedList>>
869             context,
870         ApiFuture<TargetInstanceAggregatedList> futureResponse) {
871       ApiFuture<AggregatedListPage> futurePage =
872           AggregatedListPage.createEmptyPage().createPageAsync(context, futureResponse);
873       return ApiFutures.transform(
874           futurePage,
875           input -> new AggregatedListPagedResponse(input),
876           MoreExecutors.directExecutor());
877     }
878 
AggregatedListPagedResponse(AggregatedListPage page)879     private AggregatedListPagedResponse(AggregatedListPage page) {
880       super(page, AggregatedListFixedSizeCollection.createEmptyCollection());
881     }
882   }
883 
884   public static class AggregatedListPage
885       extends AbstractPage<
886           AggregatedListTargetInstancesRequest,
887           TargetInstanceAggregatedList,
888           Map.Entry<String, TargetInstancesScopedList>,
889           AggregatedListPage> {
890 
AggregatedListPage( PageContext< AggregatedListTargetInstancesRequest, TargetInstanceAggregatedList, Map.Entry<String, TargetInstancesScopedList>> context, TargetInstanceAggregatedList response)891     private AggregatedListPage(
892         PageContext<
893                 AggregatedListTargetInstancesRequest,
894                 TargetInstanceAggregatedList,
895                 Map.Entry<String, TargetInstancesScopedList>>
896             context,
897         TargetInstanceAggregatedList response) {
898       super(context, response);
899     }
900 
createEmptyPage()901     private static AggregatedListPage createEmptyPage() {
902       return new AggregatedListPage(null, null);
903     }
904 
905     @Override
createPage( PageContext< AggregatedListTargetInstancesRequest, TargetInstanceAggregatedList, Map.Entry<String, TargetInstancesScopedList>> context, TargetInstanceAggregatedList response)906     protected AggregatedListPage createPage(
907         PageContext<
908                 AggregatedListTargetInstancesRequest,
909                 TargetInstanceAggregatedList,
910                 Map.Entry<String, TargetInstancesScopedList>>
911             context,
912         TargetInstanceAggregatedList response) {
913       return new AggregatedListPage(context, response);
914     }
915 
916     @Override
createPageAsync( PageContext< AggregatedListTargetInstancesRequest, TargetInstanceAggregatedList, Map.Entry<String, TargetInstancesScopedList>> context, ApiFuture<TargetInstanceAggregatedList> futureResponse)917     public ApiFuture<AggregatedListPage> createPageAsync(
918         PageContext<
919                 AggregatedListTargetInstancesRequest,
920                 TargetInstanceAggregatedList,
921                 Map.Entry<String, TargetInstancesScopedList>>
922             context,
923         ApiFuture<TargetInstanceAggregatedList> futureResponse) {
924       return super.createPageAsync(context, futureResponse);
925     }
926   }
927 
928   public static class AggregatedListFixedSizeCollection
929       extends AbstractFixedSizeCollection<
930           AggregatedListTargetInstancesRequest,
931           TargetInstanceAggregatedList,
932           Map.Entry<String, TargetInstancesScopedList>,
933           AggregatedListPage,
934           AggregatedListFixedSizeCollection> {
935 
AggregatedListFixedSizeCollection(List<AggregatedListPage> pages, int collectionSize)936     private AggregatedListFixedSizeCollection(List<AggregatedListPage> pages, int collectionSize) {
937       super(pages, collectionSize);
938     }
939 
createEmptyCollection()940     private static AggregatedListFixedSizeCollection createEmptyCollection() {
941       return new AggregatedListFixedSizeCollection(null, 0);
942     }
943 
944     @Override
createCollection( List<AggregatedListPage> pages, int collectionSize)945     protected AggregatedListFixedSizeCollection createCollection(
946         List<AggregatedListPage> pages, int collectionSize) {
947       return new AggregatedListFixedSizeCollection(pages, collectionSize);
948     }
949   }
950 
951   public static class ListPagedResponse
952       extends AbstractPagedListResponse<
953           ListTargetInstancesRequest,
954           TargetInstanceList,
955           TargetInstance,
956           ListPage,
957           ListFixedSizeCollection> {
958 
createAsync( PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context, ApiFuture<TargetInstanceList> futureResponse)959     public static ApiFuture<ListPagedResponse> createAsync(
960         PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context,
961         ApiFuture<TargetInstanceList> futureResponse) {
962       ApiFuture<ListPage> futurePage =
963           ListPage.createEmptyPage().createPageAsync(context, futureResponse);
964       return ApiFutures.transform(
965           futurePage, input -> new ListPagedResponse(input), MoreExecutors.directExecutor());
966     }
967 
ListPagedResponse(ListPage page)968     private ListPagedResponse(ListPage page) {
969       super(page, ListFixedSizeCollection.createEmptyCollection());
970     }
971   }
972 
973   public static class ListPage
974       extends AbstractPage<
975           ListTargetInstancesRequest, TargetInstanceList, TargetInstance, ListPage> {
976 
ListPage( PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context, TargetInstanceList response)977     private ListPage(
978         PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context,
979         TargetInstanceList response) {
980       super(context, response);
981     }
982 
createEmptyPage()983     private static ListPage createEmptyPage() {
984       return new ListPage(null, null);
985     }
986 
987     @Override
createPage( PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context, TargetInstanceList response)988     protected ListPage createPage(
989         PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context,
990         TargetInstanceList response) {
991       return new ListPage(context, response);
992     }
993 
994     @Override
createPageAsync( PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context, ApiFuture<TargetInstanceList> futureResponse)995     public ApiFuture<ListPage> createPageAsync(
996         PageContext<ListTargetInstancesRequest, TargetInstanceList, TargetInstance> context,
997         ApiFuture<TargetInstanceList> futureResponse) {
998       return super.createPageAsync(context, futureResponse);
999     }
1000   }
1001 
1002   public static class ListFixedSizeCollection
1003       extends AbstractFixedSizeCollection<
1004           ListTargetInstancesRequest,
1005           TargetInstanceList,
1006           TargetInstance,
1007           ListPage,
1008           ListFixedSizeCollection> {
1009 
ListFixedSizeCollection(List<ListPage> pages, int collectionSize)1010     private ListFixedSizeCollection(List<ListPage> pages, int collectionSize) {
1011       super(pages, collectionSize);
1012     }
1013 
createEmptyCollection()1014     private static ListFixedSizeCollection createEmptyCollection() {
1015       return new ListFixedSizeCollection(null, 0);
1016     }
1017 
1018     @Override
createCollection(List<ListPage> pages, int collectionSize)1019     protected ListFixedSizeCollection createCollection(List<ListPage> pages, int collectionSize) {
1020       return new ListFixedSizeCollection(pages, collectionSize);
1021     }
1022   }
1023 }
1024