diff --git a/java-ids/README.md b/java-ids/README.md index b6281e56d9a4..e43763719f75 100644 --- a/java-ids/README.md +++ b/java-ids/README.md @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-ids:1.1.0' +implementation 'com.google.cloud:google-cloud-ids:1.1.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-ids" % "1.1.0" +libraryDependencies += "com.google.cloud" % "google-cloud-ids" % "1.1.1" ``` ## Authentication diff --git a/java-ids/google-cloud-ids/pom.xml b/java-ids/google-cloud-ids/pom.xml index e5ba08a4d9b2..1103741e5696 100644 --- a/java-ids/google-cloud-ids/pom.xml +++ b/java-ids/google-cloud-ids/pom.xml @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -77,12 +81,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-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSClient.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSClient.java index ef6b8de9e775..934752900080 100644 --- a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSClient.java +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSClient.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.ids.v1.stub.IDSStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -100,13 +100,28 @@ * IDSClient iDSClient = IDSClient.create(iDSSettings); * } * + *

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.
+ * IDSSettings iDSSettings =
+ *     IDSSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             IDSSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * IDSClient iDSClient = IDSClient.create(iDSSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class IDSClient implements BackgroundResource { private final IDSSettings settings; private final IDSStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of IDSClient with default settings. */ public static final IDSClient create() throws IOException { @@ -136,13 +151,17 @@ public static final IDSClient create(IDSStub stub) { protected IDSClient(IDSSettings settings) throws IOException { this.settings = settings; this.stub = ((IDSStubSettings) 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 IDSClient(IDSStub 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 IDSSettings getSettings() { @@ -157,10 +176,18 @@ public IDSStub 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. /** * Lists Endpoints in a given project and location. diff --git a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSSettings.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSSettings.java index 31da22a9aeef..5073fcc7dfa0 100644 --- a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSSettings.java +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/IDSSettings.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; @@ -130,11 +131,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return IDSStubSettings.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 IDSStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return IDSStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return IDSStubSettings.defaultTransportChannelProvider(); } @@ -144,11 +152,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return IDSStubSettings.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); @@ -186,6 +200,11 @@ private static Builder createDefault() { return new Builder(IDSStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(IDSStubSettings.newHttpJsonBuilder()); + } + public IDSStubSettings.Builder getStubSettingsBuilder() { return ((IDSStubSettings.Builder) getStubSettings()); } diff --git a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSCallableFactory.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSCallableFactory.java new file mode 100644 index 000000000000..14145e55d691 --- /dev/null +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSCallableFactory.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.ids.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 IDS service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonIDSCallableFactory + 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-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSStub.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSStub.java new file mode 100644 index 000000000000..161a55f172ba --- /dev/null +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/HttpJsonIDSStub.java @@ -0,0 +1,410 @@ +/* + * 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.ids.v1.stub; + +import static com.google.cloud.ids.v1.IDSClient.ListEndpointsPagedResponse; + +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.ids.v1.CreateEndpointRequest; +import com.google.cloud.ids.v1.DeleteEndpointRequest; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.GetEndpointRequest; +import com.google.cloud.ids.v1.ListEndpointsRequest; +import com.google.cloud.ids.v1.ListEndpointsResponse; +import com.google.cloud.ids.v1.OperationMetadata; +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 IDS service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonIDSStub extends IDSStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Endpoint.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listEndpointsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.ids.v1.IDS/ListEndpoints") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/endpoints", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListEndpointsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getEndpointMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.ids.v1.IDS/GetEndpoint") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/endpoints/*}", + 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(Endpoint.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createEndpointMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.ids.v1.IDS/CreateEndpoint") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/endpoints", + 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, "endpointId", request.getEndpointId()); + serializer.putQueryParam(fields, "requestId", request.getRequestId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("endpoint", request.getEndpoint())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateEndpointRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteEndpointMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.ids.v1.IDS/DeleteEndpoint") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/endpoints/*}", + 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, "requestId", request.getRequestId()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteEndpointRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable listEndpointsCallable; + private final UnaryCallable + listEndpointsPagedCallable; + private final UnaryCallable getEndpointCallable; + private final UnaryCallable createEndpointCallable; + private final OperationCallable + createEndpointOperationCallable; + private final UnaryCallable deleteEndpointCallable; + private final OperationCallable + deleteEndpointOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonIDSStub create(IDSStubSettings settings) throws IOException { + return new HttpJsonIDSStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonIDSStub create(ClientContext clientContext) throws IOException { + return new HttpJsonIDSStub(IDSStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonIDSStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonIDSStub( + IDSStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonIDSStub, 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 HttpJsonIDSStub(IDSStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonIDSCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonIDSStub, 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 HttpJsonIDSStub( + IDSStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listEndpointsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listEndpointsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getEndpointTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getEndpointMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createEndpointTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createEndpointMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteEndpointTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteEndpointMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listEndpointsCallable = + callableFactory.createUnaryCallable( + listEndpointsTransportSettings, settings.listEndpointsSettings(), clientContext); + this.listEndpointsPagedCallable = + callableFactory.createPagedCallable( + listEndpointsTransportSettings, settings.listEndpointsSettings(), clientContext); + this.getEndpointCallable = + callableFactory.createUnaryCallable( + getEndpointTransportSettings, settings.getEndpointSettings(), clientContext); + this.createEndpointCallable = + callableFactory.createUnaryCallable( + createEndpointTransportSettings, settings.createEndpointSettings(), clientContext); + this.createEndpointOperationCallable = + callableFactory.createOperationCallable( + createEndpointTransportSettings, + settings.createEndpointOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteEndpointCallable = + callableFactory.createUnaryCallable( + deleteEndpointTransportSettings, settings.deleteEndpointSettings(), clientContext); + this.deleteEndpointOperationCallable = + callableFactory.createOperationCallable( + deleteEndpointTransportSettings, + settings.deleteEndpointOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listEndpointsMethodDescriptor); + methodDescriptors.add(getEndpointMethodDescriptor); + methodDescriptors.add(createEndpointMethodDescriptor); + methodDescriptors.add(deleteEndpointMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listEndpointsCallable() { + return listEndpointsCallable; + } + + @Override + public UnaryCallable + listEndpointsPagedCallable() { + return listEndpointsPagedCallable; + } + + @Override + public UnaryCallable getEndpointCallable() { + return getEndpointCallable; + } + + @Override + public UnaryCallable createEndpointCallable() { + return createEndpointCallable; + } + + @Override + public OperationCallable + createEndpointOperationCallable() { + return createEndpointOperationCallable; + } + + @Override + public UnaryCallable deleteEndpointCallable() { + return deleteEndpointCallable; + } + + @Override + public OperationCallable + deleteEndpointOperationCallable() { + return deleteEndpointOperationCallable; + } + + @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-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStub.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStub.java index a105e89c8796..95de03cb38fb 100644 --- a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStub.java +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStub.java @@ -43,7 +43,11 @@ public abstract class IDSStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStubSettings.java b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStubSettings.java index 6ee71b1132b2..4ef3059db590 100644 --- a/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStubSettings.java +++ b/java-ids/google-cloud-ids/src/main/java/com/google/cloud/ids/v1/stub/IDSStubSettings.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; @@ -204,6 +207,11 @@ public IDSStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcIDSStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonIDSStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -236,29 +244,54 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(IDSStubSettings.class)) .setTransportToken( GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(IDSStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return IDSStubSettings.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); @@ -400,6 +433,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 .listEndpointsSettings() diff --git a/java-ids/google-cloud-ids/src/test/java/com/google/cloud/ids/v1/IDSClientHttpJsonTest.java b/java-ids/google-cloud-ids/src/test/java/com/google/cloud/ids/v1/IDSClientHttpJsonTest.java new file mode 100644 index 000000000000..e6a082d06180 --- /dev/null +++ b/java-ids/google-cloud-ids/src/test/java/com/google/cloud/ids/v1/IDSClientHttpJsonTest.java @@ -0,0 +1,498 @@ +/* + * 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.ids.v1; + +import static com.google.cloud.ids.v1.IDSClient.ListEndpointsPagedResponse; + +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.ids.v1.stub.HttpJsonIDSStub; +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.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class IDSClientHttpJsonTest { + private static MockHttpService mockService; + private static IDSClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonIDSStub.getMethodDescriptors(), IDSSettings.getDefaultEndpoint()); + IDSSettings settings = + IDSSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + IDSSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = IDSClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listEndpointsTest() throws Exception { + Endpoint responsesElement = Endpoint.newBuilder().build(); + ListEndpointsResponse expectedResponse = + ListEndpointsResponse.newBuilder() + .setNextPageToken("") + .addAllEndpoints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEndpointsList().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 listEndpointsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listEndpoints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listEndpointsTest2() throws Exception { + Endpoint responsesElement = Endpoint.newBuilder().build(); + ListEndpointsResponse expectedResponse = + ListEndpointsResponse.newBuilder() + .setNextPageToken("") + .addAllEndpoints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEndpointsList().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 listEndpointsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listEndpoints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEndpointTest() throws Exception { + Endpoint expectedResponse = + Endpoint.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setNetwork("network1843485230") + .setEndpointForwardingRule("endpointForwardingRule1448974478") + .setEndpointIp("endpointIp-1837754980") + .setDescription("description-1724546052") + .setTrafficLogs(true) + .build(); + mockService.addResponse(expectedResponse); + + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + + Endpoint actualResponse = client.getEndpoint(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 getEndpointExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + client.getEndpoint(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEndpointTest2() throws Exception { + Endpoint expectedResponse = + Endpoint.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setNetwork("network1843485230") + .setEndpointForwardingRule("endpointForwardingRule1448974478") + .setEndpointIp("endpointIp-1837754980") + .setDescription("description-1724546052") + .setTrafficLogs(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-6164/locations/location-6164/endpoints/endpoint-6164"; + + Endpoint actualResponse = client.getEndpoint(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 getEndpointExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-6164/locations/location-6164/endpoints/endpoint-6164"; + client.getEndpoint(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createEndpointTest() throws Exception { + Endpoint expectedResponse = + Endpoint.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setNetwork("network1843485230") + .setEndpointForwardingRule("endpointForwardingRule1448974478") + .setEndpointIp("endpointIp-1837754980") + .setDescription("description-1724546052") + .setTrafficLogs(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createEndpointTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + + Endpoint actualResponse = client.createEndpointAsync(parent, endpoint, endpointId).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 createEndpointExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + client.createEndpointAsync(parent, endpoint, endpointId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createEndpointTest2() throws Exception { + Endpoint expectedResponse = + Endpoint.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setNetwork("network1843485230") + .setEndpointForwardingRule("endpointForwardingRule1448974478") + .setEndpointIp("endpointIp-1837754980") + .setDescription("description-1724546052") + .setTrafficLogs(true) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createEndpointTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + + Endpoint actualResponse = client.createEndpointAsync(parent, endpoint, endpointId).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 createEndpointExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + client.createEndpointAsync(parent, endpoint, endpointId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteEndpointTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteEndpointTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + + client.deleteEndpointAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteEndpointExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + client.deleteEndpointAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteEndpointTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteEndpointTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-6164/locations/location-6164/endpoints/endpoint-6164"; + + client.deleteEndpointAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteEndpointExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-6164/locations/location-6164/endpoints/endpoint-6164"; + client.deleteEndpointAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..066e502c9c13 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.IDSSettings; +import com.google.cloud.ids.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. + IDSSettings iDSSettings = + IDSSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + IDSClient iDSClient = IDSClient.create(iDSSettings); + } +} +// [END ids_v1_generated_idsclient_create_setcredentialsprovider_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider1.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..3148784ba9c9 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_create_setcredentialsprovider1_sync] +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.IDSSettings; + +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. + IDSSettings iDSSettings = + IDSSettings.newBuilder() + .setTransportChannelProvider( + IDSSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + IDSClient iDSClient = IDSClient.create(iDSSettings); + } +} +// [END ids_v1_generated_idsclient_create_setcredentialsprovider1_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..e80516d3d008 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,37 @@ +/* + * 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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_create_setendpoint_sync] +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.IDSSettings; +import com.google.cloud.ids.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. + IDSSettings iDSSettings = IDSSettings.newBuilder().setEndpoint(myEndpoint).build(); + IDSClient iDSClient = IDSClient.create(iDSSettings); + } +} +// [END ids_v1_generated_idsclient_create_setendpoint_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpoint.java new file mode 100644 index 000000000000..5c8ad80755b7 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpoint.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_createendpoint_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.ids.v1.CreateEndpointRequest; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; +import com.google.longrunning.Operation; + +public class AsyncCreateEndpoint { + + public static void main(String[] args) throws Exception { + asyncCreateEndpoint(); + } + + public static void asyncCreateEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + CreateEndpointRequest request = + CreateEndpointRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setEndpointId("endpointId-1837754992") + .setEndpoint(Endpoint.newBuilder().build()) + .setRequestId("requestId693933066") + .build(); + ApiFuture future = iDSClient.createEndpointCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END ids_v1_generated_idsclient_createendpoint_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpointLRO.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpointLRO.java new file mode 100644 index 000000000000..646d877b2ae2 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/AsyncCreateEndpointLRO.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_createendpoint_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.ids.v1.CreateEndpointRequest; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; +import com.google.cloud.ids.v1.OperationMetadata; + +public class AsyncCreateEndpointLRO { + + public static void main(String[] args) throws Exception { + asyncCreateEndpointLRO(); + } + + public static void asyncCreateEndpointLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + CreateEndpointRequest request = + CreateEndpointRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setEndpointId("endpointId-1837754992") + .setEndpoint(Endpoint.newBuilder().build()) + .setRequestId("requestId693933066") + .build(); + OperationFuture future = + iDSClient.createEndpointOperationCallable().futureCall(request); + // Do something. + Endpoint response = future.get(); + } + } +} +// [END ids_v1_generated_idsclient_createendpoint_lro_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpoint.java new file mode 100644 index 000000000000..0b96ca0876df --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_createendpoint_sync] +import com.google.cloud.ids.v1.CreateEndpointRequest; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; + +public class SyncCreateEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateEndpoint(); + } + + public static void syncCreateEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + CreateEndpointRequest request = + CreateEndpointRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setEndpointId("endpointId-1837754992") + .setEndpoint(Endpoint.newBuilder().build()) + .setRequestId("requestId693933066") + .build(); + Endpoint response = iDSClient.createEndpointAsync(request).get(); + } + } +} +// [END ids_v1_generated_idsclient_createendpoint_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointLocationnameEndpointString.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointLocationnameEndpointString.java new file mode 100644 index 000000000000..3629c565d817 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointLocationnameEndpointString.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_createendpoint_locationnameendpointstring_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; + +public class SyncCreateEndpointLocationnameEndpointString { + + public static void main(String[] args) throws Exception { + syncCreateEndpointLocationnameEndpointString(); + } + + public static void syncCreateEndpointLocationnameEndpointString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + Endpoint response = iDSClient.createEndpointAsync(parent, endpoint, endpointId).get(); + } + } +} +// [END ids_v1_generated_idsclient_createendpoint_locationnameendpointstring_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointStringEndpointString.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointStringEndpointString.java new file mode 100644 index 000000000000..5396b8081e8c --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/createendpoint/SyncCreateEndpointStringEndpointString.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_createendpoint_stringendpointstring_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; + +public class SyncCreateEndpointStringEndpointString { + + public static void main(String[] args) throws Exception { + syncCreateEndpointStringEndpointString(); + } + + public static void syncCreateEndpointStringEndpointString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Endpoint endpoint = Endpoint.newBuilder().build(); + String endpointId = "endpointId-1837754992"; + Endpoint response = iDSClient.createEndpointAsync(parent, endpoint, endpointId).get(); + } + } +} +// [END ids_v1_generated_idsclient_createendpoint_stringendpointstring_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpoint.java new file mode 100644 index 000000000000..7311196e7141 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_deleteendpoint_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.ids.v1.DeleteEndpointRequest; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteEndpoint { + + public static void main(String[] args) throws Exception { + asyncDeleteEndpoint(); + } + + public static void asyncDeleteEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + DeleteEndpointRequest request = + DeleteEndpointRequest.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setRequestId("requestId693933066") + .build(); + ApiFuture future = iDSClient.deleteEndpointCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END ids_v1_generated_idsclient_deleteendpoint_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpointLRO.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpointLRO.java new file mode 100644 index 000000000000..5b2937dea16f --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/AsyncDeleteEndpointLRO.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_deleteendpoint_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.ids.v1.DeleteEndpointRequest; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.OperationMetadata; +import com.google.protobuf.Empty; + +public class AsyncDeleteEndpointLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteEndpointLRO(); + } + + public static void asyncDeleteEndpointLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + DeleteEndpointRequest request = + DeleteEndpointRequest.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setRequestId("requestId693933066") + .build(); + OperationFuture future = + iDSClient.deleteEndpointOperationCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END ids_v1_generated_idsclient_deleteendpoint_lro_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpoint.java new file mode 100644 index 000000000000..d082ce86cf84 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_deleteendpoint_sync] +import com.google.cloud.ids.v1.DeleteEndpointRequest; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncDeleteEndpoint { + + public static void main(String[] args) throws Exception { + syncDeleteEndpoint(); + } + + public static void syncDeleteEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + DeleteEndpointRequest request = + DeleteEndpointRequest.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .setRequestId("requestId693933066") + .build(); + iDSClient.deleteEndpointAsync(request).get(); + } + } +} +// [END ids_v1_generated_idsclient_deleteendpoint_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointEndpointname.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointEndpointname.java new file mode 100644 index 000000000000..f1147534fca5 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointEndpointname.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_deleteendpoint_endpointname_sync] +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncDeleteEndpointEndpointname { + + public static void main(String[] args) throws Exception { + syncDeleteEndpointEndpointname(); + } + + public static void syncDeleteEndpointEndpointname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + iDSClient.deleteEndpointAsync(name).get(); + } + } +} +// [END ids_v1_generated_idsclient_deleteendpoint_endpointname_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointString.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointString.java new file mode 100644 index 000000000000..54d2562bf284 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/deleteendpoint/SyncDeleteEndpointString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_deleteendpoint_string_sync] +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncDeleteEndpointString { + + public static void main(String[] args) throws Exception { + syncDeleteEndpointString(); + } + + public static void syncDeleteEndpointString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + String name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString(); + iDSClient.deleteEndpointAsync(name).get(); + } + } +} +// [END ids_v1_generated_idsclient_deleteendpoint_string_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/AsyncGetEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/AsyncGetEndpoint.java new file mode 100644 index 000000000000..9243c314445e --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/AsyncGetEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_getendpoint_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.GetEndpointRequest; +import com.google.cloud.ids.v1.IDSClient; + +public class AsyncGetEndpoint { + + public static void main(String[] args) throws Exception { + asyncGetEndpoint(); + } + + public static void asyncGetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + GetEndpointRequest request = + GetEndpointRequest.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .build(); + ApiFuture future = iDSClient.getEndpointCallable().futureCall(request); + // Do something. + Endpoint response = future.get(); + } + } +} +// [END ids_v1_generated_idsclient_getendpoint_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpoint.java new file mode 100644 index 000000000000..6cdab42a0822 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_getendpoint_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.GetEndpointRequest; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncGetEndpoint { + + public static void main(String[] args) throws Exception { + syncGetEndpoint(); + } + + public static void syncGetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + GetEndpointRequest request = + GetEndpointRequest.newBuilder() + .setName(EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString()) + .build(); + Endpoint response = iDSClient.getEndpoint(request); + } + } +} +// [END ids_v1_generated_idsclient_getendpoint_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointEndpointname.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointEndpointname.java new file mode 100644 index 000000000000..4314abe5469e --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointEndpointname.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_getendpoint_endpointname_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncGetEndpointEndpointname { + + public static void main(String[] args) throws Exception { + syncGetEndpointEndpointname(); + } + + public static void syncGetEndpointEndpointname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]"); + Endpoint response = iDSClient.getEndpoint(name); + } + } +} +// [END ids_v1_generated_idsclient_getendpoint_endpointname_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointString.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointString.java new file mode 100644 index 000000000000..6b25541547c8 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/getendpoint/SyncGetEndpointString.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_getendpoint_string_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.EndpointName; +import com.google.cloud.ids.v1.IDSClient; + +public class SyncGetEndpointString { + + public static void main(String[] args) throws Exception { + syncGetEndpointString(); + } + + public static void syncGetEndpointString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + String name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]").toString(); + Endpoint response = iDSClient.getEndpoint(name); + } + } +} +// [END ids_v1_generated_idsclient_getendpoint_string_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpoints.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpoints.java new file mode 100644 index 000000000000..e5729e871dff --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpoints.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_listendpoints_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.ListEndpointsRequest; +import com.google.cloud.ids.v1.LocationName; + +public class AsyncListEndpoints { + + public static void main(String[] args) throws Exception { + asyncListEndpoints(); + } + + public static void asyncListEndpoints() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + ListEndpointsRequest request = + ListEndpointsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = iDSClient.listEndpointsPagedCallable().futureCall(request); + // Do something. + for (Endpoint element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END ids_v1_generated_idsclient_listendpoints_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpointsPaged.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpointsPaged.java new file mode 100644 index 000000000000..19807aa33cfc --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/AsyncListEndpointsPaged.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.ids.v1.samples; + +// [START ids_v1_generated_idsclient_listendpoints_paged_async] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.ListEndpointsRequest; +import com.google.cloud.ids.v1.ListEndpointsResponse; +import com.google.cloud.ids.v1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListEndpointsPaged { + + public static void main(String[] args) throws Exception { + asyncListEndpointsPaged(); + } + + public static void asyncListEndpointsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + ListEndpointsRequest request = + ListEndpointsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListEndpointsResponse response = iDSClient.listEndpointsCallable().call(request); + for (Endpoint element : response.getEndpointsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END ids_v1_generated_idsclient_listendpoints_paged_async] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpoints.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpoints.java new file mode 100644 index 000000000000..a9b67f22edbd --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpoints.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_listendpoints_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.ListEndpointsRequest; +import com.google.cloud.ids.v1.LocationName; + +public class SyncListEndpoints { + + public static void main(String[] args) throws Exception { + syncListEndpoints(); + } + + public static void syncListEndpoints() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + ListEndpointsRequest request = + ListEndpointsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (Endpoint element : iDSClient.listEndpoints(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END ids_v1_generated_idsclient_listendpoints_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsLocationname.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsLocationname.java new file mode 100644 index 000000000000..dd315f8ea785 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsLocationname.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_listendpoints_locationname_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; + +public class SyncListEndpointsLocationname { + + public static void main(String[] args) throws Exception { + syncListEndpointsLocationname(); + } + + public static void syncListEndpointsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Endpoint element : iDSClient.listEndpoints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END ids_v1_generated_idsclient_listendpoints_locationname_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsString.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsString.java new file mode 100644 index 000000000000..61312a9db967 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idsclient/listendpoints/SyncListEndpointsString.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.ids.v1.samples; + +// [START ids_v1_generated_idsclient_listendpoints_string_sync] +import com.google.cloud.ids.v1.Endpoint; +import com.google.cloud.ids.v1.IDSClient; +import com.google.cloud.ids.v1.LocationName; + +public class SyncListEndpointsString { + + public static void main(String[] args) throws Exception { + syncListEndpointsString(); + } + + public static void syncListEndpointsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (IDSClient iDSClient = IDSClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Endpoint element : iDSClient.listEndpoints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END ids_v1_generated_idsclient_listendpoints_string_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idssettings/getendpoint/SyncGetEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idssettings/getendpoint/SyncGetEndpoint.java new file mode 100644 index 000000000000..b9465df11b6b --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/idssettings/getendpoint/SyncGetEndpoint.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.ids.v1.samples; + +// [START ids_v1_generated_idssettings_getendpoint_sync] +import com.google.cloud.ids.v1.IDSSettings; +import java.time.Duration; + +public class SyncGetEndpoint { + + public static void main(String[] args) throws Exception { + syncGetEndpoint(); + } + + public static void syncGetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + IDSSettings.Builder iDSSettingsBuilder = IDSSettings.newBuilder(); + iDSSettingsBuilder + .getEndpointSettings() + .setRetrySettings( + iDSSettingsBuilder + .getEndpointSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + IDSSettings iDSSettings = iDSSettingsBuilder.build(); + } +} +// [END ids_v1_generated_idssettings_getendpoint_sync] diff --git a/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/stub/idsstubsettings/getendpoint/SyncGetEndpoint.java b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/stub/idsstubsettings/getendpoint/SyncGetEndpoint.java new file mode 100644 index 000000000000..5884e17b56e4 --- /dev/null +++ b/java-ids/samples/snippets/generated/com/google/cloud/ids/v1/stub/idsstubsettings/getendpoint/SyncGetEndpoint.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.ids.v1.stub.samples; + +// [START ids_v1_generated_idsstubsettings_getendpoint_sync] +import com.google.cloud.ids.v1.stub.IDSStubSettings; +import java.time.Duration; + +public class SyncGetEndpoint { + + public static void main(String[] args) throws Exception { + syncGetEndpoint(); + } + + public static void syncGetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + IDSStubSettings.Builder iDSSettingsBuilder = IDSStubSettings.newBuilder(); + iDSSettingsBuilder + .getEndpointSettings() + .setRetrySettings( + iDSSettingsBuilder + .getEndpointSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + IDSStubSettings iDSSettings = iDSSettingsBuilder.build(); + } +} +// [END ids_v1_generated_idsstubsettings_getendpoint_sync]