• 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.stub;
18 
19 import static com.google.cloud.compute.v1.NodeTemplatesClient.AggregatedListPagedResponse;
20 import static com.google.cloud.compute.v1.NodeTemplatesClient.ListPagedResponse;
21 
22 import com.google.api.core.ApiFunction;
23 import com.google.api.core.ApiFuture;
24 import com.google.api.core.BetaApi;
25 import com.google.api.gax.core.GaxProperties;
26 import com.google.api.gax.core.GoogleCredentialsProvider;
27 import com.google.api.gax.core.InstantiatingExecutorProvider;
28 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
29 import com.google.api.gax.httpjson.HttpJsonTransportChannel;
30 import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
31 import com.google.api.gax.httpjson.ProtoOperationTransformers;
32 import com.google.api.gax.longrunning.OperationSnapshot;
33 import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
34 import com.google.api.gax.retrying.RetrySettings;
35 import com.google.api.gax.rpc.ApiCallContext;
36 import com.google.api.gax.rpc.ApiClientHeaderProvider;
37 import com.google.api.gax.rpc.ClientContext;
38 import com.google.api.gax.rpc.OperationCallSettings;
39 import com.google.api.gax.rpc.PageContext;
40 import com.google.api.gax.rpc.PagedCallSettings;
41 import com.google.api.gax.rpc.PagedListDescriptor;
42 import com.google.api.gax.rpc.PagedListResponseFactory;
43 import com.google.api.gax.rpc.StatusCode;
44 import com.google.api.gax.rpc.StubSettings;
45 import com.google.api.gax.rpc.TransportChannelProvider;
46 import com.google.api.gax.rpc.UnaryCallSettings;
47 import com.google.api.gax.rpc.UnaryCallable;
48 import com.google.cloud.compute.v1.AggregatedListNodeTemplatesRequest;
49 import com.google.cloud.compute.v1.DeleteNodeTemplateRequest;
50 import com.google.cloud.compute.v1.GetIamPolicyNodeTemplateRequest;
51 import com.google.cloud.compute.v1.GetNodeTemplateRequest;
52 import com.google.cloud.compute.v1.InsertNodeTemplateRequest;
53 import com.google.cloud.compute.v1.ListNodeTemplatesRequest;
54 import com.google.cloud.compute.v1.NodeTemplate;
55 import com.google.cloud.compute.v1.NodeTemplateAggregatedList;
56 import com.google.cloud.compute.v1.NodeTemplateList;
57 import com.google.cloud.compute.v1.NodeTemplatesScopedList;
58 import com.google.cloud.compute.v1.Operation;
59 import com.google.cloud.compute.v1.Policy;
60 import com.google.cloud.compute.v1.SetIamPolicyNodeTemplateRequest;
61 import com.google.cloud.compute.v1.TestIamPermissionsNodeTemplateRequest;
62 import com.google.cloud.compute.v1.TestPermissionsResponse;
63 import com.google.common.collect.ImmutableList;
64 import com.google.common.collect.ImmutableMap;
65 import com.google.common.collect.ImmutableSet;
66 import com.google.common.collect.Lists;
67 import java.io.IOException;
68 import java.util.Collections;
69 import java.util.List;
70 import java.util.Map;
71 import javax.annotation.Generated;
72 import org.threeten.bp.Duration;
73 
74 // AUTO-GENERATED DOCUMENTATION AND CLASS.
75 /**
76  * Settings class to configure an instance of {@link NodeTemplatesStub}.
77  *
78  * <p>The default instance has everything set to sensible defaults:
79  *
80  * <ul>
81  *   <li>The default service address (compute.googleapis.com) and default port (443) are used.
82  *   <li>Credentials are acquired automatically through Application Default Credentials.
83  *   <li>Retries are configured for idempotent methods but not for non-idempotent methods.
84  * </ul>
85  *
86  * <p>The builder of this class is recursive, so contained classes are themselves builders. When
87  * build() is called, the tree of builders is called to create the complete settings object.
88  *
89  * <p>For example, to set the total timeout of get to 30 seconds:
90  *
91  * <pre>{@code
92  * // This snippet has been automatically generated and should be regarded as a code template only.
93  * // It will require modifications to work:
94  * // - It may require correct/in-range values for request initialization.
95  * // - It may require specifying regional endpoints when creating the service client as shown in
96  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
97  * NodeTemplatesStubSettings.Builder nodeTemplatesSettingsBuilder =
98  *     NodeTemplatesStubSettings.newBuilder();
99  * nodeTemplatesSettingsBuilder
100  *     .getSettings()
101  *     .setRetrySettings(
102  *         nodeTemplatesSettingsBuilder
103  *             .getSettings()
104  *             .getRetrySettings()
105  *             .toBuilder()
106  *             .setTotalTimeout(Duration.ofSeconds(30))
107  *             .build());
108  * NodeTemplatesStubSettings nodeTemplatesSettings = nodeTemplatesSettingsBuilder.build();
109  * }</pre>
110  */
111 @Generated("by gapic-generator-java")
112 public class NodeTemplatesStubSettings extends StubSettings<NodeTemplatesStubSettings> {
113   /** The default scopes of the service. */
114   private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
115       ImmutableList.<String>builder()
116           .add("https://www.googleapis.com/auth/compute")
117           .add("https://www.googleapis.com/auth/cloud-platform")
118           .build();
119 
120   private final PagedCallSettings<
121           AggregatedListNodeTemplatesRequest,
122           NodeTemplateAggregatedList,
123           AggregatedListPagedResponse>
124       aggregatedListSettings;
125   private final UnaryCallSettings<DeleteNodeTemplateRequest, Operation> deleteSettings;
126   private final OperationCallSettings<DeleteNodeTemplateRequest, Operation, Operation>
127       deleteOperationSettings;
128   private final UnaryCallSettings<GetNodeTemplateRequest, NodeTemplate> getSettings;
129   private final UnaryCallSettings<GetIamPolicyNodeTemplateRequest, Policy> getIamPolicySettings;
130   private final UnaryCallSettings<InsertNodeTemplateRequest, Operation> insertSettings;
131   private final OperationCallSettings<InsertNodeTemplateRequest, Operation, Operation>
132       insertOperationSettings;
133   private final PagedCallSettings<ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>
134       listSettings;
135   private final UnaryCallSettings<SetIamPolicyNodeTemplateRequest, Policy> setIamPolicySettings;
136   private final UnaryCallSettings<TestIamPermissionsNodeTemplateRequest, TestPermissionsResponse>
137       testIamPermissionsSettings;
138 
139   private static final PagedListDescriptor<
140           AggregatedListNodeTemplatesRequest,
141           NodeTemplateAggregatedList,
142           Map.Entry<String, NodeTemplatesScopedList>>
143       AGGREGATED_LIST_PAGE_STR_DESC =
144           new PagedListDescriptor<
145               AggregatedListNodeTemplatesRequest,
146               NodeTemplateAggregatedList,
147               Map.Entry<String, NodeTemplatesScopedList>>() {
148             @Override
149             public String emptyToken() {
150               return "";
151             }
152 
153             @Override
154             public AggregatedListNodeTemplatesRequest injectToken(
155                 AggregatedListNodeTemplatesRequest payload, String token) {
156               return AggregatedListNodeTemplatesRequest.newBuilder(payload)
157                   .setPageToken(token)
158                   .build();
159             }
160 
161             @Override
162             public AggregatedListNodeTemplatesRequest injectPageSize(
163                 AggregatedListNodeTemplatesRequest payload, int pageSize) {
164               return AggregatedListNodeTemplatesRequest.newBuilder(payload)
165                   .setMaxResults(pageSize)
166                   .build();
167             }
168 
169             @Override
170             public Integer extractPageSize(AggregatedListNodeTemplatesRequest payload) {
171               return payload.getMaxResults();
172             }
173 
174             @Override
175             public String extractNextToken(NodeTemplateAggregatedList payload) {
176               return payload.getNextPageToken();
177             }
178 
179             @Override
180             public Iterable<Map.Entry<String, NodeTemplatesScopedList>> extractResources(
181                 NodeTemplateAggregatedList payload) {
182               return payload.getItemsMap() == null
183                   ? Collections.<Map.Entry<String, NodeTemplatesScopedList>>emptySet()
184                   : payload.getItemsMap().entrySet();
185             }
186           };
187 
188   private static final PagedListDescriptor<ListNodeTemplatesRequest, NodeTemplateList, NodeTemplate>
189       LIST_PAGE_STR_DESC =
190           new PagedListDescriptor<ListNodeTemplatesRequest, NodeTemplateList, NodeTemplate>() {
191             @Override
192             public String emptyToken() {
193               return "";
194             }
195 
196             @Override
197             public ListNodeTemplatesRequest injectToken(
198                 ListNodeTemplatesRequest payload, String token) {
199               return ListNodeTemplatesRequest.newBuilder(payload).setPageToken(token).build();
200             }
201 
202             @Override
203             public ListNodeTemplatesRequest injectPageSize(
204                 ListNodeTemplatesRequest payload, int pageSize) {
205               return ListNodeTemplatesRequest.newBuilder(payload).setMaxResults(pageSize).build();
206             }
207 
208             @Override
209             public Integer extractPageSize(ListNodeTemplatesRequest payload) {
210               return payload.getMaxResults();
211             }
212 
213             @Override
214             public String extractNextToken(NodeTemplateList payload) {
215               return payload.getNextPageToken();
216             }
217 
218             @Override
219             public Iterable<NodeTemplate> extractResources(NodeTemplateList payload) {
220               return payload.getItemsList() == null
221                   ? ImmutableList.<NodeTemplate>of()
222                   : payload.getItemsList();
223             }
224           };
225 
226   private static final PagedListResponseFactory<
227           AggregatedListNodeTemplatesRequest,
228           NodeTemplateAggregatedList,
229           AggregatedListPagedResponse>
230       AGGREGATED_LIST_PAGE_STR_FACT =
231           new PagedListResponseFactory<
232               AggregatedListNodeTemplatesRequest,
233               NodeTemplateAggregatedList,
234               AggregatedListPagedResponse>() {
235             @Override
236             public ApiFuture<AggregatedListPagedResponse> getFuturePagedResponse(
237                 UnaryCallable<AggregatedListNodeTemplatesRequest, NodeTemplateAggregatedList>
238                     callable,
239                 AggregatedListNodeTemplatesRequest request,
240                 ApiCallContext context,
241                 ApiFuture<NodeTemplateAggregatedList> futureResponse) {
242               PageContext<
243                       AggregatedListNodeTemplatesRequest,
244                       NodeTemplateAggregatedList,
245                       Map.Entry<String, NodeTemplatesScopedList>>
246                   pageContext =
247                       PageContext.create(callable, AGGREGATED_LIST_PAGE_STR_DESC, request, context);
248               return AggregatedListPagedResponse.createAsync(pageContext, futureResponse);
249             }
250           };
251 
252   private static final PagedListResponseFactory<
253           ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>
254       LIST_PAGE_STR_FACT =
255           new PagedListResponseFactory<
256               ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>() {
257             @Override
258             public ApiFuture<ListPagedResponse> getFuturePagedResponse(
259                 UnaryCallable<ListNodeTemplatesRequest, NodeTemplateList> callable,
260                 ListNodeTemplatesRequest request,
261                 ApiCallContext context,
262                 ApiFuture<NodeTemplateList> futureResponse) {
263               PageContext<ListNodeTemplatesRequest, NodeTemplateList, NodeTemplate> pageContext =
264                   PageContext.create(callable, LIST_PAGE_STR_DESC, request, context);
265               return ListPagedResponse.createAsync(pageContext, futureResponse);
266             }
267           };
268 
269   /** Returns the object with the settings used for calls to aggregatedList. */
270   public PagedCallSettings<
271           AggregatedListNodeTemplatesRequest,
272           NodeTemplateAggregatedList,
273           AggregatedListPagedResponse>
aggregatedListSettings()274       aggregatedListSettings() {
275     return aggregatedListSettings;
276   }
277 
278   /** Returns the object with the settings used for calls to delete. */
deleteSettings()279   public UnaryCallSettings<DeleteNodeTemplateRequest, Operation> deleteSettings() {
280     return deleteSettings;
281   }
282 
283   /** Returns the object with the settings used for calls to delete. */
284   public OperationCallSettings<DeleteNodeTemplateRequest, Operation, Operation>
deleteOperationSettings()285       deleteOperationSettings() {
286     return deleteOperationSettings;
287   }
288 
289   /** Returns the object with the settings used for calls to get. */
getSettings()290   public UnaryCallSettings<GetNodeTemplateRequest, NodeTemplate> getSettings() {
291     return getSettings;
292   }
293 
294   /** Returns the object with the settings used for calls to getIamPolicy. */
getIamPolicySettings()295   public UnaryCallSettings<GetIamPolicyNodeTemplateRequest, Policy> getIamPolicySettings() {
296     return getIamPolicySettings;
297   }
298 
299   /** Returns the object with the settings used for calls to insert. */
insertSettings()300   public UnaryCallSettings<InsertNodeTemplateRequest, Operation> insertSettings() {
301     return insertSettings;
302   }
303 
304   /** Returns the object with the settings used for calls to insert. */
305   public OperationCallSettings<InsertNodeTemplateRequest, Operation, Operation>
insertOperationSettings()306       insertOperationSettings() {
307     return insertOperationSettings;
308   }
309 
310   /** Returns the object with the settings used for calls to list. */
311   public PagedCallSettings<ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>
listSettings()312       listSettings() {
313     return listSettings;
314   }
315 
316   /** Returns the object with the settings used for calls to setIamPolicy. */
setIamPolicySettings()317   public UnaryCallSettings<SetIamPolicyNodeTemplateRequest, Policy> setIamPolicySettings() {
318     return setIamPolicySettings;
319   }
320 
321   /** Returns the object with the settings used for calls to testIamPermissions. */
322   public UnaryCallSettings<TestIamPermissionsNodeTemplateRequest, TestPermissionsResponse>
testIamPermissionsSettings()323       testIamPermissionsSettings() {
324     return testIamPermissionsSettings;
325   }
326 
createStub()327   public NodeTemplatesStub createStub() throws IOException {
328     if (getTransportChannelProvider()
329         .getTransportName()
330         .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
331       return HttpJsonNodeTemplatesStub.create(this);
332     }
333     throw new UnsupportedOperationException(
334         String.format(
335             "Transport not supported: %s", getTransportChannelProvider().getTransportName()));
336   }
337 
338   /** Returns a builder for the default ExecutorProvider for this service. */
defaultExecutorProviderBuilder()339   public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
340     return InstantiatingExecutorProvider.newBuilder();
341   }
342 
343   /** Returns the default service endpoint. */
getDefaultEndpoint()344   public static String getDefaultEndpoint() {
345     return "compute.googleapis.com:443";
346   }
347 
348   /** Returns the default mTLS service endpoint. */
getDefaultMtlsEndpoint()349   public static String getDefaultMtlsEndpoint() {
350     return "compute.mtls.googleapis.com:443";
351   }
352 
353   /** Returns the default service scopes. */
getDefaultServiceScopes()354   public static List<String> getDefaultServiceScopes() {
355     return DEFAULT_SERVICE_SCOPES;
356   }
357 
358   /** Returns a builder for the default credentials for this service. */
defaultCredentialsProviderBuilder()359   public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
360     return GoogleCredentialsProvider.newBuilder()
361         .setScopesToApply(DEFAULT_SERVICE_SCOPES)
362         .setUseJwtAccessWithScope(true);
363   }
364 
365   /** Returns a builder for the default ChannelProvider for this service. */
366   public static InstantiatingHttpJsonChannelProvider.Builder
defaultHttpJsonTransportProviderBuilder()367       defaultHttpJsonTransportProviderBuilder() {
368     return InstantiatingHttpJsonChannelProvider.newBuilder();
369   }
370 
defaultTransportChannelProvider()371   public static TransportChannelProvider defaultTransportChannelProvider() {
372     return defaultHttpJsonTransportProviderBuilder().build();
373   }
374 
375   @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
defaultApiClientHeaderProviderBuilder()376   public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
377     return ApiClientHeaderProvider.newBuilder()
378         .setGeneratedLibToken(
379             "gapic", GaxProperties.getLibraryVersion(NodeTemplatesStubSettings.class))
380         .setTransportToken(
381             GaxHttpJsonProperties.getHttpJsonTokenName(),
382             GaxHttpJsonProperties.getHttpJsonVersion());
383   }
384 
385   /** Returns a new builder for this class. */
newBuilder()386   public static Builder newBuilder() {
387     return Builder.createDefault();
388   }
389 
390   /** Returns a new builder for this class. */
newBuilder(ClientContext clientContext)391   public static Builder newBuilder(ClientContext clientContext) {
392     return new Builder(clientContext);
393   }
394 
395   /** Returns a builder containing all the values of this settings class. */
toBuilder()396   public Builder toBuilder() {
397     return new Builder(this);
398   }
399 
NodeTemplatesStubSettings(Builder settingsBuilder)400   protected NodeTemplatesStubSettings(Builder settingsBuilder) throws IOException {
401     super(settingsBuilder);
402 
403     aggregatedListSettings = settingsBuilder.aggregatedListSettings().build();
404     deleteSettings = settingsBuilder.deleteSettings().build();
405     deleteOperationSettings = settingsBuilder.deleteOperationSettings().build();
406     getSettings = settingsBuilder.getSettings().build();
407     getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
408     insertSettings = settingsBuilder.insertSettings().build();
409     insertOperationSettings = settingsBuilder.insertOperationSettings().build();
410     listSettings = settingsBuilder.listSettings().build();
411     setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
412     testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
413   }
414 
415   /** Builder for NodeTemplatesStubSettings. */
416   public static class Builder extends StubSettings.Builder<NodeTemplatesStubSettings, Builder> {
417     private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders;
418     private final PagedCallSettings.Builder<
419             AggregatedListNodeTemplatesRequest,
420             NodeTemplateAggregatedList,
421             AggregatedListPagedResponse>
422         aggregatedListSettings;
423     private final UnaryCallSettings.Builder<DeleteNodeTemplateRequest, Operation> deleteSettings;
424     private final OperationCallSettings.Builder<DeleteNodeTemplateRequest, Operation, Operation>
425         deleteOperationSettings;
426     private final UnaryCallSettings.Builder<GetNodeTemplateRequest, NodeTemplate> getSettings;
427     private final UnaryCallSettings.Builder<GetIamPolicyNodeTemplateRequest, Policy>
428         getIamPolicySettings;
429     private final UnaryCallSettings.Builder<InsertNodeTemplateRequest, Operation> insertSettings;
430     private final OperationCallSettings.Builder<InsertNodeTemplateRequest, Operation, Operation>
431         insertOperationSettings;
432     private final PagedCallSettings.Builder<
433             ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>
434         listSettings;
435     private final UnaryCallSettings.Builder<SetIamPolicyNodeTemplateRequest, Policy>
436         setIamPolicySettings;
437     private final UnaryCallSettings.Builder<
438             TestIamPermissionsNodeTemplateRequest, TestPermissionsResponse>
439         testIamPermissionsSettings;
440     private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
441         RETRYABLE_CODE_DEFINITIONS;
442 
443     static {
444       ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =
445           ImmutableMap.builder();
446       definitions.put(
447           "retry_policy_0_codes",
448           ImmutableSet.copyOf(
449               Lists.<StatusCode.Code>newArrayList(
450                   StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
451       definitions.put(
452           "no_retry_1_codes", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));
453       RETRYABLE_CODE_DEFINITIONS = definitions.build();
454     }
455 
456     private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS;
457 
458     static {
459       ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();
460       RetrySettings settings = null;
461       settings =
462           RetrySettings.newBuilder()
463               .setInitialRetryDelay(Duration.ofMillis(100L))
464               .setRetryDelayMultiplier(1.3)
465               .setMaxRetryDelay(Duration.ofMillis(60000L))
466               .setInitialRpcTimeout(Duration.ofMillis(600000L))
467               .setRpcTimeoutMultiplier(1.0)
468               .setMaxRpcTimeout(Duration.ofMillis(600000L))
469               .setTotalTimeout(Duration.ofMillis(600000L))
470               .build();
471       definitions.put("retry_policy_0_params", settings);
472       settings =
473           RetrySettings.newBuilder()
474               .setInitialRpcTimeout(Duration.ofMillis(600000L))
475               .setRpcTimeoutMultiplier(1.0)
476               .setMaxRpcTimeout(Duration.ofMillis(600000L))
477               .setTotalTimeout(Duration.ofMillis(600000L))
478               .build();
479       definitions.put("no_retry_1_params", settings);
480       RETRY_PARAM_DEFINITIONS = definitions.build();
481     }
482 
Builder()483     protected Builder() {
484       this(((ClientContext) null));
485     }
486 
Builder(ClientContext clientContext)487     protected Builder(ClientContext clientContext) {
488       super(clientContext);
489 
490       aggregatedListSettings = PagedCallSettings.newBuilder(AGGREGATED_LIST_PAGE_STR_FACT);
491       deleteSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
492       deleteOperationSettings = OperationCallSettings.newBuilder();
493       getSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
494       getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
495       insertSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
496       insertOperationSettings = OperationCallSettings.newBuilder();
497       listSettings = PagedCallSettings.newBuilder(LIST_PAGE_STR_FACT);
498       setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
499       testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
500 
501       unaryMethodSettingsBuilders =
502           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
503               aggregatedListSettings,
504               deleteSettings,
505               getSettings,
506               getIamPolicySettings,
507               insertSettings,
508               listSettings,
509               setIamPolicySettings,
510               testIamPermissionsSettings);
511       initDefaults(this);
512     }
513 
Builder(NodeTemplatesStubSettings settings)514     protected Builder(NodeTemplatesStubSettings settings) {
515       super(settings);
516 
517       aggregatedListSettings = settings.aggregatedListSettings.toBuilder();
518       deleteSettings = settings.deleteSettings.toBuilder();
519       deleteOperationSettings = settings.deleteOperationSettings.toBuilder();
520       getSettings = settings.getSettings.toBuilder();
521       getIamPolicySettings = settings.getIamPolicySettings.toBuilder();
522       insertSettings = settings.insertSettings.toBuilder();
523       insertOperationSettings = settings.insertOperationSettings.toBuilder();
524       listSettings = settings.listSettings.toBuilder();
525       setIamPolicySettings = settings.setIamPolicySettings.toBuilder();
526       testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder();
527 
528       unaryMethodSettingsBuilders =
529           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
530               aggregatedListSettings,
531               deleteSettings,
532               getSettings,
533               getIamPolicySettings,
534               insertSettings,
535               listSettings,
536               setIamPolicySettings,
537               testIamPermissionsSettings);
538     }
539 
createDefault()540     private static Builder createDefault() {
541       Builder builder = new Builder(((ClientContext) null));
542 
543       builder.setTransportChannelProvider(defaultTransportChannelProvider());
544       builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
545       builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
546       builder.setEndpoint(getDefaultEndpoint());
547       builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
548       builder.setSwitchToMtlsEndpointAllowed(true);
549 
550       return initDefaults(builder);
551     }
552 
initDefaults(Builder builder)553     private static Builder initDefaults(Builder builder) {
554       builder
555           .aggregatedListSettings()
556           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
557           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
558 
559       builder
560           .deleteSettings()
561           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
562           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));
563 
564       builder
565           .getSettings()
566           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
567           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
568 
569       builder
570           .getIamPolicySettings()
571           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
572           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
573 
574       builder
575           .insertSettings()
576           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
577           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));
578 
579       builder
580           .listSettings()
581           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
582           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
583 
584       builder
585           .setIamPolicySettings()
586           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
587           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));
588 
589       builder
590           .testIamPermissionsSettings()
591           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
592           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));
593 
594       builder
595           .deleteOperationSettings()
596           .setInitialCallSettings(
597               UnaryCallSettings
598                   .<DeleteNodeTemplateRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
599                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
600                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"))
601                   .build())
602           .setResponseTransformer(
603               ProtoOperationTransformers.ResponseTransformer.create(Operation.class))
604           .setMetadataTransformer(
605               ProtoOperationTransformers.MetadataTransformer.create(Operation.class))
606           .setPollingAlgorithm(
607               OperationTimedPollAlgorithm.create(
608                   RetrySettings.newBuilder()
609                       .setInitialRetryDelay(Duration.ofMillis(500L))
610                       .setRetryDelayMultiplier(1.5)
611                       .setMaxRetryDelay(Duration.ofMillis(20000L))
612                       .setInitialRpcTimeout(Duration.ZERO)
613                       .setRpcTimeoutMultiplier(1.0)
614                       .setMaxRpcTimeout(Duration.ZERO)
615                       .setTotalTimeout(Duration.ofMillis(600000L))
616                       .build()));
617 
618       builder
619           .insertOperationSettings()
620           .setInitialCallSettings(
621               UnaryCallSettings
622                   .<InsertNodeTemplateRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
623                   .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
624                   .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"))
625                   .build())
626           .setResponseTransformer(
627               ProtoOperationTransformers.ResponseTransformer.create(Operation.class))
628           .setMetadataTransformer(
629               ProtoOperationTransformers.MetadataTransformer.create(Operation.class))
630           .setPollingAlgorithm(
631               OperationTimedPollAlgorithm.create(
632                   RetrySettings.newBuilder()
633                       .setInitialRetryDelay(Duration.ofMillis(500L))
634                       .setRetryDelayMultiplier(1.5)
635                       .setMaxRetryDelay(Duration.ofMillis(20000L))
636                       .setInitialRpcTimeout(Duration.ZERO)
637                       .setRpcTimeoutMultiplier(1.0)
638                       .setMaxRpcTimeout(Duration.ZERO)
639                       .setTotalTimeout(Duration.ofMillis(600000L))
640                       .build()));
641 
642       return builder;
643     }
644 
645     /**
646      * Applies the given settings updater function to all of the unary API methods in this service.
647      *
648      * <p>Note: This method does not support applying settings to streaming methods.
649      */
applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)650     public Builder applyToAllUnaryMethods(
651         ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) {
652       super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
653       return this;
654     }
655 
unaryMethodSettingsBuilders()656     public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() {
657       return unaryMethodSettingsBuilders;
658     }
659 
660     /** Returns the builder for the settings used for calls to aggregatedList. */
661     public PagedCallSettings.Builder<
662             AggregatedListNodeTemplatesRequest,
663             NodeTemplateAggregatedList,
664             AggregatedListPagedResponse>
aggregatedListSettings()665         aggregatedListSettings() {
666       return aggregatedListSettings;
667     }
668 
669     /** Returns the builder for the settings used for calls to delete. */
deleteSettings()670     public UnaryCallSettings.Builder<DeleteNodeTemplateRequest, Operation> deleteSettings() {
671       return deleteSettings;
672     }
673 
674     /** Returns the builder for the settings used for calls to delete. */
675     @BetaApi(
676         "The surface for use by generated code is not stable yet and may change in the future.")
677     public OperationCallSettings.Builder<DeleteNodeTemplateRequest, Operation, Operation>
deleteOperationSettings()678         deleteOperationSettings() {
679       return deleteOperationSettings;
680     }
681 
682     /** Returns the builder for the settings used for calls to get. */
getSettings()683     public UnaryCallSettings.Builder<GetNodeTemplateRequest, NodeTemplate> getSettings() {
684       return getSettings;
685     }
686 
687     /** Returns the builder for the settings used for calls to getIamPolicy. */
688     public UnaryCallSettings.Builder<GetIamPolicyNodeTemplateRequest, Policy>
getIamPolicySettings()689         getIamPolicySettings() {
690       return getIamPolicySettings;
691     }
692 
693     /** Returns the builder for the settings used for calls to insert. */
insertSettings()694     public UnaryCallSettings.Builder<InsertNodeTemplateRequest, Operation> insertSettings() {
695       return insertSettings;
696     }
697 
698     /** Returns the builder for the settings used for calls to insert. */
699     @BetaApi(
700         "The surface for use by generated code is not stable yet and may change in the future.")
701     public OperationCallSettings.Builder<InsertNodeTemplateRequest, Operation, Operation>
insertOperationSettings()702         insertOperationSettings() {
703       return insertOperationSettings;
704     }
705 
706     /** Returns the builder for the settings used for calls to list. */
707     public PagedCallSettings.Builder<ListNodeTemplatesRequest, NodeTemplateList, ListPagedResponse>
listSettings()708         listSettings() {
709       return listSettings;
710     }
711 
712     /** Returns the builder for the settings used for calls to setIamPolicy. */
713     public UnaryCallSettings.Builder<SetIamPolicyNodeTemplateRequest, Policy>
setIamPolicySettings()714         setIamPolicySettings() {
715       return setIamPolicySettings;
716     }
717 
718     /** Returns the builder for the settings used for calls to testIamPermissions. */
719     public UnaryCallSettings.Builder<TestIamPermissionsNodeTemplateRequest, TestPermissionsResponse>
testIamPermissionsSettings()720         testIamPermissionsSettings() {
721       return testIamPermissionsSettings;
722     }
723 
724     @Override
build()725     public NodeTemplatesStubSettings build() throws IOException {
726       return new NodeTemplatesStubSettings(this);
727     }
728   }
729 }
730