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.dataproc.v1; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.core.BetaApi; 22 import com.google.api.gax.core.BackgroundResource; 23 import com.google.api.gax.httpjson.longrunning.OperationsClient; 24 import com.google.api.gax.longrunning.OperationFuture; 25 import com.google.api.gax.paging.AbstractFixedSizeCollection; 26 import com.google.api.gax.paging.AbstractPage; 27 import com.google.api.gax.paging.AbstractPagedListResponse; 28 import com.google.api.gax.rpc.OperationCallable; 29 import com.google.api.gax.rpc.PageContext; 30 import com.google.api.gax.rpc.UnaryCallable; 31 import com.google.cloud.dataproc.v1.stub.ClusterControllerStub; 32 import com.google.cloud.dataproc.v1.stub.ClusterControllerStubSettings; 33 import com.google.common.util.concurrent.MoreExecutors; 34 import com.google.longrunning.Operation; 35 import com.google.protobuf.Empty; 36 import com.google.protobuf.FieldMask; 37 import java.io.IOException; 38 import java.util.List; 39 import java.util.concurrent.TimeUnit; 40 import javax.annotation.Generated; 41 42 // AUTO-GENERATED DOCUMENTATION AND CLASS. 43 /** 44 * Service Description: The ClusterControllerService provides methods to manage clusters of Compute 45 * Engine instances. 46 * 47 * <p>This class provides the ability to make remote calls to the backing service through method 48 * calls that map to API methods. Sample code to get started: 49 * 50 * <pre>{@code 51 * // This snippet has been automatically generated and should be regarded as a code template only. 52 * // It will require modifications to work: 53 * // - It may require correct/in-range values for request initialization. 54 * // - It may require specifying regional endpoints when creating the service client as shown in 55 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 56 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 57 * String projectId = "projectId-894832108"; 58 * String region = "region-934795532"; 59 * String clusterName = "clusterName-1141738587"; 60 * Cluster response = clusterControllerClient.getCluster(projectId, region, clusterName); 61 * } 62 * }</pre> 63 * 64 * <p>Note: close() needs to be called on the ClusterControllerClient object to clean up resources 65 * such as threads. In the example above, try-with-resources is used, which automatically calls 66 * close(). 67 * 68 * <p>The surface of this class includes several types of Java methods for each of the API's 69 * methods: 70 * 71 * <ol> 72 * <li>A "flattened" method. With this type of method, the fields of the request type have been 73 * converted into function parameters. It may be the case that not all fields are available as 74 * parameters, and not every API method will have a flattened method entry point. 75 * <li>A "request object" method. This type of method only takes one parameter, a request object, 76 * which must be constructed before the call. Not every API method will have a request object 77 * method. 78 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 79 * callable object, which can be used to initiate calls to the service. 80 * </ol> 81 * 82 * <p>See the individual methods for example code. 83 * 84 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 85 * these names, this class includes a format method for each type of name, and additionally a parse 86 * method to extract the individual identifiers contained within names that are returned. 87 * 88 * <p>This class can be customized by passing in a custom instance of ClusterControllerSettings to 89 * create(). For example: 90 * 91 * <p>To customize credentials: 92 * 93 * <pre>{@code 94 * // This snippet has been automatically generated and should be regarded as a code template only. 95 * // It will require modifications to work: 96 * // - It may require correct/in-range values for request initialization. 97 * // - It may require specifying regional endpoints when creating the service client as shown in 98 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 99 * ClusterControllerSettings clusterControllerSettings = 100 * ClusterControllerSettings.newBuilder() 101 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 102 * .build(); 103 * ClusterControllerClient clusterControllerClient = 104 * ClusterControllerClient.create(clusterControllerSettings); 105 * }</pre> 106 * 107 * <p>To customize the endpoint: 108 * 109 * <pre>{@code 110 * // This snippet has been automatically generated and should be regarded as a code template only. 111 * // It will require modifications to work: 112 * // - It may require correct/in-range values for request initialization. 113 * // - It may require specifying regional endpoints when creating the service client as shown in 114 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 115 * ClusterControllerSettings clusterControllerSettings = 116 * ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); 117 * ClusterControllerClient clusterControllerClient = 118 * ClusterControllerClient.create(clusterControllerSettings); 119 * }</pre> 120 * 121 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 122 * the wire: 123 * 124 * <pre>{@code 125 * // This snippet has been automatically generated and should be regarded as a code template only. 126 * // It will require modifications to work: 127 * // - It may require correct/in-range values for request initialization. 128 * // - It may require specifying regional endpoints when creating the service client as shown in 129 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 130 * ClusterControllerSettings clusterControllerSettings = 131 * ClusterControllerSettings.newHttpJsonBuilder().build(); 132 * ClusterControllerClient clusterControllerClient = 133 * ClusterControllerClient.create(clusterControllerSettings); 134 * }</pre> 135 * 136 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 137 */ 138 @Generated("by gapic-generator-java") 139 public class ClusterControllerClient implements BackgroundResource { 140 private final ClusterControllerSettings settings; 141 private final ClusterControllerStub stub; 142 private final OperationsClient httpJsonOperationsClient; 143 private final com.google.longrunning.OperationsClient operationsClient; 144 145 /** Constructs an instance of ClusterControllerClient with default settings. */ create()146 public static final ClusterControllerClient create() throws IOException { 147 return create(ClusterControllerSettings.newBuilder().build()); 148 } 149 150 /** 151 * Constructs an instance of ClusterControllerClient, using the given settings. The channels are 152 * created based on the settings passed in, or defaults for any settings that are not set. 153 */ create(ClusterControllerSettings settings)154 public static final ClusterControllerClient create(ClusterControllerSettings settings) 155 throws IOException { 156 return new ClusterControllerClient(settings); 157 } 158 159 /** 160 * Constructs an instance of ClusterControllerClient, using the given stub for making calls. This 161 * is for advanced usage - prefer using create(ClusterControllerSettings). 162 */ create(ClusterControllerStub stub)163 public static final ClusterControllerClient create(ClusterControllerStub stub) { 164 return new ClusterControllerClient(stub); 165 } 166 167 /** 168 * Constructs an instance of ClusterControllerClient, using the given settings. This is protected 169 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 170 * preferred. 171 */ ClusterControllerClient(ClusterControllerSettings settings)172 protected ClusterControllerClient(ClusterControllerSettings settings) throws IOException { 173 this.settings = settings; 174 this.stub = ((ClusterControllerStubSettings) settings.getStubSettings()).createStub(); 175 this.operationsClient = 176 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 177 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 178 } 179 ClusterControllerClient(ClusterControllerStub stub)180 protected ClusterControllerClient(ClusterControllerStub stub) { 181 this.settings = null; 182 this.stub = stub; 183 this.operationsClient = 184 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 185 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 186 } 187 getSettings()188 public final ClusterControllerSettings getSettings() { 189 return settings; 190 } 191 getStub()192 public ClusterControllerStub getStub() { 193 return stub; 194 } 195 196 /** 197 * Returns the OperationsClient that can be used to query the status of a long-running operation 198 * returned by another API method call. 199 */ getOperationsClient()200 public final com.google.longrunning.OperationsClient getOperationsClient() { 201 return operationsClient; 202 } 203 204 /** 205 * Returns the OperationsClient that can be used to query the status of a long-running operation 206 * returned by another API method call. 207 */ 208 @BetaApi getHttpJsonOperationsClient()209 public final OperationsClient getHttpJsonOperationsClient() { 210 return httpJsonOperationsClient; 211 } 212 213 // AUTO-GENERATED DOCUMENTATION AND METHOD. 214 /** 215 * Creates a cluster in a project. The returned 216 * [Operation.metadata][google.longrunning.Operation.metadata] will be 217 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 218 * 219 * <p>Sample code: 220 * 221 * <pre>{@code 222 * // This snippet has been automatically generated and should be regarded as a code template only. 223 * // It will require modifications to work: 224 * // - It may require correct/in-range values for request initialization. 225 * // - It may require specifying regional endpoints when creating the service client as shown in 226 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 227 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 228 * String projectId = "projectId-894832108"; 229 * String region = "region-934795532"; 230 * Cluster cluster = Cluster.newBuilder().build(); 231 * Cluster response = 232 * clusterControllerClient.createClusterAsync(projectId, region, cluster).get(); 233 * } 234 * }</pre> 235 * 236 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 237 * to. 238 * @param region Required. The Dataproc region in which to handle the request. 239 * @param cluster Required. The cluster to create. 240 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 241 */ createClusterAsync( String projectId, String region, Cluster cluster)242 public final OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsync( 243 String projectId, String region, Cluster cluster) { 244 CreateClusterRequest request = 245 CreateClusterRequest.newBuilder() 246 .setProjectId(projectId) 247 .setRegion(region) 248 .setCluster(cluster) 249 .build(); 250 return createClusterAsync(request); 251 } 252 253 // AUTO-GENERATED DOCUMENTATION AND METHOD. 254 /** 255 * Creates a cluster in a project. The returned 256 * [Operation.metadata][google.longrunning.Operation.metadata] will be 257 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 258 * 259 * <p>Sample code: 260 * 261 * <pre>{@code 262 * // This snippet has been automatically generated and should be regarded as a code template only. 263 * // It will require modifications to work: 264 * // - It may require correct/in-range values for request initialization. 265 * // - It may require specifying regional endpoints when creating the service client as shown in 266 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 267 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 268 * CreateClusterRequest request = 269 * CreateClusterRequest.newBuilder() 270 * .setProjectId("projectId-894832108") 271 * .setRegion("region-934795532") 272 * .setCluster(Cluster.newBuilder().build()) 273 * .setRequestId("requestId693933066") 274 * .setActionOnFailedPrimaryWorkers(FailureAction.forNumber(0)) 275 * .build(); 276 * Cluster response = clusterControllerClient.createClusterAsync(request).get(); 277 * } 278 * }</pre> 279 * 280 * @param request The request object containing all of the parameters for the API call. 281 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 282 */ createClusterAsync( CreateClusterRequest request)283 public final OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsync( 284 CreateClusterRequest request) { 285 return createClusterOperationCallable().futureCall(request); 286 } 287 288 // AUTO-GENERATED DOCUMENTATION AND METHOD. 289 /** 290 * Creates a cluster in a project. The returned 291 * [Operation.metadata][google.longrunning.Operation.metadata] will be 292 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 293 * 294 * <p>Sample code: 295 * 296 * <pre>{@code 297 * // This snippet has been automatically generated and should be regarded as a code template only. 298 * // It will require modifications to work: 299 * // - It may require correct/in-range values for request initialization. 300 * // - It may require specifying regional endpoints when creating the service client as shown in 301 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 302 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 303 * CreateClusterRequest request = 304 * CreateClusterRequest.newBuilder() 305 * .setProjectId("projectId-894832108") 306 * .setRegion("region-934795532") 307 * .setCluster(Cluster.newBuilder().build()) 308 * .setRequestId("requestId693933066") 309 * .setActionOnFailedPrimaryWorkers(FailureAction.forNumber(0)) 310 * .build(); 311 * OperationFuture<Cluster, ClusterOperationMetadata> future = 312 * clusterControllerClient.createClusterOperationCallable().futureCall(request); 313 * // Do something. 314 * Cluster response = future.get(); 315 * } 316 * }</pre> 317 */ 318 public final OperationCallable<CreateClusterRequest, Cluster, ClusterOperationMetadata> createClusterOperationCallable()319 createClusterOperationCallable() { 320 return stub.createClusterOperationCallable(); 321 } 322 323 // AUTO-GENERATED DOCUMENTATION AND METHOD. 324 /** 325 * Creates a cluster in a project. The returned 326 * [Operation.metadata][google.longrunning.Operation.metadata] will be 327 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 328 * 329 * <p>Sample code: 330 * 331 * <pre>{@code 332 * // This snippet has been automatically generated and should be regarded as a code template only. 333 * // It will require modifications to work: 334 * // - It may require correct/in-range values for request initialization. 335 * // - It may require specifying regional endpoints when creating the service client as shown in 336 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 337 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 338 * CreateClusterRequest request = 339 * CreateClusterRequest.newBuilder() 340 * .setProjectId("projectId-894832108") 341 * .setRegion("region-934795532") 342 * .setCluster(Cluster.newBuilder().build()) 343 * .setRequestId("requestId693933066") 344 * .setActionOnFailedPrimaryWorkers(FailureAction.forNumber(0)) 345 * .build(); 346 * ApiFuture<Operation> future = 347 * clusterControllerClient.createClusterCallable().futureCall(request); 348 * // Do something. 349 * Operation response = future.get(); 350 * } 351 * }</pre> 352 */ createClusterCallable()353 public final UnaryCallable<CreateClusterRequest, Operation> createClusterCallable() { 354 return stub.createClusterCallable(); 355 } 356 357 // AUTO-GENERATED DOCUMENTATION AND METHOD. 358 /** 359 * Updates a cluster in a project. The returned 360 * [Operation.metadata][google.longrunning.Operation.metadata] will be 361 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 362 * The cluster must be in a [`RUNNING`][google.cloud.dataproc.v1.ClusterStatus.State] state or an 363 * error is returned. 364 * 365 * <p>Sample code: 366 * 367 * <pre>{@code 368 * // This snippet has been automatically generated and should be regarded as a code template only. 369 * // It will require modifications to work: 370 * // - It may require correct/in-range values for request initialization. 371 * // - It may require specifying regional endpoints when creating the service client as shown in 372 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 373 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 374 * String projectId = "projectId-894832108"; 375 * String region = "region-934795532"; 376 * String clusterName = "clusterName-1141738587"; 377 * Cluster cluster = Cluster.newBuilder().build(); 378 * FieldMask updateMask = FieldMask.newBuilder().build(); 379 * Cluster response = 380 * clusterControllerClient 381 * .updateClusterAsync(projectId, region, clusterName, cluster, updateMask) 382 * .get(); 383 * } 384 * }</pre> 385 * 386 * @param projectId Required. The ID of the Google Cloud Platform project the cluster belongs to. 387 * @param region Required. The Dataproc region in which to handle the request. 388 * @param clusterName Required. The cluster name. 389 * @param cluster Required. The changes to the cluster. 390 * @param updateMask Required. Specifies the path, relative to `Cluster`, of the field to update. 391 * For example, to change the number of workers in a cluster to 5, the `update_mask` parameter 392 * would be specified as `config.worker_config.num_instances`, and the `PATCH` request body 393 * would specify the new value, as follows: 394 * <p>{ "config":{ "workerConfig":{ "numInstances":"5" } } } Similarly, to change the number 395 * of preemptible workers in a cluster to 5, the `update_mask` parameter would be 396 * `config.secondary_worker_config.num_instances`, and the `PATCH` request body would be set 397 * as follows: 398 * <p>{ "config":{ "secondaryWorkerConfig":{ "numInstances":"5" } } } 399 * <strong>Note:</strong> Currently, only the following fields can be updated: 400 * <p><table> <tbody> <tr> 401 * <td><strong>Mask</strong></td> 402 * <td><strong>Purpose</strong></td> </tr> <tr> 403 * <td><strong><em>labels</em></strong></td> 404 * <td>Update labels</td> </tr> <tr> 405 * <td><strong><em>config.worker_config.num_instances</em></strong></td> 406 * <td>Resize primary worker group</td> </tr> <tr> 407 * <td><strong><em>config.secondary_worker_config.num_instances</em></strong></td> 408 * <td>Resize secondary worker group</td> </tr> <tr> 409 * <td>config.autoscaling_config.policy_uri</td><td>Use, stop using, or 410 * change autoscaling policies</td> </tr> </tbody> </table> 411 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 412 */ updateClusterAsync( String projectId, String region, String clusterName, Cluster cluster, FieldMask updateMask)413 public final OperationFuture<Cluster, ClusterOperationMetadata> updateClusterAsync( 414 String projectId, String region, String clusterName, Cluster cluster, FieldMask updateMask) { 415 UpdateClusterRequest request = 416 UpdateClusterRequest.newBuilder() 417 .setProjectId(projectId) 418 .setRegion(region) 419 .setClusterName(clusterName) 420 .setCluster(cluster) 421 .setUpdateMask(updateMask) 422 .build(); 423 return updateClusterAsync(request); 424 } 425 426 // AUTO-GENERATED DOCUMENTATION AND METHOD. 427 /** 428 * Updates a cluster in a project. The returned 429 * [Operation.metadata][google.longrunning.Operation.metadata] will be 430 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 431 * The cluster must be in a [`RUNNING`][google.cloud.dataproc.v1.ClusterStatus.State] state or an 432 * error is returned. 433 * 434 * <p>Sample code: 435 * 436 * <pre>{@code 437 * // This snippet has been automatically generated and should be regarded as a code template only. 438 * // It will require modifications to work: 439 * // - It may require correct/in-range values for request initialization. 440 * // - It may require specifying regional endpoints when creating the service client as shown in 441 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 442 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 443 * UpdateClusterRequest request = 444 * UpdateClusterRequest.newBuilder() 445 * .setProjectId("projectId-894832108") 446 * .setRegion("region-934795532") 447 * .setClusterName("clusterName-1141738587") 448 * .setCluster(Cluster.newBuilder().build()) 449 * .setGracefulDecommissionTimeout(Duration.newBuilder().build()) 450 * .setUpdateMask(FieldMask.newBuilder().build()) 451 * .setRequestId("requestId693933066") 452 * .build(); 453 * Cluster response = clusterControllerClient.updateClusterAsync(request).get(); 454 * } 455 * }</pre> 456 * 457 * @param request The request object containing all of the parameters for the API call. 458 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 459 */ updateClusterAsync( UpdateClusterRequest request)460 public final OperationFuture<Cluster, ClusterOperationMetadata> updateClusterAsync( 461 UpdateClusterRequest request) { 462 return updateClusterOperationCallable().futureCall(request); 463 } 464 465 // AUTO-GENERATED DOCUMENTATION AND METHOD. 466 /** 467 * Updates a cluster in a project. The returned 468 * [Operation.metadata][google.longrunning.Operation.metadata] will be 469 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 470 * The cluster must be in a [`RUNNING`][google.cloud.dataproc.v1.ClusterStatus.State] state or an 471 * error is returned. 472 * 473 * <p>Sample code: 474 * 475 * <pre>{@code 476 * // This snippet has been automatically generated and should be regarded as a code template only. 477 * // It will require modifications to work: 478 * // - It may require correct/in-range values for request initialization. 479 * // - It may require specifying regional endpoints when creating the service client as shown in 480 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 481 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 482 * UpdateClusterRequest request = 483 * UpdateClusterRequest.newBuilder() 484 * .setProjectId("projectId-894832108") 485 * .setRegion("region-934795532") 486 * .setClusterName("clusterName-1141738587") 487 * .setCluster(Cluster.newBuilder().build()) 488 * .setGracefulDecommissionTimeout(Duration.newBuilder().build()) 489 * .setUpdateMask(FieldMask.newBuilder().build()) 490 * .setRequestId("requestId693933066") 491 * .build(); 492 * OperationFuture<Cluster, ClusterOperationMetadata> future = 493 * clusterControllerClient.updateClusterOperationCallable().futureCall(request); 494 * // Do something. 495 * Cluster response = future.get(); 496 * } 497 * }</pre> 498 */ 499 public final OperationCallable<UpdateClusterRequest, Cluster, ClusterOperationMetadata> updateClusterOperationCallable()500 updateClusterOperationCallable() { 501 return stub.updateClusterOperationCallable(); 502 } 503 504 // AUTO-GENERATED DOCUMENTATION AND METHOD. 505 /** 506 * Updates a cluster in a project. The returned 507 * [Operation.metadata][google.longrunning.Operation.metadata] will be 508 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 509 * The cluster must be in a [`RUNNING`][google.cloud.dataproc.v1.ClusterStatus.State] state or an 510 * error is returned. 511 * 512 * <p>Sample code: 513 * 514 * <pre>{@code 515 * // This snippet has been automatically generated and should be regarded as a code template only. 516 * // It will require modifications to work: 517 * // - It may require correct/in-range values for request initialization. 518 * // - It may require specifying regional endpoints when creating the service client as shown in 519 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 520 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 521 * UpdateClusterRequest request = 522 * UpdateClusterRequest.newBuilder() 523 * .setProjectId("projectId-894832108") 524 * .setRegion("region-934795532") 525 * .setClusterName("clusterName-1141738587") 526 * .setCluster(Cluster.newBuilder().build()) 527 * .setGracefulDecommissionTimeout(Duration.newBuilder().build()) 528 * .setUpdateMask(FieldMask.newBuilder().build()) 529 * .setRequestId("requestId693933066") 530 * .build(); 531 * ApiFuture<Operation> future = 532 * clusterControllerClient.updateClusterCallable().futureCall(request); 533 * // Do something. 534 * Operation response = future.get(); 535 * } 536 * }</pre> 537 */ updateClusterCallable()538 public final UnaryCallable<UpdateClusterRequest, Operation> updateClusterCallable() { 539 return stub.updateClusterCallable(); 540 } 541 542 // AUTO-GENERATED DOCUMENTATION AND METHOD. 543 /** 544 * Stops a cluster in a project. 545 * 546 * <p>Sample code: 547 * 548 * <pre>{@code 549 * // This snippet has been automatically generated and should be regarded as a code template only. 550 * // It will require modifications to work: 551 * // - It may require correct/in-range values for request initialization. 552 * // - It may require specifying regional endpoints when creating the service client as shown in 553 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 554 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 555 * StopClusterRequest request = 556 * StopClusterRequest.newBuilder() 557 * .setProjectId("projectId-894832108") 558 * .setRegion("region-934795532") 559 * .setClusterName("clusterName-1141738587") 560 * .setClusterUuid("clusterUuid-1141510955") 561 * .setRequestId("requestId693933066") 562 * .build(); 563 * Cluster response = clusterControllerClient.stopClusterAsync(request).get(); 564 * } 565 * }</pre> 566 * 567 * @param request The request object containing all of the parameters for the API call. 568 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 569 */ stopClusterAsync( StopClusterRequest request)570 public final OperationFuture<Cluster, ClusterOperationMetadata> stopClusterAsync( 571 StopClusterRequest request) { 572 return stopClusterOperationCallable().futureCall(request); 573 } 574 575 // AUTO-GENERATED DOCUMENTATION AND METHOD. 576 /** 577 * Stops a cluster in a project. 578 * 579 * <p>Sample code: 580 * 581 * <pre>{@code 582 * // This snippet has been automatically generated and should be regarded as a code template only. 583 * // It will require modifications to work: 584 * // - It may require correct/in-range values for request initialization. 585 * // - It may require specifying regional endpoints when creating the service client as shown in 586 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 587 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 588 * StopClusterRequest request = 589 * StopClusterRequest.newBuilder() 590 * .setProjectId("projectId-894832108") 591 * .setRegion("region-934795532") 592 * .setClusterName("clusterName-1141738587") 593 * .setClusterUuid("clusterUuid-1141510955") 594 * .setRequestId("requestId693933066") 595 * .build(); 596 * OperationFuture<Cluster, ClusterOperationMetadata> future = 597 * clusterControllerClient.stopClusterOperationCallable().futureCall(request); 598 * // Do something. 599 * Cluster response = future.get(); 600 * } 601 * }</pre> 602 */ 603 public final OperationCallable<StopClusterRequest, Cluster, ClusterOperationMetadata> stopClusterOperationCallable()604 stopClusterOperationCallable() { 605 return stub.stopClusterOperationCallable(); 606 } 607 608 // AUTO-GENERATED DOCUMENTATION AND METHOD. 609 /** 610 * Stops a cluster in a project. 611 * 612 * <p>Sample code: 613 * 614 * <pre>{@code 615 * // This snippet has been automatically generated and should be regarded as a code template only. 616 * // It will require modifications to work: 617 * // - It may require correct/in-range values for request initialization. 618 * // - It may require specifying regional endpoints when creating the service client as shown in 619 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 620 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 621 * StopClusterRequest request = 622 * StopClusterRequest.newBuilder() 623 * .setProjectId("projectId-894832108") 624 * .setRegion("region-934795532") 625 * .setClusterName("clusterName-1141738587") 626 * .setClusterUuid("clusterUuid-1141510955") 627 * .setRequestId("requestId693933066") 628 * .build(); 629 * ApiFuture<Operation> future = 630 * clusterControllerClient.stopClusterCallable().futureCall(request); 631 * // Do something. 632 * Operation response = future.get(); 633 * } 634 * }</pre> 635 */ stopClusterCallable()636 public final UnaryCallable<StopClusterRequest, Operation> stopClusterCallable() { 637 return stub.stopClusterCallable(); 638 } 639 640 // AUTO-GENERATED DOCUMENTATION AND METHOD. 641 /** 642 * Starts a cluster in a project. 643 * 644 * <p>Sample code: 645 * 646 * <pre>{@code 647 * // This snippet has been automatically generated and should be regarded as a code template only. 648 * // It will require modifications to work: 649 * // - It may require correct/in-range values for request initialization. 650 * // - It may require specifying regional endpoints when creating the service client as shown in 651 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 652 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 653 * StartClusterRequest request = 654 * StartClusterRequest.newBuilder() 655 * .setProjectId("projectId-894832108") 656 * .setRegion("region-934795532") 657 * .setClusterName("clusterName-1141738587") 658 * .setClusterUuid("clusterUuid-1141510955") 659 * .setRequestId("requestId693933066") 660 * .build(); 661 * Cluster response = clusterControllerClient.startClusterAsync(request).get(); 662 * } 663 * }</pre> 664 * 665 * @param request The request object containing all of the parameters for the API call. 666 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 667 */ startClusterAsync( StartClusterRequest request)668 public final OperationFuture<Cluster, ClusterOperationMetadata> startClusterAsync( 669 StartClusterRequest request) { 670 return startClusterOperationCallable().futureCall(request); 671 } 672 673 // AUTO-GENERATED DOCUMENTATION AND METHOD. 674 /** 675 * Starts a cluster in a 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 (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 686 * StartClusterRequest request = 687 * StartClusterRequest.newBuilder() 688 * .setProjectId("projectId-894832108") 689 * .setRegion("region-934795532") 690 * .setClusterName("clusterName-1141738587") 691 * .setClusterUuid("clusterUuid-1141510955") 692 * .setRequestId("requestId693933066") 693 * .build(); 694 * OperationFuture<Cluster, ClusterOperationMetadata> future = 695 * clusterControllerClient.startClusterOperationCallable().futureCall(request); 696 * // Do something. 697 * Cluster response = future.get(); 698 * } 699 * }</pre> 700 */ 701 public final OperationCallable<StartClusterRequest, Cluster, ClusterOperationMetadata> startClusterOperationCallable()702 startClusterOperationCallable() { 703 return stub.startClusterOperationCallable(); 704 } 705 706 // AUTO-GENERATED DOCUMENTATION AND METHOD. 707 /** 708 * Starts a cluster in a project. 709 * 710 * <p>Sample code: 711 * 712 * <pre>{@code 713 * // This snippet has been automatically generated and should be regarded as a code template only. 714 * // It will require modifications to work: 715 * // - It may require correct/in-range values for request initialization. 716 * // - It may require specifying regional endpoints when creating the service client as shown in 717 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 718 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 719 * StartClusterRequest request = 720 * StartClusterRequest.newBuilder() 721 * .setProjectId("projectId-894832108") 722 * .setRegion("region-934795532") 723 * .setClusterName("clusterName-1141738587") 724 * .setClusterUuid("clusterUuid-1141510955") 725 * .setRequestId("requestId693933066") 726 * .build(); 727 * ApiFuture<Operation> future = 728 * clusterControllerClient.startClusterCallable().futureCall(request); 729 * // Do something. 730 * Operation response = future.get(); 731 * } 732 * }</pre> 733 */ startClusterCallable()734 public final UnaryCallable<StartClusterRequest, Operation> startClusterCallable() { 735 return stub.startClusterCallable(); 736 } 737 738 // AUTO-GENERATED DOCUMENTATION AND METHOD. 739 /** 740 * Deletes a cluster in a project. The returned 741 * [Operation.metadata][google.longrunning.Operation.metadata] will be 742 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 743 * 744 * <p>Sample code: 745 * 746 * <pre>{@code 747 * // This snippet has been automatically generated and should be regarded as a code template only. 748 * // It will require modifications to work: 749 * // - It may require correct/in-range values for request initialization. 750 * // - It may require specifying regional endpoints when creating the service client as shown in 751 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 752 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 753 * String projectId = "projectId-894832108"; 754 * String region = "region-934795532"; 755 * String clusterName = "clusterName-1141738587"; 756 * clusterControllerClient.deleteClusterAsync(projectId, region, clusterName).get(); 757 * } 758 * }</pre> 759 * 760 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 761 * to. 762 * @param region Required. The Dataproc region in which to handle the request. 763 * @param clusterName Required. The cluster name. 764 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 765 */ deleteClusterAsync( String projectId, String region, String clusterName)766 public final OperationFuture<Empty, ClusterOperationMetadata> deleteClusterAsync( 767 String projectId, String region, String clusterName) { 768 DeleteClusterRequest request = 769 DeleteClusterRequest.newBuilder() 770 .setProjectId(projectId) 771 .setRegion(region) 772 .setClusterName(clusterName) 773 .build(); 774 return deleteClusterAsync(request); 775 } 776 777 // AUTO-GENERATED DOCUMENTATION AND METHOD. 778 /** 779 * Deletes a cluster in a project. The returned 780 * [Operation.metadata][google.longrunning.Operation.metadata] will be 781 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 782 * 783 * <p>Sample code: 784 * 785 * <pre>{@code 786 * // This snippet has been automatically generated and should be regarded as a code template only. 787 * // It will require modifications to work: 788 * // - It may require correct/in-range values for request initialization. 789 * // - It may require specifying regional endpoints when creating the service client as shown in 790 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 791 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 792 * DeleteClusterRequest request = 793 * DeleteClusterRequest.newBuilder() 794 * .setProjectId("projectId-894832108") 795 * .setRegion("region-934795532") 796 * .setClusterName("clusterName-1141738587") 797 * .setClusterUuid("clusterUuid-1141510955") 798 * .setRequestId("requestId693933066") 799 * .build(); 800 * clusterControllerClient.deleteClusterAsync(request).get(); 801 * } 802 * }</pre> 803 * 804 * @param request The request object containing all of the parameters for the API call. 805 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 806 */ deleteClusterAsync( DeleteClusterRequest request)807 public final OperationFuture<Empty, ClusterOperationMetadata> deleteClusterAsync( 808 DeleteClusterRequest request) { 809 return deleteClusterOperationCallable().futureCall(request); 810 } 811 812 // AUTO-GENERATED DOCUMENTATION AND METHOD. 813 /** 814 * Deletes a cluster in a project. The returned 815 * [Operation.metadata][google.longrunning.Operation.metadata] will be 816 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 817 * 818 * <p>Sample code: 819 * 820 * <pre>{@code 821 * // This snippet has been automatically generated and should be regarded as a code template only. 822 * // It will require modifications to work: 823 * // - It may require correct/in-range values for request initialization. 824 * // - It may require specifying regional endpoints when creating the service client as shown in 825 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 826 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 827 * DeleteClusterRequest request = 828 * DeleteClusterRequest.newBuilder() 829 * .setProjectId("projectId-894832108") 830 * .setRegion("region-934795532") 831 * .setClusterName("clusterName-1141738587") 832 * .setClusterUuid("clusterUuid-1141510955") 833 * .setRequestId("requestId693933066") 834 * .build(); 835 * OperationFuture<Empty, ClusterOperationMetadata> future = 836 * clusterControllerClient.deleteClusterOperationCallable().futureCall(request); 837 * // Do something. 838 * future.get(); 839 * } 840 * }</pre> 841 */ 842 public final OperationCallable<DeleteClusterRequest, Empty, ClusterOperationMetadata> deleteClusterOperationCallable()843 deleteClusterOperationCallable() { 844 return stub.deleteClusterOperationCallable(); 845 } 846 847 // AUTO-GENERATED DOCUMENTATION AND METHOD. 848 /** 849 * Deletes a cluster in a project. The returned 850 * [Operation.metadata][google.longrunning.Operation.metadata] will be 851 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 852 * 853 * <p>Sample code: 854 * 855 * <pre>{@code 856 * // This snippet has been automatically generated and should be regarded as a code template only. 857 * // It will require modifications to work: 858 * // - It may require correct/in-range values for request initialization. 859 * // - It may require specifying regional endpoints when creating the service client as shown in 860 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 861 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 862 * DeleteClusterRequest request = 863 * DeleteClusterRequest.newBuilder() 864 * .setProjectId("projectId-894832108") 865 * .setRegion("region-934795532") 866 * .setClusterName("clusterName-1141738587") 867 * .setClusterUuid("clusterUuid-1141510955") 868 * .setRequestId("requestId693933066") 869 * .build(); 870 * ApiFuture<Operation> future = 871 * clusterControllerClient.deleteClusterCallable().futureCall(request); 872 * // Do something. 873 * future.get(); 874 * } 875 * }</pre> 876 */ deleteClusterCallable()877 public final UnaryCallable<DeleteClusterRequest, Operation> deleteClusterCallable() { 878 return stub.deleteClusterCallable(); 879 } 880 881 // AUTO-GENERATED DOCUMENTATION AND METHOD. 882 /** 883 * Gets the resource representation for a cluster in a project. 884 * 885 * <p>Sample code: 886 * 887 * <pre>{@code 888 * // This snippet has been automatically generated and should be regarded as a code template only. 889 * // It will require modifications to work: 890 * // - It may require correct/in-range values for request initialization. 891 * // - It may require specifying regional endpoints when creating the service client as shown in 892 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 893 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 894 * String projectId = "projectId-894832108"; 895 * String region = "region-934795532"; 896 * String clusterName = "clusterName-1141738587"; 897 * Cluster response = clusterControllerClient.getCluster(projectId, region, clusterName); 898 * } 899 * }</pre> 900 * 901 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 902 * to. 903 * @param region Required. The Dataproc region in which to handle the request. 904 * @param clusterName Required. The cluster name. 905 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 906 */ getCluster(String projectId, String region, String clusterName)907 public final Cluster getCluster(String projectId, String region, String clusterName) { 908 GetClusterRequest request = 909 GetClusterRequest.newBuilder() 910 .setProjectId(projectId) 911 .setRegion(region) 912 .setClusterName(clusterName) 913 .build(); 914 return getCluster(request); 915 } 916 917 // AUTO-GENERATED DOCUMENTATION AND METHOD. 918 /** 919 * Gets the resource representation for a cluster in a project. 920 * 921 * <p>Sample code: 922 * 923 * <pre>{@code 924 * // This snippet has been automatically generated and should be regarded as a code template only. 925 * // It will require modifications to work: 926 * // - It may require correct/in-range values for request initialization. 927 * // - It may require specifying regional endpoints when creating the service client as shown in 928 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 929 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 930 * GetClusterRequest request = 931 * GetClusterRequest.newBuilder() 932 * .setProjectId("projectId-894832108") 933 * .setRegion("region-934795532") 934 * .setClusterName("clusterName-1141738587") 935 * .build(); 936 * Cluster response = clusterControllerClient.getCluster(request); 937 * } 938 * }</pre> 939 * 940 * @param request The request object containing all of the parameters for the API call. 941 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 942 */ getCluster(GetClusterRequest request)943 public final Cluster getCluster(GetClusterRequest request) { 944 return getClusterCallable().call(request); 945 } 946 947 // AUTO-GENERATED DOCUMENTATION AND METHOD. 948 /** 949 * Gets the resource representation for a cluster in a project. 950 * 951 * <p>Sample code: 952 * 953 * <pre>{@code 954 * // This snippet has been automatically generated and should be regarded as a code template only. 955 * // It will require modifications to work: 956 * // - It may require correct/in-range values for request initialization. 957 * // - It may require specifying regional endpoints when creating the service client as shown in 958 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 959 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 960 * GetClusterRequest request = 961 * GetClusterRequest.newBuilder() 962 * .setProjectId("projectId-894832108") 963 * .setRegion("region-934795532") 964 * .setClusterName("clusterName-1141738587") 965 * .build(); 966 * ApiFuture<Cluster> future = clusterControllerClient.getClusterCallable().futureCall(request); 967 * // Do something. 968 * Cluster response = future.get(); 969 * } 970 * }</pre> 971 */ getClusterCallable()972 public final UnaryCallable<GetClusterRequest, Cluster> getClusterCallable() { 973 return stub.getClusterCallable(); 974 } 975 976 // AUTO-GENERATED DOCUMENTATION AND METHOD. 977 /** 978 * Lists all regions/{region}/clusters in a project alphabetically. 979 * 980 * <p>Sample code: 981 * 982 * <pre>{@code 983 * // This snippet has been automatically generated and should be regarded as a code template only. 984 * // It will require modifications to work: 985 * // - It may require correct/in-range values for request initialization. 986 * // - It may require specifying regional endpoints when creating the service client as shown in 987 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 988 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 989 * String projectId = "projectId-894832108"; 990 * String region = "region-934795532"; 991 * for (Cluster element : clusterControllerClient.listClusters(projectId, region).iterateAll()) { 992 * // doThingsWith(element); 993 * } 994 * } 995 * }</pre> 996 * 997 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 998 * to. 999 * @param region Required. The Dataproc region in which to handle the request. 1000 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1001 */ listClusters(String projectId, String region)1002 public final ListClustersPagedResponse listClusters(String projectId, String region) { 1003 ListClustersRequest request = 1004 ListClustersRequest.newBuilder().setProjectId(projectId).setRegion(region).build(); 1005 return listClusters(request); 1006 } 1007 1008 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1009 /** 1010 * Lists all regions/{region}/clusters in a project alphabetically. 1011 * 1012 * <p>Sample code: 1013 * 1014 * <pre>{@code 1015 * // This snippet has been automatically generated and should be regarded as a code template only. 1016 * // It will require modifications to work: 1017 * // - It may require correct/in-range values for request initialization. 1018 * // - It may require specifying regional endpoints when creating the service client as shown in 1019 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1020 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1021 * String projectId = "projectId-894832108"; 1022 * String region = "region-934795532"; 1023 * String filter = "filter-1274492040"; 1024 * for (Cluster element : 1025 * clusterControllerClient.listClusters(projectId, region, filter).iterateAll()) { 1026 * // doThingsWith(element); 1027 * } 1028 * } 1029 * }</pre> 1030 * 1031 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 1032 * to. 1033 * @param region Required. The Dataproc region in which to handle the request. 1034 * @param filter Optional. A filter constraining the clusters to list. Filters are case-sensitive 1035 * and have the following syntax: 1036 * <p>field = value [AND [field = value]] ... 1037 * <p>where **field** is one of `status.state`, `clusterName`, or 1038 * `labels.[KEY]`, and `[KEY]` is a label key. **value** can be `*` to 1039 * match all values. `status.state` can be one of the following: `ACTIVE`, `INACTIVE`, 1040 * `CREATING`, `RUNNING`, `ERROR`, `DELETING`, or `UPDATING`. `ACTIVE` contains the 1041 * `CREATING`, `UPDATING`, and `RUNNING` states. `INACTIVE` contains the `DELETING` and 1042 * `ERROR` states. `clusterName` is the name of the cluster provided at creation time. Only 1043 * the logical `AND` operator is supported; space-separated items are treated as having an 1044 * implicit `AND` operator. 1045 * <p>Example filter: 1046 * <p>status.state = ACTIVE AND clusterName = mycluster AND labels.env = staging AND 1047 * labels.starred = * 1048 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1049 */ listClusters( String projectId, String region, String filter)1050 public final ListClustersPagedResponse listClusters( 1051 String projectId, String region, String filter) { 1052 ListClustersRequest request = 1053 ListClustersRequest.newBuilder() 1054 .setProjectId(projectId) 1055 .setRegion(region) 1056 .setFilter(filter) 1057 .build(); 1058 return listClusters(request); 1059 } 1060 1061 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1062 /** 1063 * Lists all regions/{region}/clusters in a project alphabetically. 1064 * 1065 * <p>Sample code: 1066 * 1067 * <pre>{@code 1068 * // This snippet has been automatically generated and should be regarded as a code template only. 1069 * // It will require modifications to work: 1070 * // - It may require correct/in-range values for request initialization. 1071 * // - It may require specifying regional endpoints when creating the service client as shown in 1072 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1073 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1074 * ListClustersRequest request = 1075 * ListClustersRequest.newBuilder() 1076 * .setProjectId("projectId-894832108") 1077 * .setRegion("region-934795532") 1078 * .setFilter("filter-1274492040") 1079 * .setPageSize(883849137) 1080 * .setPageToken("pageToken873572522") 1081 * .build(); 1082 * for (Cluster element : clusterControllerClient.listClusters(request).iterateAll()) { 1083 * // doThingsWith(element); 1084 * } 1085 * } 1086 * }</pre> 1087 * 1088 * @param request The request object containing all of the parameters for the API call. 1089 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1090 */ listClusters(ListClustersRequest request)1091 public final ListClustersPagedResponse listClusters(ListClustersRequest request) { 1092 return listClustersPagedCallable().call(request); 1093 } 1094 1095 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1096 /** 1097 * Lists all regions/{region}/clusters in a project alphabetically. 1098 * 1099 * <p>Sample code: 1100 * 1101 * <pre>{@code 1102 * // This snippet has been automatically generated and should be regarded as a code template only. 1103 * // It will require modifications to work: 1104 * // - It may require correct/in-range values for request initialization. 1105 * // - It may require specifying regional endpoints when creating the service client as shown in 1106 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1107 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1108 * ListClustersRequest request = 1109 * ListClustersRequest.newBuilder() 1110 * .setProjectId("projectId-894832108") 1111 * .setRegion("region-934795532") 1112 * .setFilter("filter-1274492040") 1113 * .setPageSize(883849137) 1114 * .setPageToken("pageToken873572522") 1115 * .build(); 1116 * ApiFuture<Cluster> future = 1117 * clusterControllerClient.listClustersPagedCallable().futureCall(request); 1118 * // Do something. 1119 * for (Cluster element : future.get().iterateAll()) { 1120 * // doThingsWith(element); 1121 * } 1122 * } 1123 * }</pre> 1124 */ 1125 public final UnaryCallable<ListClustersRequest, ListClustersPagedResponse> listClustersPagedCallable()1126 listClustersPagedCallable() { 1127 return stub.listClustersPagedCallable(); 1128 } 1129 1130 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1131 /** 1132 * Lists all regions/{region}/clusters in a project alphabetically. 1133 * 1134 * <p>Sample code: 1135 * 1136 * <pre>{@code 1137 * // This snippet has been automatically generated and should be regarded as a code template only. 1138 * // It will require modifications to work: 1139 * // - It may require correct/in-range values for request initialization. 1140 * // - It may require specifying regional endpoints when creating the service client as shown in 1141 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1142 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1143 * ListClustersRequest request = 1144 * ListClustersRequest.newBuilder() 1145 * .setProjectId("projectId-894832108") 1146 * .setRegion("region-934795532") 1147 * .setFilter("filter-1274492040") 1148 * .setPageSize(883849137) 1149 * .setPageToken("pageToken873572522") 1150 * .build(); 1151 * while (true) { 1152 * ListClustersResponse response = 1153 * clusterControllerClient.listClustersCallable().call(request); 1154 * for (Cluster element : response.getClustersList()) { 1155 * // doThingsWith(element); 1156 * } 1157 * String nextPageToken = response.getNextPageToken(); 1158 * if (!Strings.isNullOrEmpty(nextPageToken)) { 1159 * request = request.toBuilder().setPageToken(nextPageToken).build(); 1160 * } else { 1161 * break; 1162 * } 1163 * } 1164 * } 1165 * }</pre> 1166 */ listClustersCallable()1167 public final UnaryCallable<ListClustersRequest, ListClustersResponse> listClustersCallable() { 1168 return stub.listClustersCallable(); 1169 } 1170 1171 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1172 /** 1173 * Gets cluster diagnostic information. The returned 1174 * [Operation.metadata][google.longrunning.Operation.metadata] will be 1175 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 1176 * After the operation completes, [Operation.response][google.longrunning.Operation.response] 1177 * contains 1178 * [DiagnoseClusterResults](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#diagnoseclusterresults). 1179 * 1180 * <p>Sample code: 1181 * 1182 * <pre>{@code 1183 * // This snippet has been automatically generated and should be regarded as a code template only. 1184 * // It will require modifications to work: 1185 * // - It may require correct/in-range values for request initialization. 1186 * // - It may require specifying regional endpoints when creating the service client as shown in 1187 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1188 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1189 * String projectId = "projectId-894832108"; 1190 * String region = "region-934795532"; 1191 * String clusterName = "clusterName-1141738587"; 1192 * DiagnoseClusterResults response = 1193 * clusterControllerClient.diagnoseClusterAsync(projectId, region, clusterName).get(); 1194 * } 1195 * }</pre> 1196 * 1197 * @param projectId Required. The ID of the Google Cloud Platform project that the cluster belongs 1198 * to. 1199 * @param region Required. The Dataproc region in which to handle the request. 1200 * @param clusterName Required. The cluster name. 1201 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1202 */ 1203 public final OperationFuture<DiagnoseClusterResults, ClusterOperationMetadata> diagnoseClusterAsync(String projectId, String region, String clusterName)1204 diagnoseClusterAsync(String projectId, String region, String clusterName) { 1205 DiagnoseClusterRequest request = 1206 DiagnoseClusterRequest.newBuilder() 1207 .setProjectId(projectId) 1208 .setRegion(region) 1209 .setClusterName(clusterName) 1210 .build(); 1211 return diagnoseClusterAsync(request); 1212 } 1213 1214 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1215 /** 1216 * Gets cluster diagnostic information. The returned 1217 * [Operation.metadata][google.longrunning.Operation.metadata] will be 1218 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 1219 * After the operation completes, [Operation.response][google.longrunning.Operation.response] 1220 * contains 1221 * [DiagnoseClusterResults](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#diagnoseclusterresults). 1222 * 1223 * <p>Sample code: 1224 * 1225 * <pre>{@code 1226 * // This snippet has been automatically generated and should be regarded as a code template only. 1227 * // It will require modifications to work: 1228 * // - It may require correct/in-range values for request initialization. 1229 * // - It may require specifying regional endpoints when creating the service client as shown in 1230 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1231 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1232 * DiagnoseClusterRequest request = 1233 * DiagnoseClusterRequest.newBuilder() 1234 * .setProjectId("projectId-894832108") 1235 * .setRegion("region-934795532") 1236 * .setClusterName("clusterName-1141738587") 1237 * .build(); 1238 * DiagnoseClusterResults response = clusterControllerClient.diagnoseClusterAsync(request).get(); 1239 * } 1240 * }</pre> 1241 * 1242 * @param request The request object containing all of the parameters for the API call. 1243 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1244 */ 1245 public final OperationFuture<DiagnoseClusterResults, ClusterOperationMetadata> diagnoseClusterAsync(DiagnoseClusterRequest request)1246 diagnoseClusterAsync(DiagnoseClusterRequest request) { 1247 return diagnoseClusterOperationCallable().futureCall(request); 1248 } 1249 1250 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1251 /** 1252 * Gets cluster diagnostic information. The returned 1253 * [Operation.metadata][google.longrunning.Operation.metadata] will be 1254 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 1255 * After the operation completes, [Operation.response][google.longrunning.Operation.response] 1256 * contains 1257 * [DiagnoseClusterResults](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#diagnoseclusterresults). 1258 * 1259 * <p>Sample code: 1260 * 1261 * <pre>{@code 1262 * // This snippet has been automatically generated and should be regarded as a code template only. 1263 * // It will require modifications to work: 1264 * // - It may require correct/in-range values for request initialization. 1265 * // - It may require specifying regional endpoints when creating the service client as shown in 1266 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1267 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1268 * DiagnoseClusterRequest request = 1269 * DiagnoseClusterRequest.newBuilder() 1270 * .setProjectId("projectId-894832108") 1271 * .setRegion("region-934795532") 1272 * .setClusterName("clusterName-1141738587") 1273 * .build(); 1274 * OperationFuture<DiagnoseClusterResults, ClusterOperationMetadata> future = 1275 * clusterControllerClient.diagnoseClusterOperationCallable().futureCall(request); 1276 * // Do something. 1277 * DiagnoseClusterResults response = future.get(); 1278 * } 1279 * }</pre> 1280 */ 1281 public final OperationCallable< 1282 DiagnoseClusterRequest, DiagnoseClusterResults, ClusterOperationMetadata> diagnoseClusterOperationCallable()1283 diagnoseClusterOperationCallable() { 1284 return stub.diagnoseClusterOperationCallable(); 1285 } 1286 1287 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1288 /** 1289 * Gets cluster diagnostic information. The returned 1290 * [Operation.metadata][google.longrunning.Operation.metadata] will be 1291 * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). 1292 * After the operation completes, [Operation.response][google.longrunning.Operation.response] 1293 * contains 1294 * [DiagnoseClusterResults](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#diagnoseclusterresults). 1295 * 1296 * <p>Sample code: 1297 * 1298 * <pre>{@code 1299 * // This snippet has been automatically generated and should be regarded as a code template only. 1300 * // It will require modifications to work: 1301 * // - It may require correct/in-range values for request initialization. 1302 * // - It may require specifying regional endpoints when creating the service client as shown in 1303 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1304 * try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create()) { 1305 * DiagnoseClusterRequest request = 1306 * DiagnoseClusterRequest.newBuilder() 1307 * .setProjectId("projectId-894832108") 1308 * .setRegion("region-934795532") 1309 * .setClusterName("clusterName-1141738587") 1310 * .build(); 1311 * ApiFuture<Operation> future = 1312 * clusterControllerClient.diagnoseClusterCallable().futureCall(request); 1313 * // Do something. 1314 * Operation response = future.get(); 1315 * } 1316 * }</pre> 1317 */ diagnoseClusterCallable()1318 public final UnaryCallable<DiagnoseClusterRequest, Operation> diagnoseClusterCallable() { 1319 return stub.diagnoseClusterCallable(); 1320 } 1321 1322 @Override close()1323 public final void close() { 1324 stub.close(); 1325 } 1326 1327 @Override shutdown()1328 public void shutdown() { 1329 stub.shutdown(); 1330 } 1331 1332 @Override isShutdown()1333 public boolean isShutdown() { 1334 return stub.isShutdown(); 1335 } 1336 1337 @Override isTerminated()1338 public boolean isTerminated() { 1339 return stub.isTerminated(); 1340 } 1341 1342 @Override shutdownNow()1343 public void shutdownNow() { 1344 stub.shutdownNow(); 1345 } 1346 1347 @Override awaitTermination(long duration, TimeUnit unit)1348 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 1349 return stub.awaitTermination(duration, unit); 1350 } 1351 1352 public static class ListClustersPagedResponse 1353 extends AbstractPagedListResponse< 1354 ListClustersRequest, 1355 ListClustersResponse, 1356 Cluster, 1357 ListClustersPage, 1358 ListClustersFixedSizeCollection> { 1359 createAsync( PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, ApiFuture<ListClustersResponse> futureResponse)1360 public static ApiFuture<ListClustersPagedResponse> createAsync( 1361 PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, 1362 ApiFuture<ListClustersResponse> futureResponse) { 1363 ApiFuture<ListClustersPage> futurePage = 1364 ListClustersPage.createEmptyPage().createPageAsync(context, futureResponse); 1365 return ApiFutures.transform( 1366 futurePage, 1367 input -> new ListClustersPagedResponse(input), 1368 MoreExecutors.directExecutor()); 1369 } 1370 ListClustersPagedResponse(ListClustersPage page)1371 private ListClustersPagedResponse(ListClustersPage page) { 1372 super(page, ListClustersFixedSizeCollection.createEmptyCollection()); 1373 } 1374 } 1375 1376 public static class ListClustersPage 1377 extends AbstractPage<ListClustersRequest, ListClustersResponse, Cluster, ListClustersPage> { 1378 ListClustersPage( PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, ListClustersResponse response)1379 private ListClustersPage( 1380 PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, 1381 ListClustersResponse response) { 1382 super(context, response); 1383 } 1384 createEmptyPage()1385 private static ListClustersPage createEmptyPage() { 1386 return new ListClustersPage(null, null); 1387 } 1388 1389 @Override createPage( PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, ListClustersResponse response)1390 protected ListClustersPage createPage( 1391 PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, 1392 ListClustersResponse response) { 1393 return new ListClustersPage(context, response); 1394 } 1395 1396 @Override createPageAsync( PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, ApiFuture<ListClustersResponse> futureResponse)1397 public ApiFuture<ListClustersPage> createPageAsync( 1398 PageContext<ListClustersRequest, ListClustersResponse, Cluster> context, 1399 ApiFuture<ListClustersResponse> futureResponse) { 1400 return super.createPageAsync(context, futureResponse); 1401 } 1402 } 1403 1404 public static class ListClustersFixedSizeCollection 1405 extends AbstractFixedSizeCollection< 1406 ListClustersRequest, 1407 ListClustersResponse, 1408 Cluster, 1409 ListClustersPage, 1410 ListClustersFixedSizeCollection> { 1411 ListClustersFixedSizeCollection(List<ListClustersPage> pages, int collectionSize)1412 private ListClustersFixedSizeCollection(List<ListClustersPage> pages, int collectionSize) { 1413 super(pages, collectionSize); 1414 } 1415 createEmptyCollection()1416 private static ListClustersFixedSizeCollection createEmptyCollection() { 1417 return new ListClustersFixedSizeCollection(null, 0); 1418 } 1419 1420 @Override createCollection( List<ListClustersPage> pages, int collectionSize)1421 protected ListClustersFixedSizeCollection createCollection( 1422 List<ListClustersPage> pages, int collectionSize) { 1423 return new ListClustersFixedSizeCollection(pages, collectionSize); 1424 } 1425 } 1426 } 1427