diff --git a/java-assured-workloads/google-cloud-assured-workloads/pom.xml b/java-assured-workloads/google-cloud-assured-workloads/pom.xml index 3614d0daac39..0ff5536ea7c8 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/pom.xml +++ b/java-assured-workloads/google-cloud-assured-workloads/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/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClient.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClient.java index 22a6c36fc7af..1996ed87e71d 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClient.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.cloud.assuredworkloads.v1.stub.AssuredWorkloadsServiceStubSettings; 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; @@ -107,13 +107,29 @@ * AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); * } * + *

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.
+ * AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings =
+ *     AssuredWorkloadsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssuredWorkloadsServiceClient assuredWorkloadsServiceClient =
+ *     AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class AssuredWorkloadsServiceClient implements BackgroundResource { private final AssuredWorkloadsServiceSettings settings; private final AssuredWorkloadsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of AssuredWorkloadsServiceClient with default settings. */ public static final AssuredWorkloadsServiceClient create() throws IOException { @@ -146,13 +162,17 @@ protected AssuredWorkloadsServiceClient(AssuredWorkloadsServiceSettings settings throws IOException { this.settings = settings; this.stub = ((AssuredWorkloadsServiceStubSettings) 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()); } protected AssuredWorkloadsServiceClient(AssuredWorkloadsServiceStub 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 AssuredWorkloadsServiceSettings getSettings() { @@ -167,10 +187,18 @@ public AssuredWorkloadsServiceStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Creates Assured Workload. diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceSettings.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceSettings.java index 1a487ee2edeb..24d6eaf93611 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceSettings.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceSettings.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; @@ -135,11 +136,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssuredWorkloadsServiceStubSettings.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 AssuredWorkloadsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssuredWorkloadsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssuredWorkloadsServiceStubSettings.defaultTransportChannelProvider(); } @@ -149,11 +157,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssuredWorkloadsServiceStubSettings.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); @@ -192,6 +206,11 @@ private static Builder createDefault() { return new Builder(AssuredWorkloadsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder()); + } + public AssuredWorkloadsServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssuredWorkloadsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStub.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStub.java index b6082e624992..5515cbfc507d 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStub.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStub.java @@ -44,7 +44,11 @@ public abstract class AssuredWorkloadsServiceStub 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 OperationCallable diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStubSettings.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStubSettings.java index b218e2de2686..5e6b14cf365c 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStubSettings.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/AssuredWorkloadsServiceStubSettings.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; @@ -208,6 +211,11 @@ public AssuredWorkloadsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssuredWorkloadsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssuredWorkloadsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -240,18 +248,25 @@ 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(AssuredWorkloadsServiceStubSettings.class)) @@ -259,11 +274,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil 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(AssuredWorkloadsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssuredWorkloadsServiceStubSettings.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); @@ -383,6 +417,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 .createWorkloadSettings() diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.java new file mode 100644 index 000000000000..f55c5355b18c --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.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.assuredworkloads.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 AssuredWorkloadsService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAssuredWorkloadsServiceCallableFactory + 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/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceStub.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceStub.java new file mode 100644 index 000000000000..1aed44f6bfe8 --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1/stub/HttpJsonAssuredWorkloadsServiceStub.java @@ -0,0 +1,457 @@ +/* + * 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.assuredworkloads.v1.stub; + +import static com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient.ListWorkloadsPagedResponse; + +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.assuredworkloads.v1.CreateWorkloadOperationMetadata; +import com.google.cloud.assuredworkloads.v1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsResponse; +import com.google.cloud.assuredworkloads.v1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.Workload; +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 AssuredWorkloadsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAssuredWorkloadsServiceStub extends AssuredWorkloadsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Workload.getDescriptor()) + .add(CreateWorkloadOperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + createWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1.AssuredWorkloadsService/CreateWorkload") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=organizations/*/locations/*}/workloads", + 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, "externalId", request.getExternalId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workload", request.getWorkload())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateWorkloadRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1.AssuredWorkloadsService/UpdateWorkload") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{workload.name=organizations/*/locations/*/workloads/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "workload.name", request.getWorkload().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("workload", request.getWorkload())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Workload.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1.AssuredWorkloadsService/DeleteWorkload") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=organizations/*/locations/*/workloads/*}", + 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(); + serializer.putQueryParam(fields, "etag", request.getEtag()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1.AssuredWorkloadsService/GetWorkload") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=organizations/*/locations/*/workloads/*}", + 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(Workload.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listWorkloadsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1.AssuredWorkloadsService/ListWorkloads") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=organizations/*/locations/*}/workloads", + 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, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListWorkloadsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createWorkloadCallable; + private final OperationCallable + createWorkloadOperationCallable; + private final UnaryCallable updateWorkloadCallable; + private final UnaryCallable deleteWorkloadCallable; + private final UnaryCallable getWorkloadCallable; + private final UnaryCallable listWorkloadsCallable; + private final UnaryCallable + listWorkloadsPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssuredWorkloadsServiceStub create( + AssuredWorkloadsServiceStubSettings settings) throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssuredWorkloadsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssuredWorkloadsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssuredWorkloadsServiceStub, 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 HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssuredWorkloadsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssuredWorkloadsServiceStub, 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 HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listWorkloadsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listWorkloadsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createWorkloadCallable = + callableFactory.createUnaryCallable( + createWorkloadTransportSettings, settings.createWorkloadSettings(), clientContext); + this.createWorkloadOperationCallable = + callableFactory.createOperationCallable( + createWorkloadTransportSettings, + settings.createWorkloadOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateWorkloadCallable = + callableFactory.createUnaryCallable( + updateWorkloadTransportSettings, settings.updateWorkloadSettings(), clientContext); + this.deleteWorkloadCallable = + callableFactory.createUnaryCallable( + deleteWorkloadTransportSettings, settings.deleteWorkloadSettings(), clientContext); + this.getWorkloadCallable = + callableFactory.createUnaryCallable( + getWorkloadTransportSettings, settings.getWorkloadSettings(), clientContext); + this.listWorkloadsCallable = + callableFactory.createUnaryCallable( + listWorkloadsTransportSettings, settings.listWorkloadsSettings(), clientContext); + this.listWorkloadsPagedCallable = + callableFactory.createPagedCallable( + listWorkloadsTransportSettings, settings.listWorkloadsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createWorkloadMethodDescriptor); + methodDescriptors.add(updateWorkloadMethodDescriptor); + methodDescriptors.add(deleteWorkloadMethodDescriptor); + methodDescriptors.add(getWorkloadMethodDescriptor); + methodDescriptors.add(listWorkloadsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createWorkloadCallable() { + return createWorkloadCallable; + } + + @Override + public OperationCallable + createWorkloadOperationCallable() { + return createWorkloadOperationCallable; + } + + @Override + public UnaryCallable updateWorkloadCallable() { + return updateWorkloadCallable; + } + + @Override + public UnaryCallable deleteWorkloadCallable() { + return deleteWorkloadCallable; + } + + @Override + public UnaryCallable getWorkloadCallable() { + return getWorkloadCallable; + } + + @Override + public UnaryCallable listWorkloadsCallable() { + return listWorkloadsCallable; + } + + @Override + public UnaryCallable + listWorkloadsPagedCallable() { + return listWorkloadsPagedCallable; + } + + @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/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClient.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClient.java index bd7b423d53a9..c227a2a63cb3 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClient.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClient.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.assuredworkloads.v1beta1.stub.AssuredWorkloadsServiceStubSettings; 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; @@ -108,6 +108,21 @@ * AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); * } * + *

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.
+ * AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings =
+ *     AssuredWorkloadsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssuredWorkloadsServiceClient assuredWorkloadsServiceClient =
+ *     AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -115,7 +130,8 @@ public class AssuredWorkloadsServiceClient implements BackgroundResource { private final AssuredWorkloadsServiceSettings settings; private final AssuredWorkloadsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of AssuredWorkloadsServiceClient with default settings. */ public static final AssuredWorkloadsServiceClient create() throws IOException { @@ -148,13 +164,17 @@ protected AssuredWorkloadsServiceClient(AssuredWorkloadsServiceSettings settings throws IOException { this.settings = settings; this.stub = ((AssuredWorkloadsServiceStubSettings) 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()); } protected AssuredWorkloadsServiceClient(AssuredWorkloadsServiceStub 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 AssuredWorkloadsServiceSettings getSettings() { @@ -169,10 +189,18 @@ public AssuredWorkloadsServiceStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Creates Assured Workload. diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceSettings.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceSettings.java index b3b65ae43e3b..c0d48076c75d 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceSettings.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceSettings.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; @@ -136,11 +137,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssuredWorkloadsServiceStubSettings.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 AssuredWorkloadsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssuredWorkloadsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssuredWorkloadsServiceStubSettings.defaultTransportChannelProvider(); } @@ -150,11 +158,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssuredWorkloadsServiceStubSettings.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); @@ -193,6 +207,11 @@ private static Builder createDefault() { return new Builder(AssuredWorkloadsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder()); + } + public AssuredWorkloadsServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssuredWorkloadsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStub.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStub.java index 9d220ccbd303..1360d608d44f 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStub.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStub.java @@ -46,7 +46,11 @@ public abstract class AssuredWorkloadsServiceStub 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 OperationCallable diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStubSettings.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStubSettings.java index 50806cfcd5bf..4b991a4280b3 100644 --- a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStubSettings.java +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/AssuredWorkloadsServiceStubSettings.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; @@ -209,6 +212,11 @@ public AssuredWorkloadsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssuredWorkloadsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssuredWorkloadsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -241,18 +249,25 @@ 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(AssuredWorkloadsServiceStubSettings.class)) @@ -260,11 +275,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil 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(AssuredWorkloadsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssuredWorkloadsServiceStubSettings.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 +432,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 .createWorkloadSettings() diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.java new file mode 100644 index 000000000000..70ab5a3b0bf0 --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceCallableFactory.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.assuredworkloads.v1beta1.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 AssuredWorkloadsService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssuredWorkloadsServiceCallableFactory + 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/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceStub.java b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceStub.java new file mode 100644 index 000000000000..94705b903d43 --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/main/java/com/google/cloud/assuredworkloads/v1beta1/stub/HttpJsonAssuredWorkloadsServiceStub.java @@ -0,0 +1,457 @@ +/* + * 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.assuredworkloads.v1beta1.stub; + +import static com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient.ListWorkloadsPagedResponse; + +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.assuredworkloads.v1beta1.CreateWorkloadOperationMetadata; +import com.google.cloud.assuredworkloads.v1beta1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsResponse; +import com.google.cloud.assuredworkloads.v1beta1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +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 AssuredWorkloadsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssuredWorkloadsServiceStub extends AssuredWorkloadsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(CreateWorkloadOperationMetadata.getDescriptor()) + .add(Workload.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + createWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/CreateWorkload") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=organizations/*/locations/*}/workloads", + 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, "externalId", request.getExternalId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("workload", request.getWorkload())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateWorkloadRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/UpdateWorkload") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{workload.name=organizations/*/locations/*/workloads/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "workload.name", request.getWorkload().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("workload", request.getWorkload())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Workload.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/DeleteWorkload") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=organizations/*/locations/*/workloads/*}", + 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(); + serializer.putQueryParam(fields, "etag", request.getEtag()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getWorkloadMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/GetWorkload") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=organizations/*/locations/*/workloads/*}", + 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(Workload.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listWorkloadsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsService/ListWorkloads") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=organizations/*/locations/*}/workloads", + 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, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListWorkloadsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createWorkloadCallable; + private final OperationCallable + createWorkloadOperationCallable; + private final UnaryCallable updateWorkloadCallable; + private final UnaryCallable deleteWorkloadCallable; + private final UnaryCallable getWorkloadCallable; + private final UnaryCallable listWorkloadsCallable; + private final UnaryCallable + listWorkloadsPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssuredWorkloadsServiceStub create( + AssuredWorkloadsServiceStubSettings settings) throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssuredWorkloadsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssuredWorkloadsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssuredWorkloadsServiceStub, 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 HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssuredWorkloadsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssuredWorkloadsServiceStub, 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 HttpJsonAssuredWorkloadsServiceStub( + AssuredWorkloadsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getWorkloadTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getWorkloadMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listWorkloadsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listWorkloadsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createWorkloadCallable = + callableFactory.createUnaryCallable( + createWorkloadTransportSettings, settings.createWorkloadSettings(), clientContext); + this.createWorkloadOperationCallable = + callableFactory.createOperationCallable( + createWorkloadTransportSettings, + settings.createWorkloadOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateWorkloadCallable = + callableFactory.createUnaryCallable( + updateWorkloadTransportSettings, settings.updateWorkloadSettings(), clientContext); + this.deleteWorkloadCallable = + callableFactory.createUnaryCallable( + deleteWorkloadTransportSettings, settings.deleteWorkloadSettings(), clientContext); + this.getWorkloadCallable = + callableFactory.createUnaryCallable( + getWorkloadTransportSettings, settings.getWorkloadSettings(), clientContext); + this.listWorkloadsCallable = + callableFactory.createUnaryCallable( + listWorkloadsTransportSettings, settings.listWorkloadsSettings(), clientContext); + this.listWorkloadsPagedCallable = + callableFactory.createPagedCallable( + listWorkloadsTransportSettings, settings.listWorkloadsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createWorkloadMethodDescriptor); + methodDescriptors.add(updateWorkloadMethodDescriptor); + methodDescriptors.add(deleteWorkloadMethodDescriptor); + methodDescriptors.add(getWorkloadMethodDescriptor); + methodDescriptors.add(listWorkloadsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createWorkloadCallable() { + return createWorkloadCallable; + } + + @Override + public OperationCallable + createWorkloadOperationCallable() { + return createWorkloadOperationCallable; + } + + @Override + public UnaryCallable updateWorkloadCallable() { + return updateWorkloadCallable; + } + + @Override + public UnaryCallable deleteWorkloadCallable() { + return deleteWorkloadCallable; + } + + @Override + public UnaryCallable getWorkloadCallable() { + return getWorkloadCallable; + } + + @Override + public UnaryCallable listWorkloadsCallable() { + return listWorkloadsCallable; + } + + @Override + public UnaryCallable + listWorkloadsPagedCallable() { + return listWorkloadsPagedCallable; + } + + @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/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClientHttpJsonTest.java b/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..bc56604ba296 --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1/AssuredWorkloadsServiceClientHttpJsonTest.java @@ -0,0 +1,586 @@ +/* + * 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.assuredworkloads.v1; + +import static com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient.ListWorkloadsPagedResponse; + +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.assuredworkloads.v1.stub.HttpJsonAssuredWorkloadsServiceStub; +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.ArrayList; +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 AssuredWorkloadsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssuredWorkloadsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssuredWorkloadsServiceStub.getMethodDescriptors(), + AssuredWorkloadsServiceSettings.getDefaultEndpoint()); + AssuredWorkloadsServiceSettings settings = + AssuredWorkloadsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssuredWorkloadsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkloadTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + + Workload actualResponse = client.createWorkloadAsync(parent, workload).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 createWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + client.createWorkloadAsync(parent, workload).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createWorkloadTest2() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkloadTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "organizations/organization-9365/locations/location-9365"; + Workload workload = Workload.newBuilder().build(); + + Workload actualResponse = client.createWorkloadAsync(parent, workload).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 createWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "organizations/organization-9365/locations/location-9365"; + Workload workload = Workload.newBuilder().build(); + client.createWorkloadAsync(parent, workload).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Workload workload = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Workload actualResponse = client.updateWorkload(workload, updateMask); + 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 updateWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Workload workload = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateWorkload(workload, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteWorkloadTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + + client.deleteWorkload(name); + + 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 deleteWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + client.deleteWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteWorkloadTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + + client.deleteWorkload(name); + + 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 deleteWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + client.deleteWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + + Workload actualResponse = client.getWorkload(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 getWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + client.getWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkloadTest2() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + + Workload actualResponse = client.getWorkload(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 getWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + client.getWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkloadsTest() throws Exception { + Workload responsesElement = Workload.newBuilder().build(); + ListWorkloadsResponse expectedResponse = + ListWorkloadsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkloads(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + + ListWorkloadsPagedResponse pagedListResponse = client.listWorkloads(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkloadsList().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 listWorkloadsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + client.listWorkloads(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkloadsTest2() throws Exception { + Workload responsesElement = Workload.newBuilder().build(); + ListWorkloadsResponse expectedResponse = + ListWorkloadsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkloads(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "organizations/organization-9365/locations/location-9365"; + + ListWorkloadsPagedResponse pagedListResponse = client.listWorkloads(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkloadsList().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 listWorkloadsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "organizations/organization-9365/locations/location-9365"; + client.listWorkloads(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClientHttpJsonTest.java b/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..dc8c992ce7ce --- /dev/null +++ b/java-assured-workloads/google-cloud-assured-workloads/src/test/java/com/google/cloud/assuredworkloads/v1beta1/AssuredWorkloadsServiceClientHttpJsonTest.java @@ -0,0 +1,586 @@ +/* + * 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.assuredworkloads.v1beta1; + +import static com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient.ListWorkloadsPagedResponse; + +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.assuredworkloads.v1beta1.stub.HttpJsonAssuredWorkloadsServiceStub; +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.ArrayList; +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 AssuredWorkloadsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssuredWorkloadsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssuredWorkloadsServiceStub.getMethodDescriptors(), + AssuredWorkloadsServiceSettings.getDefaultEndpoint()); + AssuredWorkloadsServiceSettings settings = + AssuredWorkloadsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssuredWorkloadsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkloadTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + + Workload actualResponse = client.createWorkloadAsync(parent, workload).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 createWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + client.createWorkloadAsync(parent, workload).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createWorkloadTest2() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createWorkloadTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "organizations/organization-9365/locations/location-9365"; + Workload workload = Workload.newBuilder().build(); + + Workload actualResponse = client.createWorkloadAsync(parent, workload).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 createWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "organizations/organization-9365/locations/location-9365"; + Workload workload = Workload.newBuilder().build(); + client.createWorkloadAsync(parent, workload).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Workload workload = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Workload actualResponse = client.updateWorkload(workload, updateMask); + 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 updateWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Workload workload = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateWorkload(workload, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteWorkloadTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + + client.deleteWorkload(name); + + 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 deleteWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + client.deleteWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteWorkloadTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + + client.deleteWorkload(name); + + 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 deleteWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + client.deleteWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkloadTest() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + + Workload actualResponse = client.getWorkload(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 getWorkloadExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + client.getWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getWorkloadTest2() throws Exception { + Workload expectedResponse = + Workload.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setDisplayName("displayName1714148973") + .addAllResources(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setBillingAccount("billingAccount708726578") + .setEtag("etag3123477") + .putAllLabels(new HashMap()) + .setProvisionedResourcesParent("provisionedResourcesParent1733249115") + .setKmsSettings(Workload.KMSSettings.newBuilder().build()) + .addAllResourceSettings(new ArrayList()) + .setEnableSovereignControls(true) + .setSaaEnrollmentResponse(Workload.SaaEnrollmentResponse.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + + Workload actualResponse = client.getWorkload(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 getWorkloadExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "organizations/organization-4962/locations/location-4962/workloads/workload-4962"; + client.getWorkload(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkloadsTest() throws Exception { + Workload responsesElement = Workload.newBuilder().build(); + ListWorkloadsResponse expectedResponse = + ListWorkloadsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkloads(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + + ListWorkloadsPagedResponse pagedListResponse = client.listWorkloads(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkloadsList().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 listWorkloadsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + client.listWorkloads(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listWorkloadsTest2() throws Exception { + Workload responsesElement = Workload.newBuilder().build(); + ListWorkloadsResponse expectedResponse = + ListWorkloadsResponse.newBuilder() + .setNextPageToken("") + .addAllWorkloads(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "organizations/organization-9365/locations/location-9365"; + + ListWorkloadsPagedResponse pagedListResponse = client.listWorkloads(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getWorkloadsList().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 listWorkloadsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "organizations/organization-9365/locations/location-9365"; + client.listWorkloads(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..9c6c3750eb3e --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceSettings; +import com.google.cloud.assuredworkloads.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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..d9cfc7144ef4 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceSettings; + +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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder() + .setTransportChannelProvider( + AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..1ff0e1c9a0a7 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setendpoint_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceSettings; +import com.google.cloud.assuredworkloads.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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_create_setendpoint_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java new file mode 100644 index 000000000000..67365c6f22d9 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java @@ -0,0 +1,51 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.longrunning.Operation; + +public class AsyncCreateWorkload { + + public static void main(String[] args) throws Exception { + asyncCreateWorkload(); + } + + public static void asyncCreateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.createWorkloadCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java new file mode 100644 index 000000000000..b485dd1926af --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java @@ -0,0 +1,51 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.CreateWorkloadOperationMetadata; +import com.google.cloud.assuredworkloads.v1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class AsyncCreateWorkloadLRO { + + public static void main(String[] args) throws Exception { + asyncCreateWorkloadLRO(); + } + + public static void asyncCreateWorkloadLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + OperationFuture future = + assuredWorkloadsServiceClient.createWorkloadOperationCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_lro_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.java new file mode 100644 index 000000000000..35d43de43ea5 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncCreateWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkload(); + } + + public static void syncCreateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(request).get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.java new file mode 100644 index 000000000000..aaf4d9146226 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_locationnameworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncCreateWorkloadLocationnameWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkloadLocationnameWorkload(); + } + + public static void syncCreateWorkloadLocationnameWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(parent, workload).get(); + } + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_locationnameworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.java new file mode 100644 index 000000000000..66af260762cb --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_stringworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncCreateWorkloadStringWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkloadStringWorkload(); + } + + public static void syncCreateWorkloadStringWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String parent = LocationName.of("[ORGANIZATION]", "[LOCATION]").toString(); + Workload workload = Workload.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(parent, workload).get(); + } + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_createworkload_stringworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.java new file mode 100644 index 000000000000..33b8c3df51a7 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.WorkloadName; +import com.google.protobuf.Empty; + +public class AsyncDeleteWorkload { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkload(); + } + + public static void asyncDeleteWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + DeleteWorkloadRequest request = + DeleteWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.deleteWorkloadCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.java new file mode 100644 index 000000000000..ae1b6230d6b8 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncDeleteWorkload { + + public static void main(String[] args) throws Exception { + syncDeleteWorkload(); + } + + public static void syncDeleteWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + DeleteWorkloadRequest request = + DeleteWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setEtag("etag3123477") + .build(); + assuredWorkloadsServiceClient.deleteWorkload(request); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.java new file mode 100644 index 000000000000..94fa3b0924cc --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_string_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncDeleteWorkloadString { + + public static void main(String[] args) throws Exception { + syncDeleteWorkloadString(); + } + + public static void syncDeleteWorkloadString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString(); + assuredWorkloadsServiceClient.deleteWorkload(name); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.java new file mode 100644 index 000000000000..2eda0d3c00f0 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_workloadname_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncDeleteWorkloadWorkloadname { + + public static void main(String[] args) throws Exception { + syncDeleteWorkloadWorkloadname(); + } + + public static void syncDeleteWorkloadWorkloadname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + assuredWorkloadsServiceClient.deleteWorkload(name); + } + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_deleteworkload_workloadname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.java new file mode 100644 index 000000000000..85b4562ba4c9 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class AsyncGetWorkload { + + public static void main(String[] args) throws Exception { + asyncGetWorkload(); + } + + public static void asyncGetWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + GetWorkloadRequest request = + GetWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.getWorkloadCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.java new file mode 100644 index 000000000000..fbf42f69f89c --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncGetWorkload { + + public static void main(String[] args) throws Exception { + syncGetWorkload(); + } + + public static void syncGetWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + GetWorkloadRequest request = + GetWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .build(); + Workload response = assuredWorkloadsServiceClient.getWorkload(request); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.java new file mode 100644 index 000000000000..940488b7144d --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_string_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncGetWorkloadString { + + public static void main(String[] args) throws Exception { + syncGetWorkloadString(); + } + + public static void syncGetWorkloadString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString(); + Workload response = assuredWorkloadsServiceClient.getWorkload(name); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.java new file mode 100644 index 000000000000..80c6006dfe32 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_workloadname_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.cloud.assuredworkloads.v1.WorkloadName; + +public class SyncGetWorkloadWorkloadname { + + public static void main(String[] args) throws Exception { + syncGetWorkloadWorkloadname(); + } + + public static void syncGetWorkloadWorkloadname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + Workload response = assuredWorkloadsServiceClient.getWorkload(name); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_getworkload_workloadname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java new file mode 100644 index 000000000000..46ca44020786 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java @@ -0,0 +1,53 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class AsyncListWorkloads { + + public static void main(String[] args) throws Exception { + asyncListWorkloads(); + } + + public static void asyncListWorkloads() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.listWorkloadsPagedCallable().futureCall(request); + // Do something. + for (Workload element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java new file mode 100644 index 000000000000..434fa1008616 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java @@ -0,0 +1,61 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_paged_async] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsResponse; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.common.base.Strings; + +public class AsyncListWorkloadsPaged { + + public static void main(String[] args) throws Exception { + asyncListWorkloadsPaged(); + } + + public static void asyncListWorkloadsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListWorkloadsResponse response = + assuredWorkloadsServiceClient.listWorkloadsCallable().call(request); + for (Workload element : response.getWorkloadsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_paged_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.java new file mode 100644 index 000000000000..7760203911d6 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncListWorkloads { + + public static void main(String[] args) throws Exception { + syncListWorkloads(); + } + + public static void syncListWorkloads() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.java new file mode 100644 index 000000000000..a8ec2c099f96 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_locationname_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncListWorkloadsLocationname { + + public static void main(String[] args) throws Exception { + syncListWorkloadsLocationname(); + } + + public static void syncListWorkloadsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_locationname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.java new file mode 100644 index 000000000000..b8b5862767ee --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.java @@ -0,0 +1,42 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_string_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.LocationName; +import com.google.cloud.assuredworkloads.v1.Workload; + +public class SyncListWorkloadsString { + + public static void main(String[] args) throws Exception { + syncListWorkloadsString(); + } + + public static void syncListWorkloadsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String parent = LocationName.of("[ORGANIZATION]", "[LOCATION]").toString(); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_listworkloads_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.java new file mode 100644 index 000000000000..9422234caf2c --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkload(); + } + + public static void asyncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + UpdateWorkloadRequest request = + UpdateWorkloadRequest.newBuilder() + .setWorkload(Workload.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.updateWorkloadCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..b69e3b6c37b3 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + UpdateWorkloadRequest request = + UpdateWorkloadRequest.newBuilder() + .setWorkload(Workload.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Workload response = assuredWorkloadsServiceClient.updateWorkload(request); + } + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.java new file mode 100644 index 000000000000..5e814a655b79 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.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.assuredworkloads.v1.samples; + +// [START +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_workloadfieldmask_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1.Workload; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkloadWorkloadFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateWorkloadWorkloadFieldmask(); + } + + public static void syncUpdateWorkloadWorkloadFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + Workload workload = Workload.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.updateWorkload(workload, updateMask); + } + } +} +// [END +// assuredworkloads_v1_generated_assuredworkloadsserviceclient_updateworkload_workloadfieldmask_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..afa9fe9eccc3 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java @@ -0,0 +1,47 @@ +/* + * 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.assuredworkloads.v1.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsservicesettings_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1.AssuredWorkloadsServiceSettings; +import java.time.Duration; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssuredWorkloadsServiceSettings.Builder assuredWorkloadsServiceSettingsBuilder = + AssuredWorkloadsServiceSettings.newBuilder(); + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .setRetrySettings( + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + assuredWorkloadsServiceSettingsBuilder.build(); + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsservicesettings_updateworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..d2ac4c549232 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.java @@ -0,0 +1,47 @@ +/* + * 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.assuredworkloads.v1.stub.samples; + +// [START assuredworkloads_v1_generated_assuredworkloadsservicestubsettings_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1.stub.AssuredWorkloadsServiceStubSettings; +import java.time.Duration; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssuredWorkloadsServiceStubSettings.Builder assuredWorkloadsServiceSettingsBuilder = + AssuredWorkloadsServiceStubSettings.newBuilder(); + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .setRetrySettings( + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssuredWorkloadsServiceStubSettings assuredWorkloadsServiceSettings = + assuredWorkloadsServiceSettingsBuilder.build(); + } +} +// [END assuredworkloads_v1_generated_assuredworkloadsservicestubsettings_updateworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..eb78da5cbb9f --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceSettings; +import com.google.cloud.assuredworkloads.v1beta1.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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..4001772cf26a --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetCredentialsProvider1.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceSettings; + +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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder() + .setTransportChannelProvider( + AssuredWorkloadsServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..c2058595315b --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/create/SyncCreateSetEndpoint.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setendpoint_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceSettings; +import com.google.cloud.assuredworkloads.v1beta1.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. + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + AssuredWorkloadsServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create(assuredWorkloadsServiceSettings); + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_create_setendpoint_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java new file mode 100644 index 000000000000..c14797968a45 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkload.java @@ -0,0 +1,51 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.longrunning.Operation; + +public class AsyncCreateWorkload { + + public static void main(String[] args) throws Exception { + asyncCreateWorkload(); + } + + public static void asyncCreateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.createWorkloadCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java new file mode 100644 index 000000000000..3b649fbc1606 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/AsyncCreateWorkloadLRO.java @@ -0,0 +1,51 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.CreateWorkloadOperationMetadata; +import com.google.cloud.assuredworkloads.v1beta1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class AsyncCreateWorkloadLRO { + + public static void main(String[] args) throws Exception { + asyncCreateWorkloadLRO(); + } + + public static void asyncCreateWorkloadLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + OperationFuture future = + assuredWorkloadsServiceClient.createWorkloadOperationCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_lro_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.java new file mode 100644 index 000000000000..dac0147c977b --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.CreateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncCreateWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkload(); + } + + public static void syncCreateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + CreateWorkloadRequest request = + CreateWorkloadRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setWorkload(Workload.newBuilder().build()) + .setExternalId("externalId-1699764666") + .build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(request).get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.java new file mode 100644 index 000000000000..6bf9a1920482 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadLocationnameWorkload.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_locationnameworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncCreateWorkloadLocationnameWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkloadLocationnameWorkload(); + } + + public static void syncCreateWorkloadLocationnameWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + Workload workload = Workload.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(parent, workload).get(); + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_locationnameworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.java new file mode 100644 index 000000000000..a8c05283ce4b --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/createworkload/SyncCreateWorkloadStringWorkload.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_stringworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncCreateWorkloadStringWorkload { + + public static void main(String[] args) throws Exception { + syncCreateWorkloadStringWorkload(); + } + + public static void syncCreateWorkloadStringWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String parent = LocationName.of("[ORGANIZATION]", "[LOCATION]").toString(); + Workload workload = Workload.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.createWorkloadAsync(parent, workload).get(); + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_createworkload_stringworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.java new file mode 100644 index 000000000000..3401e96c9054 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/AsyncDeleteWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; +import com.google.protobuf.Empty; + +public class AsyncDeleteWorkload { + + public static void main(String[] args) throws Exception { + asyncDeleteWorkload(); + } + + public static void asyncDeleteWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + DeleteWorkloadRequest request = + DeleteWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.deleteWorkloadCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.java new file mode 100644 index 000000000000..f3a0289ec081 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.DeleteWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncDeleteWorkload { + + public static void main(String[] args) throws Exception { + syncDeleteWorkload(); + } + + public static void syncDeleteWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + DeleteWorkloadRequest request = + DeleteWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .setEtag("etag3123477") + .build(); + assuredWorkloadsServiceClient.deleteWorkload(request); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.java new file mode 100644 index 000000000000..4add015a415b --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadString.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_string_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncDeleteWorkloadString { + + public static void main(String[] args) throws Exception { + syncDeleteWorkloadString(); + } + + public static void syncDeleteWorkloadString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString(); + assuredWorkloadsServiceClient.deleteWorkload(name); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.java new file mode 100644 index 000000000000..1768da2254c8 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/deleteworkload/SyncDeleteWorkloadWorkloadname.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_workloadname_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncDeleteWorkloadWorkloadname { + + public static void main(String[] args) throws Exception { + syncDeleteWorkloadWorkloadname(); + } + + public static void syncDeleteWorkloadWorkloadname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + assuredWorkloadsServiceClient.deleteWorkload(name); + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_deleteworkload_workloadname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.java new file mode 100644 index 000000000000..0b9a32ac631e --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/AsyncGetWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class AsyncGetWorkload { + + public static void main(String[] args) throws Exception { + asyncGetWorkload(); + } + + public static void asyncGetWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + GetWorkloadRequest request = + GetWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.getWorkloadCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.java new file mode 100644 index 000000000000..7c2b7c85b4db --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.GetWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncGetWorkload { + + public static void main(String[] args) throws Exception { + syncGetWorkload(); + } + + public static void syncGetWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + GetWorkloadRequest request = + GetWorkloadRequest.newBuilder() + .setName(WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString()) + .build(); + Workload response = assuredWorkloadsServiceClient.getWorkload(request); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.java new file mode 100644 index 000000000000..8f13ed27c8e8 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadString.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_string_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncGetWorkloadString { + + public static void main(String[] args) throws Exception { + syncGetWorkloadString(); + } + + public static void syncGetWorkloadString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]").toString(); + Workload response = assuredWorkloadsServiceClient.getWorkload(name); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.java new file mode 100644 index 000000000000..fb95f4f37dfe --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/getworkload/SyncGetWorkloadWorkloadname.java @@ -0,0 +1,42 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_workloadname_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.cloud.assuredworkloads.v1beta1.WorkloadName; + +public class SyncGetWorkloadWorkloadname { + + public static void main(String[] args) throws Exception { + syncGetWorkloadWorkloadname(); + } + + public static void syncGetWorkloadWorkloadname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + WorkloadName name = WorkloadName.of("[ORGANIZATION]", "[LOCATION]", "[WORKLOAD]"); + Workload response = assuredWorkloadsServiceClient.getWorkload(name); + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_getworkload_workloadname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java new file mode 100644 index 000000000000..6289cf092dd5 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloads.java @@ -0,0 +1,53 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class AsyncListWorkloads { + + public static void main(String[] args) throws Exception { + asyncListWorkloads(); + } + + public static void asyncListWorkloads() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.listWorkloadsPagedCallable().futureCall(request); + // Do something. + for (Workload element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java new file mode 100644 index 000000000000..6bda848c1ff1 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/AsyncListWorkloadsPaged.java @@ -0,0 +1,62 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_paged_async] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsResponse; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.common.base.Strings; + +public class AsyncListWorkloadsPaged { + + public static void main(String[] args) throws Exception { + asyncListWorkloadsPaged(); + } + + public static void asyncListWorkloadsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListWorkloadsResponse response = + assuredWorkloadsServiceClient.listWorkloadsCallable().call(request); + for (Workload element : response.getWorkloadsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_paged_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.java new file mode 100644 index 000000000000..64a1fad330a8 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloads.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.ListWorkloadsRequest; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncListWorkloads { + + public static void main(String[] args) throws Exception { + syncListWorkloads(); + } + + public static void syncListWorkloads() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + ListWorkloadsRequest request = + ListWorkloadsRequest.newBuilder() + .setParent(LocationName.of("[ORGANIZATION]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.java new file mode 100644 index 000000000000..8ee1a108dece --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsLocationname.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_locationname_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncListWorkloadsLocationname { + + public static void main(String[] args) throws Exception { + syncListWorkloadsLocationname(); + } + + public static void syncListWorkloadsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + LocationName parent = LocationName.of("[ORGANIZATION]", "[LOCATION]"); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_locationname_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.java new file mode 100644 index 000000000000..920dcd7257fd --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/listworkloads/SyncListWorkloadsString.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_string_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.LocationName; +import com.google.cloud.assuredworkloads.v1beta1.Workload; + +public class SyncListWorkloadsString { + + public static void main(String[] args) throws Exception { + syncListWorkloadsString(); + } + + public static void syncListWorkloadsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + String parent = LocationName.of("[ORGANIZATION]", "[LOCATION]").toString(); + for (Workload element : assuredWorkloadsServiceClient.listWorkloads(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_listworkloads_string_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.java new file mode 100644 index 000000000000..c12a7f5bcf80 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/AsyncUpdateWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + asyncUpdateWorkload(); + } + + public static void asyncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + UpdateWorkloadRequest request = + UpdateWorkloadRequest.newBuilder() + .setWorkload(Workload.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + assuredWorkloadsServiceClient.updateWorkloadCallable().futureCall(request); + // Do something. + Workload response = future.get(); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_async] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..8fc14e4e96b5 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkload.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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.UpdateWorkloadRequest; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + UpdateWorkloadRequest request = + UpdateWorkloadRequest.newBuilder() + .setWorkload(Workload.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Workload response = assuredWorkloadsServiceClient.updateWorkload(request); + } + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.java new file mode 100644 index 000000000000..2eaa7984e0e2 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsserviceclient/updateworkload/SyncUpdateWorkloadWorkloadFieldmask.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.assuredworkloads.v1beta1.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_workloadfieldmask_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceClient; +import com.google.cloud.assuredworkloads.v1beta1.Workload; +import com.google.protobuf.FieldMask; + +public class SyncUpdateWorkloadWorkloadFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateWorkloadWorkloadFieldmask(); + } + + public static void syncUpdateWorkloadWorkloadFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssuredWorkloadsServiceClient assuredWorkloadsServiceClient = + AssuredWorkloadsServiceClient.create()) { + Workload workload = Workload.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Workload response = assuredWorkloadsServiceClient.updateWorkload(workload, updateMask); + } + } +} +// [END +// assuredworkloads_v1beta1_generated_assuredworkloadsserviceclient_updateworkload_workloadfieldmask_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..7d07bd3fc38e --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/assuredworkloadsservicesettings/updateworkload/SyncUpdateWorkload.java @@ -0,0 +1,47 @@ +/* + * 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.assuredworkloads.v1beta1.samples; + +// [START assuredworkloads_v1beta1_generated_assuredworkloadsservicesettings_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.AssuredWorkloadsServiceSettings; +import java.time.Duration; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssuredWorkloadsServiceSettings.Builder assuredWorkloadsServiceSettingsBuilder = + AssuredWorkloadsServiceSettings.newBuilder(); + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .setRetrySettings( + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssuredWorkloadsServiceSettings assuredWorkloadsServiceSettings = + assuredWorkloadsServiceSettingsBuilder.build(); + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsservicesettings_updateworkload_sync] diff --git a/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.java b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.java new file mode 100644 index 000000000000..1a248c4a4553 --- /dev/null +++ b/java-assured-workloads/samples/snippets/generated/com/google/cloud/assuredworkloads/v1beta1/stub/assuredworkloadsservicestubsettings/updateworkload/SyncUpdateWorkload.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.assuredworkloads.v1beta1.stub.samples; + +// [START +// assuredworkloads_v1beta1_generated_assuredworkloadsservicestubsettings_updateworkload_sync] +import com.google.cloud.assuredworkloads.v1beta1.stub.AssuredWorkloadsServiceStubSettings; +import java.time.Duration; + +public class SyncUpdateWorkload { + + public static void main(String[] args) throws Exception { + syncUpdateWorkload(); + } + + public static void syncUpdateWorkload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssuredWorkloadsServiceStubSettings.Builder assuredWorkloadsServiceSettingsBuilder = + AssuredWorkloadsServiceStubSettings.newBuilder(); + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .setRetrySettings( + assuredWorkloadsServiceSettingsBuilder + .updateWorkloadSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssuredWorkloadsServiceStubSettings assuredWorkloadsServiceSettings = + assuredWorkloadsServiceSettingsBuilder.build(); + } +} +// [END assuredworkloads_v1beta1_generated_assuredworkloadsservicestubsettings_updateworkload_sync]