• 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.devtools.cloudprofiler.v2;
18 
19 import com.google.api.gax.core.BackgroundResource;
20 import com.google.api.gax.rpc.UnaryCallable;
21 import com.google.devtools.cloudprofiler.v2.stub.ProfilerServiceStub;
22 import com.google.devtools.cloudprofiler.v2.stub.ProfilerServiceStubSettings;
23 import com.google.protobuf.FieldMask;
24 import java.io.IOException;
25 import java.util.concurrent.TimeUnit;
26 import javax.annotation.Generated;
27 
28 // AUTO-GENERATED DOCUMENTATION AND CLASS.
29 /**
30  * Service Description: Manage the collection of continuous profiling data provided by profiling
31  * agents running in the cloud or by an offline provider of profiling data.
32  *
33  * <p>General guidelines:
34  *
35  * <ul>
36  *   <li>Profiles for a single deployment must be created in ascending time order.
37  *   <li>Profiles can be created in either online or offline mode, see below.
38  * </ul>
39  *
40  * <p>This class provides the ability to make remote calls to the backing service through method
41  * calls that map to API methods. Sample code to get started:
42  *
43  * <pre>{@code
44  * // This snippet has been automatically generated and should be regarded as a code template only.
45  * // It will require modifications to work:
46  * // - It may require correct/in-range values for request initialization.
47  * // - It may require specifying regional endpoints when creating the service client as shown in
48  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
49  * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
50  *   CreateProfileRequest request =
51  *       CreateProfileRequest.newBuilder()
52  *           .setParent(ProjectName.of("[PROJECT]").toString())
53  *           .setDeployment(Deployment.newBuilder().build())
54  *           .addAllProfileType(new ArrayList<ProfileType>())
55  *           .build();
56  *   Profile response = profilerServiceClient.createProfile(request);
57  * }
58  * }</pre>
59  *
60  * <p>Note: close() needs to be called on the ProfilerServiceClient 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 ProfilerServiceSettings 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  * ProfilerServiceSettings profilerServiceSettings =
96  *     ProfilerServiceSettings.newBuilder()
97  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
98  *         .build();
99  * ProfilerServiceClient profilerServiceClient =
100  *     ProfilerServiceClient.create(profilerServiceSettings);
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  * ProfilerServiceSettings profilerServiceSettings =
112  *     ProfilerServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
113  * ProfilerServiceClient profilerServiceClient =
114  *     ProfilerServiceClient.create(profilerServiceSettings);
115  * }</pre>
116  *
117  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
118  * the wire:
119  *
120  * <pre>{@code
121  * // This snippet has been automatically generated and should be regarded as a code template only.
122  * // It will require modifications to work:
123  * // - It may require correct/in-range values for request initialization.
124  * // - It may require specifying regional endpoints when creating the service client as shown in
125  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
126  * ProfilerServiceSettings profilerServiceSettings =
127  *     ProfilerServiceSettings.newHttpJsonBuilder().build();
128  * ProfilerServiceClient profilerServiceClient =
129  *     ProfilerServiceClient.create(profilerServiceSettings);
130  * }</pre>
131  *
132  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
133  */
134 @Generated("by gapic-generator-java")
135 public class ProfilerServiceClient implements BackgroundResource {
136   private final ProfilerServiceSettings settings;
137   private final ProfilerServiceStub stub;
138 
139   /** Constructs an instance of ProfilerServiceClient with default settings. */
create()140   public static final ProfilerServiceClient create() throws IOException {
141     return create(ProfilerServiceSettings.newBuilder().build());
142   }
143 
144   /**
145    * Constructs an instance of ProfilerServiceClient, using the given settings. The channels are
146    * created based on the settings passed in, or defaults for any settings that are not set.
147    */
create(ProfilerServiceSettings settings)148   public static final ProfilerServiceClient create(ProfilerServiceSettings settings)
149       throws IOException {
150     return new ProfilerServiceClient(settings);
151   }
152 
153   /**
154    * Constructs an instance of ProfilerServiceClient, using the given stub for making calls. This is
155    * for advanced usage - prefer using create(ProfilerServiceSettings).
156    */
create(ProfilerServiceStub stub)157   public static final ProfilerServiceClient create(ProfilerServiceStub stub) {
158     return new ProfilerServiceClient(stub);
159   }
160 
161   /**
162    * Constructs an instance of ProfilerServiceClient, using the given settings. This is protected so
163    * that it is easy to make a subclass, but otherwise, the static factory methods should be
164    * preferred.
165    */
ProfilerServiceClient(ProfilerServiceSettings settings)166   protected ProfilerServiceClient(ProfilerServiceSettings settings) throws IOException {
167     this.settings = settings;
168     this.stub = ((ProfilerServiceStubSettings) settings.getStubSettings()).createStub();
169   }
170 
ProfilerServiceClient(ProfilerServiceStub stub)171   protected ProfilerServiceClient(ProfilerServiceStub stub) {
172     this.settings = null;
173     this.stub = stub;
174   }
175 
getSettings()176   public final ProfilerServiceSettings getSettings() {
177     return settings;
178   }
179 
getStub()180   public ProfilerServiceStub getStub() {
181     return stub;
182   }
183 
184   // AUTO-GENERATED DOCUMENTATION AND METHOD.
185   /**
186    * CreateProfile creates a new profile resource in the online mode.
187    *
188    * <p>The server ensures that the new profiles are created at a constant rate per deployment, so
189    * the creation request may hang for some time until the next profile session is available.
190    *
191    * <p>The request may fail with ABORTED error if the creation is not available within ~1m, the
192    * response will indicate the duration of the backoff the client should take before attempting
193    * creating a profile again. The backoff duration is returned in google.rpc.RetryInfo extension on
194    * the response status. To a gRPC client, the extension will be return as a binary-serialized
195    * proto in the trailing metadata item named "google.rpc.retryinfo-bin".
196    *
197    * <p>Sample code:
198    *
199    * <pre>{@code
200    * // This snippet has been automatically generated and should be regarded as a code template only.
201    * // It will require modifications to work:
202    * // - It may require correct/in-range values for request initialization.
203    * // - It may require specifying regional endpoints when creating the service client as shown in
204    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
205    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
206    *   CreateProfileRequest request =
207    *       CreateProfileRequest.newBuilder()
208    *           .setParent(ProjectName.of("[PROJECT]").toString())
209    *           .setDeployment(Deployment.newBuilder().build())
210    *           .addAllProfileType(new ArrayList<ProfileType>())
211    *           .build();
212    *   Profile response = profilerServiceClient.createProfile(request);
213    * }
214    * }</pre>
215    *
216    * @param request The request object containing all of the parameters for the API call.
217    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
218    */
createProfile(CreateProfileRequest request)219   public final Profile createProfile(CreateProfileRequest request) {
220     return createProfileCallable().call(request);
221   }
222 
223   // AUTO-GENERATED DOCUMENTATION AND METHOD.
224   /**
225    * CreateProfile creates a new profile resource in the online mode.
226    *
227    * <p>The server ensures that the new profiles are created at a constant rate per deployment, so
228    * the creation request may hang for some time until the next profile session is available.
229    *
230    * <p>The request may fail with ABORTED error if the creation is not available within ~1m, the
231    * response will indicate the duration of the backoff the client should take before attempting
232    * creating a profile again. The backoff duration is returned in google.rpc.RetryInfo extension on
233    * the response status. To a gRPC client, the extension will be return as a binary-serialized
234    * proto in the trailing metadata item named "google.rpc.retryinfo-bin".
235    *
236    * <p>Sample code:
237    *
238    * <pre>{@code
239    * // This snippet has been automatically generated and should be regarded as a code template only.
240    * // It will require modifications to work:
241    * // - It may require correct/in-range values for request initialization.
242    * // - It may require specifying regional endpoints when creating the service client as shown in
243    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
244    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
245    *   CreateProfileRequest request =
246    *       CreateProfileRequest.newBuilder()
247    *           .setParent(ProjectName.of("[PROJECT]").toString())
248    *           .setDeployment(Deployment.newBuilder().build())
249    *           .addAllProfileType(new ArrayList<ProfileType>())
250    *           .build();
251    *   ApiFuture<Profile> future = profilerServiceClient.createProfileCallable().futureCall(request);
252    *   // Do something.
253    *   Profile response = future.get();
254    * }
255    * }</pre>
256    */
createProfileCallable()257   public final UnaryCallable<CreateProfileRequest, Profile> createProfileCallable() {
258     return stub.createProfileCallable();
259   }
260 
261   // AUTO-GENERATED DOCUMENTATION AND METHOD.
262   /**
263    * CreateOfflineProfile creates a new profile resource in the offline mode. The client provides
264    * the profile to create along with the profile bytes, the server records it.
265    *
266    * <p>Sample code:
267    *
268    * <pre>{@code
269    * // This snippet has been automatically generated and should be regarded as a code template only.
270    * // It will require modifications to work:
271    * // - It may require correct/in-range values for request initialization.
272    * // - It may require specifying regional endpoints when creating the service client as shown in
273    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
274    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
275    *   ProjectName parent = ProjectName.of("[PROJECT]");
276    *   Profile profile = Profile.newBuilder().build();
277    *   Profile response = profilerServiceClient.createOfflineProfile(parent, profile);
278    * }
279    * }</pre>
280    *
281    * @param parent Parent project to create the profile in.
282    * @param profile Contents of the profile to create.
283    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
284    */
createOfflineProfile(ProjectName parent, Profile profile)285   public final Profile createOfflineProfile(ProjectName parent, Profile profile) {
286     CreateOfflineProfileRequest request =
287         CreateOfflineProfileRequest.newBuilder()
288             .setParent(parent == null ? null : parent.toString())
289             .setProfile(profile)
290             .build();
291     return createOfflineProfile(request);
292   }
293 
294   // AUTO-GENERATED DOCUMENTATION AND METHOD.
295   /**
296    * CreateOfflineProfile creates a new profile resource in the offline mode. The client provides
297    * the profile to create along with the profile bytes, the server records it.
298    *
299    * <p>Sample code:
300    *
301    * <pre>{@code
302    * // This snippet has been automatically generated and should be regarded as a code template only.
303    * // It will require modifications to work:
304    * // - It may require correct/in-range values for request initialization.
305    * // - It may require specifying regional endpoints when creating the service client as shown in
306    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
307    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
308    *   String parent = ProjectName.of("[PROJECT]").toString();
309    *   Profile profile = Profile.newBuilder().build();
310    *   Profile response = profilerServiceClient.createOfflineProfile(parent, profile);
311    * }
312    * }</pre>
313    *
314    * @param parent Parent project to create the profile in.
315    * @param profile Contents of the profile to create.
316    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
317    */
createOfflineProfile(String parent, Profile profile)318   public final Profile createOfflineProfile(String parent, Profile profile) {
319     CreateOfflineProfileRequest request =
320         CreateOfflineProfileRequest.newBuilder().setParent(parent).setProfile(profile).build();
321     return createOfflineProfile(request);
322   }
323 
324   // AUTO-GENERATED DOCUMENTATION AND METHOD.
325   /**
326    * CreateOfflineProfile creates a new profile resource in the offline mode. The client provides
327    * the profile to create along with the profile bytes, the server records it.
328    *
329    * <p>Sample code:
330    *
331    * <pre>{@code
332    * // This snippet has been automatically generated and should be regarded as a code template only.
333    * // It will require modifications to work:
334    * // - It may require correct/in-range values for request initialization.
335    * // - It may require specifying regional endpoints when creating the service client as shown in
336    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
337    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
338    *   CreateOfflineProfileRequest request =
339    *       CreateOfflineProfileRequest.newBuilder()
340    *           .setParent(ProjectName.of("[PROJECT]").toString())
341    *           .setProfile(Profile.newBuilder().build())
342    *           .build();
343    *   Profile response = profilerServiceClient.createOfflineProfile(request);
344    * }
345    * }</pre>
346    *
347    * @param request The request object containing all of the parameters for the API call.
348    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
349    */
createOfflineProfile(CreateOfflineProfileRequest request)350   public final Profile createOfflineProfile(CreateOfflineProfileRequest request) {
351     return createOfflineProfileCallable().call(request);
352   }
353 
354   // AUTO-GENERATED DOCUMENTATION AND METHOD.
355   /**
356    * CreateOfflineProfile creates a new profile resource in the offline mode. The client provides
357    * the profile to create along with the profile bytes, the server records it.
358    *
359    * <p>Sample code:
360    *
361    * <pre>{@code
362    * // This snippet has been automatically generated and should be regarded as a code template only.
363    * // It will require modifications to work:
364    * // - It may require correct/in-range values for request initialization.
365    * // - It may require specifying regional endpoints when creating the service client as shown in
366    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
367    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
368    *   CreateOfflineProfileRequest request =
369    *       CreateOfflineProfileRequest.newBuilder()
370    *           .setParent(ProjectName.of("[PROJECT]").toString())
371    *           .setProfile(Profile.newBuilder().build())
372    *           .build();
373    *   ApiFuture<Profile> future =
374    *       profilerServiceClient.createOfflineProfileCallable().futureCall(request);
375    *   // Do something.
376    *   Profile response = future.get();
377    * }
378    * }</pre>
379    */
createOfflineProfileCallable()380   public final UnaryCallable<CreateOfflineProfileRequest, Profile> createOfflineProfileCallable() {
381     return stub.createOfflineProfileCallable();
382   }
383 
384   // AUTO-GENERATED DOCUMENTATION AND METHOD.
385   /**
386    * UpdateProfile updates the profile bytes and labels on the profile resource created in the
387    * online mode. Updating the bytes for profiles created in the offline mode is currently not
388    * supported: the profile content must be provided at the time of the profile creation.
389    *
390    * <p>Sample code:
391    *
392    * <pre>{@code
393    * // This snippet has been automatically generated and should be regarded as a code template only.
394    * // It will require modifications to work:
395    * // - It may require correct/in-range values for request initialization.
396    * // - It may require specifying regional endpoints when creating the service client as shown in
397    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
398    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
399    *   Profile profile = Profile.newBuilder().build();
400    *   FieldMask updateMask = FieldMask.newBuilder().build();
401    *   Profile response = profilerServiceClient.updateProfile(profile, updateMask);
402    * }
403    * }</pre>
404    *
405    * @param profile Profile to update.
406    * @param updateMask Field mask used to specify the fields to be overwritten. Currently only
407    *     profile_bytes and labels fields are supported by UpdateProfile, so only those fields can be
408    *     specified in the mask. When no mask is provided, all fields are overwritten.
409    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
410    */
updateProfile(Profile profile, FieldMask updateMask)411   public final Profile updateProfile(Profile profile, FieldMask updateMask) {
412     UpdateProfileRequest request =
413         UpdateProfileRequest.newBuilder().setProfile(profile).setUpdateMask(updateMask).build();
414     return updateProfile(request);
415   }
416 
417   // AUTO-GENERATED DOCUMENTATION AND METHOD.
418   /**
419    * UpdateProfile updates the profile bytes and labels on the profile resource created in the
420    * online mode. Updating the bytes for profiles created in the offline mode is currently not
421    * supported: the profile content must be provided at the time of the profile creation.
422    *
423    * <p>Sample code:
424    *
425    * <pre>{@code
426    * // This snippet has been automatically generated and should be regarded as a code template only.
427    * // It will require modifications to work:
428    * // - It may require correct/in-range values for request initialization.
429    * // - It may require specifying regional endpoints when creating the service client as shown in
430    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
431    * try (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
432    *   UpdateProfileRequest request =
433    *       UpdateProfileRequest.newBuilder()
434    *           .setProfile(Profile.newBuilder().build())
435    *           .setUpdateMask(FieldMask.newBuilder().build())
436    *           .build();
437    *   Profile response = profilerServiceClient.updateProfile(request);
438    * }
439    * }</pre>
440    *
441    * @param request The request object containing all of the parameters for the API call.
442    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
443    */
updateProfile(UpdateProfileRequest request)444   public final Profile updateProfile(UpdateProfileRequest request) {
445     return updateProfileCallable().call(request);
446   }
447 
448   // AUTO-GENERATED DOCUMENTATION AND METHOD.
449   /**
450    * UpdateProfile updates the profile bytes and labels on the profile resource created in the
451    * online mode. Updating the bytes for profiles created in the offline mode is currently not
452    * supported: the profile content must be provided at the time of the profile creation.
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 (ProfilerServiceClient profilerServiceClient = ProfilerServiceClient.create()) {
463    *   UpdateProfileRequest request =
464    *       UpdateProfileRequest.newBuilder()
465    *           .setProfile(Profile.newBuilder().build())
466    *           .setUpdateMask(FieldMask.newBuilder().build())
467    *           .build();
468    *   ApiFuture<Profile> future = profilerServiceClient.updateProfileCallable().futureCall(request);
469    *   // Do something.
470    *   Profile response = future.get();
471    * }
472    * }</pre>
473    */
updateProfileCallable()474   public final UnaryCallable<UpdateProfileRequest, Profile> updateProfileCallable() {
475     return stub.updateProfileCallable();
476   }
477 
478   @Override
close()479   public final void close() {
480     stub.close();
481   }
482 
483   @Override
shutdown()484   public void shutdown() {
485     stub.shutdown();
486   }
487 
488   @Override
isShutdown()489   public boolean isShutdown() {
490     return stub.isShutdown();
491   }
492 
493   @Override
isTerminated()494   public boolean isTerminated() {
495     return stub.isTerminated();
496   }
497 
498   @Override
shutdownNow()499   public void shutdownNow() {
500     stub.shutdownNow();
501   }
502 
503   @Override
awaitTermination(long duration, TimeUnit unit)504   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
505     return stub.awaitTermination(duration, unit);
506   }
507 }
508