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.talent.v4; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.gax.core.BackgroundResource; 22 import com.google.api.gax.paging.AbstractFixedSizeCollection; 23 import com.google.api.gax.paging.AbstractPage; 24 import com.google.api.gax.paging.AbstractPagedListResponse; 25 import com.google.api.gax.rpc.PageContext; 26 import com.google.api.gax.rpc.UnaryCallable; 27 import com.google.cloud.talent.v4.stub.TenantServiceStub; 28 import com.google.cloud.talent.v4.stub.TenantServiceStubSettings; 29 import com.google.common.util.concurrent.MoreExecutors; 30 import com.google.protobuf.Empty; 31 import com.google.protobuf.FieldMask; 32 import java.io.IOException; 33 import java.util.List; 34 import java.util.concurrent.TimeUnit; 35 import javax.annotation.Generated; 36 37 // AUTO-GENERATED DOCUMENTATION AND CLASS. 38 /** 39 * Service Description: A service that handles tenant management, including CRUD and enumeration. 40 * 41 * <p>This class provides the ability to make remote calls to the backing service through method 42 * calls that map to API methods. Sample code to get started: 43 * 44 * <pre>{@code 45 * // This snippet has been automatically generated and should be regarded as a code template only. 46 * // It will require modifications to work: 47 * // - It may require correct/in-range values for request initialization. 48 * // - It may require specifying regional endpoints when creating the service client as shown in 49 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 50 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 51 * ProjectName parent = ProjectName.of("[PROJECT]"); 52 * Tenant tenant = Tenant.newBuilder().build(); 53 * Tenant response = tenantServiceClient.createTenant(parent, tenant); 54 * } 55 * }</pre> 56 * 57 * <p>Note: close() needs to be called on the TenantServiceClient object to clean up resources such 58 * as threads. In the example above, try-with-resources is used, which automatically calls close(). 59 * 60 * <p>The surface of this class includes several types of Java methods for each of the API's 61 * methods: 62 * 63 * <ol> 64 * <li>A "flattened" method. With this type of method, the fields of the request type have been 65 * converted into function parameters. It may be the case that not all fields are available as 66 * parameters, and not every API method will have a flattened method entry point. 67 * <li>A "request object" method. This type of method only takes one parameter, a request object, 68 * which must be constructed before the call. Not every API method will have a request object 69 * method. 70 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 71 * callable object, which can be used to initiate calls to the service. 72 * </ol> 73 * 74 * <p>See the individual methods for example code. 75 * 76 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 77 * these names, this class includes a format method for each type of name, and additionally a parse 78 * method to extract the individual identifiers contained within names that are returned. 79 * 80 * <p>This class can be customized by passing in a custom instance of TenantServiceSettings to 81 * create(). For example: 82 * 83 * <p>To customize credentials: 84 * 85 * <pre>{@code 86 * // This snippet has been automatically generated and should be regarded as a code template only. 87 * // It will require modifications to work: 88 * // - It may require correct/in-range values for request initialization. 89 * // - It may require specifying regional endpoints when creating the service client as shown in 90 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 91 * TenantServiceSettings tenantServiceSettings = 92 * TenantServiceSettings.newBuilder() 93 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 94 * .build(); 95 * TenantServiceClient tenantServiceClient = TenantServiceClient.create(tenantServiceSettings); 96 * }</pre> 97 * 98 * <p>To customize the endpoint: 99 * 100 * <pre>{@code 101 * // This snippet has been automatically generated and should be regarded as a code template only. 102 * // It will require modifications to work: 103 * // - It may require correct/in-range values for request initialization. 104 * // - It may require specifying regional endpoints when creating the service client as shown in 105 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 106 * TenantServiceSettings tenantServiceSettings = 107 * TenantServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); 108 * TenantServiceClient tenantServiceClient = TenantServiceClient.create(tenantServiceSettings); 109 * }</pre> 110 * 111 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 112 * the wire: 113 * 114 * <pre>{@code 115 * // This snippet has been automatically generated and should be regarded as a code template only. 116 * // It will require modifications to work: 117 * // - It may require correct/in-range values for request initialization. 118 * // - It may require specifying regional endpoints when creating the service client as shown in 119 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 120 * TenantServiceSettings tenantServiceSettings = 121 * TenantServiceSettings.newHttpJsonBuilder().build(); 122 * TenantServiceClient tenantServiceClient = TenantServiceClient.create(tenantServiceSettings); 123 * }</pre> 124 * 125 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 126 */ 127 @Generated("by gapic-generator-java") 128 public class TenantServiceClient implements BackgroundResource { 129 private final TenantServiceSettings settings; 130 private final TenantServiceStub stub; 131 132 /** Constructs an instance of TenantServiceClient with default settings. */ create()133 public static final TenantServiceClient create() throws IOException { 134 return create(TenantServiceSettings.newBuilder().build()); 135 } 136 137 /** 138 * Constructs an instance of TenantServiceClient, using the given settings. The channels are 139 * created based on the settings passed in, or defaults for any settings that are not set. 140 */ create(TenantServiceSettings settings)141 public static final TenantServiceClient create(TenantServiceSettings settings) 142 throws IOException { 143 return new TenantServiceClient(settings); 144 } 145 146 /** 147 * Constructs an instance of TenantServiceClient, using the given stub for making calls. This is 148 * for advanced usage - prefer using create(TenantServiceSettings). 149 */ create(TenantServiceStub stub)150 public static final TenantServiceClient create(TenantServiceStub stub) { 151 return new TenantServiceClient(stub); 152 } 153 154 /** 155 * Constructs an instance of TenantServiceClient, using the given settings. This is protected so 156 * that it is easy to make a subclass, but otherwise, the static factory methods should be 157 * preferred. 158 */ TenantServiceClient(TenantServiceSettings settings)159 protected TenantServiceClient(TenantServiceSettings settings) throws IOException { 160 this.settings = settings; 161 this.stub = ((TenantServiceStubSettings) settings.getStubSettings()).createStub(); 162 } 163 TenantServiceClient(TenantServiceStub stub)164 protected TenantServiceClient(TenantServiceStub stub) { 165 this.settings = null; 166 this.stub = stub; 167 } 168 getSettings()169 public final TenantServiceSettings getSettings() { 170 return settings; 171 } 172 getStub()173 public TenantServiceStub getStub() { 174 return stub; 175 } 176 177 // AUTO-GENERATED DOCUMENTATION AND METHOD. 178 /** 179 * Creates a new tenant entity. 180 * 181 * <p>Sample code: 182 * 183 * <pre>{@code 184 * // This snippet has been automatically generated and should be regarded as a code template only. 185 * // It will require modifications to work: 186 * // - It may require correct/in-range values for request initialization. 187 * // - It may require specifying regional endpoints when creating the service client as shown in 188 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 189 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 190 * ProjectName parent = ProjectName.of("[PROJECT]"); 191 * Tenant tenant = Tenant.newBuilder().build(); 192 * Tenant response = tenantServiceClient.createTenant(parent, tenant); 193 * } 194 * }</pre> 195 * 196 * @param parent Required. Resource name of the project under which the tenant is created. 197 * <p>The format is "projects/{project_id}", for example, "projects/foo". 198 * @param tenant Required. The tenant to be created. 199 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 200 */ createTenant(ProjectName parent, Tenant tenant)201 public final Tenant createTenant(ProjectName parent, Tenant tenant) { 202 CreateTenantRequest request = 203 CreateTenantRequest.newBuilder() 204 .setParent(parent == null ? null : parent.toString()) 205 .setTenant(tenant) 206 .build(); 207 return createTenant(request); 208 } 209 210 // AUTO-GENERATED DOCUMENTATION AND METHOD. 211 /** 212 * Creates a new tenant entity. 213 * 214 * <p>Sample code: 215 * 216 * <pre>{@code 217 * // This snippet has been automatically generated and should be regarded as a code template only. 218 * // It will require modifications to work: 219 * // - It may require correct/in-range values for request initialization. 220 * // - It may require specifying regional endpoints when creating the service client as shown in 221 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 222 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 223 * String parent = ProjectName.of("[PROJECT]").toString(); 224 * Tenant tenant = Tenant.newBuilder().build(); 225 * Tenant response = tenantServiceClient.createTenant(parent, tenant); 226 * } 227 * }</pre> 228 * 229 * @param parent Required. Resource name of the project under which the tenant is created. 230 * <p>The format is "projects/{project_id}", for example, "projects/foo". 231 * @param tenant Required. The tenant to be created. 232 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 233 */ createTenant(String parent, Tenant tenant)234 public final Tenant createTenant(String parent, Tenant tenant) { 235 CreateTenantRequest request = 236 CreateTenantRequest.newBuilder().setParent(parent).setTenant(tenant).build(); 237 return createTenant(request); 238 } 239 240 // AUTO-GENERATED DOCUMENTATION AND METHOD. 241 /** 242 * Creates a new tenant entity. 243 * 244 * <p>Sample code: 245 * 246 * <pre>{@code 247 * // This snippet has been automatically generated and should be regarded as a code template only. 248 * // It will require modifications to work: 249 * // - It may require correct/in-range values for request initialization. 250 * // - It may require specifying regional endpoints when creating the service client as shown in 251 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 252 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 253 * CreateTenantRequest request = 254 * CreateTenantRequest.newBuilder() 255 * .setParent(ProjectName.of("[PROJECT]").toString()) 256 * .setTenant(Tenant.newBuilder().build()) 257 * .build(); 258 * Tenant response = tenantServiceClient.createTenant(request); 259 * } 260 * }</pre> 261 * 262 * @param request The request object containing all of the parameters for the API call. 263 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 264 */ createTenant(CreateTenantRequest request)265 public final Tenant createTenant(CreateTenantRequest request) { 266 return createTenantCallable().call(request); 267 } 268 269 // AUTO-GENERATED DOCUMENTATION AND METHOD. 270 /** 271 * Creates a new tenant entity. 272 * 273 * <p>Sample code: 274 * 275 * <pre>{@code 276 * // This snippet has been automatically generated and should be regarded as a code template only. 277 * // It will require modifications to work: 278 * // - It may require correct/in-range values for request initialization. 279 * // - It may require specifying regional endpoints when creating the service client as shown in 280 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 281 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 282 * CreateTenantRequest request = 283 * CreateTenantRequest.newBuilder() 284 * .setParent(ProjectName.of("[PROJECT]").toString()) 285 * .setTenant(Tenant.newBuilder().build()) 286 * .build(); 287 * ApiFuture<Tenant> future = tenantServiceClient.createTenantCallable().futureCall(request); 288 * // Do something. 289 * Tenant response = future.get(); 290 * } 291 * }</pre> 292 */ createTenantCallable()293 public final UnaryCallable<CreateTenantRequest, Tenant> createTenantCallable() { 294 return stub.createTenantCallable(); 295 } 296 297 // AUTO-GENERATED DOCUMENTATION AND METHOD. 298 /** 299 * Retrieves specified tenant. 300 * 301 * <p>Sample code: 302 * 303 * <pre>{@code 304 * // This snippet has been automatically generated and should be regarded as a code template only. 305 * // It will require modifications to work: 306 * // - It may require correct/in-range values for request initialization. 307 * // - It may require specifying regional endpoints when creating the service client as shown in 308 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 309 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 310 * TenantName name = TenantName.of("[PROJECT]", "[TENANT]"); 311 * Tenant response = tenantServiceClient.getTenant(name); 312 * } 313 * }</pre> 314 * 315 * @param name Required. The resource name of the tenant to be retrieved. 316 * <p>The format is "projects/{project_id}/tenants/{tenant_id}", for example, 317 * "projects/foo/tenants/bar". 318 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 319 */ getTenant(TenantName name)320 public final Tenant getTenant(TenantName name) { 321 GetTenantRequest request = 322 GetTenantRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 323 return getTenant(request); 324 } 325 326 // AUTO-GENERATED DOCUMENTATION AND METHOD. 327 /** 328 * Retrieves specified tenant. 329 * 330 * <p>Sample code: 331 * 332 * <pre>{@code 333 * // This snippet has been automatically generated and should be regarded as a code template only. 334 * // It will require modifications to work: 335 * // - It may require correct/in-range values for request initialization. 336 * // - It may require specifying regional endpoints when creating the service client as shown in 337 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 338 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 339 * String name = TenantName.of("[PROJECT]", "[TENANT]").toString(); 340 * Tenant response = tenantServiceClient.getTenant(name); 341 * } 342 * }</pre> 343 * 344 * @param name Required. The resource name of the tenant to be retrieved. 345 * <p>The format is "projects/{project_id}/tenants/{tenant_id}", for example, 346 * "projects/foo/tenants/bar". 347 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 348 */ getTenant(String name)349 public final Tenant getTenant(String name) { 350 GetTenantRequest request = GetTenantRequest.newBuilder().setName(name).build(); 351 return getTenant(request); 352 } 353 354 // AUTO-GENERATED DOCUMENTATION AND METHOD. 355 /** 356 * Retrieves specified tenant. 357 * 358 * <p>Sample code: 359 * 360 * <pre>{@code 361 * // This snippet has been automatically generated and should be regarded as a code template only. 362 * // It will require modifications to work: 363 * // - It may require correct/in-range values for request initialization. 364 * // - It may require specifying regional endpoints when creating the service client as shown in 365 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 366 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 367 * GetTenantRequest request = 368 * GetTenantRequest.newBuilder() 369 * .setName(TenantName.of("[PROJECT]", "[TENANT]").toString()) 370 * .build(); 371 * Tenant response = tenantServiceClient.getTenant(request); 372 * } 373 * }</pre> 374 * 375 * @param request The request object containing all of the parameters for the API call. 376 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 377 */ getTenant(GetTenantRequest request)378 public final Tenant getTenant(GetTenantRequest request) { 379 return getTenantCallable().call(request); 380 } 381 382 // AUTO-GENERATED DOCUMENTATION AND METHOD. 383 /** 384 * Retrieves specified tenant. 385 * 386 * <p>Sample code: 387 * 388 * <pre>{@code 389 * // This snippet has been automatically generated and should be regarded as a code template only. 390 * // It will require modifications to work: 391 * // - It may require correct/in-range values for request initialization. 392 * // - It may require specifying regional endpoints when creating the service client as shown in 393 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 394 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 395 * GetTenantRequest request = 396 * GetTenantRequest.newBuilder() 397 * .setName(TenantName.of("[PROJECT]", "[TENANT]").toString()) 398 * .build(); 399 * ApiFuture<Tenant> future = tenantServiceClient.getTenantCallable().futureCall(request); 400 * // Do something. 401 * Tenant response = future.get(); 402 * } 403 * }</pre> 404 */ getTenantCallable()405 public final UnaryCallable<GetTenantRequest, Tenant> getTenantCallable() { 406 return stub.getTenantCallable(); 407 } 408 409 // AUTO-GENERATED DOCUMENTATION AND METHOD. 410 /** 411 * Updates specified tenant. 412 * 413 * <p>Sample code: 414 * 415 * <pre>{@code 416 * // This snippet has been automatically generated and should be regarded as a code template only. 417 * // It will require modifications to work: 418 * // - It may require correct/in-range values for request initialization. 419 * // - It may require specifying regional endpoints when creating the service client as shown in 420 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 421 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 422 * Tenant tenant = Tenant.newBuilder().build(); 423 * FieldMask updateMask = FieldMask.newBuilder().build(); 424 * Tenant response = tenantServiceClient.updateTenant(tenant, updateMask); 425 * } 426 * }</pre> 427 * 428 * @param tenant Required. The tenant resource to replace the current resource in the system. 429 * @param updateMask Strongly recommended for the best service experience. 430 * <p>If [update_mask][google.cloud.talent.v4.UpdateTenantRequest.update_mask] is provided, 431 * only the specified fields in [tenant][google.cloud.talent.v4.UpdateTenantRequest.tenant] 432 * are updated. Otherwise all the fields are updated. 433 * <p>A field mask to specify the tenant fields to be updated. Only top level fields of 434 * [Tenant][google.cloud.talent.v4.Tenant] are supported. 435 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 436 */ updateTenant(Tenant tenant, FieldMask updateMask)437 public final Tenant updateTenant(Tenant tenant, FieldMask updateMask) { 438 UpdateTenantRequest request = 439 UpdateTenantRequest.newBuilder().setTenant(tenant).setUpdateMask(updateMask).build(); 440 return updateTenant(request); 441 } 442 443 // AUTO-GENERATED DOCUMENTATION AND METHOD. 444 /** 445 * Updates specified tenant. 446 * 447 * <p>Sample code: 448 * 449 * <pre>{@code 450 * // This snippet has been automatically generated and should be regarded as a code template only. 451 * // It will require modifications to work: 452 * // - It may require correct/in-range values for request initialization. 453 * // - It may require specifying regional endpoints when creating the service client as shown in 454 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 455 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 456 * UpdateTenantRequest request = 457 * UpdateTenantRequest.newBuilder() 458 * .setTenant(Tenant.newBuilder().build()) 459 * .setUpdateMask(FieldMask.newBuilder().build()) 460 * .build(); 461 * Tenant response = tenantServiceClient.updateTenant(request); 462 * } 463 * }</pre> 464 * 465 * @param request The request object containing all of the parameters for the API call. 466 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 467 */ updateTenant(UpdateTenantRequest request)468 public final Tenant updateTenant(UpdateTenantRequest request) { 469 return updateTenantCallable().call(request); 470 } 471 472 // AUTO-GENERATED DOCUMENTATION AND METHOD. 473 /** 474 * Updates specified tenant. 475 * 476 * <p>Sample code: 477 * 478 * <pre>{@code 479 * // This snippet has been automatically generated and should be regarded as a code template only. 480 * // It will require modifications to work: 481 * // - It may require correct/in-range values for request initialization. 482 * // - It may require specifying regional endpoints when creating the service client as shown in 483 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 484 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 485 * UpdateTenantRequest request = 486 * UpdateTenantRequest.newBuilder() 487 * .setTenant(Tenant.newBuilder().build()) 488 * .setUpdateMask(FieldMask.newBuilder().build()) 489 * .build(); 490 * ApiFuture<Tenant> future = tenantServiceClient.updateTenantCallable().futureCall(request); 491 * // Do something. 492 * Tenant response = future.get(); 493 * } 494 * }</pre> 495 */ updateTenantCallable()496 public final UnaryCallable<UpdateTenantRequest, Tenant> updateTenantCallable() { 497 return stub.updateTenantCallable(); 498 } 499 500 // AUTO-GENERATED DOCUMENTATION AND METHOD. 501 /** 502 * Deletes specified tenant. 503 * 504 * <p>Sample code: 505 * 506 * <pre>{@code 507 * // This snippet has been automatically generated and should be regarded as a code template only. 508 * // It will require modifications to work: 509 * // - It may require correct/in-range values for request initialization. 510 * // - It may require specifying regional endpoints when creating the service client as shown in 511 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 512 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 513 * TenantName name = TenantName.of("[PROJECT]", "[TENANT]"); 514 * tenantServiceClient.deleteTenant(name); 515 * } 516 * }</pre> 517 * 518 * @param name Required. The resource name of the tenant to be deleted. 519 * <p>The format is "projects/{project_id}/tenants/{tenant_id}", for example, 520 * "projects/foo/tenants/bar". 521 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 522 */ deleteTenant(TenantName name)523 public final void deleteTenant(TenantName name) { 524 DeleteTenantRequest request = 525 DeleteTenantRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 526 deleteTenant(request); 527 } 528 529 // AUTO-GENERATED DOCUMENTATION AND METHOD. 530 /** 531 * Deletes specified tenant. 532 * 533 * <p>Sample code: 534 * 535 * <pre>{@code 536 * // This snippet has been automatically generated and should be regarded as a code template only. 537 * // It will require modifications to work: 538 * // - It may require correct/in-range values for request initialization. 539 * // - It may require specifying regional endpoints when creating the service client as shown in 540 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 541 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 542 * String name = TenantName.of("[PROJECT]", "[TENANT]").toString(); 543 * tenantServiceClient.deleteTenant(name); 544 * } 545 * }</pre> 546 * 547 * @param name Required. The resource name of the tenant to be deleted. 548 * <p>The format is "projects/{project_id}/tenants/{tenant_id}", for example, 549 * "projects/foo/tenants/bar". 550 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 551 */ deleteTenant(String name)552 public final void deleteTenant(String name) { 553 DeleteTenantRequest request = DeleteTenantRequest.newBuilder().setName(name).build(); 554 deleteTenant(request); 555 } 556 557 // AUTO-GENERATED DOCUMENTATION AND METHOD. 558 /** 559 * Deletes specified tenant. 560 * 561 * <p>Sample code: 562 * 563 * <pre>{@code 564 * // This snippet has been automatically generated and should be regarded as a code template only. 565 * // It will require modifications to work: 566 * // - It may require correct/in-range values for request initialization. 567 * // - It may require specifying regional endpoints when creating the service client as shown in 568 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 569 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 570 * DeleteTenantRequest request = 571 * DeleteTenantRequest.newBuilder() 572 * .setName(TenantName.of("[PROJECT]", "[TENANT]").toString()) 573 * .build(); 574 * tenantServiceClient.deleteTenant(request); 575 * } 576 * }</pre> 577 * 578 * @param request The request object containing all of the parameters for the API call. 579 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 580 */ deleteTenant(DeleteTenantRequest request)581 public final void deleteTenant(DeleteTenantRequest request) { 582 deleteTenantCallable().call(request); 583 } 584 585 // AUTO-GENERATED DOCUMENTATION AND METHOD. 586 /** 587 * Deletes specified tenant. 588 * 589 * <p>Sample code: 590 * 591 * <pre>{@code 592 * // This snippet has been automatically generated and should be regarded as a code template only. 593 * // It will require modifications to work: 594 * // - It may require correct/in-range values for request initialization. 595 * // - It may require specifying regional endpoints when creating the service client as shown in 596 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 597 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 598 * DeleteTenantRequest request = 599 * DeleteTenantRequest.newBuilder() 600 * .setName(TenantName.of("[PROJECT]", "[TENANT]").toString()) 601 * .build(); 602 * ApiFuture<Empty> future = tenantServiceClient.deleteTenantCallable().futureCall(request); 603 * // Do something. 604 * future.get(); 605 * } 606 * }</pre> 607 */ deleteTenantCallable()608 public final UnaryCallable<DeleteTenantRequest, Empty> deleteTenantCallable() { 609 return stub.deleteTenantCallable(); 610 } 611 612 // AUTO-GENERATED DOCUMENTATION AND METHOD. 613 /** 614 * Lists all tenants associated with the project. 615 * 616 * <p>Sample code: 617 * 618 * <pre>{@code 619 * // This snippet has been automatically generated and should be regarded as a code template only. 620 * // It will require modifications to work: 621 * // - It may require correct/in-range values for request initialization. 622 * // - It may require specifying regional endpoints when creating the service client as shown in 623 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 624 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 625 * ProjectName parent = ProjectName.of("[PROJECT]"); 626 * for (Tenant element : tenantServiceClient.listTenants(parent).iterateAll()) { 627 * // doThingsWith(element); 628 * } 629 * } 630 * }</pre> 631 * 632 * @param parent Required. Resource name of the project under which the tenant is created. 633 * <p>The format is "projects/{project_id}", for example, "projects/foo". 634 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 635 */ listTenants(ProjectName parent)636 public final ListTenantsPagedResponse listTenants(ProjectName parent) { 637 ListTenantsRequest request = 638 ListTenantsRequest.newBuilder() 639 .setParent(parent == null ? null : parent.toString()) 640 .build(); 641 return listTenants(request); 642 } 643 644 // AUTO-GENERATED DOCUMENTATION AND METHOD. 645 /** 646 * Lists all tenants associated with the project. 647 * 648 * <p>Sample code: 649 * 650 * <pre>{@code 651 * // This snippet has been automatically generated and should be regarded as a code template only. 652 * // It will require modifications to work: 653 * // - It may require correct/in-range values for request initialization. 654 * // - It may require specifying regional endpoints when creating the service client as shown in 655 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 656 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 657 * String parent = ProjectName.of("[PROJECT]").toString(); 658 * for (Tenant element : tenantServiceClient.listTenants(parent).iterateAll()) { 659 * // doThingsWith(element); 660 * } 661 * } 662 * }</pre> 663 * 664 * @param parent Required. Resource name of the project under which the tenant is created. 665 * <p>The format is "projects/{project_id}", for example, "projects/foo". 666 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 667 */ listTenants(String parent)668 public final ListTenantsPagedResponse listTenants(String parent) { 669 ListTenantsRequest request = ListTenantsRequest.newBuilder().setParent(parent).build(); 670 return listTenants(request); 671 } 672 673 // AUTO-GENERATED DOCUMENTATION AND METHOD. 674 /** 675 * Lists all tenants associated with the project. 676 * 677 * <p>Sample code: 678 * 679 * <pre>{@code 680 * // This snippet has been automatically generated and should be regarded as a code template only. 681 * // It will require modifications to work: 682 * // - It may require correct/in-range values for request initialization. 683 * // - It may require specifying regional endpoints when creating the service client as shown in 684 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 685 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 686 * ListTenantsRequest request = 687 * ListTenantsRequest.newBuilder() 688 * .setParent(ProjectName.of("[PROJECT]").toString()) 689 * .setPageToken("pageToken873572522") 690 * .setPageSize(883849137) 691 * .build(); 692 * for (Tenant element : tenantServiceClient.listTenants(request).iterateAll()) { 693 * // doThingsWith(element); 694 * } 695 * } 696 * }</pre> 697 * 698 * @param request The request object containing all of the parameters for the API call. 699 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 700 */ listTenants(ListTenantsRequest request)701 public final ListTenantsPagedResponse listTenants(ListTenantsRequest request) { 702 return listTenantsPagedCallable().call(request); 703 } 704 705 // AUTO-GENERATED DOCUMENTATION AND METHOD. 706 /** 707 * Lists all tenants associated with the project. 708 * 709 * <p>Sample code: 710 * 711 * <pre>{@code 712 * // This snippet has been automatically generated and should be regarded as a code template only. 713 * // It will require modifications to work: 714 * // - It may require correct/in-range values for request initialization. 715 * // - It may require specifying regional endpoints when creating the service client as shown in 716 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 717 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 718 * ListTenantsRequest request = 719 * ListTenantsRequest.newBuilder() 720 * .setParent(ProjectName.of("[PROJECT]").toString()) 721 * .setPageToken("pageToken873572522") 722 * .setPageSize(883849137) 723 * .build(); 724 * ApiFuture<Tenant> future = tenantServiceClient.listTenantsPagedCallable().futureCall(request); 725 * // Do something. 726 * for (Tenant element : future.get().iterateAll()) { 727 * // doThingsWith(element); 728 * } 729 * } 730 * }</pre> 731 */ 732 public final UnaryCallable<ListTenantsRequest, ListTenantsPagedResponse> listTenantsPagedCallable()733 listTenantsPagedCallable() { 734 return stub.listTenantsPagedCallable(); 735 } 736 737 // AUTO-GENERATED DOCUMENTATION AND METHOD. 738 /** 739 * Lists all tenants associated with the project. 740 * 741 * <p>Sample code: 742 * 743 * <pre>{@code 744 * // This snippet has been automatically generated and should be regarded as a code template only. 745 * // It will require modifications to work: 746 * // - It may require correct/in-range values for request initialization. 747 * // - It may require specifying regional endpoints when creating the service client as shown in 748 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 749 * try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) { 750 * ListTenantsRequest request = 751 * ListTenantsRequest.newBuilder() 752 * .setParent(ProjectName.of("[PROJECT]").toString()) 753 * .setPageToken("pageToken873572522") 754 * .setPageSize(883849137) 755 * .build(); 756 * while (true) { 757 * ListTenantsResponse response = tenantServiceClient.listTenantsCallable().call(request); 758 * for (Tenant element : response.getTenantsList()) { 759 * // doThingsWith(element); 760 * } 761 * String nextPageToken = response.getNextPageToken(); 762 * if (!Strings.isNullOrEmpty(nextPageToken)) { 763 * request = request.toBuilder().setPageToken(nextPageToken).build(); 764 * } else { 765 * break; 766 * } 767 * } 768 * } 769 * }</pre> 770 */ listTenantsCallable()771 public final UnaryCallable<ListTenantsRequest, ListTenantsResponse> listTenantsCallable() { 772 return stub.listTenantsCallable(); 773 } 774 775 @Override close()776 public final void close() { 777 stub.close(); 778 } 779 780 @Override shutdown()781 public void shutdown() { 782 stub.shutdown(); 783 } 784 785 @Override isShutdown()786 public boolean isShutdown() { 787 return stub.isShutdown(); 788 } 789 790 @Override isTerminated()791 public boolean isTerminated() { 792 return stub.isTerminated(); 793 } 794 795 @Override shutdownNow()796 public void shutdownNow() { 797 stub.shutdownNow(); 798 } 799 800 @Override awaitTermination(long duration, TimeUnit unit)801 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 802 return stub.awaitTermination(duration, unit); 803 } 804 805 public static class ListTenantsPagedResponse 806 extends AbstractPagedListResponse< 807 ListTenantsRequest, 808 ListTenantsResponse, 809 Tenant, 810 ListTenantsPage, 811 ListTenantsFixedSizeCollection> { 812 createAsync( PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, ApiFuture<ListTenantsResponse> futureResponse)813 public static ApiFuture<ListTenantsPagedResponse> createAsync( 814 PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, 815 ApiFuture<ListTenantsResponse> futureResponse) { 816 ApiFuture<ListTenantsPage> futurePage = 817 ListTenantsPage.createEmptyPage().createPageAsync(context, futureResponse); 818 return ApiFutures.transform( 819 futurePage, input -> new ListTenantsPagedResponse(input), MoreExecutors.directExecutor()); 820 } 821 ListTenantsPagedResponse(ListTenantsPage page)822 private ListTenantsPagedResponse(ListTenantsPage page) { 823 super(page, ListTenantsFixedSizeCollection.createEmptyCollection()); 824 } 825 } 826 827 public static class ListTenantsPage 828 extends AbstractPage<ListTenantsRequest, ListTenantsResponse, Tenant, ListTenantsPage> { 829 ListTenantsPage( PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, ListTenantsResponse response)830 private ListTenantsPage( 831 PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, 832 ListTenantsResponse response) { 833 super(context, response); 834 } 835 createEmptyPage()836 private static ListTenantsPage createEmptyPage() { 837 return new ListTenantsPage(null, null); 838 } 839 840 @Override createPage( PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, ListTenantsResponse response)841 protected ListTenantsPage createPage( 842 PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, 843 ListTenantsResponse response) { 844 return new ListTenantsPage(context, response); 845 } 846 847 @Override createPageAsync( PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, ApiFuture<ListTenantsResponse> futureResponse)848 public ApiFuture<ListTenantsPage> createPageAsync( 849 PageContext<ListTenantsRequest, ListTenantsResponse, Tenant> context, 850 ApiFuture<ListTenantsResponse> futureResponse) { 851 return super.createPageAsync(context, futureResponse); 852 } 853 } 854 855 public static class ListTenantsFixedSizeCollection 856 extends AbstractFixedSizeCollection< 857 ListTenantsRequest, 858 ListTenantsResponse, 859 Tenant, 860 ListTenantsPage, 861 ListTenantsFixedSizeCollection> { 862 ListTenantsFixedSizeCollection(List<ListTenantsPage> pages, int collectionSize)863 private ListTenantsFixedSizeCollection(List<ListTenantsPage> pages, int collectionSize) { 864 super(pages, collectionSize); 865 } 866 createEmptyCollection()867 private static ListTenantsFixedSizeCollection createEmptyCollection() { 868 return new ListTenantsFixedSizeCollection(null, 0); 869 } 870 871 @Override createCollection( List<ListTenantsPage> pages, int collectionSize)872 protected ListTenantsFixedSizeCollection createCollection( 873 List<ListTenantsPage> pages, int collectionSize) { 874 return new ListTenantsFixedSizeCollection(pages, collectionSize); 875 } 876 } 877 } 878