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