diff --git a/google-cloud-workflows/pom.xml b/google-cloud-workflows/pom.xml index b095980b..6e7513aa 100644 --- a/google-cloud-workflows/pom.xml +++ b/google-cloud-workflows/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -86,12 +90,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsClient.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsClient.java index 70ce92e6..a15206dd 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsClient.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsClient.java @@ -20,6 +20,7 @@ import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -31,7 +32,6 @@ import com.google.cloud.workflows.v1.stub.WorkflowsStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -104,13 +104,28 @@ * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * WorkflowsSettings workflowsSettings =
+ *     WorkflowsSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             WorkflowsSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class WorkflowsClient implements BackgroundResource { private final WorkflowsSettings settings; private final WorkflowsStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of WorkflowsClient with default settings. */ public static final WorkflowsClient create() throws IOException { @@ -129,7 +144,6 @@ public static final WorkflowsClient create(WorkflowsSettings settings) throws IO * Constructs an instance of WorkflowsClient, using the given stub for making calls. This is for * advanced usage - prefer using create(WorkflowsSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final WorkflowsClient create(WorkflowsStub stub) { return new WorkflowsClient(stub); } @@ -141,21 +155,23 @@ public static final WorkflowsClient create(WorkflowsStub stub) { protected WorkflowsClient(WorkflowsSettings settings) throws IOException { this.settings = settings; this.stub = ((WorkflowsStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected WorkflowsClient(WorkflowsStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final WorkflowsSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public WorkflowsStub getStub() { return stub; } @@ -164,10 +180,19 @@ public WorkflowsStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists Workflows in a given project and location. The default order is not specified. @@ -305,7 +330,7 @@ public final ListWorkflowsPagedResponse listWorkflows(ListWorkflowsRequest reque * .build(); * while (true) { * ListWorkflowsResponse response = workflowsClient.listWorkflowsCallable().call(request); - * for (Workflow element : response.getResponsesList()) { + * for (Workflow element : response.getWorkflowsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsSettings.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsSettings.java index b941005a..5d2e664a 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsSettings.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/WorkflowsSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -141,11 +142,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return WorkflowsStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return WorkflowsStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return WorkflowsStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return WorkflowsStubSettings.defaultTransportChannelProvider(); } @@ -155,11 +163,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return WorkflowsStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -197,6 +211,11 @@ private static Builder createDefault() { return new Builder(WorkflowsStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(WorkflowsStubSettings.newHttpJsonBuilder()); + } + public WorkflowsStubSettings.Builder getStubSettingsBuilder() { return ((WorkflowsStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsCallableFactory.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsCallableFactory.java new file mode 100644 index 00000000..dbed8e36 --- /dev/null +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Workflows service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonWorkflowsCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsStub.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsStub.java new file mode 100644 index 00000000..51bd7f2a --- /dev/null +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/HttpJsonWorkflowsStub.java @@ -0,0 +1,483 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.stub; + +import static com.google.cloud.workflows.v1.WorkflowsClient.ListWorkflowsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.workflows.v1.CreateWorkflowRequest; +import com.google.cloud.workflows.v1.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1.GetWorkflowRequest; +import com.google.cloud.workflows.v1.ListWorkflowsRequest; +import com.google.cloud.workflows.v1.ListWorkflowsResponse; +import com.google.cloud.workflows.v1.OperationMetadata; +import com.google.cloud.workflows.v1.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Workflows service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonWorkflowsStub extends WorkflowsStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Workflow.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listWorkflowsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1.Workflows/ListWorkflows") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/workflows", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListWorkflowsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1.Workflows/GetWorkflow") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Workflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1.Workflows/CreateWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/workflows", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "workflowId", request.getWorkflowId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workflow", request.getWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1.Workflows/DeleteWorkflow") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1.Workflows/UpdateWorkflow") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{workflow.name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "workflow.name", request.getWorkflow().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workflow", request.getWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listWorkflowsCallable; + private final UnaryCallable + listWorkflowsPagedCallable; + private final UnaryCallable getWorkflowCallable; + private final UnaryCallable createWorkflowCallable; + private final OperationCallable + createWorkflowOperationCallable; + private final UnaryCallable deleteWorkflowCallable; + private final OperationCallable + deleteWorkflowOperationCallable; + private final UnaryCallable updateWorkflowCallable; + private final OperationCallable + updateWorkflowOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonWorkflowsStub create(WorkflowsStubSettings settings) + throws IOException { + return new HttpJsonWorkflowsStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonWorkflowsStub create(ClientContext clientContext) throws IOException { + return new HttpJsonWorkflowsStub( + WorkflowsStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonWorkflowsStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonWorkflowsStub( + WorkflowsStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonWorkflowsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonWorkflowsStub(WorkflowsStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonWorkflowsCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonWorkflowsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonWorkflowsStub( + WorkflowsStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listWorkflowsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listWorkflowsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listWorkflowsCallable = + callableFactory.createUnaryCallable( + listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext); + this.listWorkflowsPagedCallable = + callableFactory.createPagedCallable( + listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext); + this.getWorkflowCallable = + callableFactory.createUnaryCallable( + getWorkflowTransportSettings, settings.getWorkflowSettings(), clientContext); + this.createWorkflowCallable = + callableFactory.createUnaryCallable( + createWorkflowTransportSettings, settings.createWorkflowSettings(), clientContext); + this.createWorkflowOperationCallable = + callableFactory.createOperationCallable( + createWorkflowTransportSettings, + settings.createWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteWorkflowCallable = + callableFactory.createUnaryCallable( + deleteWorkflowTransportSettings, settings.deleteWorkflowSettings(), clientContext); + this.deleteWorkflowOperationCallable = + callableFactory.createOperationCallable( + deleteWorkflowTransportSettings, + settings.deleteWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateWorkflowCallable = + callableFactory.createUnaryCallable( + updateWorkflowTransportSettings, settings.updateWorkflowSettings(), clientContext); + this.updateWorkflowOperationCallable = + callableFactory.createOperationCallable( + updateWorkflowTransportSettings, + settings.updateWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listWorkflowsMethodDescriptor); + methodDescriptors.add(getWorkflowMethodDescriptor); + methodDescriptors.add(createWorkflowMethodDescriptor); + methodDescriptors.add(deleteWorkflowMethodDescriptor); + methodDescriptors.add(updateWorkflowMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listWorkflowsCallable() { + return listWorkflowsCallable; + } + + @Override + public UnaryCallable + listWorkflowsPagedCallable() { + return listWorkflowsPagedCallable; + } + + @Override + public UnaryCallable getWorkflowCallable() { + return getWorkflowCallable; + } + + @Override + public UnaryCallable createWorkflowCallable() { + return createWorkflowCallable; + } + + @Override + public OperationCallable + createWorkflowOperationCallable() { + return createWorkflowOperationCallable; + } + + @Override + public UnaryCallable deleteWorkflowCallable() { + return deleteWorkflowCallable; + } + + @Override + public OperationCallable + deleteWorkflowOperationCallable() { + return deleteWorkflowOperationCallable; + } + + @Override + public UnaryCallable updateWorkflowCallable() { + return updateWorkflowCallable; + } + + @Override + public OperationCallable + updateWorkflowOperationCallable() { + return updateWorkflowOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStub.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStub.java index 186534f4..6eef508d 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStub.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStub.java @@ -44,7 +44,11 @@ public abstract class WorkflowsStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStubSettings.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStubSettings.java index 23f33e67..1b51a2ed 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStubSettings.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1/stub/WorkflowsStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -213,13 +216,17 @@ public UnaryCallSettings updateWorkflowSetting return updateWorkflowOperationSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public WorkflowsStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcWorkflowsStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonWorkflowsStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -252,29 +259,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(WorkflowsStubSettings.class)) .setTransportToken( GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(WorkflowsStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return WorkflowsStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -397,6 +429,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listWorkflowsSettings() diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsClient.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsClient.java index 5832a287..e0108de4 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsClient.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsClient.java @@ -20,6 +20,7 @@ import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -31,7 +32,6 @@ import com.google.cloud.workflows.v1beta.stub.WorkflowsStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -104,6 +104,20 @@ * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * WorkflowsSettings workflowsSettings =
+ *     WorkflowsSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             WorkflowsSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -111,7 +125,8 @@ public class WorkflowsClient implements BackgroundResource { private final WorkflowsSettings settings; private final WorkflowsStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of WorkflowsClient with default settings. */ public static final WorkflowsClient create() throws IOException { @@ -130,7 +145,6 @@ public static final WorkflowsClient create(WorkflowsSettings settings) throws IO * Constructs an instance of WorkflowsClient, using the given stub for making calls. This is for * advanced usage - prefer using create(WorkflowsSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final WorkflowsClient create(WorkflowsStub stub) { return new WorkflowsClient(stub); } @@ -142,21 +156,23 @@ public static final WorkflowsClient create(WorkflowsStub stub) { protected WorkflowsClient(WorkflowsSettings settings) throws IOException { this.settings = settings; this.stub = ((WorkflowsStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected WorkflowsClient(WorkflowsStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final WorkflowsSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public WorkflowsStub getStub() { return stub; } @@ -165,10 +181,19 @@ public WorkflowsStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists Workflows in a given project and location. The default order is not specified. @@ -306,7 +331,7 @@ public final ListWorkflowsPagedResponse listWorkflows(ListWorkflowsRequest reque * .build(); * while (true) { * ListWorkflowsResponse response = workflowsClient.listWorkflowsCallable().call(request); - * for (Workflow element : response.getResponsesList()) { + * for (Workflow element : response.getWorkflowsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsSettings.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsSettings.java index c2b32290..b6fab433 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsSettings.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/WorkflowsSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -142,11 +143,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return WorkflowsStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return WorkflowsStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return WorkflowsStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return WorkflowsStubSettings.defaultTransportChannelProvider(); } @@ -156,11 +164,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return WorkflowsStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -198,6 +212,11 @@ private static Builder createDefault() { return new Builder(WorkflowsStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(WorkflowsStubSettings.newHttpJsonBuilder()); + } + public WorkflowsStubSettings.Builder getStubSettingsBuilder() { return ((WorkflowsStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsCallableFactory.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsCallableFactory.java new file mode 100644 index 00000000..7f5af182 --- /dev/null +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Workflows service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonWorkflowsCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsStub.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsStub.java new file mode 100644 index 00000000..346d2227 --- /dev/null +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/HttpJsonWorkflowsStub.java @@ -0,0 +1,483 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.stub; + +import static com.google.cloud.workflows.v1beta.WorkflowsClient.ListWorkflowsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.workflows.v1beta.CreateWorkflowRequest; +import com.google.cloud.workflows.v1beta.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1beta.GetWorkflowRequest; +import com.google.cloud.workflows.v1beta.ListWorkflowsRequest; +import com.google.cloud.workflows.v1beta.ListWorkflowsResponse; +import com.google.cloud.workflows.v1beta.OperationMetadata; +import com.google.cloud.workflows.v1beta.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Workflows service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonWorkflowsStub extends WorkflowsStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(Workflow.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listWorkflowsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1beta.Workflows/ListWorkflows") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/workflows", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListWorkflowsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1beta.Workflows/GetWorkflow") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Workflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1beta.Workflows/CreateWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/workflows", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "workflowId", request.getWorkflowId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workflow", request.getWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1beta.Workflows/DeleteWorkflow") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.workflows.v1beta.Workflows/UpdateWorkflow") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{workflow.name=projects/*/locations/*/workflows/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "workflow.name", request.getWorkflow().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workflow", request.getWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateWorkflowRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listWorkflowsCallable; + private final UnaryCallable + listWorkflowsPagedCallable; + private final UnaryCallable getWorkflowCallable; + private final UnaryCallable createWorkflowCallable; + private final OperationCallable + createWorkflowOperationCallable; + private final UnaryCallable deleteWorkflowCallable; + private final OperationCallable + deleteWorkflowOperationCallable; + private final UnaryCallable updateWorkflowCallable; + private final OperationCallable + updateWorkflowOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonWorkflowsStub create(WorkflowsStubSettings settings) + throws IOException { + return new HttpJsonWorkflowsStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonWorkflowsStub create(ClientContext clientContext) throws IOException { + return new HttpJsonWorkflowsStub( + WorkflowsStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonWorkflowsStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonWorkflowsStub( + WorkflowsStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonWorkflowsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonWorkflowsStub(WorkflowsStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonWorkflowsCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonWorkflowsStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonWorkflowsStub( + WorkflowsStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listWorkflowsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listWorkflowsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listWorkflowsCallable = + callableFactory.createUnaryCallable( + listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext); + this.listWorkflowsPagedCallable = + callableFactory.createPagedCallable( + listWorkflowsTransportSettings, settings.listWorkflowsSettings(), clientContext); + this.getWorkflowCallable = + callableFactory.createUnaryCallable( + getWorkflowTransportSettings, settings.getWorkflowSettings(), clientContext); + this.createWorkflowCallable = + callableFactory.createUnaryCallable( + createWorkflowTransportSettings, settings.createWorkflowSettings(), clientContext); + this.createWorkflowOperationCallable = + callableFactory.createOperationCallable( + createWorkflowTransportSettings, + settings.createWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteWorkflowCallable = + callableFactory.createUnaryCallable( + deleteWorkflowTransportSettings, settings.deleteWorkflowSettings(), clientContext); + this.deleteWorkflowOperationCallable = + callableFactory.createOperationCallable( + deleteWorkflowTransportSettings, + settings.deleteWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateWorkflowCallable = + callableFactory.createUnaryCallable( + updateWorkflowTransportSettings, settings.updateWorkflowSettings(), clientContext); + this.updateWorkflowOperationCallable = + callableFactory.createOperationCallable( + updateWorkflowTransportSettings, + settings.updateWorkflowOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listWorkflowsMethodDescriptor); + methodDescriptors.add(getWorkflowMethodDescriptor); + methodDescriptors.add(createWorkflowMethodDescriptor); + methodDescriptors.add(deleteWorkflowMethodDescriptor); + methodDescriptors.add(updateWorkflowMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listWorkflowsCallable() { + return listWorkflowsCallable; + } + + @Override + public UnaryCallable + listWorkflowsPagedCallable() { + return listWorkflowsPagedCallable; + } + + @Override + public UnaryCallable getWorkflowCallable() { + return getWorkflowCallable; + } + + @Override + public UnaryCallable createWorkflowCallable() { + return createWorkflowCallable; + } + + @Override + public OperationCallable + createWorkflowOperationCallable() { + return createWorkflowOperationCallable; + } + + @Override + public UnaryCallable deleteWorkflowCallable() { + return deleteWorkflowCallable; + } + + @Override + public OperationCallable + deleteWorkflowOperationCallable() { + return deleteWorkflowOperationCallable; + } + + @Override + public UnaryCallable updateWorkflowCallable() { + return updateWorkflowCallable; + } + + @Override + public OperationCallable + updateWorkflowOperationCallable() { + return updateWorkflowOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStub.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStub.java index 8031bbde..5d7f5288 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStub.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStub.java @@ -46,7 +46,11 @@ public abstract class WorkflowsStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStubSettings.java b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStubSettings.java index 47052d46..272c1749 100644 --- a/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStubSettings.java +++ b/google-cloud-workflows/src/main/java/com/google/cloud/workflows/v1beta/stub/WorkflowsStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -214,13 +217,17 @@ public UnaryCallSettings updateWorkflowSetting return updateWorkflowOperationSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public WorkflowsStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcWorkflowsStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonWorkflowsStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -253,29 +260,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(WorkflowsStubSettings.class)) .setTransportToken( GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(WorkflowsStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return WorkflowsStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -398,6 +430,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listWorkflowsSettings() diff --git a/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1/WorkflowsClientHttpJsonTest.java b/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1/WorkflowsClientHttpJsonTest.java new file mode 100644 index 00000000..f7b150ce --- /dev/null +++ b/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1/WorkflowsClientHttpJsonTest.java @@ -0,0 +1,573 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1; + +import static com.google.cloud.workflows.v1.WorkflowsClient.ListWorkflowsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.workflows.v1.stub.HttpJsonWorkflowsStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class WorkflowsClientHttpJsonTest { + private static MockHttpService mockService; + private static WorkflowsClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonWorkflowsStub.getMethodDescriptors(), WorkflowsSettings.getDefaultEndpoint()); + WorkflowsSettings settings = + WorkflowsSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + WorkflowsSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = WorkflowsClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listWorkflowsTest() throws Exception { + Workflow responsesElement = Workflow.newBuilder().build(); + ListWorkflowsResponse expectedResponse = + ListWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListWorkflowsPagedResponse pagedListResponse = client.listWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkflowsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listWorkflowsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkflowsTest2() throws Exception { + Workflow responsesElement = Workflow.newBuilder().build(); + ListWorkflowsResponse expectedResponse = + ListWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListWorkflowsPagedResponse pagedListResponse = client.listWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkflowsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listWorkflowsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + mockService.addResponse(expectedResponse); + + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + Workflow actualResponse = client.getWorkflow(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.getWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkflowTest2() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + Workflow actualResponse = client.getWorkflow(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.getWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + + Workflow actualResponse = client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createWorkflowTest2() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + + Workflow actualResponse = client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.deleteWorkflowAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.deleteWorkflowAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.deleteWorkflowAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.deleteWorkflowAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Workflow workflow = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Workflow actualResponse = client.updateWorkflowAsync(workflow, updateMask).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Workflow workflow = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateWorkflowAsync(workflow, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1beta/WorkflowsClientHttpJsonTest.java b/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1beta/WorkflowsClientHttpJsonTest.java new file mode 100644 index 00000000..3487acdc --- /dev/null +++ b/google-cloud-workflows/src/test/java/com/google/cloud/workflows/v1beta/WorkflowsClientHttpJsonTest.java @@ -0,0 +1,573 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta; + +import static com.google.cloud.workflows.v1beta.WorkflowsClient.ListWorkflowsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.workflows.v1beta.stub.HttpJsonWorkflowsStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class WorkflowsClientHttpJsonTest { + private static MockHttpService mockService; + private static WorkflowsClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonWorkflowsStub.getMethodDescriptors(), WorkflowsSettings.getDefaultEndpoint()); + WorkflowsSettings settings = + WorkflowsSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + WorkflowsSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = WorkflowsClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listWorkflowsTest() throws Exception { + Workflow responsesElement = Workflow.newBuilder().build(); + ListWorkflowsResponse expectedResponse = + ListWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListWorkflowsPagedResponse pagedListResponse = client.listWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkflowsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listWorkflowsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkflowsTest2() throws Exception { + Workflow responsesElement = Workflow.newBuilder().build(); + ListWorkflowsResponse expectedResponse = + ListWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListWorkflowsPagedResponse pagedListResponse = client.listWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkflowsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listWorkflowsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + mockService.addResponse(expectedResponse); + + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + Workflow actualResponse = client.getWorkflow(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.getWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkflowTest2() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + Workflow actualResponse = client.getWorkflow(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.getWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + + Workflow actualResponse = client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createWorkflowTest2() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + + Workflow actualResponse = client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + client.createWorkflowAsync(parent, workflow, workflowId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.deleteWorkflowAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.deleteWorkflowAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.deleteWorkflowAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.deleteWorkflowAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateWorkflowTest() throws Exception { + Workflow expectedResponse = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateWorkflowTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Workflow workflow = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Workflow actualResponse = client.updateWorkflowAsync(workflow, updateMask).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Workflow workflow = + Workflow.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDescription("description-1724546052") + .setRevisionId("revisionId-1507445162") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setRevisionCreateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setServiceAccount("serviceAccount1079137720") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateWorkflowAsync(workflow, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..32eac989 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.stub.samples; + +// [START workflows_v1_generated_workflowsstubsettings_getworkflow_sync] +import com.google.cloud.workflows.v1.stub.WorkflowsStubSettings; +import java.time.Duration; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsStubSettings.Builder workflowsSettingsBuilder = WorkflowsStubSettings.newBuilder(); + workflowsSettingsBuilder + .getWorkflowSettings() + .setRetrySettings( + workflowsSettingsBuilder + .getWorkflowSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + WorkflowsStubSettings workflowsSettings = workflowsSettingsBuilder.build(); + } +} +// [END workflows_v1_generated_workflowsstubsettings_getworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..7ac5c218 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.cloud.workflows.v1.WorkflowsSettings; +import com.google.cloud.workflows.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1_generated_workflowsclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..bb008399 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_create_setcredentialsprovider1_sync] +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.cloud.workflows.v1.WorkflowsSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder() + .setTransportChannelProvider( + WorkflowsSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1_generated_workflowsclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..9c53e49f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_create_setendpoint_sync] +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.cloud.workflows.v1.WorkflowsSettings; +import com.google.cloud.workflows.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder().setEndpoint(myEndpoint).build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1_generated_workflowsclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflow.java new file mode 100644 index 00000000..94d50a3c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflow.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_createworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1.CreateWorkflowRequest; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.longrunning.Operation; + +public class AsyncCreateWorkflow { + + public static void main(String[] args) throws Exception { + asyncCreateWorkflow(); + } + + public static void asyncCreateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + ApiFuture future = workflowsClient.createWorkflowCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_createworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java new file mode 100644 index 00000000..901fdacb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_createworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1.CreateWorkflowRequest; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.OperationMetadata; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class AsyncCreateWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncCreateWorkflowLRO(); + } + + public static void asyncCreateWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + OperationFuture future = + workflowsClient.createWorkflowOperationCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_createworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflow.java new file mode 100644 index 00000000..f8665534 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_createworkflow_sync] +import com.google.cloud.workflows.v1.CreateWorkflowRequest; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncCreateWorkflow { + + public static void main(String[] args) throws Exception { + syncCreateWorkflow(); + } + + public static void syncCreateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + Workflow response = workflowsClient.createWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_createworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java new file mode 100644 index 00000000..567ced9c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_createworkflow_locationnameworkflowstring_sync] +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncCreateWorkflowLocationnameWorkflowString { + + public static void main(String[] args) throws Exception { + syncCreateWorkflowLocationnameWorkflowString(); + } + + public static void syncCreateWorkflowLocationnameWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_createworkflow_locationnameworkflowstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java new file mode 100644 index 00000000..b293f4dc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_createworkflow_stringworkflowstring_sync] +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncCreateWorkflowStringWorkflowString { + + public static void main(String[] args) throws Exception { + syncCreateWorkflowStringWorkflowString(); + } + + public static void syncCreateWorkflowStringWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_createworkflow_stringworkflowstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java new file mode 100644 index 00000000..f7bf0218 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_deleteworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteWorkflow { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkflow(); + } + + public static void asyncDeleteWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + ApiFuture future = workflowsClient.deleteWorkflowCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_deleteworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java new file mode 100644 index 00000000..e6f35070 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_deleteworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1.OperationMetadata; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.Empty; + +public class AsyncDeleteWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkflowLRO(); + } + + public static void asyncDeleteWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + OperationFuture future = + workflowsClient.deleteWorkflowOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_deleteworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java new file mode 100644 index 00000000..2d1ef3f9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_deleteworkflow_sync] +import com.google.cloud.workflows.v1.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflow { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflow(); + } + + public static void syncDeleteWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + workflowsClient.deleteWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_deleteworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java new file mode 100644 index 00000000..53d00d04 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_deleteworkflow_string_sync] +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflowString { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflowString(); + } + + public static void syncDeleteWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); + workflowsClient.deleteWorkflowAsync(name).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_deleteworkflow_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java new file mode 100644 index 00000000..537bc575 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_deleteworkflow_workflowname_sync] +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflowWorkflowname { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflowWorkflowname(); + } + + public static void syncDeleteWorkflowWorkflowname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + workflowsClient.deleteWorkflowAsync(name).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_deleteworkflow_workflowname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/AsyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/AsyncGetWorkflow.java new file mode 100644 index 00000000..e716e195 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/AsyncGetWorkflow.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_getworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1.GetWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class AsyncGetWorkflow { + + public static void main(String[] args) throws Exception { + asyncGetWorkflow(); + } + + public static void asyncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + GetWorkflowRequest request = + GetWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + ApiFuture future = workflowsClient.getWorkflowCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_getworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..c8a068d3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_getworkflow_sync] +import com.google.cloud.workflows.v1.GetWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + GetWorkflowRequest request = + GetWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + Workflow response = workflowsClient.getWorkflow(request); + } + } +} +// [END workflows_v1_generated_workflowsclient_getworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowString.java new file mode 100644 index 00000000..6373327a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_getworkflow_string_sync] +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncGetWorkflowString { + + public static void main(String[] args) throws Exception { + syncGetWorkflowString(); + } + + public static void syncGetWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); + Workflow response = workflowsClient.getWorkflow(name); + } + } +} +// [END workflows_v1_generated_workflowsclient_getworkflow_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java new file mode 100644 index 00000000..bc4357d6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_getworkflow_workflowname_sync] +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowName; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncGetWorkflowWorkflowname { + + public static void main(String[] args) throws Exception { + syncGetWorkflowWorkflowname(); + } + + public static void syncGetWorkflowWorkflowname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + Workflow response = workflowsClient.getWorkflow(name); + } + } +} +// [END workflows_v1_generated_workflowsclient_getworkflow_workflowname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflows.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflows.java new file mode 100644 index 00000000..4cf19ab8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflows.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_listworkflows_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1.ListWorkflowsRequest; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class AsyncListWorkflows { + + public static void main(String[] args) throws Exception { + asyncListWorkflows(); + } + + public static void asyncListWorkflows() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = workflowsClient.listWorkflowsPagedCallable().futureCall(request); + // Do something. + for (Workflow element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1_generated_workflowsclient_listworkflows_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java new file mode 100644 index 00000000..fa4b31aa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_listworkflows_paged_async] +import com.google.cloud.workflows.v1.ListWorkflowsRequest; +import com.google.cloud.workflows.v1.ListWorkflowsResponse; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.common.base.Strings; + +public class AsyncListWorkflowsPaged { + + public static void main(String[] args) throws Exception { + asyncListWorkflowsPaged(); + } + + public static void asyncListWorkflowsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListWorkflowsResponse response = workflowsClient.listWorkflowsCallable().call(request); + for (Workflow element : response.getWorkflowsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END workflows_v1_generated_workflowsclient_listworkflows_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflows.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflows.java new file mode 100644 index 00000000..bf55125e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflows.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_listworkflows_sync] +import com.google.cloud.workflows.v1.ListWorkflowsRequest; +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncListWorkflows { + + public static void main(String[] args) throws Exception { + syncListWorkflows(); + } + + public static void syncListWorkflows() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (Workflow element : workflowsClient.listWorkflows(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1_generated_workflowsclient_listworkflows_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java new file mode 100644 index 00000000..b50bfc25 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_listworkflows_locationname_sync] +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncListWorkflowsLocationname { + + public static void main(String[] args) throws Exception { + syncListWorkflowsLocationname(); + } + + public static void syncListWorkflowsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1_generated_workflowsclient_listworkflows_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsString.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsString.java new file mode 100644 index 00000000..f805cd66 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/listworkflows/SyncListWorkflowsString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_listworkflows_string_sync] +import com.google.cloud.workflows.v1.LocationName; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; + +public class SyncListWorkflowsString { + + public static void main(String[] args) throws Exception { + syncListWorkflowsString(); + } + + public static void syncListWorkflowsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1_generated_workflowsclient_listworkflows_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java new file mode 100644 index 00000000..450cdd06 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_updateworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkflow { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkflow(); + } + + public static void asyncUpdateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = workflowsClient.updateWorkflowCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_updateworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java new file mode 100644 index 00000000..eff1a869 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_updateworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1.OperationMetadata; +import com.google.cloud.workflows.v1.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkflowLRO(); + } + + public static void asyncUpdateWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + OperationFuture future = + workflowsClient.updateWorkflowOperationCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_updateworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflow.java new file mode 100644 index 00000000..be8aaff7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflow.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_updateworkflow_sync] +import com.google.cloud.workflows.v1.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkflow { + + public static void main(String[] args) throws Exception { + syncUpdateWorkflow(); + } + + public static void syncUpdateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Workflow response = workflowsClient.updateWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_updateworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java new file mode 100644 index 00000000..ade87920 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowsclient_updateworkflow_workflowfieldmask_sync] +import com.google.cloud.workflows.v1.Workflow; +import com.google.cloud.workflows.v1.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkflowWorkflowFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateWorkflowWorkflowFieldmask(); + } + + public static void syncUpdateWorkflowWorkflowFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + Workflow workflow = Workflow.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Workflow response = workflowsClient.updateWorkflowAsync(workflow, updateMask).get(); + } + } +} +// [END workflows_v1_generated_workflowsclient_updateworkflow_workflowfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1/workflowssettings/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowssettings/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..5ba1995e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1/workflowssettings/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1.samples; + +// [START workflows_v1_generated_workflowssettings_getworkflow_sync] +import com.google.cloud.workflows.v1.WorkflowsSettings; +import java.time.Duration; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings.Builder workflowsSettingsBuilder = WorkflowsSettings.newBuilder(); + workflowsSettingsBuilder + .getWorkflowSettings() + .setRetrySettings( + workflowsSettingsBuilder + .getWorkflowSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + WorkflowsSettings workflowsSettings = workflowsSettingsBuilder.build(); + } +} +// [END workflows_v1_generated_workflowssettings_getworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..15215a4d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/stub/workflowsstubsettings/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.stub.samples; + +// [START workflows_v1beta_generated_workflowsstubsettings_getworkflow_sync] +import com.google.cloud.workflows.v1beta.stub.WorkflowsStubSettings; +import java.time.Duration; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsStubSettings.Builder workflowsSettingsBuilder = WorkflowsStubSettings.newBuilder(); + workflowsSettingsBuilder + .getWorkflowSettings() + .setRetrySettings( + workflowsSettingsBuilder + .getWorkflowSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + WorkflowsStubSettings workflowsSettings = workflowsSettingsBuilder.build(); + } +} +// [END workflows_v1beta_generated_workflowsstubsettings_getworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..e897b6ce --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.cloud.workflows.v1beta.WorkflowsSettings; +import com.google.cloud.workflows.v1beta.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1beta_generated_workflowsclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..5b8058f9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_create_setcredentialsprovider1_sync] +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.cloud.workflows.v1beta.WorkflowsSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder() + .setTransportChannelProvider( + WorkflowsSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1beta_generated_workflowsclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..12de4da0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_create_setendpoint_sync] +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.cloud.workflows.v1beta.WorkflowsSettings; +import com.google.cloud.workflows.v1beta.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings workflowsSettings = + WorkflowsSettings.newBuilder().setEndpoint(myEndpoint).build(); + WorkflowsClient workflowsClient = WorkflowsClient.create(workflowsSettings); + } +} +// [END workflows_v1beta_generated_workflowsclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflow.java new file mode 100644 index 00000000..75518586 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflow.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_createworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1beta.CreateWorkflowRequest; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.longrunning.Operation; + +public class AsyncCreateWorkflow { + + public static void main(String[] args) throws Exception { + asyncCreateWorkflow(); + } + + public static void asyncCreateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + ApiFuture future = workflowsClient.createWorkflowCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_createworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java new file mode 100644 index 00000000..e6129c7d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/AsyncCreateWorkflowLRO.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_createworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1beta.CreateWorkflowRequest; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.OperationMetadata; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class AsyncCreateWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncCreateWorkflowLRO(); + } + + public static void asyncCreateWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + OperationFuture future = + workflowsClient.createWorkflowOperationCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_createworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflow.java new file mode 100644 index 00000000..ee4748a9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_createworkflow_sync] +import com.google.cloud.workflows.v1beta.CreateWorkflowRequest; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncCreateWorkflow { + + public static void main(String[] args) throws Exception { + syncCreateWorkflow(); + } + + public static void syncCreateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + CreateWorkflowRequest request = + CreateWorkflowRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setWorkflow(Workflow.newBuilder().build()) + .setWorkflowId("workflowId-360387270") + .build(); + Workflow response = workflowsClient.createWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_createworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java new file mode 100644 index 00000000..bd651610 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowLocationnameWorkflowString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_createworkflow_locationnameworkflowstring_sync] +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncCreateWorkflowLocationnameWorkflowString { + + public static void main(String[] args) throws Exception { + syncCreateWorkflowLocationnameWorkflowString(); + } + + public static void syncCreateWorkflowLocationnameWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_createworkflow_locationnameworkflowstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java new file mode 100644 index 00000000..b5d7c966 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/createworkflow/SyncCreateWorkflowStringWorkflowString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_createworkflow_stringworkflowstring_sync] +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncCreateWorkflowStringWorkflowString { + + public static void main(String[] args) throws Exception { + syncCreateWorkflowStringWorkflowString(); + } + + public static void syncCreateWorkflowStringWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Workflow workflow = Workflow.newBuilder().build(); + String workflowId = "workflowId-360387270"; + Workflow response = workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_createworkflow_stringworkflowstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java new file mode 100644 index 00000000..c59d36af --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflow.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_deleteworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1beta.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteWorkflow { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkflow(); + } + + public static void asyncDeleteWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + ApiFuture future = workflowsClient.deleteWorkflowCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_deleteworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java new file mode 100644 index 00000000..f2a0bd65 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/AsyncDeleteWorkflowLRO.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_deleteworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1beta.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1beta.OperationMetadata; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.Empty; + +public class AsyncDeleteWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkflowLRO(); + } + + public static void asyncDeleteWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + OperationFuture future = + workflowsClient.deleteWorkflowOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_deleteworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java new file mode 100644 index 00000000..c0268628 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflow.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_deleteworkflow_sync] +import com.google.cloud.workflows.v1beta.DeleteWorkflowRequest; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflow { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflow(); + } + + public static void syncDeleteWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + DeleteWorkflowRequest request = + DeleteWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + workflowsClient.deleteWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_deleteworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java new file mode 100644 index 00000000..cdc20d06 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_deleteworkflow_string_sync] +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflowString { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflowString(); + } + + public static void syncDeleteWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); + workflowsClient.deleteWorkflowAsync(name).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_deleteworkflow_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java new file mode 100644 index 00000000..3fbf218e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/deleteworkflow/SyncDeleteWorkflowWorkflowname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_deleteworkflow_workflowname_sync] +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.Empty; + +public class SyncDeleteWorkflowWorkflowname { + + public static void main(String[] args) throws Exception { + syncDeleteWorkflowWorkflowname(); + } + + public static void syncDeleteWorkflowWorkflowname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + workflowsClient.deleteWorkflowAsync(name).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_deleteworkflow_workflowname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/AsyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/AsyncGetWorkflow.java new file mode 100644 index 00000000..d6b795f3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/AsyncGetWorkflow.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_getworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1beta.GetWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class AsyncGetWorkflow { + + public static void main(String[] args) throws Exception { + asyncGetWorkflow(); + } + + public static void asyncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + GetWorkflowRequest request = + GetWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + ApiFuture future = workflowsClient.getWorkflowCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_getworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..98668b71 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_getworkflow_sync] +import com.google.cloud.workflows.v1beta.GetWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + GetWorkflowRequest request = + GetWorkflowRequest.newBuilder() + .setName(WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .build(); + Workflow response = workflowsClient.getWorkflow(request); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_getworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowString.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowString.java new file mode 100644 index 00000000..284250d7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_getworkflow_string_sync] +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncGetWorkflowString { + + public static void main(String[] args) throws Exception { + syncGetWorkflowString(); + } + + public static void syncGetWorkflowString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString(); + Workflow response = workflowsClient.getWorkflow(name); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_getworkflow_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java new file mode 100644 index 00000000..0f823c4a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/getworkflow/SyncGetWorkflowWorkflowname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_getworkflow_workflowname_sync] +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowName; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncGetWorkflowWorkflowname { + + public static void main(String[] args) throws Exception { + syncGetWorkflowWorkflowname(); + } + + public static void syncGetWorkflowWorkflowname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + WorkflowName name = WorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + Workflow response = workflowsClient.getWorkflow(name); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_getworkflow_workflowname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflows.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflows.java new file mode 100644 index 00000000..9d29ba06 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflows.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_listworkflows_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1beta.ListWorkflowsRequest; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class AsyncListWorkflows { + + public static void main(String[] args) throws Exception { + asyncListWorkflows(); + } + + public static void asyncListWorkflows() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = workflowsClient.listWorkflowsPagedCallable().futureCall(request); + // Do something. + for (Workflow element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1beta_generated_workflowsclient_listworkflows_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java new file mode 100644 index 00000000..e332da73 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/AsyncListWorkflowsPaged.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_listworkflows_paged_async] +import com.google.cloud.workflows.v1beta.ListWorkflowsRequest; +import com.google.cloud.workflows.v1beta.ListWorkflowsResponse; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.common.base.Strings; + +public class AsyncListWorkflowsPaged { + + public static void main(String[] args) throws Exception { + asyncListWorkflowsPaged(); + } + + public static void asyncListWorkflowsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListWorkflowsResponse response = workflowsClient.listWorkflowsCallable().call(request); + for (Workflow element : response.getWorkflowsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END workflows_v1beta_generated_workflowsclient_listworkflows_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflows.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflows.java new file mode 100644 index 00000000..60508569 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflows.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_listworkflows_sync] +import com.google.cloud.workflows.v1beta.ListWorkflowsRequest; +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncListWorkflows { + + public static void main(String[] args) throws Exception { + syncListWorkflows(); + } + + public static void syncListWorkflows() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + ListWorkflowsRequest request = + ListWorkflowsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (Workflow element : workflowsClient.listWorkflows(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1beta_generated_workflowsclient_listworkflows_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java new file mode 100644 index 00000000..2c7ab091 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsLocationname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_listworkflows_locationname_sync] +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncListWorkflowsLocationname { + + public static void main(String[] args) throws Exception { + syncListWorkflowsLocationname(); + } + + public static void syncListWorkflowsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1beta_generated_workflowsclient_listworkflows_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsString.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsString.java new file mode 100644 index 00000000..b4e9e6f6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/listworkflows/SyncListWorkflowsString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_listworkflows_string_sync] +import com.google.cloud.workflows.v1beta.LocationName; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; + +public class SyncListWorkflowsString { + + public static void main(String[] args) throws Exception { + syncListWorkflowsString(); + } + + public static void syncListWorkflowsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Workflow element : workflowsClient.listWorkflows(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END workflows_v1beta_generated_workflowsclient_listworkflows_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java new file mode 100644 index 00000000..bc4b63e9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflow.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_updateworkflow_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.workflows.v1beta.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.longrunning.Operation; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkflow { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkflow(); + } + + public static void asyncUpdateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = workflowsClient.updateWorkflowCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_updateworkflow_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java new file mode 100644 index 00000000..40a11b42 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/AsyncUpdateWorkflowLRO.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_updateworkflow_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.workflows.v1beta.OperationMetadata; +import com.google.cloud.workflows.v1beta.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkflowLRO { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkflowLRO(); + } + + public static void asyncUpdateWorkflowLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + OperationFuture future = + workflowsClient.updateWorkflowOperationCallable().futureCall(request); + // Do something. + Workflow response = future.get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_updateworkflow_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflow.java new file mode 100644 index 00000000..ceaf3d90 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflow.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_updateworkflow_sync] +import com.google.cloud.workflows.v1beta.UpdateWorkflowRequest; +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkflow { + + public static void main(String[] args) throws Exception { + syncUpdateWorkflow(); + } + + public static void syncUpdateWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + UpdateWorkflowRequest request = + UpdateWorkflowRequest.newBuilder() + .setWorkflow(Workflow.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Workflow response = workflowsClient.updateWorkflowAsync(request).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_updateworkflow_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java new file mode 100644 index 00000000..2527c716 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowsclient/updateworkflow/SyncUpdateWorkflowWorkflowFieldmask.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowsclient_updateworkflow_workflowfieldmask_sync] +import com.google.cloud.workflows.v1beta.Workflow; +import com.google.cloud.workflows.v1beta.WorkflowsClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkflowWorkflowFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateWorkflowWorkflowFieldmask(); + } + + public static void syncUpdateWorkflowWorkflowFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (WorkflowsClient workflowsClient = WorkflowsClient.create()) { + Workflow workflow = Workflow.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Workflow response = workflowsClient.updateWorkflowAsync(workflow, updateMask).get(); + } + } +} +// [END workflows_v1beta_generated_workflowsclient_updateworkflow_workflowfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowssettings/getworkflow/SyncGetWorkflow.java b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowssettings/getworkflow/SyncGetWorkflow.java new file mode 100644 index 00000000..e745b10e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/workflows/v1beta/workflowssettings/getworkflow/SyncGetWorkflow.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.workflows.v1beta.samples; + +// [START workflows_v1beta_generated_workflowssettings_getworkflow_sync] +import com.google.cloud.workflows.v1beta.WorkflowsSettings; +import java.time.Duration; + +public class SyncGetWorkflow { + + public static void main(String[] args) throws Exception { + syncGetWorkflow(); + } + + public static void syncGetWorkflow() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + WorkflowsSettings.Builder workflowsSettingsBuilder = WorkflowsSettings.newBuilder(); + workflowsSettingsBuilder + .getWorkflowSettings() + .setRetrySettings( + workflowsSettingsBuilder + .getWorkflowSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + WorkflowsSettings workflowsSettings = workflowsSettingsBuilder.build(); + } +} +// [END workflows_v1beta_generated_workflowssettings_getworkflow_sync]