• 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 com.google.api.core.ApiFunction;
20 import com.google.api.core.BetaApi;
21 import com.google.api.gax.core.GaxProperties;
22 import com.google.api.gax.core.GoogleCredentialsProvider;
23 import com.google.api.gax.core.InstantiatingExecutorProvider;
24 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
25 import com.google.api.gax.httpjson.HttpJsonTransportChannel;
26 import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
27 import com.google.api.gax.retrying.RetrySettings;
28 import com.google.api.gax.rpc.ApiClientHeaderProvider;
29 import com.google.api.gax.rpc.ClientContext;
30 import com.google.api.gax.rpc.StatusCode;
31 import com.google.api.gax.rpc.StubSettings;
32 import com.google.api.gax.rpc.TransportChannelProvider;
33 import com.google.api.gax.rpc.UnaryCallSettings;
34 import com.google.cloud.compute.v1.GetLicenseCodeRequest;
35 import com.google.cloud.compute.v1.LicenseCode;
36 import com.google.cloud.compute.v1.TestIamPermissionsLicenseCodeRequest;
37 import com.google.cloud.compute.v1.TestPermissionsResponse;
38 import com.google.common.collect.ImmutableList;
39 import com.google.common.collect.ImmutableMap;
40 import com.google.common.collect.ImmutableSet;
41 import com.google.common.collect.Lists;
42 import java.io.IOException;
43 import java.util.List;
44 import javax.annotation.Generated;
45 import org.threeten.bp.Duration;
46 
47 // AUTO-GENERATED DOCUMENTATION AND CLASS.
48 /**
49  * Settings class to configure an instance of {@link LicenseCodesStub}.
50  *
51  * <p>The default instance has everything set to sensible defaults:
52  *
53  * <ul>
54  *   <li>The default service address (compute.googleapis.com) and default port (443) are used.
55  *   <li>Credentials are acquired automatically through Application Default Credentials.
56  *   <li>Retries are configured for idempotent methods but not for non-idempotent methods.
57  * </ul>
58  *
59  * <p>The builder of this class is recursive, so contained classes are themselves builders. When
60  * build() is called, the tree of builders is called to create the complete settings object.
61  *
62  * <p>For example, to set the total timeout of get to 30 seconds:
63  *
64  * <pre>{@code
65  * // This snippet has been automatically generated and should be regarded as a code template only.
66  * // It will require modifications to work:
67  * // - It may require correct/in-range values for request initialization.
68  * // - It may require specifying regional endpoints when creating the service client as shown in
69  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
70  * LicenseCodesStubSettings.Builder licenseCodesSettingsBuilder =
71  *     LicenseCodesStubSettings.newBuilder();
72  * licenseCodesSettingsBuilder
73  *     .getSettings()
74  *     .setRetrySettings(
75  *         licenseCodesSettingsBuilder
76  *             .getSettings()
77  *             .getRetrySettings()
78  *             .toBuilder()
79  *             .setTotalTimeout(Duration.ofSeconds(30))
80  *             .build());
81  * LicenseCodesStubSettings licenseCodesSettings = licenseCodesSettingsBuilder.build();
82  * }</pre>
83  */
84 @Generated("by gapic-generator-java")
85 public class LicenseCodesStubSettings extends StubSettings<LicenseCodesStubSettings> {
86   /** The default scopes of the service. */
87   private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES =
88       ImmutableList.<String>builder()
89           .add("https://www.googleapis.com/auth/compute.readonly")
90           .add("https://www.googleapis.com/auth/compute")
91           .add("https://www.googleapis.com/auth/cloud-platform")
92           .build();
93 
94   private final UnaryCallSettings<GetLicenseCodeRequest, LicenseCode> getSettings;
95   private final UnaryCallSettings<TestIamPermissionsLicenseCodeRequest, TestPermissionsResponse>
96       testIamPermissionsSettings;
97 
98   /** Returns the object with the settings used for calls to get. */
getSettings()99   public UnaryCallSettings<GetLicenseCodeRequest, LicenseCode> getSettings() {
100     return getSettings;
101   }
102 
103   /** Returns the object with the settings used for calls to testIamPermissions. */
104   public UnaryCallSettings<TestIamPermissionsLicenseCodeRequest, TestPermissionsResponse>
testIamPermissionsSettings()105       testIamPermissionsSettings() {
106     return testIamPermissionsSettings;
107   }
108 
createStub()109   public LicenseCodesStub createStub() throws IOException {
110     if (getTransportChannelProvider()
111         .getTransportName()
112         .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
113       return HttpJsonLicenseCodesStub.create(this);
114     }
115     throw new UnsupportedOperationException(
116         String.format(
117             "Transport not supported: %s", getTransportChannelProvider().getTransportName()));
118   }
119 
120   /** Returns a builder for the default ExecutorProvider for this service. */
defaultExecutorProviderBuilder()121   public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
122     return InstantiatingExecutorProvider.newBuilder();
123   }
124 
125   /** Returns the default service endpoint. */
getDefaultEndpoint()126   public static String getDefaultEndpoint() {
127     return "compute.googleapis.com:443";
128   }
129 
130   /** Returns the default mTLS service endpoint. */
getDefaultMtlsEndpoint()131   public static String getDefaultMtlsEndpoint() {
132     return "compute.mtls.googleapis.com:443";
133   }
134 
135   /** Returns the default service scopes. */
getDefaultServiceScopes()136   public static List<String> getDefaultServiceScopes() {
137     return DEFAULT_SERVICE_SCOPES;
138   }
139 
140   /** Returns a builder for the default credentials for this service. */
defaultCredentialsProviderBuilder()141   public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
142     return GoogleCredentialsProvider.newBuilder()
143         .setScopesToApply(DEFAULT_SERVICE_SCOPES)
144         .setUseJwtAccessWithScope(true);
145   }
146 
147   /** Returns a builder for the default ChannelProvider for this service. */
148   public static InstantiatingHttpJsonChannelProvider.Builder
defaultHttpJsonTransportProviderBuilder()149       defaultHttpJsonTransportProviderBuilder() {
150     return InstantiatingHttpJsonChannelProvider.newBuilder();
151   }
152 
defaultTransportChannelProvider()153   public static TransportChannelProvider defaultTransportChannelProvider() {
154     return defaultHttpJsonTransportProviderBuilder().build();
155   }
156 
157   @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
defaultApiClientHeaderProviderBuilder()158   public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
159     return ApiClientHeaderProvider.newBuilder()
160         .setGeneratedLibToken(
161             "gapic", GaxProperties.getLibraryVersion(LicenseCodesStubSettings.class))
162         .setTransportToken(
163             GaxHttpJsonProperties.getHttpJsonTokenName(),
164             GaxHttpJsonProperties.getHttpJsonVersion());
165   }
166 
167   /** Returns a new builder for this class. */
newBuilder()168   public static Builder newBuilder() {
169     return Builder.createDefault();
170   }
171 
172   /** Returns a new builder for this class. */
newBuilder(ClientContext clientContext)173   public static Builder newBuilder(ClientContext clientContext) {
174     return new Builder(clientContext);
175   }
176 
177   /** Returns a builder containing all the values of this settings class. */
toBuilder()178   public Builder toBuilder() {
179     return new Builder(this);
180   }
181 
LicenseCodesStubSettings(Builder settingsBuilder)182   protected LicenseCodesStubSettings(Builder settingsBuilder) throws IOException {
183     super(settingsBuilder);
184 
185     getSettings = settingsBuilder.getSettings().build();
186     testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
187   }
188 
189   /** Builder for LicenseCodesStubSettings. */
190   public static class Builder extends StubSettings.Builder<LicenseCodesStubSettings, Builder> {
191     private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders;
192     private final UnaryCallSettings.Builder<GetLicenseCodeRequest, LicenseCode> getSettings;
193     private final UnaryCallSettings.Builder<
194             TestIamPermissionsLicenseCodeRequest, TestPermissionsResponse>
195         testIamPermissionsSettings;
196     private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
197         RETRYABLE_CODE_DEFINITIONS;
198 
199     static {
200       ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =
201           ImmutableMap.builder();
202       definitions.put(
203           "retry_policy_0_codes",
204           ImmutableSet.copyOf(
205               Lists.<StatusCode.Code>newArrayList(
206                   StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE)));
207       definitions.put(
208           "no_retry_1_codes", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));
209       RETRYABLE_CODE_DEFINITIONS = definitions.build();
210     }
211 
212     private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS;
213 
214     static {
215       ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();
216       RetrySettings settings = null;
217       settings =
218           RetrySettings.newBuilder()
219               .setInitialRetryDelay(Duration.ofMillis(100L))
220               .setRetryDelayMultiplier(1.3)
221               .setMaxRetryDelay(Duration.ofMillis(60000L))
222               .setInitialRpcTimeout(Duration.ofMillis(600000L))
223               .setRpcTimeoutMultiplier(1.0)
224               .setMaxRpcTimeout(Duration.ofMillis(600000L))
225               .setTotalTimeout(Duration.ofMillis(600000L))
226               .build();
227       definitions.put("retry_policy_0_params", settings);
228       settings =
229           RetrySettings.newBuilder()
230               .setInitialRpcTimeout(Duration.ofMillis(600000L))
231               .setRpcTimeoutMultiplier(1.0)
232               .setMaxRpcTimeout(Duration.ofMillis(600000L))
233               .setTotalTimeout(Duration.ofMillis(600000L))
234               .build();
235       definitions.put("no_retry_1_params", settings);
236       RETRY_PARAM_DEFINITIONS = definitions.build();
237     }
238 
Builder()239     protected Builder() {
240       this(((ClientContext) null));
241     }
242 
Builder(ClientContext clientContext)243     protected Builder(ClientContext clientContext) {
244       super(clientContext);
245 
246       getSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
247       testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
248 
249       unaryMethodSettingsBuilders =
250           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
251               getSettings, testIamPermissionsSettings);
252       initDefaults(this);
253     }
254 
Builder(LicenseCodesStubSettings settings)255     protected Builder(LicenseCodesStubSettings settings) {
256       super(settings);
257 
258       getSettings = settings.getSettings.toBuilder();
259       testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder();
260 
261       unaryMethodSettingsBuilders =
262           ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
263               getSettings, testIamPermissionsSettings);
264     }
265 
createDefault()266     private static Builder createDefault() {
267       Builder builder = new Builder(((ClientContext) null));
268 
269       builder.setTransportChannelProvider(defaultTransportChannelProvider());
270       builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
271       builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
272       builder.setEndpoint(getDefaultEndpoint());
273       builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
274       builder.setSwitchToMtlsEndpointAllowed(true);
275 
276       return initDefaults(builder);
277     }
278 
initDefaults(Builder builder)279     private static Builder initDefaults(Builder builder) {
280       builder
281           .getSettings()
282           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
283           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
284 
285       builder
286           .testIamPermissionsSettings()
287           .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
288           .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));
289 
290       return builder;
291     }
292 
293     /**
294      * Applies the given settings updater function to all of the unary API methods in this service.
295      *
296      * <p>Note: This method does not support applying settings to streaming methods.
297      */
applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)298     public Builder applyToAllUnaryMethods(
299         ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) {
300       super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
301       return this;
302     }
303 
unaryMethodSettingsBuilders()304     public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() {
305       return unaryMethodSettingsBuilders;
306     }
307 
308     /** Returns the builder for the settings used for calls to get. */
getSettings()309     public UnaryCallSettings.Builder<GetLicenseCodeRequest, LicenseCode> getSettings() {
310       return getSettings;
311     }
312 
313     /** Returns the builder for the settings used for calls to testIamPermissions. */
314     public UnaryCallSettings.Builder<TestIamPermissionsLicenseCodeRequest, TestPermissionsResponse>
testIamPermissionsSettings()315         testIamPermissionsSettings() {
316       return testIamPermissionsSettings;
317     }
318 
319     @Override
build()320     public LicenseCodesStubSettings build() throws IOException {
321       return new LicenseCodesStubSettings(this);
322     }
323   }
324 }
325