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.JobControllerStub; 32 import com.google.cloud.dataproc.v1.stub.JobControllerStubSettings; 33 import com.google.common.util.concurrent.MoreExecutors; 34 import com.google.longrunning.Operation; 35 import com.google.protobuf.Empty; 36 import java.io.IOException; 37 import java.util.List; 38 import java.util.concurrent.TimeUnit; 39 import javax.annotation.Generated; 40 41 // AUTO-GENERATED DOCUMENTATION AND CLASS. 42 /** 43 * Service Description: The JobController provides methods to manage jobs. 44 * 45 * <p>This class provides the ability to make remote calls to the backing service through method 46 * calls that map to API methods. Sample code to get started: 47 * 48 * <pre>{@code 49 * // This snippet has been automatically generated and should be regarded as a code template only. 50 * // It will require modifications to work: 51 * // - It may require correct/in-range values for request initialization. 52 * // - It may require specifying regional endpoints when creating the service client as shown in 53 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 54 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 55 * String projectId = "projectId-894832108"; 56 * String region = "region-934795532"; 57 * Job job = Job.newBuilder().build(); 58 * Job response = jobControllerClient.submitJob(projectId, region, job); 59 * } 60 * }</pre> 61 * 62 * <p>Note: close() needs to be called on the JobControllerClient object to clean up resources such 63 * as threads. In the example above, try-with-resources is used, which automatically calls close(). 64 * 65 * <p>The surface of this class includes several types of Java methods for each of the API's 66 * methods: 67 * 68 * <ol> 69 * <li>A "flattened" method. With this type of method, the fields of the request type have been 70 * converted into function parameters. It may be the case that not all fields are available as 71 * parameters, and not every API method will have a flattened method entry point. 72 * <li>A "request object" method. This type of method only takes one parameter, a request object, 73 * which must be constructed before the call. Not every API method will have a request object 74 * method. 75 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 76 * callable object, which can be used to initiate calls to the service. 77 * </ol> 78 * 79 * <p>See the individual methods for example code. 80 * 81 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 82 * these names, this class includes a format method for each type of name, and additionally a parse 83 * method to extract the individual identifiers contained within names that are returned. 84 * 85 * <p>This class can be customized by passing in a custom instance of JobControllerSettings to 86 * create(). For example: 87 * 88 * <p>To customize credentials: 89 * 90 * <pre>{@code 91 * // This snippet has been automatically generated and should be regarded as a code template only. 92 * // It will require modifications to work: 93 * // - It may require correct/in-range values for request initialization. 94 * // - It may require specifying regional endpoints when creating the service client as shown in 95 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 96 * JobControllerSettings jobControllerSettings = 97 * JobControllerSettings.newBuilder() 98 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 99 * .build(); 100 * JobControllerClient jobControllerClient = JobControllerClient.create(jobControllerSettings); 101 * }</pre> 102 * 103 * <p>To customize the endpoint: 104 * 105 * <pre>{@code 106 * // This snippet has been automatically generated and should be regarded as a code template only. 107 * // It will require modifications to work: 108 * // - It may require correct/in-range values for request initialization. 109 * // - It may require specifying regional endpoints when creating the service client as shown in 110 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 111 * JobControllerSettings jobControllerSettings = 112 * JobControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); 113 * JobControllerClient jobControllerClient = JobControllerClient.create(jobControllerSettings); 114 * }</pre> 115 * 116 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 117 * the wire: 118 * 119 * <pre>{@code 120 * // This snippet has been automatically generated and should be regarded as a code template only. 121 * // It will require modifications to work: 122 * // - It may require correct/in-range values for request initialization. 123 * // - It may require specifying regional endpoints when creating the service client as shown in 124 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 125 * JobControllerSettings jobControllerSettings = 126 * JobControllerSettings.newHttpJsonBuilder().build(); 127 * JobControllerClient jobControllerClient = JobControllerClient.create(jobControllerSettings); 128 * }</pre> 129 * 130 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 131 */ 132 @Generated("by gapic-generator-java") 133 public class JobControllerClient implements BackgroundResource { 134 private final JobControllerSettings settings; 135 private final JobControllerStub stub; 136 private final OperationsClient httpJsonOperationsClient; 137 private final com.google.longrunning.OperationsClient operationsClient; 138 139 /** Constructs an instance of JobControllerClient with default settings. */ create()140 public static final JobControllerClient create() throws IOException { 141 return create(JobControllerSettings.newBuilder().build()); 142 } 143 144 /** 145 * Constructs an instance of JobControllerClient, using the given settings. The channels are 146 * created based on the settings passed in, or defaults for any settings that are not set. 147 */ create(JobControllerSettings settings)148 public static final JobControllerClient create(JobControllerSettings settings) 149 throws IOException { 150 return new JobControllerClient(settings); 151 } 152 153 /** 154 * Constructs an instance of JobControllerClient, using the given stub for making calls. This is 155 * for advanced usage - prefer using create(JobControllerSettings). 156 */ create(JobControllerStub stub)157 public static final JobControllerClient create(JobControllerStub stub) { 158 return new JobControllerClient(stub); 159 } 160 161 /** 162 * Constructs an instance of JobControllerClient, using the given settings. This is protected so 163 * that it is easy to make a subclass, but otherwise, the static factory methods should be 164 * preferred. 165 */ JobControllerClient(JobControllerSettings settings)166 protected JobControllerClient(JobControllerSettings settings) throws IOException { 167 this.settings = settings; 168 this.stub = ((JobControllerStubSettings) settings.getStubSettings()).createStub(); 169 this.operationsClient = 170 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 171 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 172 } 173 JobControllerClient(JobControllerStub stub)174 protected JobControllerClient(JobControllerStub stub) { 175 this.settings = null; 176 this.stub = stub; 177 this.operationsClient = 178 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 179 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 180 } 181 getSettings()182 public final JobControllerSettings getSettings() { 183 return settings; 184 } 185 getStub()186 public JobControllerStub getStub() { 187 return stub; 188 } 189 190 /** 191 * Returns the OperationsClient that can be used to query the status of a long-running operation 192 * returned by another API method call. 193 */ getOperationsClient()194 public final com.google.longrunning.OperationsClient getOperationsClient() { 195 return operationsClient; 196 } 197 198 /** 199 * Returns the OperationsClient that can be used to query the status of a long-running operation 200 * returned by another API method call. 201 */ 202 @BetaApi getHttpJsonOperationsClient()203 public final OperationsClient getHttpJsonOperationsClient() { 204 return httpJsonOperationsClient; 205 } 206 207 // AUTO-GENERATED DOCUMENTATION AND METHOD. 208 /** 209 * Submits a job to a cluster. 210 * 211 * <p>Sample code: 212 * 213 * <pre>{@code 214 * // This snippet has been automatically generated and should be regarded as a code template only. 215 * // It will require modifications to work: 216 * // - It may require correct/in-range values for request initialization. 217 * // - It may require specifying regional endpoints when creating the service client as shown in 218 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 219 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 220 * String projectId = "projectId-894832108"; 221 * String region = "region-934795532"; 222 * Job job = Job.newBuilder().build(); 223 * Job response = jobControllerClient.submitJob(projectId, region, job); 224 * } 225 * }</pre> 226 * 227 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 228 * @param region Required. The Dataproc region in which to handle the request. 229 * @param job Required. The job resource. 230 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 231 */ submitJob(String projectId, String region, Job job)232 public final Job submitJob(String projectId, String region, Job job) { 233 SubmitJobRequest request = 234 SubmitJobRequest.newBuilder().setProjectId(projectId).setRegion(region).setJob(job).build(); 235 return submitJob(request); 236 } 237 238 // AUTO-GENERATED DOCUMENTATION AND METHOD. 239 /** 240 * Submits a job to a cluster. 241 * 242 * <p>Sample code: 243 * 244 * <pre>{@code 245 * // This snippet has been automatically generated and should be regarded as a code template only. 246 * // It will require modifications to work: 247 * // - It may require correct/in-range values for request initialization. 248 * // - It may require specifying regional endpoints when creating the service client as shown in 249 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 250 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 251 * SubmitJobRequest request = 252 * SubmitJobRequest.newBuilder() 253 * .setProjectId("projectId-894832108") 254 * .setRegion("region-934795532") 255 * .setJob(Job.newBuilder().build()) 256 * .setRequestId("requestId693933066") 257 * .build(); 258 * Job response = jobControllerClient.submitJob(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 */ submitJob(SubmitJobRequest request)265 public final Job submitJob(SubmitJobRequest request) { 266 return submitJobCallable().call(request); 267 } 268 269 // AUTO-GENERATED DOCUMENTATION AND METHOD. 270 /** 271 * Submits a job to a cluster. 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 (JobControllerClient jobControllerClient = JobControllerClient.create()) { 282 * SubmitJobRequest request = 283 * SubmitJobRequest.newBuilder() 284 * .setProjectId("projectId-894832108") 285 * .setRegion("region-934795532") 286 * .setJob(Job.newBuilder().build()) 287 * .setRequestId("requestId693933066") 288 * .build(); 289 * ApiFuture<Job> future = jobControllerClient.submitJobCallable().futureCall(request); 290 * // Do something. 291 * Job response = future.get(); 292 * } 293 * }</pre> 294 */ submitJobCallable()295 public final UnaryCallable<SubmitJobRequest, Job> submitJobCallable() { 296 return stub.submitJobCallable(); 297 } 298 299 // AUTO-GENERATED DOCUMENTATION AND METHOD. 300 /** 301 * Submits job to a cluster. 302 * 303 * <p>Sample code: 304 * 305 * <pre>{@code 306 * // This snippet has been automatically generated and should be regarded as a code template only. 307 * // It will require modifications to work: 308 * // - It may require correct/in-range values for request initialization. 309 * // - It may require specifying regional endpoints when creating the service client as shown in 310 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 311 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 312 * String projectId = "projectId-894832108"; 313 * String region = "region-934795532"; 314 * Job job = Job.newBuilder().build(); 315 * Job response = jobControllerClient.submitJobAsOperationAsync(projectId, region, job).get(); 316 * } 317 * }</pre> 318 * 319 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 320 * @param region Required. The Dataproc region in which to handle the request. 321 * @param job Required. The job resource. 322 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 323 */ submitJobAsOperationAsync( String projectId, String region, Job job)324 public final OperationFuture<Job, JobMetadata> submitJobAsOperationAsync( 325 String projectId, String region, Job job) { 326 SubmitJobRequest request = 327 SubmitJobRequest.newBuilder().setProjectId(projectId).setRegion(region).setJob(job).build(); 328 return submitJobAsOperationAsync(request); 329 } 330 331 // AUTO-GENERATED DOCUMENTATION AND METHOD. 332 /** 333 * Submits job to a cluster. 334 * 335 * <p>Sample code: 336 * 337 * <pre>{@code 338 * // This snippet has been automatically generated and should be regarded as a code template only. 339 * // It will require modifications to work: 340 * // - It may require correct/in-range values for request initialization. 341 * // - It may require specifying regional endpoints when creating the service client as shown in 342 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 343 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 344 * SubmitJobRequest request = 345 * SubmitJobRequest.newBuilder() 346 * .setProjectId("projectId-894832108") 347 * .setRegion("region-934795532") 348 * .setJob(Job.newBuilder().build()) 349 * .setRequestId("requestId693933066") 350 * .build(); 351 * Job response = jobControllerClient.submitJobAsOperationAsync(request).get(); 352 * } 353 * }</pre> 354 * 355 * @param request The request object containing all of the parameters for the API call. 356 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 357 */ submitJobAsOperationAsync( SubmitJobRequest request)358 public final OperationFuture<Job, JobMetadata> submitJobAsOperationAsync( 359 SubmitJobRequest request) { 360 return submitJobAsOperationOperationCallable().futureCall(request); 361 } 362 363 // AUTO-GENERATED DOCUMENTATION AND METHOD. 364 /** 365 * Submits job to a cluster. 366 * 367 * <p>Sample code: 368 * 369 * <pre>{@code 370 * // This snippet has been automatically generated and should be regarded as a code template only. 371 * // It will require modifications to work: 372 * // - It may require correct/in-range values for request initialization. 373 * // - It may require specifying regional endpoints when creating the service client as shown in 374 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 375 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 376 * SubmitJobRequest request = 377 * SubmitJobRequest.newBuilder() 378 * .setProjectId("projectId-894832108") 379 * .setRegion("region-934795532") 380 * .setJob(Job.newBuilder().build()) 381 * .setRequestId("requestId693933066") 382 * .build(); 383 * OperationFuture<Job, JobMetadata> future = 384 * jobControllerClient.submitJobAsOperationOperationCallable().futureCall(request); 385 * // Do something. 386 * Job response = future.get(); 387 * } 388 * }</pre> 389 */ 390 public final OperationCallable<SubmitJobRequest, Job, JobMetadata> submitJobAsOperationOperationCallable()391 submitJobAsOperationOperationCallable() { 392 return stub.submitJobAsOperationOperationCallable(); 393 } 394 395 // AUTO-GENERATED DOCUMENTATION AND METHOD. 396 /** 397 * Submits job to a cluster. 398 * 399 * <p>Sample code: 400 * 401 * <pre>{@code 402 * // This snippet has been automatically generated and should be regarded as a code template only. 403 * // It will require modifications to work: 404 * // - It may require correct/in-range values for request initialization. 405 * // - It may require specifying regional endpoints when creating the service client as shown in 406 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 407 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 408 * SubmitJobRequest request = 409 * SubmitJobRequest.newBuilder() 410 * .setProjectId("projectId-894832108") 411 * .setRegion("region-934795532") 412 * .setJob(Job.newBuilder().build()) 413 * .setRequestId("requestId693933066") 414 * .build(); 415 * ApiFuture<Operation> future = 416 * jobControllerClient.submitJobAsOperationCallable().futureCall(request); 417 * // Do something. 418 * Operation response = future.get(); 419 * } 420 * }</pre> 421 */ submitJobAsOperationCallable()422 public final UnaryCallable<SubmitJobRequest, Operation> submitJobAsOperationCallable() { 423 return stub.submitJobAsOperationCallable(); 424 } 425 426 // AUTO-GENERATED DOCUMENTATION AND METHOD. 427 /** 428 * Gets the resource representation for a job in a project. 429 * 430 * <p>Sample code: 431 * 432 * <pre>{@code 433 * // This snippet has been automatically generated and should be regarded as a code template only. 434 * // It will require modifications to work: 435 * // - It may require correct/in-range values for request initialization. 436 * // - It may require specifying regional endpoints when creating the service client as shown in 437 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 438 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 439 * String projectId = "projectId-894832108"; 440 * String region = "region-934795532"; 441 * String jobId = "jobId101296568"; 442 * Job response = jobControllerClient.getJob(projectId, region, jobId); 443 * } 444 * }</pre> 445 * 446 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 447 * @param region Required. The Dataproc region in which to handle the request. 448 * @param jobId Required. The job ID. 449 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 450 */ getJob(String projectId, String region, String jobId)451 public final Job getJob(String projectId, String region, String jobId) { 452 GetJobRequest request = 453 GetJobRequest.newBuilder() 454 .setProjectId(projectId) 455 .setRegion(region) 456 .setJobId(jobId) 457 .build(); 458 return getJob(request); 459 } 460 461 // AUTO-GENERATED DOCUMENTATION AND METHOD. 462 /** 463 * Gets the resource representation for a job in a project. 464 * 465 * <p>Sample code: 466 * 467 * <pre>{@code 468 * // This snippet has been automatically generated and should be regarded as a code template only. 469 * // It will require modifications to work: 470 * // - It may require correct/in-range values for request initialization. 471 * // - It may require specifying regional endpoints when creating the service client as shown in 472 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 473 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 474 * GetJobRequest request = 475 * GetJobRequest.newBuilder() 476 * .setProjectId("projectId-894832108") 477 * .setRegion("region-934795532") 478 * .setJobId("jobId101296568") 479 * .build(); 480 * Job response = jobControllerClient.getJob(request); 481 * } 482 * }</pre> 483 * 484 * @param request The request object containing all of the parameters for the API call. 485 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 486 */ getJob(GetJobRequest request)487 public final Job getJob(GetJobRequest request) { 488 return getJobCallable().call(request); 489 } 490 491 // AUTO-GENERATED DOCUMENTATION AND METHOD. 492 /** 493 * Gets the resource representation for a job in a project. 494 * 495 * <p>Sample code: 496 * 497 * <pre>{@code 498 * // This snippet has been automatically generated and should be regarded as a code template only. 499 * // It will require modifications to work: 500 * // - It may require correct/in-range values for request initialization. 501 * // - It may require specifying regional endpoints when creating the service client as shown in 502 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 503 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 504 * GetJobRequest request = 505 * GetJobRequest.newBuilder() 506 * .setProjectId("projectId-894832108") 507 * .setRegion("region-934795532") 508 * .setJobId("jobId101296568") 509 * .build(); 510 * ApiFuture<Job> future = jobControllerClient.getJobCallable().futureCall(request); 511 * // Do something. 512 * Job response = future.get(); 513 * } 514 * }</pre> 515 */ getJobCallable()516 public final UnaryCallable<GetJobRequest, Job> getJobCallable() { 517 return stub.getJobCallable(); 518 } 519 520 // AUTO-GENERATED DOCUMENTATION AND METHOD. 521 /** 522 * Lists regions/{region}/jobs in a project. 523 * 524 * <p>Sample code: 525 * 526 * <pre>{@code 527 * // This snippet has been automatically generated and should be regarded as a code template only. 528 * // It will require modifications to work: 529 * // - It may require correct/in-range values for request initialization. 530 * // - It may require specifying regional endpoints when creating the service client as shown in 531 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 532 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 533 * String projectId = "projectId-894832108"; 534 * String region = "region-934795532"; 535 * for (Job element : jobControllerClient.listJobs(projectId, region).iterateAll()) { 536 * // doThingsWith(element); 537 * } 538 * } 539 * }</pre> 540 * 541 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 542 * @param region Required. The Dataproc region in which to handle the request. 543 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 544 */ listJobs(String projectId, String region)545 public final ListJobsPagedResponse listJobs(String projectId, String region) { 546 ListJobsRequest request = 547 ListJobsRequest.newBuilder().setProjectId(projectId).setRegion(region).build(); 548 return listJobs(request); 549 } 550 551 // AUTO-GENERATED DOCUMENTATION AND METHOD. 552 /** 553 * Lists regions/{region}/jobs in a project. 554 * 555 * <p>Sample code: 556 * 557 * <pre>{@code 558 * // This snippet has been automatically generated and should be regarded as a code template only. 559 * // It will require modifications to work: 560 * // - It may require correct/in-range values for request initialization. 561 * // - It may require specifying regional endpoints when creating the service client as shown in 562 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 563 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 564 * String projectId = "projectId-894832108"; 565 * String region = "region-934795532"; 566 * String filter = "filter-1274492040"; 567 * for (Job element : jobControllerClient.listJobs(projectId, region, filter).iterateAll()) { 568 * // doThingsWith(element); 569 * } 570 * } 571 * }</pre> 572 * 573 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 574 * @param region Required. The Dataproc region in which to handle the request. 575 * @param filter Optional. A filter constraining the jobs to list. Filters are case-sensitive and 576 * have the following syntax: 577 * <p>[field = value] AND [field [= value]] ... 578 * <p>where **field** is `status.state` or `labels.[KEY]`, and `[KEY]` is a 579 * label key. **value** can be `*` to match all values. `status.state` can 580 * be either `ACTIVE` or `NON_ACTIVE`. Only the logical `AND` operator is supported; 581 * space-separated items are treated as having an implicit `AND` operator. 582 * <p>Example filter: 583 * <p>status.state = ACTIVE AND labels.env = staging AND labels.starred = * 584 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 585 */ listJobs(String projectId, String region, String filter)586 public final ListJobsPagedResponse listJobs(String projectId, String region, String filter) { 587 ListJobsRequest request = 588 ListJobsRequest.newBuilder() 589 .setProjectId(projectId) 590 .setRegion(region) 591 .setFilter(filter) 592 .build(); 593 return listJobs(request); 594 } 595 596 // AUTO-GENERATED DOCUMENTATION AND METHOD. 597 /** 598 * Lists regions/{region}/jobs in a project. 599 * 600 * <p>Sample code: 601 * 602 * <pre>{@code 603 * // This snippet has been automatically generated and should be regarded as a code template only. 604 * // It will require modifications to work: 605 * // - It may require correct/in-range values for request initialization. 606 * // - It may require specifying regional endpoints when creating the service client as shown in 607 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 608 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 609 * ListJobsRequest request = 610 * ListJobsRequest.newBuilder() 611 * .setProjectId("projectId-894832108") 612 * .setRegion("region-934795532") 613 * .setPageSize(883849137) 614 * .setPageToken("pageToken873572522") 615 * .setClusterName("clusterName-1141738587") 616 * .setFilter("filter-1274492040") 617 * .build(); 618 * for (Job element : jobControllerClient.listJobs(request).iterateAll()) { 619 * // doThingsWith(element); 620 * } 621 * } 622 * }</pre> 623 * 624 * @param request The request object containing all of the parameters for the API call. 625 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 626 */ listJobs(ListJobsRequest request)627 public final ListJobsPagedResponse listJobs(ListJobsRequest request) { 628 return listJobsPagedCallable().call(request); 629 } 630 631 // AUTO-GENERATED DOCUMENTATION AND METHOD. 632 /** 633 * Lists regions/{region}/jobs in a project. 634 * 635 * <p>Sample code: 636 * 637 * <pre>{@code 638 * // This snippet has been automatically generated and should be regarded as a code template only. 639 * // It will require modifications to work: 640 * // - It may require correct/in-range values for request initialization. 641 * // - It may require specifying regional endpoints when creating the service client as shown in 642 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 643 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 644 * ListJobsRequest request = 645 * ListJobsRequest.newBuilder() 646 * .setProjectId("projectId-894832108") 647 * .setRegion("region-934795532") 648 * .setPageSize(883849137) 649 * .setPageToken("pageToken873572522") 650 * .setClusterName("clusterName-1141738587") 651 * .setFilter("filter-1274492040") 652 * .build(); 653 * ApiFuture<Job> future = jobControllerClient.listJobsPagedCallable().futureCall(request); 654 * // Do something. 655 * for (Job element : future.get().iterateAll()) { 656 * // doThingsWith(element); 657 * } 658 * } 659 * }</pre> 660 */ listJobsPagedCallable()661 public final UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable() { 662 return stub.listJobsPagedCallable(); 663 } 664 665 // AUTO-GENERATED DOCUMENTATION AND METHOD. 666 /** 667 * Lists regions/{region}/jobs in a project. 668 * 669 * <p>Sample code: 670 * 671 * <pre>{@code 672 * // This snippet has been automatically generated and should be regarded as a code template only. 673 * // It will require modifications to work: 674 * // - It may require correct/in-range values for request initialization. 675 * // - It may require specifying regional endpoints when creating the service client as shown in 676 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 677 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 678 * ListJobsRequest request = 679 * ListJobsRequest.newBuilder() 680 * .setProjectId("projectId-894832108") 681 * .setRegion("region-934795532") 682 * .setPageSize(883849137) 683 * .setPageToken("pageToken873572522") 684 * .setClusterName("clusterName-1141738587") 685 * .setFilter("filter-1274492040") 686 * .build(); 687 * while (true) { 688 * ListJobsResponse response = jobControllerClient.listJobsCallable().call(request); 689 * for (Job element : response.getJobsList()) { 690 * // doThingsWith(element); 691 * } 692 * String nextPageToken = response.getNextPageToken(); 693 * if (!Strings.isNullOrEmpty(nextPageToken)) { 694 * request = request.toBuilder().setPageToken(nextPageToken).build(); 695 * } else { 696 * break; 697 * } 698 * } 699 * } 700 * }</pre> 701 */ listJobsCallable()702 public final UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable() { 703 return stub.listJobsCallable(); 704 } 705 706 // AUTO-GENERATED DOCUMENTATION AND METHOD. 707 /** 708 * Updates a job 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 (JobControllerClient jobControllerClient = JobControllerClient.create()) { 719 * UpdateJobRequest request = 720 * UpdateJobRequest.newBuilder() 721 * .setProjectId("projectId-894832108") 722 * .setRegion("region-934795532") 723 * .setJobId("jobId101296568") 724 * .setJob(Job.newBuilder().build()) 725 * .setUpdateMask(FieldMask.newBuilder().build()) 726 * .build(); 727 * Job response = jobControllerClient.updateJob(request); 728 * } 729 * }</pre> 730 * 731 * @param request The request object containing all of the parameters for the API call. 732 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 733 */ updateJob(UpdateJobRequest request)734 public final Job updateJob(UpdateJobRequest request) { 735 return updateJobCallable().call(request); 736 } 737 738 // AUTO-GENERATED DOCUMENTATION AND METHOD. 739 /** 740 * Updates a job in a project. 741 * 742 * <p>Sample code: 743 * 744 * <pre>{@code 745 * // This snippet has been automatically generated and should be regarded as a code template only. 746 * // It will require modifications to work: 747 * // - It may require correct/in-range values for request initialization. 748 * // - It may require specifying regional endpoints when creating the service client as shown in 749 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 750 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 751 * UpdateJobRequest request = 752 * UpdateJobRequest.newBuilder() 753 * .setProjectId("projectId-894832108") 754 * .setRegion("region-934795532") 755 * .setJobId("jobId101296568") 756 * .setJob(Job.newBuilder().build()) 757 * .setUpdateMask(FieldMask.newBuilder().build()) 758 * .build(); 759 * ApiFuture<Job> future = jobControllerClient.updateJobCallable().futureCall(request); 760 * // Do something. 761 * Job response = future.get(); 762 * } 763 * }</pre> 764 */ updateJobCallable()765 public final UnaryCallable<UpdateJobRequest, Job> updateJobCallable() { 766 return stub.updateJobCallable(); 767 } 768 769 // AUTO-GENERATED DOCUMENTATION AND METHOD. 770 /** 771 * Starts a job cancellation request. To access the job resource after cancellation, call 772 * [regions/{region}/jobs.list](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/list) 773 * or 774 * [regions/{region}/jobs.get](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/get). 775 * 776 * <p>Sample code: 777 * 778 * <pre>{@code 779 * // This snippet has been automatically generated and should be regarded as a code template only. 780 * // It will require modifications to work: 781 * // - It may require correct/in-range values for request initialization. 782 * // - It may require specifying regional endpoints when creating the service client as shown in 783 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 784 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 785 * String projectId = "projectId-894832108"; 786 * String region = "region-934795532"; 787 * String jobId = "jobId101296568"; 788 * Job response = jobControllerClient.cancelJob(projectId, region, jobId); 789 * } 790 * }</pre> 791 * 792 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 793 * @param region Required. The Dataproc region in which to handle the request. 794 * @param jobId Required. The job ID. 795 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 796 */ cancelJob(String projectId, String region, String jobId)797 public final Job cancelJob(String projectId, String region, String jobId) { 798 CancelJobRequest request = 799 CancelJobRequest.newBuilder() 800 .setProjectId(projectId) 801 .setRegion(region) 802 .setJobId(jobId) 803 .build(); 804 return cancelJob(request); 805 } 806 807 // AUTO-GENERATED DOCUMENTATION AND METHOD. 808 /** 809 * Starts a job cancellation request. To access the job resource after cancellation, call 810 * [regions/{region}/jobs.list](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/list) 811 * or 812 * [regions/{region}/jobs.get](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/get). 813 * 814 * <p>Sample code: 815 * 816 * <pre>{@code 817 * // This snippet has been automatically generated and should be regarded as a code template only. 818 * // It will require modifications to work: 819 * // - It may require correct/in-range values for request initialization. 820 * // - It may require specifying regional endpoints when creating the service client as shown in 821 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 822 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 823 * CancelJobRequest request = 824 * CancelJobRequest.newBuilder() 825 * .setProjectId("projectId-894832108") 826 * .setRegion("region-934795532") 827 * .setJobId("jobId101296568") 828 * .build(); 829 * Job response = jobControllerClient.cancelJob(request); 830 * } 831 * }</pre> 832 * 833 * @param request The request object containing all of the parameters for the API call. 834 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 835 */ cancelJob(CancelJobRequest request)836 public final Job cancelJob(CancelJobRequest request) { 837 return cancelJobCallable().call(request); 838 } 839 840 // AUTO-GENERATED DOCUMENTATION AND METHOD. 841 /** 842 * Starts a job cancellation request. To access the job resource after cancellation, call 843 * [regions/{region}/jobs.list](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/list) 844 * or 845 * [regions/{region}/jobs.get](https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/get). 846 * 847 * <p>Sample code: 848 * 849 * <pre>{@code 850 * // This snippet has been automatically generated and should be regarded as a code template only. 851 * // It will require modifications to work: 852 * // - It may require correct/in-range values for request initialization. 853 * // - It may require specifying regional endpoints when creating the service client as shown in 854 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 855 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 856 * CancelJobRequest request = 857 * CancelJobRequest.newBuilder() 858 * .setProjectId("projectId-894832108") 859 * .setRegion("region-934795532") 860 * .setJobId("jobId101296568") 861 * .build(); 862 * ApiFuture<Job> future = jobControllerClient.cancelJobCallable().futureCall(request); 863 * // Do something. 864 * Job response = future.get(); 865 * } 866 * }</pre> 867 */ cancelJobCallable()868 public final UnaryCallable<CancelJobRequest, Job> cancelJobCallable() { 869 return stub.cancelJobCallable(); 870 } 871 872 // AUTO-GENERATED DOCUMENTATION AND METHOD. 873 /** 874 * Deletes the job from the project. If the job is active, the delete fails, and the response 875 * returns `FAILED_PRECONDITION`. 876 * 877 * <p>Sample code: 878 * 879 * <pre>{@code 880 * // This snippet has been automatically generated and should be regarded as a code template only. 881 * // It will require modifications to work: 882 * // - It may require correct/in-range values for request initialization. 883 * // - It may require specifying regional endpoints when creating the service client as shown in 884 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 885 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 886 * String projectId = "projectId-894832108"; 887 * String region = "region-934795532"; 888 * String jobId = "jobId101296568"; 889 * jobControllerClient.deleteJob(projectId, region, jobId); 890 * } 891 * }</pre> 892 * 893 * @param projectId Required. The ID of the Google Cloud Platform project that the job belongs to. 894 * @param region Required. The Dataproc region in which to handle the request. 895 * @param jobId Required. The job ID. 896 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 897 */ deleteJob(String projectId, String region, String jobId)898 public final void deleteJob(String projectId, String region, String jobId) { 899 DeleteJobRequest request = 900 DeleteJobRequest.newBuilder() 901 .setProjectId(projectId) 902 .setRegion(region) 903 .setJobId(jobId) 904 .build(); 905 deleteJob(request); 906 } 907 908 // AUTO-GENERATED DOCUMENTATION AND METHOD. 909 /** 910 * Deletes the job from the project. If the job is active, the delete fails, and the response 911 * returns `FAILED_PRECONDITION`. 912 * 913 * <p>Sample code: 914 * 915 * <pre>{@code 916 * // This snippet has been automatically generated and should be regarded as a code template only. 917 * // It will require modifications to work: 918 * // - It may require correct/in-range values for request initialization. 919 * // - It may require specifying regional endpoints when creating the service client as shown in 920 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 921 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 922 * DeleteJobRequest request = 923 * DeleteJobRequest.newBuilder() 924 * .setProjectId("projectId-894832108") 925 * .setRegion("region-934795532") 926 * .setJobId("jobId101296568") 927 * .build(); 928 * jobControllerClient.deleteJob(request); 929 * } 930 * }</pre> 931 * 932 * @param request The request object containing all of the parameters for the API call. 933 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 934 */ deleteJob(DeleteJobRequest request)935 public final void deleteJob(DeleteJobRequest request) { 936 deleteJobCallable().call(request); 937 } 938 939 // AUTO-GENERATED DOCUMENTATION AND METHOD. 940 /** 941 * Deletes the job from the project. If the job is active, the delete fails, and the response 942 * returns `FAILED_PRECONDITION`. 943 * 944 * <p>Sample code: 945 * 946 * <pre>{@code 947 * // This snippet has been automatically generated and should be regarded as a code template only. 948 * // It will require modifications to work: 949 * // - It may require correct/in-range values for request initialization. 950 * // - It may require specifying regional endpoints when creating the service client as shown in 951 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 952 * try (JobControllerClient jobControllerClient = JobControllerClient.create()) { 953 * DeleteJobRequest request = 954 * DeleteJobRequest.newBuilder() 955 * .setProjectId("projectId-894832108") 956 * .setRegion("region-934795532") 957 * .setJobId("jobId101296568") 958 * .build(); 959 * ApiFuture<Empty> future = jobControllerClient.deleteJobCallable().futureCall(request); 960 * // Do something. 961 * future.get(); 962 * } 963 * }</pre> 964 */ deleteJobCallable()965 public final UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable() { 966 return stub.deleteJobCallable(); 967 } 968 969 @Override close()970 public final void close() { 971 stub.close(); 972 } 973 974 @Override shutdown()975 public void shutdown() { 976 stub.shutdown(); 977 } 978 979 @Override isShutdown()980 public boolean isShutdown() { 981 return stub.isShutdown(); 982 } 983 984 @Override isTerminated()985 public boolean isTerminated() { 986 return stub.isTerminated(); 987 } 988 989 @Override shutdownNow()990 public void shutdownNow() { 991 stub.shutdownNow(); 992 } 993 994 @Override awaitTermination(long duration, TimeUnit unit)995 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 996 return stub.awaitTermination(duration, unit); 997 } 998 999 public static class ListJobsPagedResponse 1000 extends AbstractPagedListResponse< 1001 ListJobsRequest, ListJobsResponse, Job, ListJobsPage, ListJobsFixedSizeCollection> { 1002 createAsync( PageContext<ListJobsRequest, ListJobsResponse, Job> context, ApiFuture<ListJobsResponse> futureResponse)1003 public static ApiFuture<ListJobsPagedResponse> createAsync( 1004 PageContext<ListJobsRequest, ListJobsResponse, Job> context, 1005 ApiFuture<ListJobsResponse> futureResponse) { 1006 ApiFuture<ListJobsPage> futurePage = 1007 ListJobsPage.createEmptyPage().createPageAsync(context, futureResponse); 1008 return ApiFutures.transform( 1009 futurePage, input -> new ListJobsPagedResponse(input), MoreExecutors.directExecutor()); 1010 } 1011 ListJobsPagedResponse(ListJobsPage page)1012 private ListJobsPagedResponse(ListJobsPage page) { 1013 super(page, ListJobsFixedSizeCollection.createEmptyCollection()); 1014 } 1015 } 1016 1017 public static class ListJobsPage 1018 extends AbstractPage<ListJobsRequest, ListJobsResponse, Job, ListJobsPage> { 1019 ListJobsPage( PageContext<ListJobsRequest, ListJobsResponse, Job> context, ListJobsResponse response)1020 private ListJobsPage( 1021 PageContext<ListJobsRequest, ListJobsResponse, Job> context, ListJobsResponse response) { 1022 super(context, response); 1023 } 1024 createEmptyPage()1025 private static ListJobsPage createEmptyPage() { 1026 return new ListJobsPage(null, null); 1027 } 1028 1029 @Override createPage( PageContext<ListJobsRequest, ListJobsResponse, Job> context, ListJobsResponse response)1030 protected ListJobsPage createPage( 1031 PageContext<ListJobsRequest, ListJobsResponse, Job> context, ListJobsResponse response) { 1032 return new ListJobsPage(context, response); 1033 } 1034 1035 @Override createPageAsync( PageContext<ListJobsRequest, ListJobsResponse, Job> context, ApiFuture<ListJobsResponse> futureResponse)1036 public ApiFuture<ListJobsPage> createPageAsync( 1037 PageContext<ListJobsRequest, ListJobsResponse, Job> context, 1038 ApiFuture<ListJobsResponse> futureResponse) { 1039 return super.createPageAsync(context, futureResponse); 1040 } 1041 } 1042 1043 public static class ListJobsFixedSizeCollection 1044 extends AbstractFixedSizeCollection< 1045 ListJobsRequest, ListJobsResponse, Job, ListJobsPage, ListJobsFixedSizeCollection> { 1046 ListJobsFixedSizeCollection(List<ListJobsPage> pages, int collectionSize)1047 private ListJobsFixedSizeCollection(List<ListJobsPage> pages, int collectionSize) { 1048 super(pages, collectionSize); 1049 } 1050 createEmptyCollection()1051 private static ListJobsFixedSizeCollection createEmptyCollection() { 1052 return new ListJobsFixedSizeCollection(null, 0); 1053 } 1054 1055 @Override createCollection( List<ListJobsPage> pages, int collectionSize)1056 protected ListJobsFixedSizeCollection createCollection( 1057 List<ListJobsPage> pages, int collectionSize) { 1058 return new ListJobsFixedSizeCollection(pages, collectionSize); 1059 } 1060 } 1061 } 1062