diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index a79f062..a454a61 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:2567a120ce90fadb6201999b87d649d9f67459de28815ad239bce9ebfaa18a74 -# created: 2022-05-19T15:12:45.278246753Z + digest: sha256:6d4e3a15c62cfdcb823d60e16da7521e7c6fc00eba07c8ff12e4de9924a57d28 +# created: 2022-06-29T23:17:33.110417661Z diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml index 8bfbe60..e18774c 100644 --- a/.github/.OwlBot.yaml +++ b/.github/.OwlBot.yaml @@ -16,6 +16,7 @@ docker: image: "gcr.io/cloud-devrel-public-resources/owlbot-java:latest" deep-remove-regex: +- "/samples/snippets/generated" - "/grpc-google-.*/src" - "/proto-google-.*/src" - "/google-.*/src" @@ -30,3 +31,5 @@ deep-copy-regex: dest: "/owl-bot-staging/$1/grpc-google-cloud-optimization-$1/src" - source: "/google/cloud/optimization/(v.*)/.*-java/gapic-google-.*/src" dest: "/owl-bot-staging/$1/google-cloud-optimization/src" +- source: "/google/cloud/optimization/(v.*)/.*-java/samples/snippets/generated" + dest: "/owl-bot-staging/$1/samples/snippets/generated" diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 4ebfe4b..4ea0953 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -44,7 +44,6 @@ branchProtectionRules: - "dependencies (8)" - "dependencies (11)" - "lint" - - "clirr" - "units (8)" - "units (11)" - "Kokoro - Test: Integration" diff --git a/.kokoro/common.sh b/.kokoro/common.sh index ace89f4..f8f957a 100644 --- a/.kokoro/common.sh +++ b/.kokoro/common.sh @@ -55,4 +55,6 @@ function retry_with_backoff { ## Helper functionss function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; } function msg() { println "$*" >&2; } -function println() { printf '%s\n' "$(now) $*"; } \ No newline at end of file +function println() { printf '%s\n' "$(now) $*"; } + +## Helper comment to trigger updated repo dependency release \ No newline at end of file diff --git a/.kokoro/release/stage.sh b/.kokoro/release/stage.sh index 77dc4e8..1dba8de 100755 --- a/.kokoro/release/stage.sh +++ b/.kokoro/release/stage.sh @@ -32,6 +32,7 @@ retry_with_backoff 3 10 \ mvn clean deploy -B \ --settings ${MAVEN_SETTINGS_FILE} \ -DskipTests=true \ + -Dclirr.skip=true \ -DperformRelease=true \ -Dgpg.executable=gpg \ -Dgpg.passphrase=${GPG_PASSPHRASE} \ @@ -42,4 +43,4 @@ then mvn nexus-staging:release -B \ -DperformRelease=true \ --settings=settings.xml -fi \ No newline at end of file +fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 7503481..c977d3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [1.1.0](https://github.com/googleapis/java-optimization/compare/v1.0.0...v1.1.0) (2022-07-01) + + +### Features + +* Enable REST transport for most of Java and Go clients ([#54](https://github.com/googleapis/java-optimization/issues/54)) ([e9284c1](https://github.com/googleapis/java-optimization/commit/e9284c1bd63cce756bda321edb3b2e0f9551efae)) + + +### Bug Fixes + +* update gapic-generator-java with mock service generation fixes ([#56](https://github.com/googleapis/java-optimization/issues/56)) ([fa19046](https://github.com/googleapis/java-optimization/commit/fa1904610fe7a42131e6802e126eab131b674846)) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.13.0 ([#53](https://github.com/googleapis/java-optimization/issues/53)) ([9d960a3](https://github.com/googleapis/java-optimization/commit/9d960a304dd3bdcf0c11bce0dbf8d8f9efd30f4d)) +* update dependency com.google.cloud:google-cloud-storage to v2.7.0 ([#49](https://github.com/googleapis/java-optimization/issues/49)) ([a6f9b2c](https://github.com/googleapis/java-optimization/commit/a6f9b2c34d9d2aca9ecc5f17857be55d2b74f11d)) + ## [1.0.0](https://github.com/googleapis/java-optimization/compare/v0.1.2...v1.0.0) (2022-05-19) diff --git a/README.md b/README.md index e7c8eb0..453c702 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-optimization - 0.1.2 + 1.0.0 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-optimization:0.1.2' +implementation 'com.google.cloud:google-cloud-optimization:1.0.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-optimization" % "0.1.2" +libraryDependencies += "com.google.cloud" % "google-cloud-optimization" % "1.0.0" ``` ## Authentication diff --git a/google-cloud-optimization-bom/pom.xml b/google-cloud-optimization-bom/pom.xml index b99dad7..c92fce8 100644 --- a/google-cloud-optimization-bom/pom.xml +++ b/google-cloud-optimization-bom/pom.xml @@ -3,12 +3,12 @@ 4.0.0 com.google.cloud google-cloud-optimization-bom - 1.0.0 + 1.1.0 pom com.google.cloud google-cloud-shared-config - 1.4.0 + 1.5.0 Google Cloud Fleet Routing BOM @@ -65,17 +65,17 @@ com.google.cloud google-cloud-optimization - 1.0.0 + 1.1.0 com.google.api.grpc grpc-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 com.google.api.grpc proto-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 diff --git a/google-cloud-optimization/pom.xml b/google-cloud-optimization/pom.xml index 93fd2df..2113a30 100644 --- a/google-cloud-optimization/pom.xml +++ b/google-cloud-optimization/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-optimization - 1.0.0 + 1.1.0 jar Google Cloud Fleet Routing https://github.com/googleapis/java-optimization @@ -11,7 +11,7 @@ com.google.cloud google-cloud-optimization-parent - 1.0.0 + 1.1.0 google-cloud-optimization @@ -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/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingClient.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingClient.java index 4275fab..9e39a2e 100644 --- a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingClient.java +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingClient.java @@ -18,13 +18,13 @@ import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.optimization.v1.stub.FleetRoutingStub; import com.google.cloud.optimization.v1.stub.FleetRoutingStubSettings; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -121,13 +121,28 @@ * FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings); * } * + *

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.
+ * FleetRoutingSettings fleetRoutingSettings =
+ *     FleetRoutingSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             FleetRoutingSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class FleetRoutingClient implements BackgroundResource { private final FleetRoutingSettings settings; private final FleetRoutingStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of FleetRoutingClient with default settings. */ public static final FleetRoutingClient create() throws IOException { @@ -146,7 +161,6 @@ public static final FleetRoutingClient create(FleetRoutingSettings settings) thr * Constructs an instance of FleetRoutingClient, using the given stub for making calls. This is * for advanced usage - prefer using create(FleetRoutingSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final FleetRoutingClient create(FleetRoutingStub stub) { return new FleetRoutingClient(stub); } @@ -159,21 +173,23 @@ public static final FleetRoutingClient create(FleetRoutingStub stub) { protected FleetRoutingClient(FleetRoutingSettings settings) throws IOException { this.settings = settings; this.stub = ((FleetRoutingStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected FleetRoutingClient(FleetRoutingStub 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 FleetRoutingSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public FleetRoutingStub getStub() { return stub; } @@ -182,10 +198,19 @@ public FleetRoutingStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an diff --git a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingSettings.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingSettings.java index 93da45a..d945f64 100644 --- a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingSettings.java +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/FleetRoutingSettings.java @@ -21,6 +21,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; @@ -112,11 +113,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return FleetRoutingStubSettings.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 FleetRoutingStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return FleetRoutingStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return FleetRoutingStubSettings.defaultTransportChannelProvider(); } @@ -126,11 +134,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return FleetRoutingStubSettings.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); @@ -168,6 +182,11 @@ private static Builder createDefault() { return new Builder(FleetRoutingStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(FleetRoutingStubSettings.newHttpJsonBuilder()); + } + public FleetRoutingStubSettings.Builder getStubSettingsBuilder() { return ((FleetRoutingStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStub.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStub.java index 4d71d13..a5b687b 100644 --- a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStub.java +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStub.java @@ -38,7 +38,11 @@ public abstract class FleetRoutingStub 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 optimizeToursCallable() { diff --git a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStubSettings.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStubSettings.java index ea19358..c65e70c 100644 --- a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStubSettings.java +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/FleetRoutingStubSettings.java @@ -25,6 +25,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; @@ -115,13 +118,17 @@ public UnaryCallSettings batchOptimizeTour return batchOptimizeToursOperationSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public FleetRoutingStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcFleetRoutingStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonFleetRoutingStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -154,18 +161,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(FleetRoutingStubSettings.class)) @@ -173,11 +187,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(FleetRoutingStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return FleetRoutingStubSettings.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); @@ -295,6 +328,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 .optimizeToursSettings() diff --git a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingCallableFactory.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingCallableFactory.java new file mode 100644 index 0000000..a72dc08 --- /dev/null +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingCallableFactory.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.optimization.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 FleetRouting service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonFleetRoutingCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingStub.java b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingStub.java new file mode 100644 index 0000000..de95502 --- /dev/null +++ b/google-cloud-optimization/src/main/java/com/google/cloud/optimization/v1/stub/HttpJsonFleetRoutingStub.java @@ -0,0 +1,287 @@ +/* + * 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.optimization.v1.stub; + +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.optimization.v1.AsyncModelMetadata; +import com.google.cloud.optimization.v1.BatchOptimizeToursRequest; +import com.google.cloud.optimization.v1.BatchOptimizeToursResponse; +import com.google.cloud.optimization.v1.OptimizeToursRequest; +import com.google.cloud.optimization.v1.OptimizeToursResponse; +import com.google.longrunning.Operation; +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 FleetRouting service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonFleetRoutingStub extends FleetRoutingStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(BatchOptimizeToursResponse.getDescriptor()) + .add(AsyncModelMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + optimizeToursMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.optimization.v1.FleetRouting/OptimizeTours") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}:optimizeTours", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v1/{parent=projects/*}:optimizeTours") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(OptimizeToursResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + batchOptimizeToursMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.optimization.v1.FleetRouting/BatchOptimizeTours") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}:batchOptimizeTours", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v1/{parent=projects/*}:batchOptimizeTours") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (BatchOptimizeToursRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable optimizeToursCallable; + private final UnaryCallable batchOptimizeToursCallable; + private final OperationCallable< + BatchOptimizeToursRequest, BatchOptimizeToursResponse, AsyncModelMetadata> + batchOptimizeToursOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonFleetRoutingStub create(FleetRoutingStubSettings settings) + throws IOException { + return new HttpJsonFleetRoutingStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonFleetRoutingStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonFleetRoutingStub( + FleetRoutingStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonFleetRoutingStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonFleetRoutingStub( + FleetRoutingStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonFleetRoutingStub, 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 HttpJsonFleetRoutingStub(FleetRoutingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonFleetRoutingCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonFleetRoutingStub, 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 HttpJsonFleetRoutingStub( + FleetRoutingStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + optimizeToursTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(optimizeToursMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings batchOptimizeToursTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchOptimizeToursMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.optimizeToursCallable = + callableFactory.createUnaryCallable( + optimizeToursTransportSettings, settings.optimizeToursSettings(), clientContext); + this.batchOptimizeToursCallable = + callableFactory.createUnaryCallable( + batchOptimizeToursTransportSettings, + settings.batchOptimizeToursSettings(), + clientContext); + this.batchOptimizeToursOperationCallable = + callableFactory.createOperationCallable( + batchOptimizeToursTransportSettings, + settings.batchOptimizeToursOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(optimizeToursMethodDescriptor); + methodDescriptors.add(batchOptimizeToursMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable optimizeToursCallable() { + return optimizeToursCallable; + } + + @Override + public UnaryCallable batchOptimizeToursCallable() { + return batchOptimizeToursCallable; + } + + @Override + public OperationCallable< + BatchOptimizeToursRequest, BatchOptimizeToursResponse, AsyncModelMetadata> + batchOptimizeToursOperationCallable() { + return batchOptimizeToursOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-optimization/src/test/java/com/google/cloud/optimization/v1/FleetRoutingClientHttpJsonTest.java b/google-cloud-optimization/src/test/java/com/google/cloud/optimization/v1/FleetRoutingClientHttpJsonTest.java new file mode 100644 index 0000000..3bdd6cb --- /dev/null +++ b/google-cloud-optimization/src/test/java/com/google/cloud/optimization/v1/FleetRoutingClientHttpJsonTest.java @@ -0,0 +1,217 @@ +/* + * 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.optimization.v1; + +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.optimization.v1.stub.HttpJsonFleetRoutingStub; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Duration; +import java.io.IOException; +import java.util.ArrayList; +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 FleetRoutingClientHttpJsonTest { + private static MockHttpService mockService; + private static FleetRoutingClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonFleetRoutingStub.getMethodDescriptors(), + FleetRoutingSettings.getDefaultEndpoint()); + FleetRoutingSettings settings = + FleetRoutingSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + FleetRoutingSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = FleetRoutingClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void optimizeToursTest() throws Exception { + OptimizeToursResponse expectedResponse = + OptimizeToursResponse.newBuilder() + .addAllRoutes(new ArrayList()) + .setRequestLabel("requestLabel1285152165") + .addAllSkippedShipments(new ArrayList()) + .addAllValidationErrors(new ArrayList()) + .setMetrics(OptimizeToursResponse.Metrics.newBuilder().build()) + .setTotalCost(-705890328) + .build(); + mockService.addResponse(expectedResponse); + + OptimizeToursRequest request = + OptimizeToursRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setTimeout(Duration.newBuilder().build()) + .setModel(ShipmentModel.newBuilder().build()) + .setMaxValidationErrors(-1367418922) + .addAllInjectedFirstSolutionRoutes(new ArrayList()) + .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build()) + .addAllRefreshDetailsRoutes(new ArrayList()) + .setInterpretInjectedSolutionsUsingLabels(true) + .setConsiderRoadTraffic(true) + .setPopulatePolylines(true) + .setPopulateTransitionPolylines(true) + .setAllowLargeDeadlineDespiteInterruptionRisk(true) + .setUseGeodesicDistances(true) + .setGeodesicMetersPerSecond(-2129658905) + .setLabel("label102727412") + .setPopulateTravelStepPolylines(true) + .build(); + + OptimizeToursResponse actualResponse = client.optimizeTours(request); + 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 optimizeToursExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OptimizeToursRequest request = + OptimizeToursRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setTimeout(Duration.newBuilder().build()) + .setModel(ShipmentModel.newBuilder().build()) + .setMaxValidationErrors(-1367418922) + .addAllInjectedFirstSolutionRoutes(new ArrayList()) + .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build()) + .addAllRefreshDetailsRoutes(new ArrayList()) + .setInterpretInjectedSolutionsUsingLabels(true) + .setConsiderRoadTraffic(true) + .setPopulatePolylines(true) + .setPopulateTransitionPolylines(true) + .setAllowLargeDeadlineDespiteInterruptionRisk(true) + .setUseGeodesicDistances(true) + .setGeodesicMetersPerSecond(-2129658905) + .setLabel("label102727412") + .setPopulateTravelStepPolylines(true) + .build(); + client.optimizeTours(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchOptimizeToursTest() throws Exception { + BatchOptimizeToursResponse expectedResponse = BatchOptimizeToursResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchOptimizeToursTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + BatchOptimizeToursRequest request = + BatchOptimizeToursRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .addAllModelConfigs(new ArrayList()) + .build(); + + BatchOptimizeToursResponse actualResponse = client.batchOptimizeToursAsync(request).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 batchOptimizeToursExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchOptimizeToursRequest request = + BatchOptimizeToursRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .addAllModelConfigs(new ArrayList()) + .build(); + client.batchOptimizeToursAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/grpc-google-cloud-optimization-v1/pom.xml b/grpc-google-cloud-optimization-v1/pom.xml index 2ae6d97..f80a0bb 100644 --- a/grpc-google-cloud-optimization-v1/pom.xml +++ b/grpc-google-cloud-optimization-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 grpc-google-cloud-optimization-v1 GRPC library for google-cloud-optimization com.google.cloud google-cloud-optimization-parent - 1.0.0 + 1.1.0 diff --git a/pom.xml b/pom.xml index 3adbfc9..14509cf 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-optimization-parent pom - 1.0.0 + 1.1.0 Google Cloud Fleet Routing Parent https://github.com/googleapis/java-optimization @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 1.4.0 + 1.5.0 @@ -69,23 +69,23 @@ com.google.cloud google-cloud-optimization - 1.0.0 + 1.1.0 com.google.api.grpc grpc-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 com.google.api.grpc proto-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 com.google.cloud google-cloud-shared-dependencies - 2.12.0 + 2.13.0 pom import diff --git a/proto-google-cloud-optimization-v1/pom.xml b/proto-google-cloud-optimization-v1/pom.xml index 07d6c1b..2ad5228 100644 --- a/proto-google-cloud-optimization-v1/pom.xml +++ b/proto-google-cloud-optimization-v1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-optimization-v1 - 1.0.0 + 1.1.0 proto-google-cloud-optimization-v1 Proto library for google-cloud-optimization com.google.cloud google-cloud-optimization-parent - 1.0.0 + 1.1.0 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index b371c71..db474b0 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,13 +29,13 @@ com.google.cloud google-cloud-optimization - 0.1.2 + 1.0.0 com.google.cloud google-cloud-storage - 2.6.1 + 2.7.0 junit diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 0790e9f..e36e5da 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,14 +28,14 @@ com.google.cloud google-cloud-optimization - 1.0.0 + 1.1.0 com.google.cloud google-cloud-storage - 2.6.1 + 2.7.0 junit diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeTours.java new file mode 100644 index 0000000..005ceb6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeTours.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_batchoptimizetours_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.optimization.v1.BatchOptimizeToursRequest; +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.longrunning.Operation; +import java.util.ArrayList; + +public class AsyncBatchOptimizeTours { + + public static void main(String[] args) throws Exception { + asyncBatchOptimizeTours(); + } + + public static void asyncBatchOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) { + BatchOptimizeToursRequest request = + BatchOptimizeToursRequest.newBuilder() + .setParent("parent-995424086") + .addAllModelConfigs(new ArrayList()) + .build(); + ApiFuture future = + fleetRoutingClient.batchOptimizeToursCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END optimization_v1_generated_fleetroutingclient_batchoptimizetours_async] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeToursLRO.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeToursLRO.java new file mode 100644 index 0000000..c940969 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/AsyncBatchOptimizeToursLRO.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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_batchoptimizetours_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.optimization.v1.AsyncModelMetadata; +import com.google.cloud.optimization.v1.BatchOptimizeToursRequest; +import com.google.cloud.optimization.v1.BatchOptimizeToursResponse; +import com.google.cloud.optimization.v1.FleetRoutingClient; +import java.util.ArrayList; + +public class AsyncBatchOptimizeToursLRO { + + public static void main(String[] args) throws Exception { + asyncBatchOptimizeToursLRO(); + } + + public static void asyncBatchOptimizeToursLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) { + BatchOptimizeToursRequest request = + BatchOptimizeToursRequest.newBuilder() + .setParent("parent-995424086") + .addAllModelConfigs(new ArrayList()) + .build(); + OperationFuture future = + fleetRoutingClient.batchOptimizeToursOperationCallable().futureCall(request); + // Do something. + BatchOptimizeToursResponse response = future.get(); + } + } +} +// [END optimization_v1_generated_fleetroutingclient_batchoptimizetours_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/SyncBatchOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/SyncBatchOptimizeTours.java new file mode 100644 index 0000000..f619b46 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/batchoptimizetours/SyncBatchOptimizeTours.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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_batchoptimizetours_sync] +import com.google.cloud.optimization.v1.BatchOptimizeToursRequest; +import com.google.cloud.optimization.v1.BatchOptimizeToursResponse; +import com.google.cloud.optimization.v1.FleetRoutingClient; +import java.util.ArrayList; + +public class SyncBatchOptimizeTours { + + public static void main(String[] args) throws Exception { + syncBatchOptimizeTours(); + } + + public static void syncBatchOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) { + BatchOptimizeToursRequest request = + BatchOptimizeToursRequest.newBuilder() + .setParent("parent-995424086") + .addAllModelConfigs(new ArrayList()) + .build(); + BatchOptimizeToursResponse response = + fleetRoutingClient.batchOptimizeToursAsync(request).get(); + } + } +} +// [END optimization_v1_generated_fleetroutingclient_batchoptimizetours_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000..a12b132 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.cloud.optimization.v1.FleetRoutingSettings; +import com.google.cloud.optimization.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. + FleetRoutingSettings fleetRoutingSettings = + FleetRoutingSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings); + } +} +// [END optimization_v1_generated_fleetroutingclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000..3e68985 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_create_setcredentialsprovider1_sync] +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.cloud.optimization.v1.FleetRoutingSettings; + +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. + FleetRoutingSettings fleetRoutingSettings = + FleetRoutingSettings.newBuilder() + .setTransportChannelProvider( + FleetRoutingSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings); + } +} +// [END optimization_v1_generated_fleetroutingclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000..f264383 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_create_setendpoint_sync] +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.cloud.optimization.v1.FleetRoutingSettings; +import com.google.cloud.optimization.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. + FleetRoutingSettings fleetRoutingSettings = + FleetRoutingSettings.newBuilder().setEndpoint(myEndpoint).build(); + FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings); + } +} +// [END optimization_v1_generated_fleetroutingclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/AsyncOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/AsyncOptimizeTours.java new file mode 100644 index 0000000..61eda2d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/AsyncOptimizeTours.java @@ -0,0 +1,66 @@ +/* + * 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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_optimizetours_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.cloud.optimization.v1.InjectedSolutionConstraint; +import com.google.cloud.optimization.v1.OptimizeToursRequest; +import com.google.cloud.optimization.v1.OptimizeToursResponse; +import com.google.cloud.optimization.v1.ShipmentModel; +import com.google.cloud.optimization.v1.ShipmentRoute; +import com.google.protobuf.Duration; +import java.util.ArrayList; + +public class AsyncOptimizeTours { + + public static void main(String[] args) throws Exception { + asyncOptimizeTours(); + } + + public static void asyncOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) { + OptimizeToursRequest request = + OptimizeToursRequest.newBuilder() + .setParent("parent-995424086") + .setTimeout(Duration.newBuilder().build()) + .setModel(ShipmentModel.newBuilder().build()) + .setMaxValidationErrors(-1367418922) + .addAllInjectedFirstSolutionRoutes(new ArrayList()) + .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build()) + .addAllRefreshDetailsRoutes(new ArrayList()) + .setInterpretInjectedSolutionsUsingLabels(true) + .setConsiderRoadTraffic(true) + .setPopulatePolylines(true) + .setPopulateTransitionPolylines(true) + .setAllowLargeDeadlineDespiteInterruptionRisk(true) + .setUseGeodesicDistances(true) + .setGeodesicMetersPerSecond(-2129658905) + .setLabel("label102727412") + .setPopulateTravelStepPolylines(true) + .build(); + ApiFuture future = + fleetRoutingClient.optimizeToursCallable().futureCall(request); + // Do something. + OptimizeToursResponse response = future.get(); + } + } +} +// [END optimization_v1_generated_fleetroutingclient_optimizetours_async] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/SyncOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/SyncOptimizeTours.java new file mode 100644 index 0000000..ad5f8da --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingclient/optimizetours/SyncOptimizeTours.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingclient_optimizetours_sync] +import com.google.cloud.optimization.v1.FleetRoutingClient; +import com.google.cloud.optimization.v1.InjectedSolutionConstraint; +import com.google.cloud.optimization.v1.OptimizeToursRequest; +import com.google.cloud.optimization.v1.OptimizeToursResponse; +import com.google.cloud.optimization.v1.ShipmentModel; +import com.google.cloud.optimization.v1.ShipmentRoute; +import com.google.protobuf.Duration; +import java.util.ArrayList; + +public class SyncOptimizeTours { + + public static void main(String[] args) throws Exception { + syncOptimizeTours(); + } + + public static void syncOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) { + OptimizeToursRequest request = + OptimizeToursRequest.newBuilder() + .setParent("parent-995424086") + .setTimeout(Duration.newBuilder().build()) + .setModel(ShipmentModel.newBuilder().build()) + .setMaxValidationErrors(-1367418922) + .addAllInjectedFirstSolutionRoutes(new ArrayList()) + .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build()) + .addAllRefreshDetailsRoutes(new ArrayList()) + .setInterpretInjectedSolutionsUsingLabels(true) + .setConsiderRoadTraffic(true) + .setPopulatePolylines(true) + .setPopulateTransitionPolylines(true) + .setAllowLargeDeadlineDespiteInterruptionRisk(true) + .setUseGeodesicDistances(true) + .setGeodesicMetersPerSecond(-2129658905) + .setLabel("label102727412") + .setPopulateTravelStepPolylines(true) + .build(); + OptimizeToursResponse response = fleetRoutingClient.optimizeTours(request); + } + } +} +// [END optimization_v1_generated_fleetroutingclient_optimizetours_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingsettings/optimizetours/SyncOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingsettings/optimizetours/SyncOptimizeTours.java new file mode 100644 index 0000000..563228a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/fleetroutingsettings/optimizetours/SyncOptimizeTours.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.optimization.v1.samples; + +// [START optimization_v1_generated_fleetroutingsettings_optimizetours_sync] +import com.google.cloud.optimization.v1.FleetRoutingSettings; +import java.time.Duration; + +public class SyncOptimizeTours { + + public static void main(String[] args) throws Exception { + syncOptimizeTours(); + } + + public static void syncOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + FleetRoutingSettings.Builder fleetRoutingSettingsBuilder = FleetRoutingSettings.newBuilder(); + fleetRoutingSettingsBuilder + .optimizeToursSettings() + .setRetrySettings( + fleetRoutingSettingsBuilder + .optimizeToursSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + FleetRoutingSettings fleetRoutingSettings = fleetRoutingSettingsBuilder.build(); + } +} +// [END optimization_v1_generated_fleetroutingsettings_optimizetours_sync] diff --git a/samples/snippets/generated/com/google/cloud/optimization/v1/stub/fleetroutingstubsettings/optimizetours/SyncOptimizeTours.java b/samples/snippets/generated/com/google/cloud/optimization/v1/stub/fleetroutingstubsettings/optimizetours/SyncOptimizeTours.java new file mode 100644 index 0000000..931c07b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/optimization/v1/stub/fleetroutingstubsettings/optimizetours/SyncOptimizeTours.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.optimization.v1.stub.samples; + +// [START optimization_v1_generated_fleetroutingstubsettings_optimizetours_sync] +import com.google.cloud.optimization.v1.stub.FleetRoutingStubSettings; +import java.time.Duration; + +public class SyncOptimizeTours { + + public static void main(String[] args) throws Exception { + syncOptimizeTours(); + } + + public static void syncOptimizeTours() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + FleetRoutingStubSettings.Builder fleetRoutingSettingsBuilder = + FleetRoutingStubSettings.newBuilder(); + fleetRoutingSettingsBuilder + .optimizeToursSettings() + .setRetrySettings( + fleetRoutingSettingsBuilder + .optimizeToursSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + FleetRoutingStubSettings fleetRoutingSettings = fleetRoutingSettingsBuilder.build(); + } +} +// [END optimization_v1_generated_fleetroutingstubsettings_optimizetours_sync] diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 1de8918..7ee76b2 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -32,7 +32,7 @@ com.google.cloud libraries-bom - 25.3.0 + 25.4.0 pom import @@ -43,7 +43,7 @@ com.google.cloud google-cloud-optimization - 0.1.2 + 1.0.0 com.google.cloud diff --git a/versions.txt b/versions.txt index 8ca1918..5acbbcb 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -google-cloud-optimization:1.0.0:1.0.0 -proto-google-cloud-optimization-v1:1.0.0:1.0.0 -grpc-google-cloud-optimization-v1:1.0.0:1.0.0 +google-cloud-optimization:1.1.0:1.1.0 +proto-google-cloud-optimization-v1:1.1.0:1.1.0 +grpc-google-cloud-optimization-v1:1.1.0:1.1.0