Borra un flujo de trabajo de migración

Borra un flujo de trabajo de migración especificado de un proyecto del Servicio de migración de BigQuery. El flujo de trabajo no debe estar en ejecución en este momento.

Muestra de código

Java

Antes de probar este ejemplo, sigue las instrucciones de configuración para Java incluidas en la guía de inicio rápido de BigQuery sobre cómo usar bibliotecas cliente. Para obtener más información, consulta la documentación de referencia de la API de BigQuery para Java.

Para autenticarte en BigQuery, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para bibliotecas cliente.

import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.NotFoundException;
import com.google.cloud.bigquery.migration.v2.DeleteMigrationWorkflowRequest;
import com.google.cloud.bigquery.migration.v2.MigrationServiceClient;
import com.google.cloud.bigquery.migration.v2.MigrationWorkflowName;
import java.io.IOException;

public class DeleteMigrationWorkflow {

  /**
   * Deletes a migration workflow by name. The migration workflow is a top-level resource that
   * contains all details about a migration. Deleting the workflow also deletes all of its
   * sub-resources, such as migration tasks.
   *
   * @param projectId The Google Cloud project ID (for example, "example-project-id").
   * @param location The geographic location of the migration workflow (for example, "us").
   * @param workflowId The ID of the migration workflow to delete (for example,
   *     "12345678-abcd-4372-a567-0e02b2c3d479").
   */
  public static void deleteMigrationWorkflow(String projectId, String location, String workflowId) {
    MigrationWorkflowName name = MigrationWorkflowName.of(projectId, location, workflowId);

    DeleteMigrationWorkflowRequest request =
        DeleteMigrationWorkflowRequest.newBuilder().setName(name.toString()).build();

    try (MigrationServiceClient client = MigrationServiceClient.create()) {
      client.deleteMigrationWorkflow(request);
      System.out.printf("Deleted migration workflow: %s%n", name);
    } catch (NotFoundException err) {
      System.out.printf("Migration workflow not found: %s%n", name);
    } catch (ApiException | IOException err) {
      System.err.printf(
          "error: failed to delete migration workflow '%s': %s%n", name, err.getMessage());
    }
  }

Node.js

Antes de probar este ejemplo, sigue las instrucciones de configuración para Node.js incluidas en la guía de inicio rápido de BigQuery sobre cómo usar bibliotecas cliente. Para obtener más información, consulta la documentación de referencia de la API de BigQuery para Node.js.

Para autenticarte en BigQuery, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para bibliotecas cliente.

const {MigrationServiceClient} = require('@google-cloud/bigquery-migration').v2;
const {status} = require('@grpc/grpc-js');

const client = new MigrationServiceClient();

/**
 * Deletes a migration workflow by name.
 *
 * This is useful to clean up migration resources that are no longer needed.
 *
 * @param {string} projectId The Google Cloud project ID.
 * @param {string} location The workflow's location (for example, 'us').
 * @param {string} workflowId The ID of the migration workflow to delete (for example, '12345678-abcd-4372-a567-0e02b2c3d479').
 */
async function deleteMigrationWorkflow(
  projectId,
  location = 'us',
  workflowId = '12345678-abcd-4372-a567-0e02b2c3d479',
) {
  const name = client.migrationWorkflowPath(projectId, location, workflowId);

  const request = {
    name,
  };

  try {
    await client.deleteMigrationWorkflow(request);
    console.log(`Migration workflow ${workflowId} deleted successfully.`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Migration workflow ${workflowId} not found.`);
    } else {
      console.error(
        'An error occurred while deleting the migration workflow:',
        err,
      );
    }
  }
}

Python

Antes de probar este ejemplo, sigue las instrucciones de configuración para Python incluidas en la guía de inicio rápido de BigQuery sobre cómo usar bibliotecas cliente. Para obtener más información, consulta la documentación de referencia de la API de BigQuery para Python.

Para autenticarte en BigQuery, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para bibliotecas cliente.

from google.api_core import exceptions
from google.cloud import bigquery_migration_v2

client = bigquery_migration_v2.MigrationServiceClient()


def delete_migration_workflow(project_id: str, location: str, workflow_id: str) -> None:
    """Deletes a migration workflow.

    The migration workflow is a top-level resource that contains all the
    details about a migration. Deleting it will also delete all its
    sub-resources, such as migration tasks.

    Args:
        project_id: The Google Cloud project ID.
        location: The location of the migration workflow, for example, "us".
        workflow_id: The ID of the migration workflow to delete.
    """
    name = client.migration_workflow_path(project_id, location, workflow_id)

    try:
        client.delete_migration_workflow(name=name)
        print(f"Deleted migration workflow: {name}")
    except exceptions.NotFound:
        print(f"Migration workflow not found: {name}")

¿Qué sigue?

Si quieres buscar y filtrar muestras de código para otros productos de Google Cloud , consulta el navegador de muestras deGoogle Cloud .