Elenco dei flussi di lavoro di migrazione

Elenca tutti i workflow di migrazione per l'API BigQuery Migration in un progetto specificato.

Esempio di codice

Node.js

Prima di provare questo esempio, segui le istruzioni di configurazione di Node.js nella guida rapida di BigQuery per l'utilizzo delle librerie client. Per saperne di più, consulta la documentazione di riferimento dell'API BigQuery Node.js.

Per eseguire l'autenticazione in BigQuery, configura le Credenziali predefinite dell'applicazione. Per saperne di più, vedi Configurare l'autenticazione per le librerie client.

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

const client = new MigrationServiceClient();

/**
 * Lists all migration workflows in a project.
 *
 * This is useful to get an overview of all migration workflows in a project and location.
 *
 * @param {string} projectId The Google Cloud project ID (for example, 'example-project-id')
 * @param {string} location The Google Cloud location (for example, 'us')
 */
async function listMigrationWorkflows(projectId, location = 'us') {
  const request = {
    parent: client.locationPath(projectId, location),
  };

  try {
    const [workflows] = await client.listMigrationWorkflows(request);

    if (workflows.length === 0) {
      console.error(
        `No workflows found in project ${projectId} at location ${location}.`,
      );
      return;
    }

    console.log('Workflows:');
    for (const workflow of workflows) {
      console.log(`  ${workflow.name}`);
      console.log(`    Display Name: ${workflow.displayName}`);
      console.log(`    State: ${workflow.state}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Project ${projectId} or location ${location} not found.`);
    } else {
      console.error('Error listing migration workflows:', err);
    }
  }
}

Python

Prima di provare questo esempio, segui le istruzioni di configurazione di Python nella guida rapida di BigQuery per l'utilizzo delle librerie client. Per saperne di più, consulta la documentazione di riferimento dell'API BigQuery Python.

Per eseguire l'autenticazione in BigQuery, configura le Credenziali predefinite dell'applicazione. Per saperne di più, vedi Configurare l'autenticazione per le librerie client.

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

client = bigquery_migration_v2.MigrationServiceClient()


def list_migration_workflows(project_id: str, location: str) -> None:
    """Lists migration workflows in a given project and location.

    Args:
        project_id: The Google Cloud project ID.
        location: The location of the migration workflows, for example, "us".
    """

    parent = f"projects/{project_id}/locations/{location}"

    try:
        workflow_pager = client.list_migration_workflows(parent=parent)

        print(f"Workflows in parent '{parent}':")
        count = 0
        for workflow in workflow_pager:
            print(f"- {workflow.name}")
            count += 1

        if not count:
            print("No migration workflows found.")

    except exceptions.NotFound:
        print(f"The parent resource '{parent}' was not found.")
        print("Please check that the project ID and location are correct.")

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .