diff --git a/java-scheduler/google-cloud-scheduler/pom.xml b/java-scheduler/google-cloud-scheduler/pom.xml index 6d0a7e043a6c..759e03ee987e 100644 --- a/java-scheduler/google-cloud-scheduler/pom.xml +++ b/java-scheduler/google-cloud-scheduler/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -100,12 +104,24 @@ + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerClient.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerClient.java index 24efc245f33b..de39d76f22d6 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerClient.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerClient.java @@ -99,6 +99,20 @@ * CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); * } * + *

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.
+ * CloudSchedulerSettings cloudSchedulerSettings =
+ *     CloudSchedulerSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerSettings.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerSettings.java index 17938456f868..b065c107ee77 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerSettings.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/CloudSchedulerSettings.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; @@ -139,11 +140,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudSchedulerStubSettings.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 CloudSchedulerStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudSchedulerStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudSchedulerStubSettings.defaultTransportChannelProvider(); } @@ -153,11 +161,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudSchedulerStubSettings.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); @@ -195,6 +209,11 @@ private static Builder createDefault() { return new Builder(CloudSchedulerStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudSchedulerStubSettings.newHttpJsonBuilder()); + } + public CloudSchedulerStubSettings.Builder getStubSettingsBuilder() { return ((CloudSchedulerStubSettings.Builder) getStubSettings()); } diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/CloudSchedulerStubSettings.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/CloudSchedulerStubSettings.java index fd48d0bbb596..fa706a24c277 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/CloudSchedulerStubSettings.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/CloudSchedulerStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +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.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -210,6 +213,11 @@ public CloudSchedulerStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudSchedulerStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudSchedulerStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -242,18 +250,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(CloudSchedulerStubSettings.class)) @@ -261,11 +276,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(CloudSchedulerStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudSchedulerStubSettings.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); @@ -411,6 +445,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 .listJobsSettings() diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerCallableFactory.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerCallableFactory.java new file mode 100644 index 000000000000..ed9f51aa02ed --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerCallableFactory.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.scheduler.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 CloudScheduler service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudSchedulerCallableFactory + 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-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerStub.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerStub.java new file mode 100644 index 000000000000..7b1f796ab344 --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1/stub/HttpJsonCloudSchedulerStub.java @@ -0,0 +1,554 @@ +/* + * 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.scheduler.v1.stub; + +import static com.google.cloud.scheduler.v1.CloudSchedulerClient.ListJobsPagedResponse; + +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.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.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.scheduler.v1.CreateJobRequest; +import com.google.cloud.scheduler.v1.DeleteJobRequest; +import com.google.cloud.scheduler.v1.GetJobRequest; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.ListJobsRequest; +import com.google.cloud.scheduler.v1.ListJobsResponse; +import com.google.cloud.scheduler.v1.PauseJobRequest; +import com.google.cloud.scheduler.v1.ResumeJobRequest; +import com.google.cloud.scheduler.v1.RunJobRequest; +import com.google.cloud.scheduler.v1.UpdateJobRequest; +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 CloudScheduler service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudSchedulerStub extends CloudSchedulerStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listJobsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/ListJobs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/jobs", + 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, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListJobsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/GetJob") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/jobs/*}", + 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(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/CreateJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/jobs", + 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(); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("job", request.getJob())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/UpdateJob") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{job.name=projects/*/locations/*/jobs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "job.name", request.getJob().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("job", request.getJob())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/DeleteJob") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/jobs/*}", + 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(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor pauseJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/PauseJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/jobs/*}:pause", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor resumeJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/ResumeJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/jobs/*}:resume", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor runJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/RunJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/jobs/*}:run", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listJobsCallable; + private final UnaryCallable listJobsPagedCallable; + private final UnaryCallable getJobCallable; + private final UnaryCallable createJobCallable; + private final UnaryCallable updateJobCallable; + private final UnaryCallable deleteJobCallable; + private final UnaryCallable pauseJobCallable; + private final UnaryCallable resumeJobCallable; + private final UnaryCallable runJobCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudSchedulerStub create(CloudSchedulerStubSettings settings) + throws IOException { + return new HttpJsonCloudSchedulerStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudSchedulerStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudSchedulerStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudSchedulerStub, 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 HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonCloudSchedulerCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudSchedulerStub, 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 HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listJobsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listJobsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pauseJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pauseJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings resumeJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(resumeJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings runJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listJobsCallable = + callableFactory.createUnaryCallable( + listJobsTransportSettings, settings.listJobsSettings(), clientContext); + this.listJobsPagedCallable = + callableFactory.createPagedCallable( + listJobsTransportSettings, settings.listJobsSettings(), clientContext); + this.getJobCallable = + callableFactory.createUnaryCallable( + getJobTransportSettings, settings.getJobSettings(), clientContext); + this.createJobCallable = + callableFactory.createUnaryCallable( + createJobTransportSettings, settings.createJobSettings(), clientContext); + this.updateJobCallable = + callableFactory.createUnaryCallable( + updateJobTransportSettings, settings.updateJobSettings(), clientContext); + this.deleteJobCallable = + callableFactory.createUnaryCallable( + deleteJobTransportSettings, settings.deleteJobSettings(), clientContext); + this.pauseJobCallable = + callableFactory.createUnaryCallable( + pauseJobTransportSettings, settings.pauseJobSettings(), clientContext); + this.resumeJobCallable = + callableFactory.createUnaryCallable( + resumeJobTransportSettings, settings.resumeJobSettings(), clientContext); + this.runJobCallable = + callableFactory.createUnaryCallable( + runJobTransportSettings, settings.runJobSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listJobsMethodDescriptor); + methodDescriptors.add(getJobMethodDescriptor); + methodDescriptors.add(createJobMethodDescriptor); + methodDescriptors.add(updateJobMethodDescriptor); + methodDescriptors.add(deleteJobMethodDescriptor); + methodDescriptors.add(pauseJobMethodDescriptor); + methodDescriptors.add(resumeJobMethodDescriptor); + methodDescriptors.add(runJobMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listJobsCallable() { + return listJobsCallable; + } + + @Override + public UnaryCallable listJobsPagedCallable() { + return listJobsPagedCallable; + } + + @Override + public UnaryCallable getJobCallable() { + return getJobCallable; + } + + @Override + public UnaryCallable createJobCallable() { + return createJobCallable; + } + + @Override + public UnaryCallable updateJobCallable() { + return updateJobCallable; + } + + @Override + public UnaryCallable deleteJobCallable() { + return deleteJobCallable; + } + + @Override + public UnaryCallable pauseJobCallable() { + return pauseJobCallable; + } + + @Override + public UnaryCallable resumeJobCallable() { + return resumeJobCallable; + } + + @Override + public UnaryCallable runJobCallable() { + return runJobCallable; + } + + @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-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClient.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClient.java index e8c28b1f9972..5e9460a1efe2 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClient.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClient.java @@ -100,6 +100,20 @@ * CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); * } * + *

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.
+ * CloudSchedulerSettings cloudSchedulerSettings =
+ *     CloudSchedulerSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerSettings.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerSettings.java index 5efcdb4065fb..513da07eedb1 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerSettings.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerSettings.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; @@ -140,11 +141,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudSchedulerStubSettings.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 CloudSchedulerStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudSchedulerStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudSchedulerStubSettings.defaultTransportChannelProvider(); } @@ -154,11 +162,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudSchedulerStubSettings.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); @@ -196,6 +210,11 @@ private static Builder createDefault() { return new Builder(CloudSchedulerStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudSchedulerStubSettings.newHttpJsonBuilder()); + } + public CloudSchedulerStubSettings.Builder getStubSettingsBuilder() { return ((CloudSchedulerStubSettings.Builder) getStubSettings()); } diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/CloudSchedulerStubSettings.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/CloudSchedulerStubSettings.java index 3d342c6208aa..4e8aa498bc23 100644 --- a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/CloudSchedulerStubSettings.java +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/CloudSchedulerStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +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.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -211,6 +214,11 @@ public CloudSchedulerStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudSchedulerStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudSchedulerStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -243,18 +251,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(CloudSchedulerStubSettings.class)) @@ -262,11 +277,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(CloudSchedulerStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudSchedulerStubSettings.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); @@ -412,6 +446,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 .listJobsSettings() diff --git a/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerCallableFactory.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerCallableFactory.java new file mode 100644 index 000000000000..1e6b5fe2ecf8 --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerCallableFactory.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.scheduler.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the CloudScheduler service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudSchedulerCallableFactory + 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-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerStub.java b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerStub.java new file mode 100644 index 000000000000..f23fb043e39c --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/main/java/com/google/cloud/scheduler/v1beta1/stub/HttpJsonCloudSchedulerStub.java @@ -0,0 +1,554 @@ +/* + * 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.scheduler.v1beta1.stub; + +import static com.google.cloud.scheduler.v1beta1.CloudSchedulerClient.ListJobsPagedResponse; + +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.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.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.scheduler.v1beta1.CreateJobRequest; +import com.google.cloud.scheduler.v1beta1.DeleteJobRequest; +import com.google.cloud.scheduler.v1beta1.GetJobRequest; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.ListJobsRequest; +import com.google.cloud.scheduler.v1beta1.ListJobsResponse; +import com.google.cloud.scheduler.v1beta1.PauseJobRequest; +import com.google.cloud.scheduler.v1beta1.ResumeJobRequest; +import com.google.cloud.scheduler.v1beta1.RunJobRequest; +import com.google.cloud.scheduler.v1beta1.UpdateJobRequest; +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 CloudScheduler service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudSchedulerStub extends CloudSchedulerStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listJobsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/ListJobs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*}/jobs", + 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, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListJobsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/GetJob") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/jobs/*}", + 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(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/CreateJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*}/jobs", + 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(); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("job", request.getJob())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/UpdateJob") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{job.name=projects/*/locations/*/jobs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "job.name", request.getJob().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("job", request.getJob())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/DeleteJob") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/jobs/*}", + 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(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor pauseJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/PauseJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/jobs/*}:pause", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor resumeJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/ResumeJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/jobs/*}:resume", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor runJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.scheduler.v1beta1.CloudScheduler/RunJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/jobs/*}:run", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Job.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listJobsCallable; + private final UnaryCallable listJobsPagedCallable; + private final UnaryCallable getJobCallable; + private final UnaryCallable createJobCallable; + private final UnaryCallable updateJobCallable; + private final UnaryCallable deleteJobCallable; + private final UnaryCallable pauseJobCallable; + private final UnaryCallable resumeJobCallable; + private final UnaryCallable runJobCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudSchedulerStub create(CloudSchedulerStubSettings settings) + throws IOException { + return new HttpJsonCloudSchedulerStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudSchedulerStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudSchedulerStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudSchedulerStub, 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 HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonCloudSchedulerCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudSchedulerStub, 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 HttpJsonCloudSchedulerStub( + CloudSchedulerStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listJobsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listJobsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pauseJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pauseJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings resumeJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(resumeJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings runJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listJobsCallable = + callableFactory.createUnaryCallable( + listJobsTransportSettings, settings.listJobsSettings(), clientContext); + this.listJobsPagedCallable = + callableFactory.createPagedCallable( + listJobsTransportSettings, settings.listJobsSettings(), clientContext); + this.getJobCallable = + callableFactory.createUnaryCallable( + getJobTransportSettings, settings.getJobSettings(), clientContext); + this.createJobCallable = + callableFactory.createUnaryCallable( + createJobTransportSettings, settings.createJobSettings(), clientContext); + this.updateJobCallable = + callableFactory.createUnaryCallable( + updateJobTransportSettings, settings.updateJobSettings(), clientContext); + this.deleteJobCallable = + callableFactory.createUnaryCallable( + deleteJobTransportSettings, settings.deleteJobSettings(), clientContext); + this.pauseJobCallable = + callableFactory.createUnaryCallable( + pauseJobTransportSettings, settings.pauseJobSettings(), clientContext); + this.resumeJobCallable = + callableFactory.createUnaryCallable( + resumeJobTransportSettings, settings.resumeJobSettings(), clientContext); + this.runJobCallable = + callableFactory.createUnaryCallable( + runJobTransportSettings, settings.runJobSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listJobsMethodDescriptor); + methodDescriptors.add(getJobMethodDescriptor); + methodDescriptors.add(createJobMethodDescriptor); + methodDescriptors.add(updateJobMethodDescriptor); + methodDescriptors.add(deleteJobMethodDescriptor); + methodDescriptors.add(pauseJobMethodDescriptor); + methodDescriptors.add(resumeJobMethodDescriptor); + methodDescriptors.add(runJobMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listJobsCallable() { + return listJobsCallable; + } + + @Override + public UnaryCallable listJobsPagedCallable() { + return listJobsPagedCallable; + } + + @Override + public UnaryCallable getJobCallable() { + return getJobCallable; + } + + @Override + public UnaryCallable createJobCallable() { + return createJobCallable; + } + + @Override + public UnaryCallable updateJobCallable() { + return updateJobCallable; + } + + @Override + public UnaryCallable deleteJobCallable() { + return deleteJobCallable; + } + + @Override + public UnaryCallable pauseJobCallable() { + return pauseJobCallable; + } + + @Override + public UnaryCallable resumeJobCallable() { + return resumeJobCallable; + } + + @Override + public UnaryCallable runJobCallable() { + return runJobCallable; + } + + @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-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1/CloudSchedulerClientHttpJsonTest.java b/java-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1/CloudSchedulerClientHttpJsonTest.java new file mode 100644 index 000000000000..e7689f242f53 --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1/CloudSchedulerClientHttpJsonTest.java @@ -0,0 +1,875 @@ +/* + * 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.scheduler.v1; + +import static com.google.cloud.scheduler.v1.CloudSchedulerClient.ListJobsPagedResponse; + +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.scheduler.v1.stub.HttpJsonCloudSchedulerStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.google.rpc.Status; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +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 CloudSchedulerClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudSchedulerClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudSchedulerStub.getMethodDescriptors(), + CloudSchedulerSettings.getDefaultEndpoint()); + CloudSchedulerSettings settings = + CloudSchedulerSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudSchedulerClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listJobsTest() throws Exception { + Job responsesElement = Job.newBuilder().build(); + ListJobsResponse expectedResponse = + ListJobsResponse.newBuilder() + .setNextPageToken("") + .addAllJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListJobsPagedResponse pagedListResponse = client.listJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getJobsList().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 listJobsExceptionTest() 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.listJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listJobsTest2() throws Exception { + Job responsesElement = Job.newBuilder().build(); + ListJobsResponse expectedResponse = + ListJobsResponse.newBuilder() + .setNextPageToken("") + .addAllJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListJobsPagedResponse pagedListResponse = client.listJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getJobsList().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 listJobsExceptionTest2() 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.listJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.getJob(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 getJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.getJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.getJob(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 getJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.getJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Job job = Job.newBuilder().build(); + + Job actualResponse = client.createJob(parent, job); + 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 createJobExceptionTest() 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]"); + Job job = Job.newBuilder().build(); + client.createJob(parent, job); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + Job job = Job.newBuilder().build(); + + Job actualResponse = client.createJob(parent, job); + 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 createJobExceptionTest2() 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"; + Job job = Job.newBuilder().build(); + client.createJob(parent, job); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Job job = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Job actualResponse = client.updateJob(job, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Job job = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateJob(job, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteJobTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + client.deleteJob(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.deleteJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteJobTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + client.deleteJob(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.deleteJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.pauseJob(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 pauseJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.pauseJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.pauseJob(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 pauseJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.pauseJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.resumeJob(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 resumeJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.resumeJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.resumeJob(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 resumeJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.resumeJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.runJob(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 runJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.runJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.runJob(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 runJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.runJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClientHttpJsonTest.java b/java-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClientHttpJsonTest.java new file mode 100644 index 000000000000..a336c188f3ef --- /dev/null +++ b/java-scheduler/google-cloud-scheduler/src/test/java/com/google/cloud/scheduler/v1beta1/CloudSchedulerClientHttpJsonTest.java @@ -0,0 +1,875 @@ +/* + * 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.scheduler.v1beta1; + +import static com.google.cloud.scheduler.v1beta1.CloudSchedulerClient.ListJobsPagedResponse; + +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.scheduler.v1beta1.stub.HttpJsonCloudSchedulerStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.google.rpc.Status; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +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 CloudSchedulerClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudSchedulerClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudSchedulerStub.getMethodDescriptors(), + CloudSchedulerSettings.getDefaultEndpoint()); + CloudSchedulerSettings settings = + CloudSchedulerSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudSchedulerClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listJobsTest() throws Exception { + Job responsesElement = Job.newBuilder().build(); + ListJobsResponse expectedResponse = + ListJobsResponse.newBuilder() + .setNextPageToken("") + .addAllJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListJobsPagedResponse pagedListResponse = client.listJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getJobsList().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 listJobsExceptionTest() 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.listJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listJobsTest2() throws Exception { + Job responsesElement = Job.newBuilder().build(); + ListJobsResponse expectedResponse = + ListJobsResponse.newBuilder() + .setNextPageToken("") + .addAllJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListJobsPagedResponse pagedListResponse = client.listJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getJobsList().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 listJobsExceptionTest2() 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.listJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.getJob(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 getJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.getJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.getJob(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 getJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.getJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Job job = Job.newBuilder().build(); + + Job actualResponse = client.createJob(parent, job); + 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 createJobExceptionTest() 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]"); + Job job = Job.newBuilder().build(); + client.createJob(parent, job); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + Job job = Job.newBuilder().build(); + + Job actualResponse = client.createJob(parent, job); + 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 createJobExceptionTest2() 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"; + Job job = Job.newBuilder().build(); + client.createJob(parent, job); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Job job = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Job actualResponse = client.updateJob(job, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Job job = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateJob(job, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteJobTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + client.deleteJob(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.deleteJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteJobTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + client.deleteJob(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.deleteJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.pauseJob(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 pauseJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.pauseJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.pauseJob(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 pauseJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.pauseJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.resumeJob(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 resumeJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.resumeJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.resumeJob(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 resumeJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.resumeJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runJobTest() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + + Job actualResponse = client.runJob(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 runJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + client.runJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runJobTest2() throws Exception { + Job expectedResponse = + Job.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .setDescription("description-1724546052") + .setSchedule("schedule-697920873") + .setTimeZone("timeZone-2077180903") + .setUserUpdateTime(Timestamp.newBuilder().build()) + .setStatus(Status.newBuilder().build()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setLastAttemptTime(Timestamp.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setAttemptDeadline(Duration.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + + Job actualResponse = client.runJob(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 runJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3306/locations/location-3306/jobs/job-3306"; + client.runJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..a4af734cbc93 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.CloudSchedulerSettings; +import com.google.cloud.scheduler.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. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1_generated_cloudschedulerclient_create_setcredentialsprovider_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider1.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..c9b0b2c6ee15 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_create_setcredentialsprovider1_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.CloudSchedulerSettings; + +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. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder() + .setTransportChannelProvider( + CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1_generated_cloudschedulerclient_create_setcredentialsprovider1_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetEndpoint.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..c9c07d49b10c --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_create_setendpoint_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.CloudSchedulerSettings; +import com.google.cloud.scheduler.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. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1_generated_cloudschedulerclient_create_setendpoint_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/AsyncCreateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/AsyncCreateJob.java new file mode 100644 index 000000000000..8f87b838fd21 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/AsyncCreateJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_createjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.CreateJobRequest; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class AsyncCreateJob { + + public static void main(String[] args) throws Exception { + asyncCreateJob(); + } + + public static void asyncCreateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + CreateJobRequest request = + CreateJobRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setJob(Job.newBuilder().build()) + .build(); + ApiFuture future = cloudSchedulerClient.createJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_createjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJob.java new file mode 100644 index 000000000000..e64236a062e1 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJob.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_createjob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.CreateJobRequest; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncCreateJob { + + public static void main(String[] args) throws Exception { + syncCreateJob(); + } + + public static void syncCreateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + CreateJobRequest request = + CreateJobRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setJob(Job.newBuilder().build()) + .build(); + Job response = cloudSchedulerClient.createJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_createjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.java new file mode 100644 index 000000000000..195c8ac993be --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_createjob_locationnamejob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncCreateJobLocationnameJob { + + public static void main(String[] args) throws Exception { + syncCreateJobLocationnameJob(); + } + + public static void syncCreateJobLocationnameJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Job job = Job.newBuilder().build(); + Job response = cloudSchedulerClient.createJob(parent, job); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_createjob_locationnamejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobStringJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobStringJob.java new file mode 100644 index 000000000000..e0b5795e61b9 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/createjob/SyncCreateJobStringJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_createjob_stringjob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncCreateJobStringJob { + + public static void main(String[] args) throws Exception { + syncCreateJobStringJob(); + } + + public static void syncCreateJobStringJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Job job = Job.newBuilder().build(); + Job response = cloudSchedulerClient.createJob(parent, job); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_createjob_stringjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/AsyncDeleteJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/AsyncDeleteJob.java new file mode 100644 index 000000000000..18abb40fc9a3 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/AsyncDeleteJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_deletejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.DeleteJobRequest; +import com.google.cloud.scheduler.v1.JobName; +import com.google.protobuf.Empty; + +public class AsyncDeleteJob { + + public static void main(String[] args) throws Exception { + asyncDeleteJob(); + } + + public static void asyncDeleteJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + DeleteJobRequest request = + DeleteJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.deleteJobCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_deletejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJob.java new file mode 100644 index 000000000000..45995ffcf386 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJob.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_deletejob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.DeleteJobRequest; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncDeleteJob { + + public static void main(String[] args) throws Exception { + syncDeleteJob(); + } + + public static void syncDeleteJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + DeleteJobRequest request = + DeleteJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + cloudSchedulerClient.deleteJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_deletejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.java new file mode 100644 index 000000000000..97e14c2d1106 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_deletejob_jobname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncDeleteJobJobname { + + public static void main(String[] args) throws Exception { + syncDeleteJobJobname(); + } + + public static void syncDeleteJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + cloudSchedulerClient.deleteJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_deletejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobString.java new file mode 100644 index 000000000000..d84aebbe666f --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/deletejob/SyncDeleteJobString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_deletejob_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncDeleteJobString { + + public static void main(String[] args) throws Exception { + syncDeleteJobString(); + } + + public static void syncDeleteJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + cloudSchedulerClient.deleteJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_deletejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/AsyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/AsyncGetJob.java new file mode 100644 index 000000000000..4bba66b0b7f2 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/AsyncGetJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_getjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.GetJobRequest; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class AsyncGetJob { + + public static void main(String[] args) throws Exception { + asyncGetJob(); + } + + public static void asyncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + GetJobRequest request = + GetJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.getJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_getjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJob.java new file mode 100644 index 000000000000..252599db8140 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_getjob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.GetJobRequest; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + GetJobRequest request = + GetJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.getJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_getjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobJobname.java new file mode 100644 index 000000000000..b9f311729919 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobJobname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_getjob_jobname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncGetJobJobname { + + public static void main(String[] args) throws Exception { + syncGetJobJobname(); + } + + public static void syncGetJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.getJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_getjob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobString.java new file mode 100644 index 000000000000..afacfa88439e --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/getjob/SyncGetJobString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_getjob_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncGetJobString { + + public static void main(String[] args) throws Exception { + syncGetJobString(); + } + + public static void syncGetJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.getJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_getjob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobs.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobs.java new file mode 100644 index 000000000000..589e7cbff526 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobs.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_listjobs_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.ListJobsRequest; +import com.google.cloud.scheduler.v1.LocationName; + +public class AsyncListJobs { + + public static void main(String[] args) throws Exception { + asyncListJobs(); + } + + public static void asyncListJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = cloudSchedulerClient.listJobsPagedCallable().futureCall(request); + // Do something. + for (Job element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_listjobs_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java new file mode 100644 index 000000000000..947a54f3f656 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java @@ -0,0 +1,58 @@ +/* + * 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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_listjobs_paged_async] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.ListJobsRequest; +import com.google.cloud.scheduler.v1.ListJobsResponse; +import com.google.cloud.scheduler.v1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListJobsPaged { + + public static void main(String[] args) throws Exception { + asyncListJobsPaged(); + } + + public static void asyncListJobsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListJobsResponse response = cloudSchedulerClient.listJobsCallable().call(request); + for (Job element : response.getJobsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_listjobs_paged_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobs.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobs.java new file mode 100644 index 000000000000..d9c021c652a9 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobs.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_listjobs_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.ListJobsRequest; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncListJobs { + + public static void main(String[] args) throws Exception { + syncListJobs(); + } + + public static void syncListJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Job element : cloudSchedulerClient.listJobs(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_listjobs_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsLocationname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsLocationname.java new file mode 100644 index 000000000000..a1f499eb2bf2 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsLocationname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_listjobs_locationname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncListJobsLocationname { + + public static void main(String[] args) throws Exception { + syncListJobsLocationname(); + } + + public static void syncListJobsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_listjobs_locationname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsString.java new file mode 100644 index 000000000000..9c0ed2490a9d --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/listjobs/SyncListJobsString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_listjobs_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.LocationName; + +public class SyncListJobsString { + + public static void main(String[] args) throws Exception { + syncListJobsString(); + } + + public static void syncListJobsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_listjobs_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/AsyncPauseJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/AsyncPauseJob.java new file mode 100644 index 000000000000..58daeda48ca8 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/AsyncPauseJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_pausejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.PauseJobRequest; + +public class AsyncPauseJob { + + public static void main(String[] args) throws Exception { + asyncPauseJob(); + } + + public static void asyncPauseJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + PauseJobRequest request = + PauseJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.pauseJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_pausejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJob.java new file mode 100644 index 000000000000..7990b740f4b1 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_pausejob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.PauseJobRequest; + +public class SyncPauseJob { + + public static void main(String[] args) throws Exception { + syncPauseJob(); + } + + public static void syncPauseJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + PauseJobRequest request = + PauseJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.pauseJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_pausejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobJobname.java new file mode 100644 index 000000000000..0a917b56302a --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobJobname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_pausejob_jobname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncPauseJobJobname { + + public static void main(String[] args) throws Exception { + syncPauseJobJobname(); + } + + public static void syncPauseJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.pauseJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_pausejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobString.java new file mode 100644 index 000000000000..d769eac95f97 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/pausejob/SyncPauseJobString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_pausejob_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncPauseJobString { + + public static void main(String[] args) throws Exception { + syncPauseJobString(); + } + + public static void syncPauseJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.pauseJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_pausejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/AsyncResumeJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/AsyncResumeJob.java new file mode 100644 index 000000000000..f5613616782b --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/AsyncResumeJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_resumejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.ResumeJobRequest; + +public class AsyncResumeJob { + + public static void main(String[] args) throws Exception { + asyncResumeJob(); + } + + public static void asyncResumeJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ResumeJobRequest request = + ResumeJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.resumeJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_resumejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJob.java new file mode 100644 index 000000000000..95a3d43d0107 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_resumejob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.ResumeJobRequest; + +public class SyncResumeJob { + + public static void main(String[] args) throws Exception { + syncResumeJob(); + } + + public static void syncResumeJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ResumeJobRequest request = + ResumeJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.resumeJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_resumejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobJobname.java new file mode 100644 index 000000000000..ce1b7b19f40c --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobJobname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_resumejob_jobname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncResumeJobJobname { + + public static void main(String[] args) throws Exception { + syncResumeJobJobname(); + } + + public static void syncResumeJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.resumeJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_resumejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobString.java new file mode 100644 index 000000000000..28f1e4efdcf3 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/resumejob/SyncResumeJobString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_resumejob_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncResumeJobString { + + public static void main(String[] args) throws Exception { + syncResumeJobString(); + } + + public static void syncResumeJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.resumeJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_resumejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/AsyncRunJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/AsyncRunJob.java new file mode 100644 index 000000000000..14620fe33f33 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/AsyncRunJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_runjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.RunJobRequest; + +public class AsyncRunJob { + + public static void main(String[] args) throws Exception { + asyncRunJob(); + } + + public static void asyncRunJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + RunJobRequest request = + RunJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.runJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_runjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJob.java new file mode 100644 index 000000000000..01b89f645628 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_runjob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; +import com.google.cloud.scheduler.v1.RunJobRequest; + +public class SyncRunJob { + + public static void main(String[] args) throws Exception { + syncRunJob(); + } + + public static void syncRunJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + RunJobRequest request = + RunJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.runJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_runjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobJobname.java new file mode 100644 index 000000000000..04d06d486311 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobJobname.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_runjob_jobname_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncRunJobJobname { + + public static void main(String[] args) throws Exception { + syncRunJobJobname(); + } + + public static void syncRunJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.runJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_runjob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobString.java new file mode 100644 index 000000000000..19f2a4dff122 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/runjob/SyncRunJobString.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_runjob_string_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.JobName; + +public class SyncRunJobString { + + public static void main(String[] args) throws Exception { + syncRunJobString(); + } + + public static void syncRunJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.runJob(name); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_runjob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/AsyncUpdateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/AsyncUpdateJob.java new file mode 100644 index 000000000000..22d735bf7c37 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/AsyncUpdateJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_updatejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.UpdateJobRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateJob { + + public static void main(String[] args) throws Exception { + asyncUpdateJob(); + } + + public static void asyncUpdateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + UpdateJobRequest request = + UpdateJobRequest.newBuilder() + .setJob(Job.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = cloudSchedulerClient.updateJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_updatejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJob.java new file mode 100644 index 000000000000..a8c9484e73e5 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJob.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_updatejob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.cloud.scheduler.v1.UpdateJobRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateJob { + + public static void main(String[] args) throws Exception { + syncUpdateJob(); + } + + public static void syncUpdateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + UpdateJobRequest request = + UpdateJobRequest.newBuilder() + .setJob(Job.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Job response = cloudSchedulerClient.updateJob(request); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_updatejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.java new file mode 100644 index 000000000000..f84b46634922 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulerclient_updatejob_jobfieldmask_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1.Job; +import com.google.protobuf.FieldMask; + +public class SyncUpdateJobJobFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateJobJobFieldmask(); + } + + public static void syncUpdateJobJobFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + Job job = Job.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Job response = cloudSchedulerClient.updateJob(job, updateMask); + } + } +} +// [END scheduler_v1_generated_cloudschedulerclient_updatejob_jobfieldmask_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulersettings/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulersettings/getjob/SyncGetJob.java new file mode 100644 index 000000000000..ee4ff1f1a8da --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/cloudschedulersettings/getjob/SyncGetJob.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.scheduler.v1.samples; + +// [START scheduler_v1_generated_cloudschedulersettings_getjob_sync] +import com.google.cloud.scheduler.v1.CloudSchedulerSettings; +import java.time.Duration; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerSettings.Builder cloudSchedulerSettingsBuilder = + CloudSchedulerSettings.newBuilder(); + cloudSchedulerSettingsBuilder + .getJobSettings() + .setRetrySettings( + cloudSchedulerSettingsBuilder + .getJobSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudSchedulerSettings cloudSchedulerSettings = cloudSchedulerSettingsBuilder.build(); + } +} +// [END scheduler_v1_generated_cloudschedulersettings_getjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.java new file mode 100644 index 000000000000..7a3b7e18f70c --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.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.scheduler.v1.stub.samples; + +// [START scheduler_v1_generated_cloudschedulerstubsettings_getjob_sync] +import com.google.cloud.scheduler.v1.stub.CloudSchedulerStubSettings; +import java.time.Duration; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerStubSettings.Builder cloudSchedulerSettingsBuilder = + CloudSchedulerStubSettings.newBuilder(); + cloudSchedulerSettingsBuilder + .getJobSettings() + .setRetrySettings( + cloudSchedulerSettingsBuilder + .getJobSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudSchedulerStubSettings cloudSchedulerSettings = cloudSchedulerSettingsBuilder.build(); + } +} +// [END scheduler_v1_generated_cloudschedulerstubsettings_getjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..2d2f4bd01d70 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerSettings; +import com.google.cloud.scheduler.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_create_setcredentialsprovider_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider1.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..57a5e157c6f8 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_create_setcredentialsprovider1_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerSettings; + +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. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder() + .setTransportChannelProvider( + CloudSchedulerSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_create_setcredentialsprovider1_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetEndpoint.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..2d9d001da09e --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_create_setendpoint_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerSettings; +import com.google.cloud.scheduler.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerSettings cloudSchedulerSettings = + CloudSchedulerSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings); + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_create_setendpoint_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/AsyncCreateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/AsyncCreateJob.java new file mode 100644 index 000000000000..6ff39df60c42 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/AsyncCreateJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_createjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.CreateJobRequest; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class AsyncCreateJob { + + public static void main(String[] args) throws Exception { + asyncCreateJob(); + } + + public static void asyncCreateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + CreateJobRequest request = + CreateJobRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setJob(Job.newBuilder().build()) + .build(); + ApiFuture future = cloudSchedulerClient.createJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_createjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJob.java new file mode 100644 index 000000000000..de761e19d733 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJob.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_createjob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.CreateJobRequest; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncCreateJob { + + public static void main(String[] args) throws Exception { + syncCreateJob(); + } + + public static void syncCreateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + CreateJobRequest request = + CreateJobRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setJob(Job.newBuilder().build()) + .build(); + Job response = cloudSchedulerClient.createJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_createjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.java new file mode 100644 index 000000000000..dd28bfa01155 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobLocationnameJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_createjob_locationnamejob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncCreateJobLocationnameJob { + + public static void main(String[] args) throws Exception { + syncCreateJobLocationnameJob(); + } + + public static void syncCreateJobLocationnameJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Job job = Job.newBuilder().build(); + Job response = cloudSchedulerClient.createJob(parent, job); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_createjob_locationnamejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobStringJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobStringJob.java new file mode 100644 index 000000000000..06e806088c38 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/createjob/SyncCreateJobStringJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_createjob_stringjob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncCreateJobStringJob { + + public static void main(String[] args) throws Exception { + syncCreateJobStringJob(); + } + + public static void syncCreateJobStringJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Job job = Job.newBuilder().build(); + Job response = cloudSchedulerClient.createJob(parent, job); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_createjob_stringjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/AsyncDeleteJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/AsyncDeleteJob.java new file mode 100644 index 000000000000..a524acfca2b9 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/AsyncDeleteJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_deletejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.DeleteJobRequest; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.protobuf.Empty; + +public class AsyncDeleteJob { + + public static void main(String[] args) throws Exception { + asyncDeleteJob(); + } + + public static void asyncDeleteJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + DeleteJobRequest request = + DeleteJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.deleteJobCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_deletejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJob.java new file mode 100644 index 000000000000..1faee9723bf1 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJob.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_deletejob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.DeleteJobRequest; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncDeleteJob { + + public static void main(String[] args) throws Exception { + syncDeleteJob(); + } + + public static void syncDeleteJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + DeleteJobRequest request = + DeleteJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + cloudSchedulerClient.deleteJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_deletejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.java new file mode 100644 index 000000000000..2503b646761f --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobJobname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_deletejob_jobname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncDeleteJobJobname { + + public static void main(String[] args) throws Exception { + syncDeleteJobJobname(); + } + + public static void syncDeleteJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + cloudSchedulerClient.deleteJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_deletejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobString.java new file mode 100644 index 000000000000..bfa1952a5323 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/deletejob/SyncDeleteJobString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_deletejob_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncDeleteJobString { + + public static void main(String[] args) throws Exception { + syncDeleteJobString(); + } + + public static void syncDeleteJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + cloudSchedulerClient.deleteJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_deletejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/AsyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/AsyncGetJob.java new file mode 100644 index 000000000000..9444ca00f5bd --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/AsyncGetJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_getjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.GetJobRequest; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class AsyncGetJob { + + public static void main(String[] args) throws Exception { + asyncGetJob(); + } + + public static void asyncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + GetJobRequest request = + GetJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.getJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_getjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJob.java new file mode 100644 index 000000000000..036ffd358bae --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_getjob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.GetJobRequest; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + GetJobRequest request = + GetJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.getJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_getjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobJobname.java new file mode 100644 index 000000000000..0769975f346f --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobJobname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_getjob_jobname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncGetJobJobname { + + public static void main(String[] args) throws Exception { + syncGetJobJobname(); + } + + public static void syncGetJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.getJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_getjob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobString.java new file mode 100644 index 000000000000..67b2e02a4a9f --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/getjob/SyncGetJobString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_getjob_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncGetJobString { + + public static void main(String[] args) throws Exception { + syncGetJobString(); + } + + public static void syncGetJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.getJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_getjob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobs.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobs.java new file mode 100644 index 000000000000..70baf34121f8 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobs.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_listjobs_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.ListJobsRequest; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class AsyncListJobs { + + public static void main(String[] args) throws Exception { + asyncListJobs(); + } + + public static void asyncListJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = cloudSchedulerClient.listJobsPagedCallable().futureCall(request); + // Do something. + for (Job element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_listjobs_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java new file mode 100644 index 000000000000..cdb253e0c91c --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/AsyncListJobsPaged.java @@ -0,0 +1,58 @@ +/* + * 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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_listjobs_paged_async] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.ListJobsRequest; +import com.google.cloud.scheduler.v1beta1.ListJobsResponse; +import com.google.cloud.scheduler.v1beta1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListJobsPaged { + + public static void main(String[] args) throws Exception { + asyncListJobsPaged(); + } + + public static void asyncListJobsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListJobsResponse response = cloudSchedulerClient.listJobsCallable().call(request); + for (Job element : response.getJobsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_listjobs_paged_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobs.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobs.java new file mode 100644 index 000000000000..7869a56a03e6 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobs.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_listjobs_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.ListJobsRequest; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncListJobs { + + public static void main(String[] args) throws Exception { + syncListJobs(); + } + + public static void syncListJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ListJobsRequest request = + ListJobsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Job element : cloudSchedulerClient.listJobs(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_listjobs_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsLocationname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsLocationname.java new file mode 100644 index 000000000000..585ba77c4de5 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsLocationname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_listjobs_locationname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncListJobsLocationname { + + public static void main(String[] args) throws Exception { + syncListJobsLocationname(); + } + + public static void syncListJobsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_listjobs_locationname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsString.java new file mode 100644 index 000000000000..0de2f5f07412 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/listjobs/SyncListJobsString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_listjobs_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.LocationName; + +public class SyncListJobsString { + + public static void main(String[] args) throws Exception { + syncListJobsString(); + } + + public static void syncListJobsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_listjobs_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/AsyncPauseJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/AsyncPauseJob.java new file mode 100644 index 000000000000..f9ef47f02d48 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/AsyncPauseJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_pausejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.PauseJobRequest; + +public class AsyncPauseJob { + + public static void main(String[] args) throws Exception { + asyncPauseJob(); + } + + public static void asyncPauseJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + PauseJobRequest request = + PauseJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.pauseJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_pausejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJob.java new file mode 100644 index 000000000000..47d90b019e2a --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_pausejob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.PauseJobRequest; + +public class SyncPauseJob { + + public static void main(String[] args) throws Exception { + syncPauseJob(); + } + + public static void syncPauseJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + PauseJobRequest request = + PauseJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.pauseJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_pausejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobJobname.java new file mode 100644 index 000000000000..23c41e7e7694 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobJobname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_pausejob_jobname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncPauseJobJobname { + + public static void main(String[] args) throws Exception { + syncPauseJobJobname(); + } + + public static void syncPauseJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.pauseJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_pausejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobString.java new file mode 100644 index 000000000000..57e4896f5fdf --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/pausejob/SyncPauseJobString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_pausejob_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncPauseJobString { + + public static void main(String[] args) throws Exception { + syncPauseJobString(); + } + + public static void syncPauseJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.pauseJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_pausejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/AsyncResumeJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/AsyncResumeJob.java new file mode 100644 index 000000000000..2665117d3b62 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/AsyncResumeJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_resumejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.ResumeJobRequest; + +public class AsyncResumeJob { + + public static void main(String[] args) throws Exception { + asyncResumeJob(); + } + + public static void asyncResumeJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ResumeJobRequest request = + ResumeJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.resumeJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_resumejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJob.java new file mode 100644 index 000000000000..e9bcf78d7fe7 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_resumejob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.ResumeJobRequest; + +public class SyncResumeJob { + + public static void main(String[] args) throws Exception { + syncResumeJob(); + } + + public static void syncResumeJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + ResumeJobRequest request = + ResumeJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.resumeJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_resumejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobJobname.java new file mode 100644 index 000000000000..5f0476355287 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobJobname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_resumejob_jobname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncResumeJobJobname { + + public static void main(String[] args) throws Exception { + syncResumeJobJobname(); + } + + public static void syncResumeJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.resumeJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_resumejob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobString.java new file mode 100644 index 000000000000..cb009861b8bf --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/resumejob/SyncResumeJobString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_resumejob_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncResumeJobString { + + public static void main(String[] args) throws Exception { + syncResumeJobString(); + } + + public static void syncResumeJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.resumeJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_resumejob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/AsyncRunJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/AsyncRunJob.java new file mode 100644 index 000000000000..19ce12c6d608 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/AsyncRunJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_runjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.RunJobRequest; + +public class AsyncRunJob { + + public static void main(String[] args) throws Exception { + asyncRunJob(); + } + + public static void asyncRunJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + RunJobRequest request = + RunJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + ApiFuture future = cloudSchedulerClient.runJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_runjob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJob.java new file mode 100644 index 000000000000..3a9959fe4eda --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_runjob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; +import com.google.cloud.scheduler.v1beta1.RunJobRequest; + +public class SyncRunJob { + + public static void main(String[] args) throws Exception { + syncRunJob(); + } + + public static void syncRunJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + RunJobRequest request = + RunJobRequest.newBuilder() + .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString()) + .build(); + Job response = cloudSchedulerClient.runJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_runjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobJobname.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobJobname.java new file mode 100644 index 000000000000..bcaed62197a0 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobJobname.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_runjob_jobname_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncRunJobJobname { + + public static void main(String[] args) throws Exception { + syncRunJobJobname(); + } + + public static void syncRunJobJobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); + Job response = cloudSchedulerClient.runJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_runjob_jobname_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobString.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobString.java new file mode 100644 index 000000000000..fbbe6631c094 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/runjob/SyncRunJobString.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_runjob_string_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.JobName; + +public class SyncRunJobString { + + public static void main(String[] args) throws Exception { + syncRunJobString(); + } + + public static void syncRunJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + String name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString(); + Job response = cloudSchedulerClient.runJob(name); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_runjob_string_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/AsyncUpdateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/AsyncUpdateJob.java new file mode 100644 index 000000000000..6f9c4c14478e --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/AsyncUpdateJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_updatejob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.UpdateJobRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateJob { + + public static void main(String[] args) throws Exception { + asyncUpdateJob(); + } + + public static void asyncUpdateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + UpdateJobRequest request = + UpdateJobRequest.newBuilder() + .setJob(Job.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = cloudSchedulerClient.updateJobCallable().futureCall(request); + // Do something. + Job response = future.get(); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_updatejob_async] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJob.java new file mode 100644 index 000000000000..fd3aeefd2786 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJob.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_updatejob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.cloud.scheduler.v1beta1.UpdateJobRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateJob { + + public static void main(String[] args) throws Exception { + syncUpdateJob(); + } + + public static void syncUpdateJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + UpdateJobRequest request = + UpdateJobRequest.newBuilder() + .setJob(Job.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Job response = cloudSchedulerClient.updateJob(request); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_updatejob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.java new file mode 100644 index 000000000000..f86e559443c5 --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulerclient/updatejob/SyncUpdateJobJobFieldmask.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerclient_updatejob_jobfieldmask_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerClient; +import com.google.cloud.scheduler.v1beta1.Job; +import com.google.protobuf.FieldMask; + +public class SyncUpdateJobJobFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateJobJobFieldmask(); + } + + public static void syncUpdateJobJobFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { + Job job = Job.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Job response = cloudSchedulerClient.updateJob(job, updateMask); + } + } +} +// [END scheduler_v1beta1_generated_cloudschedulerclient_updatejob_jobfieldmask_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulersettings/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulersettings/getjob/SyncGetJob.java new file mode 100644 index 000000000000..f3efe7582cba --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/cloudschedulersettings/getjob/SyncGetJob.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.scheduler.v1beta1.samples; + +// [START scheduler_v1beta1_generated_cloudschedulersettings_getjob_sync] +import com.google.cloud.scheduler.v1beta1.CloudSchedulerSettings; +import java.time.Duration; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerSettings.Builder cloudSchedulerSettingsBuilder = + CloudSchedulerSettings.newBuilder(); + cloudSchedulerSettingsBuilder + .getJobSettings() + .setRetrySettings( + cloudSchedulerSettingsBuilder + .getJobSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudSchedulerSettings cloudSchedulerSettings = cloudSchedulerSettingsBuilder.build(); + } +} +// [END scheduler_v1beta1_generated_cloudschedulersettings_getjob_sync] diff --git a/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.java b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.java new file mode 100644 index 000000000000..7303e1a6350b --- /dev/null +++ b/java-scheduler/samples/snippets/generated/com/google/cloud/scheduler/v1beta1/stub/cloudschedulerstubsettings/getjob/SyncGetJob.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.scheduler.v1beta1.stub.samples; + +// [START scheduler_v1beta1_generated_cloudschedulerstubsettings_getjob_sync] +import com.google.cloud.scheduler.v1beta1.stub.CloudSchedulerStubSettings; +import java.time.Duration; + +public class SyncGetJob { + + public static void main(String[] args) throws Exception { + syncGetJob(); + } + + public static void syncGetJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudSchedulerStubSettings.Builder cloudSchedulerSettingsBuilder = + CloudSchedulerStubSettings.newBuilder(); + cloudSchedulerSettingsBuilder + .getJobSettings() + .setRetrySettings( + cloudSchedulerSettingsBuilder + .getJobSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudSchedulerStubSettings cloudSchedulerSettings = cloudSchedulerSettingsBuilder.build(); + } +} +// [END scheduler_v1beta1_generated_cloudschedulerstubsettings_getjob_sync]