Class JobsClient (0.20.0)

publicclass JobsClientimplementsBackgroundResource

Service Description: Cloud Run Job Control Plane API.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=jobsClient.getJob(name);
}

Note: close() needs to be called on the JobsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of JobsSettings to create(). For example:

To customize credentials:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
JobsSettingsjobsSettings=
JobsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
JobsClientjobsClient=JobsClient.create(jobsSettings);

To customize the endpoint:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
JobsSettingsjobsSettings=JobsSettings.newBuilder().setEndpoint(myEndpoint).build();
JobsClientjobsClient=JobsClient.create(jobsSettings);

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
JobsSettingsjobsSettings=JobsSettings.newHttpJsonBuilder().build();
JobsClientjobsClient=JobsClient.create(jobsSettings);

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > JobsClient

Implements

BackgroundResource

Static Methods

create()

publicstaticfinalJobsClientcreate()

Constructs an instance of JobsClient with default settings.

Returns
Type Description
JobsClient
Exceptions
Type Description
IOException

create(JobsSettings settings)

publicstaticfinalJobsClientcreate(JobsSettingssettings)

Constructs an instance of JobsClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings JobsSettings
Returns
Type Description
JobsClient
Exceptions
Type Description
IOException

create(JobsStub stub)

publicstaticfinalJobsClientcreate(JobsStubstub)

Constructs an instance of JobsClient, using the given stub for making calls. This is for advanced usage - prefer using create(JobsSettings).

Parameter
Name Description
stub JobsStub
Returns
Type Description
JobsClient

Constructors

JobsClient(JobsSettings settings)

protectedJobsClient(JobsSettingssettings)

Constructs an instance of JobsClient, 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.

Parameter
Name Description
settings JobsSettings

JobsClient(JobsStub stub)

protectedJobsClient(JobsStubstub)
Parameter
Name Description
stub JobsStub

Methods

awaitTermination(long duration, TimeUnit unit)

publicbooleanawaitTermination(longduration,TimeUnitunit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

publicfinalvoidclose()

createJobAsync(CreateJobRequest request)

publicfinalOperationFuture<Job,Job>createJobAsync(CreateJobRequestrequest)

Creates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
CreateJobRequestrequest=
CreateJobRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setJob(Job.newBuilder().build())
.setJobId("jobId101296568")
.setValidateOnly(true)
.build();
Jobresponse=jobsClient.createJobAsync(request).get();
}
Parameter
Name Description
request CreateJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Job,Job>

createJobAsync(LocationName parent, Job job, String jobId)

publicfinalOperationFuture<Job,Job>createJobAsync(LocationNameparent,Jobjob,StringjobId)

Creates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
Jobjob=Job.newBuilder().build();
StringjobId="jobId101296568";
Jobresponse=jobsClient.createJobAsync(parent,job,jobId).get();
}
Parameters
Name Description
parent LocationName

Required. The location and project in which this Job should be created. Format: projects/{project}/locations/{location}, where {project} can be project id or number.

job Job

Required. The Job instance to create.

jobId String

Required. The unique identifier for the Job. The name of the job becomes {parent}/jobs/{job_id}.

Returns
Type Description
OperationFuture<Job,Job>

createJobAsync(String parent, Job job, String jobId)

publicfinalOperationFuture<Job,Job>createJobAsync(Stringparent,Jobjob,StringjobId)

Creates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
Jobjob=Job.newBuilder().build();
StringjobId="jobId101296568";
Jobresponse=jobsClient.createJobAsync(parent,job,jobId).get();
}
Parameters
Name Description
parent String

Required. The location and project in which this Job should be created. Format: projects/{project}/locations/{location}, where {project} can be project id or number.

job Job

Required. The Job instance to create.

jobId String

Required. The unique identifier for the Job. The name of the job becomes {parent}/jobs/{job_id}.

Returns
Type Description
OperationFuture<Job,Job>

createJobCallable()

publicfinalUnaryCallable<CreateJobRequest,Operation>createJobCallable()

Creates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
CreateJobRequestrequest=
CreateJobRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setJob(Job.newBuilder().build())
.setJobId("jobId101296568")
.setValidateOnly(true)
.build();
ApiFuture<Operation>future=jobsClient.createJobCallable().futureCall(request);
// Do something.
Operationresponse=future.get();
}
Returns
Type Description
UnaryCallable<CreateJobRequest,Operation>

createJobOperationCallable()

publicfinalOperationCallable<CreateJobRequest,Job,Job>createJobOperationCallable()

Creates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
CreateJobRequestrequest=
CreateJobRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setJob(Job.newBuilder().build())
.setJobId("jobId101296568")
.setValidateOnly(true)
.build();
OperationFuture<Job,Job>future=
jobsClient.createJobOperationCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
OperationCallable<CreateJobRequest,Job,Job>

deleteJobAsync(DeleteJobRequest request)

publicfinalOperationFuture<Job,Job>deleteJobAsync(DeleteJobRequestrequest)

Deletes a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
DeleteJobRequestrequest=
DeleteJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
Jobresponse=jobsClient.deleteJobAsync(request).get();
}
Parameter
Name Description
request DeleteJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Job,Job>

deleteJobAsync(JobName name)

publicfinalOperationFuture<Job,Job>deleteJobAsync(JobNamename)

Deletes a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=jobsClient.deleteJobAsync(name).get();
}
Parameter
Name Description
name JobName

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
OperationFuture<Job,Job>

deleteJobAsync(String name)

publicfinalOperationFuture<Job,Job>deleteJobAsync(Stringname)

Deletes a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=jobsClient.deleteJobAsync(name).get();
}
Parameter
Name Description
name String

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
OperationFuture<Job,Job>

deleteJobCallable()

publicfinalUnaryCallable<DeleteJobRequest,Operation>deleteJobCallable()

Deletes a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
DeleteJobRequestrequest=
DeleteJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
ApiFuture<Operation>future=jobsClient.deleteJobCallable().futureCall(request);
// Do something.
Operationresponse=future.get();
}
Returns
Type Description
UnaryCallable<DeleteJobRequest,Operation>

deleteJobOperationCallable()

publicfinalOperationCallable<DeleteJobRequest,Job,Job>deleteJobOperationCallable()

Deletes a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
DeleteJobRequestrequest=
DeleteJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
OperationFuture<Job,Job>future=
jobsClient.deleteJobOperationCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
OperationCallable<DeleteJobRequest,Job,Job>

getHttpJsonOperationsClient()

publicfinalOperationsClientgetHttpJsonOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getIamPolicy(GetIamPolicyRequest request)

publicfinalPolicygetIamPolicy(GetIamPolicyRequestrequest)

Gets the IAM Access Control policy currently in effect for the given Job. This result does not include any inherited policies.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
GetIamPolicyRequestrequest=
GetIamPolicyRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
Policyresponse=jobsClient.getIamPolicy(request);
}
Parameter
Name Description
request com.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicyCallable()

publicfinalUnaryCallable<GetIamPolicyRequest,Policy>getIamPolicyCallable()

Gets the IAM Access Control policy currently in effect for the given Job. This result does not include any inherited policies.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
GetIamPolicyRequestrequest=
GetIamPolicyRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
ApiFuture<Policy>future=jobsClient.getIamPolicyCallable().futureCall(request);
// Do something.
Policyresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getJob(GetJobRequest request)

publicfinalJobgetJob(GetJobRequestrequest)

Gets information about a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
GetJobRequestrequest=
GetJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
Jobresponse=jobsClient.getJob(request);
}
Parameter
Name Description
request GetJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Job

getJob(JobName name)

publicfinalJobgetJob(JobNamename)

Gets information about a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Jobresponse=jobsClient.getJob(name);
}
Parameter
Name Description
name JobName

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
Job

getJob(String name)

publicfinalJobgetJob(Stringname)

Gets information about a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Jobresponse=jobsClient.getJob(name);
}
Parameter
Name Description
name String

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
Job

getJobCallable()

publicfinalUnaryCallable<GetJobRequest,Job>getJobCallable()

Gets information about a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
GetJobRequestrequest=
GetJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.build();
ApiFuture<Job>future=jobsClient.getJobCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
UnaryCallable<GetJobRequest,Job>

getOperationsClient()

publicfinalOperationsClientgetOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getSettings()

publicfinalJobsSettingsgetSettings()
Returns
Type Description
JobsSettings

getStub()

publicJobsStubgetStub()
Returns
Type Description
JobsStub

isShutdown()

publicbooleanisShutdown()
Returns
Type Description
boolean

isTerminated()

publicbooleanisTerminated()
Returns
Type Description
boolean

listJobs(ListJobsRequest request)

publicfinalJobsClient.ListJobsPagedResponselistJobs(ListJobsRequestrequest)

Lists Jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setShowDeleted(true)
.build();
for(Jobelement:jobsClient.listJobs(request).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
request ListJobsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
JobsClient.ListJobsPagedResponse

listJobs(LocationName parent)

publicfinalJobsClient.ListJobsPagedResponselistJobs(LocationNameparent)

Lists Jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
for(Jobelement:jobsClient.listJobs(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent LocationName

Required. The location and project to list resources on. Format: projects/{project}/locations/{location}, where {project} can be project id or number.

Returns
Type Description
JobsClient.ListJobsPagedResponse

listJobs(String parent)

publicfinalJobsClient.ListJobsPagedResponselistJobs(Stringparent)

Lists Jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
for(Jobelement:jobsClient.listJobs(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent String

Required. The location and project to list resources on. Format: projects/{project}/locations/{location}, where {project} can be project id or number.

Returns
Type Description
JobsClient.ListJobsPagedResponse

listJobsCallable()

publicfinalUnaryCallable<ListJobsRequest,ListJobsResponse>listJobsCallable()

Lists Jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setShowDeleted(true)
.build();
while(true){
ListJobsResponseresponse=jobsClient.listJobsCallable().call(request);
for(Jobelement:response.getJobsList()){
// doThingsWith(element);
}
StringnextPageToken=response.getNextPageToken();
if(!Strings.isNullOrEmpty(nextPageToken)){
request=request.toBuilder().setPageToken(nextPageToken).build();
}else{
break;
}
}
}
Returns
Type Description
UnaryCallable<ListJobsRequest,ListJobsResponse>

listJobsPagedCallable()

publicfinalUnaryCallable<ListJobsRequest,JobsClient.ListJobsPagedResponse>listJobsPagedCallable()

Lists Jobs.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
ListJobsRequestrequest=
ListJobsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.setShowDeleted(true)
.build();
ApiFuture<Job>future=jobsClient.listJobsPagedCallable().futureCall(request);
// Do something.
for(Jobelement:future.get().iterateAll()){
// doThingsWith(element);
}
}
Returns
Type Description
UnaryCallable<ListJobsRequest,ListJobsPagedResponse>

runJobAsync(JobName name)

publicfinalOperationFuture<Execution,Execution>runJobAsync(JobNamename)

Triggers creation of a new Execution of this Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
JobNamename=JobName.of("[PROJECT]","[LOCATION]","[JOB]");
Executionresponse=jobsClient.runJobAsync(name).get();
}
Parameter
Name Description
name JobName

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
OperationFuture<Execution,Execution>

runJobAsync(RunJobRequest request)

publicfinalOperationFuture<Execution,Execution>runJobAsync(RunJobRequestrequest)

Triggers creation of a new Execution of this Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
RunJobRequestrequest=
RunJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
Executionresponse=jobsClient.runJobAsync(request).get();
}
Parameter
Name Description
request RunJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Execution,Execution>

runJobAsync(String name)

publicfinalOperationFuture<Execution,Execution>runJobAsync(Stringname)

Triggers creation of a new Execution of this Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Stringname=JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString();
Executionresponse=jobsClient.runJobAsync(name).get();
}
Parameter
Name Description
name String

Required. The full name of the Job. Format: projects/{project}/locations/{location}/jobs/{job}, where {project} can be project id or number.

Returns
Type Description
OperationFuture<Execution,Execution>

runJobCallable()

publicfinalUnaryCallable<RunJobRequest,Operation>runJobCallable()

Triggers creation of a new Execution of this Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
RunJobRequestrequest=
RunJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
ApiFuture<Operation>future=jobsClient.runJobCallable().futureCall(request);
// Do something.
Operationresponse=future.get();
}
Returns
Type Description
UnaryCallable<RunJobRequest,Operation>

runJobOperationCallable()

publicfinalOperationCallable<RunJobRequest,Execution,Execution>runJobOperationCallable()

Triggers creation of a new Execution of this Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
RunJobRequestrequest=
RunJobRequest.newBuilder()
.setName(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setValidateOnly(true)
.setEtag("etag3123477")
.build();
OperationFuture<Execution,Execution>future=
jobsClient.runJobOperationCallable().futureCall(request);
// Do something.
Executionresponse=future.get();
}
Returns
Type Description
OperationCallable<RunJobRequest,Execution,Execution>

setIamPolicy(SetIamPolicyRequest request)

publicfinalPolicysetIamPolicy(SetIamPolicyRequestrequest)

Sets the IAM Access control policy for the specified Job. Overwrites any existing policy.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
SetIamPolicyRequestrequest=
SetIamPolicyRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Policyresponse=jobsClient.setIamPolicy(request);
}
Parameter
Name Description
request com.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicyCallable()

publicfinalUnaryCallable<SetIamPolicyRequest,Policy>setIamPolicyCallable()

Sets the IAM Access control policy for the specified Job. Overwrites any existing policy.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
SetIamPolicyRequestrequest=
SetIamPolicyRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Policy>future=jobsClient.setIamPolicyCallable().futureCall(request);
// Do something.
Policyresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

publicvoidshutdown()

shutdownNow()

publicvoidshutdownNow()

testIamPermissions(TestIamPermissionsRequest request)

publicfinalTestIamPermissionsResponsetestIamPermissions(TestIamPermissionsRequestrequest)

Returns permissions that a caller has on the specified Project.

There are no permissions required for making this API call.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
TestIamPermissionsRequestrequest=
TestIamPermissionsRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.addAllPermissions(newArrayList<String>())
.build();
TestIamPermissionsResponseresponse=jobsClient.testIamPermissions(request);
}
Parameter
Name Description
request com.google.iam.v1.TestIamPermissionsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissionsCallable()

publicfinalUnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse>testIamPermissionsCallable()

Returns permissions that a caller has on the specified Project.

There are no permissions required for making this API call.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
TestIamPermissionsRequestrequest=
TestIamPermissionsRequest.newBuilder()
.setResource(JobName.of("[PROJECT]","[LOCATION]","[JOB]").toString())
.addAllPermissions(newArrayList<String>())
.build();
ApiFuture<TestIamPermissionsResponse>future=
jobsClient.testIamPermissionsCallable().futureCall(request);
// Do something.
TestIamPermissionsResponseresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

updateJobAsync(Job job)

publicfinalOperationFuture<Job,Job>updateJobAsync(Jobjob)

Updates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
Jobjob=Job.newBuilder().build();
Jobresponse=jobsClient.updateJobAsync(job).get();
}
Parameter
Name Description
job Job

Required. The Job to be updated.

Returns
Type Description
OperationFuture<Job,Job>

updateJobAsync(UpdateJobRequest request)

publicfinalOperationFuture<Job,Job>updateJobAsync(UpdateJobRequestrequest)

Updates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
UpdateJobRequestrequest=
UpdateJobRequest.newBuilder()
.setJob(Job.newBuilder().build())
.setValidateOnly(true)
.setAllowMissing(true)
.build();
Jobresponse=jobsClient.updateJobAsync(request).get();
}
Parameter
Name Description
request UpdateJobRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Job,Job>

updateJobCallable()

publicfinalUnaryCallable<UpdateJobRequest,Operation>updateJobCallable()

Updates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
UpdateJobRequestrequest=
UpdateJobRequest.newBuilder()
.setJob(Job.newBuilder().build())
.setValidateOnly(true)
.setAllowMissing(true)
.build();
ApiFuture<Operation>future=jobsClient.updateJobCallable().futureCall(request);
// Do something.
Operationresponse=future.get();
}
Returns
Type Description
UnaryCallable<UpdateJobRequest,Operation>

updateJobOperationCallable()

publicfinalOperationCallable<UpdateJobRequest,Job,Job>updateJobOperationCallable()

Updates a Job.

Sample code:


// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(JobsClientjobsClient=JobsClient.create()){
UpdateJobRequestrequest=
UpdateJobRequest.newBuilder()
.setJob(Job.newBuilder().build())
.setValidateOnly(true)
.setAllowMissing(true)
.build();
OperationFuture<Job,Job>future=
jobsClient.updateJobOperationCallable().futureCall(request);
// Do something.
Jobresponse=future.get();
}
Returns
Type Description
OperationCallable<UpdateJobRequest,Job,Job>

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.