Migrationsworkflow abrufen

Ruft einen bestimmten Migrationsworkflow aus dem BigQuery Migration Service ab.

Codebeispiel

Node.js

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Node.js in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Node.js API.

Richten Sie zur Authentifizierung bei BigQuery die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für Clientbibliotheken einrichten.

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

const client = new MigrationServiceClient();

/**
 * Gets a previously created migration workflow.
 *
 * A migration workflow is a collection of tasks that you can create to support
 * data warehouse migration to BigQuery.
 *
 * @param {string} projectId The Google Cloud project ID.
 * @param {string} location The Google Cloud location of the workflow (for example, 'us').
 * @param {string} workflowId The ID of the migration workflow (for example, '12345678-abcd-4372-a567-0e02b2c3d479').
 */
async function getMigrationWorkflow(
  projectId,
  location = 'us',
  workflowId = '12345678-abcd-4372-a567-0e02b2c3d479',
) {
  const name = client.migrationWorkflowPath(projectId, location, workflowId);
  const request = {
    name,
  };

  try {
    const [workflow] = await client.getMigrationWorkflow(request);
    console.log(`Migration workflow found: ${workflow.name}`);
    console.log(`  Display Name: ${workflow.displayName}`);
    console.log(`  State: ${workflow.state}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Migration workflow not found: ${name}`);
    } else {
      console.error('Error getting migration workflow:', err);
    }
  }
}

Python

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Python-Einrichtungsanleitung in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Python API.

Richten Sie zur Authentifizierung bei BigQuery die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für Clientbibliotheken einrichten.

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

client = bigquery_migration_v2.MigrationServiceClient()


def get_migration_workflow(project_id: str, location: str, workflow_id: str) -> None:
    """Gets a previously created migration workflow.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the migration workflow, for example, "us".
        workflow_id: The ID of the migration workflow to retrieve.
    """

    name = client.migration_workflow_path(project_id, location, workflow_id)

    try:
        workflow = client.get_migration_workflow(name=name)
        print(f"Successfully retrieved migration workflow: {workflow.name}")
        print(f"Display Name: {workflow.display_name}")
        print(f"State: {workflow.state.name}")
    except NotFound:
        print(f"Migration workflow not found: {name}")

Weitere Informationen

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.