/** Constructs an instance of CloudSchedulerClient with default settings. */ public static final CloudSchedulerClient create() throws IOException { return create(CloudSchedulerSettings.newBuilder().build()); }
/** * Creates a job. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * Job job = Job.newBuilder().build(); * Job response = cloudSchedulerClient.createJob(parent.toString(), job); * } * </code></pre> * * @param parent Required. * <p>The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`. * @param job Required. * <p>The job to add. The user can optionally specify a name for the job in * [name][google.cloud.scheduler.v1beta1.Job.name]. * [name][google.cloud.scheduler.v1beta1.Job.name] cannot be the same as an existing job. If a * name is not specified then the system will generate a random unique name that will be * returned ([name][google.cloud.scheduler.v1beta1.Job.name]) in the response. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job createJob(String parent, Job job) { CreateJobRequest request = CreateJobRequest.newBuilder().setParent(parent).setJob(job).build(); return createJob(request); }
/** * Deletes a job. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * cloudSchedulerClient.deleteJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void deleteJob(String name) { DeleteJobRequest request = DeleteJobRequest.newBuilder().setName(name).build(); deleteJob(request); }
/** * Pauses a job. * * <p>If a job is paused then the system will stop executing the job until it is re-enabled via * [ResumeJob][google.cloud.scheduler.v1beta1.CloudScheduler.ResumeJob]. The state of the job is * stored in [state][google.cloud.scheduler.v1beta1.Job.state]; if paused it will be set to * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. A job must be in * [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED] to be paused. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.pauseJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job pauseJob(String name) { PauseJobRequest request = PauseJobRequest.newBuilder().setName(name).build(); return pauseJob(request); }
/** * Gets a job. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.getJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job getJob(String name) { GetJobRequest request = GetJobRequest.newBuilder().setName(name).build(); return getJob(request); }
/** * Resume a job. * * <p>This method reenables a job after it has been * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. The state of a job is * stored in [Job.state][google.cloud.scheduler.v1beta1.Job.state]; after calling this method it * will be set to [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED]. A job * must be in [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED] to be resumed. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.resumeJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job resumeJob(String name) { ResumeJobRequest request = ResumeJobRequest.newBuilder().setName(name).build(); return resumeJob(request); }
/** * Lists jobs. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (Job element : cloudSchedulerClient.listJobs(parent.toString()).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. * <p>The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListJobsPagedResponse listJobs(String parent) { ListJobsRequest request = ListJobsRequest.newBuilder().setParent(parent).build(); return listJobs(request); }
/** * Forces a job to run now. * * <p>When this method is called, Cloud Scheduler will dispatch the job, even if the job is * already running. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.runJob(name.toString()); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job runJob(String name) { RunJobRequest request = RunJobRequest.newBuilder().setName(name).build(); return runJob(request); }
return updateJob(request);
/** * Constructs an instance of CloudSchedulerClient, using the given settings. The channels are * created based on the settings passed in, or defaults for any settings that are not set. */ public static final CloudSchedulerClient create(CloudSchedulerSettings settings) throws IOException { return new CloudSchedulerClient(settings); }
/** * Pauses a job. * * <p>If a job is paused then the system will stop executing the job until it is re-enabled via * [ResumeJob][google.cloud.scheduler.v1beta1.CloudScheduler.ResumeJob]. The state of the job is * stored in [state][google.cloud.scheduler.v1beta1.Job.state]; if paused it will be set to * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. A job must be in * [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED] to be paused. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.pauseJob(name); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job pauseJob(JobName name) { PauseJobRequest request = PauseJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return pauseJob(request); }
/** * Gets a job. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.getJob(name); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job getJob(JobName name) { GetJobRequest request = GetJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return getJob(request); }
/** * Resume a job. * * <p>This method reenables a job after it has been * [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED]. The state of a job is * stored in [Job.state][google.cloud.scheduler.v1beta1.Job.state]; after calling this method it * will be set to [Job.State.ENABLED][google.cloud.scheduler.v1beta1.Job.State.ENABLED]. A job * must be in [Job.State.PAUSED][google.cloud.scheduler.v1beta1.Job.State.PAUSED] to be resumed. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.resumeJob(name); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job resumeJob(JobName name) { ResumeJobRequest request = ResumeJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return resumeJob(request); }
/** * Lists jobs. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (Job element : cloudSchedulerClient.listJobs(parent).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. * <p>The location name. For example: `projects/PROJECT_ID/locations/LOCATION_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListJobsPagedResponse listJobs(LocationName parent) { ListJobsRequest request = ListJobsRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); return listJobs(request); }
/** * Forces a job to run now. * * <p>When this method is called, Cloud Scheduler will dispatch the job, even if the job is * already running. * * <p>Sample code: * * <pre><code> * try (CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create()) { * JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); * Job response = cloudSchedulerClient.runJob(name); * } * </code></pre> * * @param name Required. * <p>The job name. For example: `projects/PROJECT_ID/locations/LOCATION_ID/jobs/JOB_ID`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Job runJob(JobName name) { RunJobRequest request = RunJobRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return runJob(request); }
@Test @SuppressWarnings("all") public void updateJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { Job job = Job.newBuilder().build(); FieldMask updateMask = FieldMask.newBuilder().build(); client.updateJob(job, updateMask); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
/** * Constructs an instance of CloudSchedulerClient, using the given stub for making calls. This is * for advanced usage - prefer to use CloudSchedulerSettings}. */ @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudSchedulerClient create(CloudSchedulerStub stub) { return new CloudSchedulerClient(stub); }
@Test @SuppressWarnings("all") public void pauseJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); client.pauseJob(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void getJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); client.getJob(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void resumeJobExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudScheduler.addException(exception); try { JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]"); client.resumeJob(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }