Delete a data labeling job

Deletes a data labeling job using the delete_data_labeling_job method.

Code sample

Java

Before trying this sample, follow the Java setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Java API reference documentation.

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.DataLabelingJobName;
import com.google.cloud.aiplatform.v1.DeleteOperationMetadata;
import com.google.cloud.aiplatform.v1.JobServiceClient;
import com.google.cloud.aiplatform.v1.JobServiceSettings;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteDataLabelingJobSample {
  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String dataLabelingJobId = "YOUR_DATA_LABELING_JOB_ID";
    deleteDataLabelingJob(project, dataLabelingJobId);
  }

  static void deleteDataLabelingJob(String project, String dataLabelingJobId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    JobServiceSettings jobServiceSettings =
        JobServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
      String location = "us-central1";

      DataLabelingJobName dataLabelingJobName =
          DataLabelingJobName.of(project, location, dataLabelingJobId);

      OperationFuture<Empty, DeleteOperationMetadata> operationFuture =
          jobServiceClient.deleteDataLabelingJobAsync(dataLabelingJobName);
      System.out.format("Operation name: %s\n", operationFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      operationFuture.get(300, TimeUnit.SECONDS);

      System.out.format("Deleted Data Labeling Job.");
    }
  }
}

Python

Before trying this sample, follow the Python setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Python API reference documentation.

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

from google.cloud import aiplatform


def delete_data_labeling_job_sample(
    project: str,
    data_labeling_job_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 300,
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.JobServiceClient(client_options=client_options)
    name = client.data_labeling_job_path(
        project=project, location=location, data_labeling_job=data_labeling_job_id
    )
    response = client.delete_data_labeling_job(name=name)
    print("Long running operation:", response.operation.name)
    delete_data_labeling_job_response = response.result(timeout=timeout)
    print("delete_data_labeling_job_response:", delete_data_labeling_job_response)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.