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.workflows.v1beta; 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.workflows.v1beta.stub.WorkflowsStub; 32 import com.google.cloud.workflows.v1beta.stub.WorkflowsStubSettings; 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: Workflows is used to deploy and execute workflow programs. Workflows makes 45 * sure the program executes reliably, despite hardware and networking interruptions. 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 (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 57 * WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 58 * Workflow response = workflowsClient.getWorkflow(name); 59 * } 60 * }</pre> 61 * 62 * <p>Note: close() needs to be called on the WorkflowsClient object to clean up resources such as 63 * 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 WorkflowsSettings to create(). 86 * 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 * WorkflowsSettings workflowsSettings = 97 * WorkflowsSettings.newBuilder() 98 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 99 * .build(); 100 * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); 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 * WorkflowsSettings workflowsSettings = 112 * WorkflowsSettings.newBuilder().setEndpoint(myEndpoint).build(); 113 * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); 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 * WorkflowsSettings workflowsSettings = WorkflowsSettings.newHttpJsonBuilder().build(); 126 * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); 127 * }</pre> 128 * 129 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 130 */ 131 @BetaApi 132 @Generated("by gapic-generator-java") 133 public class WorkflowsClient implements BackgroundResource { 134 private final WorkflowsSettings settings; 135 private final WorkflowsStub stub; 136 private final OperationsClient httpJsonOperationsClient; 137 private final com.google.longrunning.OperationsClient operationsClient; 138 139 /** Constructs an instance of WorkflowsClient with default settings. */ create()140 public static final WorkflowsClient create() throws IOException { 141 return create(WorkflowsSettings.newBuilder().build()); 142 } 143 144 /** 145 * Constructs an instance of WorkflowsClient, using the given settings. The channels are created 146 * based on the settings passed in, or defaults for any settings that are not set. 147 */ create(WorkflowsSettings settings)148 public static final WorkflowsClient create(WorkflowsSettings settings) throws IOException { 149 return new WorkflowsClient(settings); 150 } 151 152 /** 153 * Constructs an instance of WorkflowsClient, using the given stub for making calls. This is for 154 * advanced usage - prefer using create(WorkflowsSettings). 155 */ create(WorkflowsStub stub)156 public static final WorkflowsClient create(WorkflowsStub stub) { 157 return new WorkflowsClient(stub); 158 } 159 160 /** 161 * Constructs an instance of WorkflowsClient, using the given settings. This is protected so that 162 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 163 */ WorkflowsClient(WorkflowsSettings settings)164 protected WorkflowsClient(WorkflowsSettings settings) throws IOException { 165 this.settings = settings; 166 this.stub = ((WorkflowsStubSettings) settings.getStubSettings()).createStub(); 167 this.operationsClient = 168 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 169 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 170 } 171 WorkflowsClient(WorkflowsStub stub)172 protected WorkflowsClient(WorkflowsStub stub) { 173 this.settings = null; 174 this.stub = stub; 175 this.operationsClient = 176 com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); 177 this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); 178 } 179 getSettings()180 public final WorkflowsSettings getSettings() { 181 return settings; 182 } 183 getStub()184 public WorkflowsStub getStub() { 185 return stub; 186 } 187 188 /** 189 * Returns the OperationsClient that can be used to query the status of a long-running operation 190 * returned by another API method call. 191 */ getOperationsClient()192 public final com.google.longrunning.OperationsClient getOperationsClient() { 193 return operationsClient; 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 */ 200 @BetaApi getHttpJsonOperationsClient()201 public final OperationsClient getHttpJsonOperationsClient() { 202 return httpJsonOperationsClient; 203 } 204 205 // AUTO-GENERATED DOCUMENTATION AND METHOD. 206 /** 207 * Lists Workflows in a given project and location. The default order is not specified. 208 * 209 * <p>Sample code: 210 * 211 * <pre>{@code 212 * // This snippet has been automatically generated and should be regarded as a code template only. 213 * // It will require modifications to work: 214 * // - It may require correct/in-range values for request initialization. 215 * // - It may require specifying regional endpoints when creating the service client as shown in 216 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 217 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 218 * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 219 * for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { 220 * // doThingsWith(element); 221 * } 222 * } 223 * }</pre> 224 * 225 * @param parent Required. Project and location from which the workflows should be listed. Format: 226 * projects/{project}/locations/{location} 227 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 228 */ listWorkflows(LocationName parent)229 public final ListWorkflowsPagedResponse listWorkflows(LocationName parent) { 230 ListWorkflowsRequest request = 231 ListWorkflowsRequest.newBuilder() 232 .setParent(parent == null ? null : parent.toString()) 233 .build(); 234 return listWorkflows(request); 235 } 236 237 // AUTO-GENERATED DOCUMENTATION AND METHOD. 238 /** 239 * Lists Workflows in a given project and location. The default order is not specified. 240 * 241 * <p>Sample code: 242 * 243 * <pre>{@code 244 * // This snippet has been automatically generated and should be regarded as a code template only. 245 * // It will require modifications to work: 246 * // - It may require correct/in-range values for request initialization. 247 * // - It may require specifying regional endpoints when creating the service client as shown in 248 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 249 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 250 * String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); 251 * for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { 252 * // doThingsWith(element); 253 * } 254 * } 255 * }</pre> 256 * 257 * @param parent Required. Project and location from which the workflows should be listed. Format: 258 * projects/{project}/locations/{location} 259 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 260 */ listWorkflows(String parent)261 public final ListWorkflowsPagedResponse listWorkflows(String parent) { 262 ListWorkflowsRequest request = ListWorkflowsRequest.newBuilder().setParent(parent).build(); 263 return listWorkflows(request); 264 } 265 266 // AUTO-GENERATED DOCUMENTATION AND METHOD. 267 /** 268 * Lists Workflows in a given project and location. The default order is not specified. 269 * 270 * <p>Sample code: 271 * 272 * <pre>{@code 273 * // This snippet has been automatically generated and should be regarded as a code template only. 274 * // It will require modifications to work: 275 * // - It may require correct/in-range values for request initialization. 276 * // - It may require specifying regional endpoints when creating the service client as shown in 277 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 278 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 279 * ListWorkflowsRequest request = 280 * ListWorkflowsRequest.newBuilder() 281 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 282 * .setPageSize(883849137) 283 * .setPageToken("pageToken873572522") 284 * .setFilter("filter-1274492040") 285 * .setOrderBy("orderBy-1207110587") 286 * .build(); 287 * for (Workflow element : workflowsClient.listWorkflows(request).iterateAll()) { 288 * // doThingsWith(element); 289 * } 290 * } 291 * }</pre> 292 * 293 * @param request The request object containing all of the parameters for the API call. 294 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 295 */ listWorkflows(ListWorkflowsRequest request)296 public final ListWorkflowsPagedResponse listWorkflows(ListWorkflowsRequest request) { 297 return listWorkflowsPagedCallable().call(request); 298 } 299 300 // AUTO-GENERATED DOCUMENTATION AND METHOD. 301 /** 302 * Lists Workflows in a given project and location. The default order is not specified. 303 * 304 * <p>Sample code: 305 * 306 * <pre>{@code 307 * // This snippet has been automatically generated and should be regarded as a code template only. 308 * // It will require modifications to work: 309 * // - It may require correct/in-range values for request initialization. 310 * // - It may require specifying regional endpoints when creating the service client as shown in 311 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 312 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 313 * ListWorkflowsRequest request = 314 * ListWorkflowsRequest.newBuilder() 315 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 316 * .setPageSize(883849137) 317 * .setPageToken("pageToken873572522") 318 * .setFilter("filter-1274492040") 319 * .setOrderBy("orderBy-1207110587") 320 * .build(); 321 * ApiFuture<Workflow> future = workflowsClient.listWorkflowsPagedCallable().futureCall(request); 322 * // Do something. 323 * for (Workflow element : future.get().iterateAll()) { 324 * // doThingsWith(element); 325 * } 326 * } 327 * }</pre> 328 */ 329 public final UnaryCallable<ListWorkflowsRequest, ListWorkflowsPagedResponse> listWorkflowsPagedCallable()330 listWorkflowsPagedCallable() { 331 return stub.listWorkflowsPagedCallable(); 332 } 333 334 // AUTO-GENERATED DOCUMENTATION AND METHOD. 335 /** 336 * Lists Workflows in a given project and location. The default order is not specified. 337 * 338 * <p>Sample code: 339 * 340 * <pre>{@code 341 * // This snippet has been automatically generated and should be regarded as a code template only. 342 * // It will require modifications to work: 343 * // - It may require correct/in-range values for request initialization. 344 * // - It may require specifying regional endpoints when creating the service client as shown in 345 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 346 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 347 * ListWorkflowsRequest request = 348 * ListWorkflowsRequest.newBuilder() 349 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 350 * .setPageSize(883849137) 351 * .setPageToken("pageToken873572522") 352 * .setFilter("filter-1274492040") 353 * .setOrderBy("orderBy-1207110587") 354 * .build(); 355 * while (true) { 356 * ListWorkflowsResponse response = workflowsClient.listWorkflowsCallable().call(request); 357 * for (Workflow element : response.getWorkflowsList()) { 358 * // doThingsWith(element); 359 * } 360 * String nextPageToken = response.getNextPageToken(); 361 * if (!Strings.isNullOrEmpty(nextPageToken)) { 362 * request = request.toBuilder().setPageToken(nextPageToken).build(); 363 * } else { 364 * break; 365 * } 366 * } 367 * } 368 * }</pre> 369 */ listWorkflowsCallable()370 public final UnaryCallable<ListWorkflowsRequest, ListWorkflowsResponse> listWorkflowsCallable() { 371 return stub.listWorkflowsCallable(); 372 } 373 374 // AUTO-GENERATED DOCUMENTATION AND METHOD. 375 /** 376 * Gets details of a single Workflow. 377 * 378 * <p>Sample code: 379 * 380 * <pre>{@code 381 * // This snippet has been automatically generated and should be regarded as a code template only. 382 * // It will require modifications to work: 383 * // - It may require correct/in-range values for request initialization. 384 * // - It may require specifying regional endpoints when creating the service client as shown in 385 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 386 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 387 * WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 388 * Workflow response = workflowsClient.getWorkflow(name); 389 * } 390 * }</pre> 391 * 392 * @param name Required. Name of the workflow which information should be retrieved. Format: 393 * projects/{project}/locations/{location}/workflows/{workflow} 394 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 395 */ getWorkflow(WorkflowName name)396 public final Workflow getWorkflow(WorkflowName name) { 397 GetWorkflowRequest request = 398 GetWorkflowRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 399 return getWorkflow(request); 400 } 401 402 // AUTO-GENERATED DOCUMENTATION AND METHOD. 403 /** 404 * Gets details of a single Workflow. 405 * 406 * <p>Sample code: 407 * 408 * <pre>{@code 409 * // This snippet has been automatically generated and should be regarded as a code template only. 410 * // It will require modifications to work: 411 * // - It may require correct/in-range values for request initialization. 412 * // - It may require specifying regional endpoints when creating the service client as shown in 413 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 414 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 415 * String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); 416 * Workflow response = workflowsClient.getWorkflow(name); 417 * } 418 * }</pre> 419 * 420 * @param name Required. Name of the workflow which information should be retrieved. Format: 421 * projects/{project}/locations/{location}/workflows/{workflow} 422 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 423 */ getWorkflow(String name)424 public final Workflow getWorkflow(String name) { 425 GetWorkflowRequest request = GetWorkflowRequest.newBuilder().setName(name).build(); 426 return getWorkflow(request); 427 } 428 429 // AUTO-GENERATED DOCUMENTATION AND METHOD. 430 /** 431 * Gets details of a single Workflow. 432 * 433 * <p>Sample code: 434 * 435 * <pre>{@code 436 * // This snippet has been automatically generated and should be regarded as a code template only. 437 * // It will require modifications to work: 438 * // - It may require correct/in-range values for request initialization. 439 * // - It may require specifying regional endpoints when creating the service client as shown in 440 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 441 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 442 * GetWorkflowRequest request = 443 * GetWorkflowRequest.newBuilder() 444 * .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 445 * .build(); 446 * Workflow response = workflowsClient.getWorkflow(request); 447 * } 448 * }</pre> 449 * 450 * @param request The request object containing all of the parameters for the API call. 451 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 452 */ getWorkflow(GetWorkflowRequest request)453 public final Workflow getWorkflow(GetWorkflowRequest request) { 454 return getWorkflowCallable().call(request); 455 } 456 457 // AUTO-GENERATED DOCUMENTATION AND METHOD. 458 /** 459 * Gets details of a single Workflow. 460 * 461 * <p>Sample code: 462 * 463 * <pre>{@code 464 * // This snippet has been automatically generated and should be regarded as a code template only. 465 * // It will require modifications to work: 466 * // - It may require correct/in-range values for request initialization. 467 * // - It may require specifying regional endpoints when creating the service client as shown in 468 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 469 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 470 * GetWorkflowRequest request = 471 * GetWorkflowRequest.newBuilder() 472 * .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 473 * .build(); 474 * ApiFuture<Workflow> future = workflowsClient.getWorkflowCallable().futureCall(request); 475 * // Do something. 476 * Workflow response = future.get(); 477 * } 478 * }</pre> 479 */ getWorkflowCallable()480 public final UnaryCallable<GetWorkflowRequest, Workflow> getWorkflowCallable() { 481 return stub.getWorkflowCallable(); 482 } 483 484 // AUTO-GENERATED DOCUMENTATION AND METHOD. 485 /** 486 * Creates a new workflow. If a workflow with the specified name already exists in the specified 487 * project and location, the long running operation will return 488 * [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. 489 * 490 * <p>Sample code: 491 * 492 * <pre>{@code 493 * // This snippet has been automatically generated and should be regarded as a code template only. 494 * // It will require modifications to work: 495 * // - It may require correct/in-range values for request initialization. 496 * // - It may require specifying regional endpoints when creating the service client as shown in 497 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 498 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 499 * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 500 * Workflow workflow = Workflow.newBuilder().build(); 501 * String workflowId = "workflowId-360387270"; 502 * Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); 503 * } 504 * }</pre> 505 * 506 * @param parent Required. Project and location in which the workflow should be created. Format: 507 * projects/{project}/locations/{location} 508 * @param workflow Required. Workflow to be created. 509 * @param workflowId Required. The ID of the workflow to be created. It has to fulfill the 510 * following requirements: 511 * <ul> 512 * <li>Must contain only letters, numbers, underscores and hyphens. 513 * <li>Must start with a letter. 514 * <li>Must be between 1-64 characters. 515 * <li>Must end with a number or a letter. 516 * <li>Must be unique within the customer project and location. 517 * </ul> 518 * 519 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 520 */ createWorkflowAsync( LocationName parent, Workflow workflow, String workflowId)521 public final OperationFuture<Workflow, OperationMetadata> createWorkflowAsync( 522 LocationName parent, Workflow workflow, String workflowId) { 523 CreateWorkflowRequest request = 524 CreateWorkflowRequest.newBuilder() 525 .setParent(parent == null ? null : parent.toString()) 526 .setWorkflow(workflow) 527 .setWorkflowId(workflowId) 528 .build(); 529 return createWorkflowAsync(request); 530 } 531 532 // AUTO-GENERATED DOCUMENTATION AND METHOD. 533 /** 534 * Creates a new workflow. If a workflow with the specified name already exists in the specified 535 * project and location, the long running operation will return 536 * [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. 537 * 538 * <p>Sample code: 539 * 540 * <pre>{@code 541 * // This snippet has been automatically generated and should be regarded as a code template only. 542 * // It will require modifications to work: 543 * // - It may require correct/in-range values for request initialization. 544 * // - It may require specifying regional endpoints when creating the service client as shown in 545 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 546 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 547 * String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); 548 * Workflow workflow = Workflow.newBuilder().build(); 549 * String workflowId = "workflowId-360387270"; 550 * Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); 551 * } 552 * }</pre> 553 * 554 * @param parent Required. Project and location in which the workflow should be created. Format: 555 * projects/{project}/locations/{location} 556 * @param workflow Required. Workflow to be created. 557 * @param workflowId Required. The ID of the workflow to be created. It has to fulfill the 558 * following requirements: 559 * <ul> 560 * <li>Must contain only letters, numbers, underscores and hyphens. 561 * <li>Must start with a letter. 562 * <li>Must be between 1-64 characters. 563 * <li>Must end with a number or a letter. 564 * <li>Must be unique within the customer project and location. 565 * </ul> 566 * 567 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 568 */ createWorkflowAsync( String parent, Workflow workflow, String workflowId)569 public final OperationFuture<Workflow, OperationMetadata> createWorkflowAsync( 570 String parent, Workflow workflow, String workflowId) { 571 CreateWorkflowRequest request = 572 CreateWorkflowRequest.newBuilder() 573 .setParent(parent) 574 .setWorkflow(workflow) 575 .setWorkflowId(workflowId) 576 .build(); 577 return createWorkflowAsync(request); 578 } 579 580 // AUTO-GENERATED DOCUMENTATION AND METHOD. 581 /** 582 * Creates a new workflow. If a workflow with the specified name already exists in the specified 583 * project and location, the long running operation will return 584 * [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. 585 * 586 * <p>Sample code: 587 * 588 * <pre>{@code 589 * // This snippet has been automatically generated and should be regarded as a code template only. 590 * // It will require modifications to work: 591 * // - It may require correct/in-range values for request initialization. 592 * // - It may require specifying regional endpoints when creating the service client as shown in 593 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 594 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 595 * CreateWorkflowRequest request = 596 * CreateWorkflowRequest.newBuilder() 597 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 598 * .setWorkflow(Workflow.newBuilder().build()) 599 * .setWorkflowId("workflowId-360387270") 600 * .build(); 601 * Workflow response = workflowsClient.createWorkflowAsync(request).get(); 602 * } 603 * }</pre> 604 * 605 * @param request The request object containing all of the parameters for the API call. 606 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 607 */ createWorkflowAsync( CreateWorkflowRequest request)608 public final OperationFuture<Workflow, OperationMetadata> createWorkflowAsync( 609 CreateWorkflowRequest request) { 610 return createWorkflowOperationCallable().futureCall(request); 611 } 612 613 // AUTO-GENERATED DOCUMENTATION AND METHOD. 614 /** 615 * Creates a new workflow. If a workflow with the specified name already exists in the specified 616 * project and location, the long running operation will return 617 * [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. 618 * 619 * <p>Sample code: 620 * 621 * <pre>{@code 622 * // This snippet has been automatically generated and should be regarded as a code template only. 623 * // It will require modifications to work: 624 * // - It may require correct/in-range values for request initialization. 625 * // - It may require specifying regional endpoints when creating the service client as shown in 626 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 627 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 628 * CreateWorkflowRequest request = 629 * CreateWorkflowRequest.newBuilder() 630 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 631 * .setWorkflow(Workflow.newBuilder().build()) 632 * .setWorkflowId("workflowId-360387270") 633 * .build(); 634 * OperationFuture<Workflow, OperationMetadata> future = 635 * workflowsClient.createWorkflowOperationCallable().futureCall(request); 636 * // Do something. 637 * Workflow response = future.get(); 638 * } 639 * }</pre> 640 */ 641 public final OperationCallable<CreateWorkflowRequest, Workflow, OperationMetadata> createWorkflowOperationCallable()642 createWorkflowOperationCallable() { 643 return stub.createWorkflowOperationCallable(); 644 } 645 646 // AUTO-GENERATED DOCUMENTATION AND METHOD. 647 /** 648 * Creates a new workflow. If a workflow with the specified name already exists in the specified 649 * project and location, the long running operation will return 650 * [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. 651 * 652 * <p>Sample code: 653 * 654 * <pre>{@code 655 * // This snippet has been automatically generated and should be regarded as a code template only. 656 * // It will require modifications to work: 657 * // - It may require correct/in-range values for request initialization. 658 * // - It may require specifying regional endpoints when creating the service client as shown in 659 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 660 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 661 * CreateWorkflowRequest request = 662 * CreateWorkflowRequest.newBuilder() 663 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 664 * .setWorkflow(Workflow.newBuilder().build()) 665 * .setWorkflowId("workflowId-360387270") 666 * .build(); 667 * ApiFuture<Operation> future = workflowsClient.createWorkflowCallable().futureCall(request); 668 * // Do something. 669 * Operation response = future.get(); 670 * } 671 * }</pre> 672 */ createWorkflowCallable()673 public final UnaryCallable<CreateWorkflowRequest, Operation> createWorkflowCallable() { 674 return stub.createWorkflowCallable(); 675 } 676 677 // AUTO-GENERATED DOCUMENTATION AND METHOD. 678 /** 679 * Deletes a workflow with the specified name. This method also cancels and deletes all running 680 * executions of the workflow. 681 * 682 * <p>Sample code: 683 * 684 * <pre>{@code 685 * // This snippet has been automatically generated and should be regarded as a code template only. 686 * // It will require modifications to work: 687 * // - It may require correct/in-range values for request initialization. 688 * // - It may require specifying regional endpoints when creating the service client as shown in 689 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 690 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 691 * WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 692 * workflowsClient.deleteWorkflowAsync(name).get(); 693 * } 694 * }</pre> 695 * 696 * @param name Required. Name of the workflow to be deleted. Format: 697 * projects/{project}/locations/{location}/workflows/{workflow} 698 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 699 */ deleteWorkflowAsync(WorkflowName name)700 public final OperationFuture<Empty, OperationMetadata> deleteWorkflowAsync(WorkflowName name) { 701 DeleteWorkflowRequest request = 702 DeleteWorkflowRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 703 return deleteWorkflowAsync(request); 704 } 705 706 // AUTO-GENERATED DOCUMENTATION AND METHOD. 707 /** 708 * Deletes a workflow with the specified name. This method also cancels and deletes all running 709 * executions of the workflow. 710 * 711 * <p>Sample code: 712 * 713 * <pre>{@code 714 * // This snippet has been automatically generated and should be regarded as a code template only. 715 * // It will require modifications to work: 716 * // - It may require correct/in-range values for request initialization. 717 * // - It may require specifying regional endpoints when creating the service client as shown in 718 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 719 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 720 * String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); 721 * workflowsClient.deleteWorkflowAsync(name).get(); 722 * } 723 * }</pre> 724 * 725 * @param name Required. Name of the workflow to be deleted. Format: 726 * projects/{project}/locations/{location}/workflows/{workflow} 727 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 728 */ deleteWorkflowAsync(String name)729 public final OperationFuture<Empty, OperationMetadata> deleteWorkflowAsync(String name) { 730 DeleteWorkflowRequest request = DeleteWorkflowRequest.newBuilder().setName(name).build(); 731 return deleteWorkflowAsync(request); 732 } 733 734 // AUTO-GENERATED DOCUMENTATION AND METHOD. 735 /** 736 * Deletes a workflow with the specified name. This method also cancels and deletes all running 737 * executions of the workflow. 738 * 739 * <p>Sample code: 740 * 741 * <pre>{@code 742 * // This snippet has been automatically generated and should be regarded as a code template only. 743 * // It will require modifications to work: 744 * // - It may require correct/in-range values for request initialization. 745 * // - It may require specifying regional endpoints when creating the service client as shown in 746 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 747 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 748 * DeleteWorkflowRequest request = 749 * DeleteWorkflowRequest.newBuilder() 750 * .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 751 * .build(); 752 * workflowsClient.deleteWorkflowAsync(request).get(); 753 * } 754 * }</pre> 755 * 756 * @param request The request object containing all of the parameters for the API call. 757 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 758 */ deleteWorkflowAsync( DeleteWorkflowRequest request)759 public final OperationFuture<Empty, OperationMetadata> deleteWorkflowAsync( 760 DeleteWorkflowRequest request) { 761 return deleteWorkflowOperationCallable().futureCall(request); 762 } 763 764 // AUTO-GENERATED DOCUMENTATION AND METHOD. 765 /** 766 * Deletes a workflow with the specified name. This method also cancels and deletes all running 767 * executions of the workflow. 768 * 769 * <p>Sample code: 770 * 771 * <pre>{@code 772 * // This snippet has been automatically generated and should be regarded as a code template only. 773 * // It will require modifications to work: 774 * // - It may require correct/in-range values for request initialization. 775 * // - It may require specifying regional endpoints when creating the service client as shown in 776 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 777 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 778 * DeleteWorkflowRequest request = 779 * DeleteWorkflowRequest.newBuilder() 780 * .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 781 * .build(); 782 * OperationFuture<Empty, OperationMetadata> future = 783 * workflowsClient.deleteWorkflowOperationCallable().futureCall(request); 784 * // Do something. 785 * future.get(); 786 * } 787 * }</pre> 788 */ 789 public final OperationCallable<DeleteWorkflowRequest, Empty, OperationMetadata> deleteWorkflowOperationCallable()790 deleteWorkflowOperationCallable() { 791 return stub.deleteWorkflowOperationCallable(); 792 } 793 794 // AUTO-GENERATED DOCUMENTATION AND METHOD. 795 /** 796 * Deletes a workflow with the specified name. This method also cancels and deletes all running 797 * executions of the workflow. 798 * 799 * <p>Sample code: 800 * 801 * <pre>{@code 802 * // This snippet has been automatically generated and should be regarded as a code template only. 803 * // It will require modifications to work: 804 * // - It may require correct/in-range values for request initialization. 805 * // - It may require specifying regional endpoints when creating the service client as shown in 806 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 807 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 808 * DeleteWorkflowRequest request = 809 * DeleteWorkflowRequest.newBuilder() 810 * .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 811 * .build(); 812 * ApiFuture<Operation> future = workflowsClient.deleteWorkflowCallable().futureCall(request); 813 * // Do something. 814 * future.get(); 815 * } 816 * }</pre> 817 */ deleteWorkflowCallable()818 public final UnaryCallable<DeleteWorkflowRequest, Operation> deleteWorkflowCallable() { 819 return stub.deleteWorkflowCallable(); 820 } 821 822 // AUTO-GENERATED DOCUMENTATION AND METHOD. 823 /** 824 * Updates an existing workflow. Running this method has no impact on already running executions 825 * of the workflow. A new revision of the workflow may be created as a result of a successful 826 * update operation. In that case, such revision will be used in new workflow executions. 827 * 828 * <p>Sample code: 829 * 830 * <pre>{@code 831 * // This snippet has been automatically generated and should be regarded as a code template only. 832 * // It will require modifications to work: 833 * // - It may require correct/in-range values for request initialization. 834 * // - It may require specifying regional endpoints when creating the service client as shown in 835 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 836 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 837 * Workflow workflow = Workflow.newBuilder().build(); 838 * FieldMask updateMask = FieldMask.newBuilder().build(); 839 * Workflow response = workflowsClient.updateWorkflowAsync(workflow, updateMask).get(); 840 * } 841 * }</pre> 842 * 843 * @param workflow Required. Workflow to be updated. 844 * @param updateMask List of fields to be updated. If not present, the entire workflow will be 845 * updated. 846 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 847 */ updateWorkflowAsync( Workflow workflow, FieldMask updateMask)848 public final OperationFuture<Workflow, OperationMetadata> updateWorkflowAsync( 849 Workflow workflow, FieldMask updateMask) { 850 UpdateWorkflowRequest request = 851 UpdateWorkflowRequest.newBuilder().setWorkflow(workflow).setUpdateMask(updateMask).build(); 852 return updateWorkflowAsync(request); 853 } 854 855 // AUTO-GENERATED DOCUMENTATION AND METHOD. 856 /** 857 * Updates an existing workflow. Running this method has no impact on already running executions 858 * of the workflow. A new revision of the workflow may be created as a result of a successful 859 * update operation. In that case, such revision will be used in new workflow executions. 860 * 861 * <p>Sample code: 862 * 863 * <pre>{@code 864 * // This snippet has been automatically generated and should be regarded as a code template only. 865 * // It will require modifications to work: 866 * // - It may require correct/in-range values for request initialization. 867 * // - It may require specifying regional endpoints when creating the service client as shown in 868 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 869 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 870 * UpdateWorkflowRequest request = 871 * UpdateWorkflowRequest.newBuilder() 872 * .setWorkflow(Workflow.newBuilder().build()) 873 * .setUpdateMask(FieldMask.newBuilder().build()) 874 * .build(); 875 * Workflow response = workflowsClient.updateWorkflowAsync(request).get(); 876 * } 877 * }</pre> 878 * 879 * @param request The request object containing all of the parameters for the API call. 880 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 881 */ updateWorkflowAsync( UpdateWorkflowRequest request)882 public final OperationFuture<Workflow, OperationMetadata> updateWorkflowAsync( 883 UpdateWorkflowRequest request) { 884 return updateWorkflowOperationCallable().futureCall(request); 885 } 886 887 // AUTO-GENERATED DOCUMENTATION AND METHOD. 888 /** 889 * Updates an existing workflow. Running this method has no impact on already running executions 890 * of the workflow. A new revision of the workflow may be created as a result of a successful 891 * update operation. In that case, such revision will be used in new workflow executions. 892 * 893 * <p>Sample code: 894 * 895 * <pre>{@code 896 * // This snippet has been automatically generated and should be regarded as a code template only. 897 * // It will require modifications to work: 898 * // - It may require correct/in-range values for request initialization. 899 * // - It may require specifying regional endpoints when creating the service client as shown in 900 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 901 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 902 * UpdateWorkflowRequest request = 903 * UpdateWorkflowRequest.newBuilder() 904 * .setWorkflow(Workflow.newBuilder().build()) 905 * .setUpdateMask(FieldMask.newBuilder().build()) 906 * .build(); 907 * OperationFuture<Workflow, OperationMetadata> future = 908 * workflowsClient.updateWorkflowOperationCallable().futureCall(request); 909 * // Do something. 910 * Workflow response = future.get(); 911 * } 912 * }</pre> 913 */ 914 public final OperationCallable<UpdateWorkflowRequest, Workflow, OperationMetadata> updateWorkflowOperationCallable()915 updateWorkflowOperationCallable() { 916 return stub.updateWorkflowOperationCallable(); 917 } 918 919 // AUTO-GENERATED DOCUMENTATION AND METHOD. 920 /** 921 * Updates an existing workflow. Running this method has no impact on already running executions 922 * of the workflow. A new revision of the workflow may be created as a result of a successful 923 * update operation. In that case, such revision will be used in new workflow executions. 924 * 925 * <p>Sample code: 926 * 927 * <pre>{@code 928 * // This snippet has been automatically generated and should be regarded as a code template only. 929 * // It will require modifications to work: 930 * // - It may require correct/in-range values for request initialization. 931 * // - It may require specifying regional endpoints when creating the service client as shown in 932 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 933 * try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { 934 * UpdateWorkflowRequest request = 935 * UpdateWorkflowRequest.newBuilder() 936 * .setWorkflow(Workflow.newBuilder().build()) 937 * .setUpdateMask(FieldMask.newBuilder().build()) 938 * .build(); 939 * ApiFuture<Operation> future = workflowsClient.updateWorkflowCallable().futureCall(request); 940 * // Do something. 941 * Operation response = future.get(); 942 * } 943 * }</pre> 944 */ updateWorkflowCallable()945 public final UnaryCallable<UpdateWorkflowRequest, Operation> updateWorkflowCallable() { 946 return stub.updateWorkflowCallable(); 947 } 948 949 @Override close()950 public final void close() { 951 stub.close(); 952 } 953 954 @Override shutdown()955 public void shutdown() { 956 stub.shutdown(); 957 } 958 959 @Override isShutdown()960 public boolean isShutdown() { 961 return stub.isShutdown(); 962 } 963 964 @Override isTerminated()965 public boolean isTerminated() { 966 return stub.isTerminated(); 967 } 968 969 @Override shutdownNow()970 public void shutdownNow() { 971 stub.shutdownNow(); 972 } 973 974 @Override awaitTermination(long duration, TimeUnit unit)975 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 976 return stub.awaitTermination(duration, unit); 977 } 978 979 public static class ListWorkflowsPagedResponse 980 extends AbstractPagedListResponse< 981 ListWorkflowsRequest, 982 ListWorkflowsResponse, 983 Workflow, 984 ListWorkflowsPage, 985 ListWorkflowsFixedSizeCollection> { 986 createAsync( PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, ApiFuture<ListWorkflowsResponse> futureResponse)987 public static ApiFuture<ListWorkflowsPagedResponse> createAsync( 988 PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, 989 ApiFuture<ListWorkflowsResponse> futureResponse) { 990 ApiFuture<ListWorkflowsPage> futurePage = 991 ListWorkflowsPage.createEmptyPage().createPageAsync(context, futureResponse); 992 return ApiFutures.transform( 993 futurePage, 994 input -> new ListWorkflowsPagedResponse(input), 995 MoreExecutors.directExecutor()); 996 } 997 ListWorkflowsPagedResponse(ListWorkflowsPage page)998 private ListWorkflowsPagedResponse(ListWorkflowsPage page) { 999 super(page, ListWorkflowsFixedSizeCollection.createEmptyCollection()); 1000 } 1001 } 1002 1003 public static class ListWorkflowsPage 1004 extends AbstractPage< 1005 ListWorkflowsRequest, ListWorkflowsResponse, Workflow, ListWorkflowsPage> { 1006 ListWorkflowsPage( PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, ListWorkflowsResponse response)1007 private ListWorkflowsPage( 1008 PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, 1009 ListWorkflowsResponse response) { 1010 super(context, response); 1011 } 1012 createEmptyPage()1013 private static ListWorkflowsPage createEmptyPage() { 1014 return new ListWorkflowsPage(null, null); 1015 } 1016 1017 @Override createPage( PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, ListWorkflowsResponse response)1018 protected ListWorkflowsPage createPage( 1019 PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, 1020 ListWorkflowsResponse response) { 1021 return new ListWorkflowsPage(context, response); 1022 } 1023 1024 @Override createPageAsync( PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, ApiFuture<ListWorkflowsResponse> futureResponse)1025 public ApiFuture<ListWorkflowsPage> createPageAsync( 1026 PageContext<ListWorkflowsRequest, ListWorkflowsResponse, Workflow> context, 1027 ApiFuture<ListWorkflowsResponse> futureResponse) { 1028 return super.createPageAsync(context, futureResponse); 1029 } 1030 } 1031 1032 public static class ListWorkflowsFixedSizeCollection 1033 extends AbstractFixedSizeCollection< 1034 ListWorkflowsRequest, 1035 ListWorkflowsResponse, 1036 Workflow, 1037 ListWorkflowsPage, 1038 ListWorkflowsFixedSizeCollection> { 1039 ListWorkflowsFixedSizeCollection(List<ListWorkflowsPage> pages, int collectionSize)1040 private ListWorkflowsFixedSizeCollection(List<ListWorkflowsPage> pages, int collectionSize) { 1041 super(pages, collectionSize); 1042 } 1043 createEmptyCollection()1044 private static ListWorkflowsFixedSizeCollection createEmptyCollection() { 1045 return new ListWorkflowsFixedSizeCollection(null, 0); 1046 } 1047 1048 @Override createCollection( List<ListWorkflowsPage> pages, int collectionSize)1049 protected ListWorkflowsFixedSizeCollection createCollection( 1050 List<ListWorkflowsPage> pages, int collectionSize) { 1051 return new ListWorkflowsFixedSizeCollection(pages, collectionSize); 1052 } 1053 } 1054 } 1055