• 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.gax.core.BackgroundResource;
20 import com.google.api.gax.rpc.UnaryCallable;
21 import com.google.cloud.compute.v1.stub.LicenseCodesStub;
22 import com.google.cloud.compute.v1.stub.LicenseCodesStubSettings;
23 import java.io.IOException;
24 import java.util.concurrent.TimeUnit;
25 import javax.annotation.Generated;
26 
27 // AUTO-GENERATED DOCUMENTATION AND CLASS.
28 /**
29  * Service Description: The LicenseCodes API.
30  *
31  * <p>This class provides the ability to make remote calls to the backing service through method
32  * calls that map to API methods. Sample code to get started:
33  *
34  * <pre>{@code
35  * // This snippet has been automatically generated and should be regarded as a code template only.
36  * // It will require modifications to work:
37  * // - It may require correct/in-range values for request initialization.
38  * // - It may require specifying regional endpoints when creating the service client as shown in
39  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
40  * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
41  *   String project = "project-309310695";
42  *   String licenseCode = "licenseCode-641557042";
43  *   LicenseCode response = licenseCodesClient.get(project, licenseCode);
44  * }
45  * }</pre>
46  *
47  * <p>Note: close() needs to be called on the LicenseCodesClient object to clean up resources such
48  * as threads. In the example above, try-with-resources is used, which automatically calls close().
49  *
50  * <p>The surface of this class includes several types of Java methods for each of the API's
51  * methods:
52  *
53  * <ol>
54  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
55  *       converted into function parameters. It may be the case that not all fields are available as
56  *       parameters, and not every API method will have a flattened method entry point.
57  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
58  *       which must be constructed before the call. Not every API method will have a request object
59  *       method.
60  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
61  *       callable object, which can be used to initiate calls to the service.
62  * </ol>
63  *
64  * <p>See the individual methods for example code.
65  *
66  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
67  * these names, this class includes a format method for each type of name, and additionally a parse
68  * method to extract the individual identifiers contained within names that are returned.
69  *
70  * <p>This class can be customized by passing in a custom instance of LicenseCodesSettings to
71  * create(). For example:
72  *
73  * <p>To customize credentials:
74  *
75  * <pre>{@code
76  * // This snippet has been automatically generated and should be regarded as a code template only.
77  * // It will require modifications to work:
78  * // - It may require correct/in-range values for request initialization.
79  * // - It may require specifying regional endpoints when creating the service client as shown in
80  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
81  * LicenseCodesSettings licenseCodesSettings =
82  *     LicenseCodesSettings.newBuilder()
83  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
84  *         .build();
85  * LicenseCodesClient licenseCodesClient = LicenseCodesClient.create(licenseCodesSettings);
86  * }</pre>
87  *
88  * <p>To customize the endpoint:
89  *
90  * <pre>{@code
91  * // This snippet has been automatically generated and should be regarded as a code template only.
92  * // It will require modifications to work:
93  * // - It may require correct/in-range values for request initialization.
94  * // - It may require specifying regional endpoints when creating the service client as shown in
95  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
96  * LicenseCodesSettings licenseCodesSettings =
97  *     LicenseCodesSettings.newBuilder().setEndpoint(myEndpoint).build();
98  * LicenseCodesClient licenseCodesClient = LicenseCodesClient.create(licenseCodesSettings);
99  * }</pre>
100  *
101  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
102  */
103 @Generated("by gapic-generator-java")
104 public class LicenseCodesClient implements BackgroundResource {
105   private final LicenseCodesSettings settings;
106   private final LicenseCodesStub stub;
107 
108   /** Constructs an instance of LicenseCodesClient with default settings. */
create()109   public static final LicenseCodesClient create() throws IOException {
110     return create(LicenseCodesSettings.newBuilder().build());
111   }
112 
113   /**
114    * Constructs an instance of LicenseCodesClient, using the given settings. The channels are
115    * created based on the settings passed in, or defaults for any settings that are not set.
116    */
create(LicenseCodesSettings settings)117   public static final LicenseCodesClient create(LicenseCodesSettings settings) throws IOException {
118     return new LicenseCodesClient(settings);
119   }
120 
121   /**
122    * Constructs an instance of LicenseCodesClient, using the given stub for making calls. This is
123    * for advanced usage - prefer using create(LicenseCodesSettings).
124    */
create(LicenseCodesStub stub)125   public static final LicenseCodesClient create(LicenseCodesStub stub) {
126     return new LicenseCodesClient(stub);
127   }
128 
129   /**
130    * Constructs an instance of LicenseCodesClient, using the given settings. This is protected so
131    * that it is easy to make a subclass, but otherwise, the static factory methods should be
132    * preferred.
133    */
LicenseCodesClient(LicenseCodesSettings settings)134   protected LicenseCodesClient(LicenseCodesSettings settings) throws IOException {
135     this.settings = settings;
136     this.stub = ((LicenseCodesStubSettings) settings.getStubSettings()).createStub();
137   }
138 
LicenseCodesClient(LicenseCodesStub stub)139   protected LicenseCodesClient(LicenseCodesStub stub) {
140     this.settings = null;
141     this.stub = stub;
142   }
143 
getSettings()144   public final LicenseCodesSettings getSettings() {
145     return settings;
146   }
147 
getStub()148   public LicenseCodesStub getStub() {
149     return stub;
150   }
151 
152   // AUTO-GENERATED DOCUMENTATION AND METHOD.
153   /**
154    * Return a specified license code. License codes are mirrored across all projects that have
155    * permissions to read the License Code. &#42;Caution&#42; This resource is intended for use only
156    * by third-party partners who are creating Cloud Marketplace images.
157    *
158    * <p>Sample code:
159    *
160    * <pre>{@code
161    * // This snippet has been automatically generated and should be regarded as a code template only.
162    * // It will require modifications to work:
163    * // - It may require correct/in-range values for request initialization.
164    * // - It may require specifying regional endpoints when creating the service client as shown in
165    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
166    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
167    *   String project = "project-309310695";
168    *   String licenseCode = "licenseCode-641557042";
169    *   LicenseCode response = licenseCodesClient.get(project, licenseCode);
170    * }
171    * }</pre>
172    *
173    * @param project Project ID for this request.
174    * @param licenseCode Number corresponding to the License code resource to return.
175    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
176    */
get(String project, String licenseCode)177   public final LicenseCode get(String project, String licenseCode) {
178     GetLicenseCodeRequest request =
179         GetLicenseCodeRequest.newBuilder().setProject(project).setLicenseCode(licenseCode).build();
180     return get(request);
181   }
182 
183   // AUTO-GENERATED DOCUMENTATION AND METHOD.
184   /**
185    * Return a specified license code. License codes are mirrored across all projects that have
186    * permissions to read the License Code. &#42;Caution&#42; This resource is intended for use only
187    * by third-party partners who are creating Cloud Marketplace images.
188    *
189    * <p>Sample code:
190    *
191    * <pre>{@code
192    * // This snippet has been automatically generated and should be regarded as a code template only.
193    * // It will require modifications to work:
194    * // - It may require correct/in-range values for request initialization.
195    * // - It may require specifying regional endpoints when creating the service client as shown in
196    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
197    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
198    *   GetLicenseCodeRequest request =
199    *       GetLicenseCodeRequest.newBuilder()
200    *           .setLicenseCode("licenseCode-641557042")
201    *           .setProject("project-309310695")
202    *           .build();
203    *   LicenseCode response = licenseCodesClient.get(request);
204    * }
205    * }</pre>
206    *
207    * @param request The request object containing all of the parameters for the API call.
208    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
209    */
get(GetLicenseCodeRequest request)210   public final LicenseCode get(GetLicenseCodeRequest request) {
211     return getCallable().call(request);
212   }
213 
214   // AUTO-GENERATED DOCUMENTATION AND METHOD.
215   /**
216    * Return a specified license code. License codes are mirrored across all projects that have
217    * permissions to read the License Code. &#42;Caution&#42; This resource is intended for use only
218    * by third-party partners who are creating Cloud Marketplace images.
219    *
220    * <p>Sample code:
221    *
222    * <pre>{@code
223    * // This snippet has been automatically generated and should be regarded as a code template only.
224    * // It will require modifications to work:
225    * // - It may require correct/in-range values for request initialization.
226    * // - It may require specifying regional endpoints when creating the service client as shown in
227    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
228    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
229    *   GetLicenseCodeRequest request =
230    *       GetLicenseCodeRequest.newBuilder()
231    *           .setLicenseCode("licenseCode-641557042")
232    *           .setProject("project-309310695")
233    *           .build();
234    *   ApiFuture<LicenseCode> future = licenseCodesClient.getCallable().futureCall(request);
235    *   // Do something.
236    *   LicenseCode response = future.get();
237    * }
238    * }</pre>
239    */
getCallable()240   public final UnaryCallable<GetLicenseCodeRequest, LicenseCode> getCallable() {
241     return stub.getCallable();
242   }
243 
244   // AUTO-GENERATED DOCUMENTATION AND METHOD.
245   /**
246    * Returns permissions that a caller has on the specified resource. &#42;Caution&#42; This
247    * resource is intended for use only by third-party partners who are creating Cloud Marketplace
248    * images.
249    *
250    * <p>Sample code:
251    *
252    * <pre>{@code
253    * // This snippet has been automatically generated and should be regarded as a code template only.
254    * // It will require modifications to work:
255    * // - It may require correct/in-range values for request initialization.
256    * // - It may require specifying regional endpoints when creating the service client as shown in
257    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
258    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
259    *   String project = "project-309310695";
260    *   String resource = "resource-341064690";
261    *   TestPermissionsRequest testPermissionsRequestResource =
262    *       TestPermissionsRequest.newBuilder().build();
263    *   TestPermissionsResponse response =
264    *       licenseCodesClient.testIamPermissions(project, resource, testPermissionsRequestResource);
265    * }
266    * }</pre>
267    *
268    * @param project Project ID for this request.
269    * @param resource Name or id of the resource for this request.
270    * @param testPermissionsRequestResource The body resource for this request
271    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
272    */
testIamPermissions( String project, String resource, TestPermissionsRequest testPermissionsRequestResource)273   public final TestPermissionsResponse testIamPermissions(
274       String project, String resource, TestPermissionsRequest testPermissionsRequestResource) {
275     TestIamPermissionsLicenseCodeRequest request =
276         TestIamPermissionsLicenseCodeRequest.newBuilder()
277             .setProject(project)
278             .setResource(resource)
279             .setTestPermissionsRequestResource(testPermissionsRequestResource)
280             .build();
281     return testIamPermissions(request);
282   }
283 
284   // AUTO-GENERATED DOCUMENTATION AND METHOD.
285   /**
286    * Returns permissions that a caller has on the specified resource. &#42;Caution&#42; This
287    * resource is intended for use only by third-party partners who are creating Cloud Marketplace
288    * images.
289    *
290    * <p>Sample code:
291    *
292    * <pre>{@code
293    * // This snippet has been automatically generated and should be regarded as a code template only.
294    * // It will require modifications to work:
295    * // - It may require correct/in-range values for request initialization.
296    * // - It may require specifying regional endpoints when creating the service client as shown in
297    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
298    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
299    *   TestIamPermissionsLicenseCodeRequest request =
300    *       TestIamPermissionsLicenseCodeRequest.newBuilder()
301    *           .setProject("project-309310695")
302    *           .setResource("resource-341064690")
303    *           .setTestPermissionsRequestResource(TestPermissionsRequest.newBuilder().build())
304    *           .build();
305    *   TestPermissionsResponse response = licenseCodesClient.testIamPermissions(request);
306    * }
307    * }</pre>
308    *
309    * @param request The request object containing all of the parameters for the API call.
310    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
311    */
testIamPermissions( TestIamPermissionsLicenseCodeRequest request)312   public final TestPermissionsResponse testIamPermissions(
313       TestIamPermissionsLicenseCodeRequest request) {
314     return testIamPermissionsCallable().call(request);
315   }
316 
317   // AUTO-GENERATED DOCUMENTATION AND METHOD.
318   /**
319    * Returns permissions that a caller has on the specified resource. &#42;Caution&#42; This
320    * resource is intended for use only by third-party partners who are creating Cloud Marketplace
321    * images.
322    *
323    * <p>Sample code:
324    *
325    * <pre>{@code
326    * // This snippet has been automatically generated and should be regarded as a code template only.
327    * // It will require modifications to work:
328    * // - It may require correct/in-range values for request initialization.
329    * // - It may require specifying regional endpoints when creating the service client as shown in
330    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
331    * try (LicenseCodesClient licenseCodesClient = LicenseCodesClient.create()) {
332    *   TestIamPermissionsLicenseCodeRequest request =
333    *       TestIamPermissionsLicenseCodeRequest.newBuilder()
334    *           .setProject("project-309310695")
335    *           .setResource("resource-341064690")
336    *           .setTestPermissionsRequestResource(TestPermissionsRequest.newBuilder().build())
337    *           .build();
338    *   ApiFuture<TestPermissionsResponse> future =
339    *       licenseCodesClient.testIamPermissionsCallable().futureCall(request);
340    *   // Do something.
341    *   TestPermissionsResponse response = future.get();
342    * }
343    * }</pre>
344    */
345   public final UnaryCallable<TestIamPermissionsLicenseCodeRequest, TestPermissionsResponse>
testIamPermissionsCallable()346       testIamPermissionsCallable() {
347     return stub.testIamPermissionsCallable();
348   }
349 
350   @Override
close()351   public final void close() {
352     stub.close();
353   }
354 
355   @Override
shutdown()356   public void shutdown() {
357     stub.shutdown();
358   }
359 
360   @Override
isShutdown()361   public boolean isShutdown() {
362     return stub.isShutdown();
363   }
364 
365   @Override
isTerminated()366   public boolean isTerminated() {
367     return stub.isTerminated();
368   }
369 
370   @Override
shutdownNow()371   public void shutdownNow() {
372     stub.shutdownNow();
373   }
374 
375   @Override
awaitTermination(long duration, TimeUnit unit)376   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
377     return stub.awaitTermination(duration, unit);
378   }
379 }
380