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