마이그레이션 워크플로 나열

지정된 프로젝트의 BigQuery Migration API에 대한 모든 이전 워크플로를 나열합니다.

코드 샘플

Node.js

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Node.js 설정 안내를 따르세요. 자세한 내용은 BigQuery Node.js API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

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

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 BigQuery Python API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

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.")

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.