列出叢集
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
列出執行個體中的所有叢集名稱。
程式碼範例
C++
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to list all cluster names within a specified Bigtable instance using code examples in C++, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample utilizes the respective Bigtable client library to connect to the instance and retrieve a list of cluster names, which are then printed to the console.\u003c/p\u003e\n"],["\u003cp\u003eThe code also shows how to handle cases where certain locations are temporarily unavailable, and displays a message about it.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples also point the user to resources to learn more about the Bigtable client library and authentication setup.\u003c/p\u003e\n"]]],[],null,["List all of the cluster names in an instance.\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id) {\n std::string instance_name = cbt::InstanceName(project_id, instance_id);\n StatusOr\u003cgoogle::bigtable::admin::v2::ListClustersResponse\u003e clusters =\n instance_admin.ListClusters(instance_name);\n if (!clusters) throw std::move(clusters).status();\n std::cout \u003c\u003c \"Cluster Name List\\n\";\n for (auto const& cluster : clusters-\u003eclusters()) {\n std::cout \u003c\u003c \"Cluster Name:\" \u003c\u003c cluster.name() \u003c\u003c \"\\n\";\n }\n if (!clusters-\u003efailed_locations().empty()) {\n std::cout \u003c\u003c \"The Cloud Bigtable service reports that the following \"\n \"locations are temporarily unavailable and no information \"\n \"about clusters in these locations can be obtained:\\n\";\n for (auto const& failed_location : clusters-\u003efailed_locations()) {\n std::cout \u003c\u003c failed_location \u003c\u003c \"\\n\";\n }\n }\n }\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id) {\n std::string instance_name = cbt::InstanceName(project_id, \"-\");\n StatusOr\u003cgoogle::bigtable::admin::v2::ListClustersResponse\u003e clusters =\n instance_admin.ListClusters(instance_name);\n if (!clusters) throw std::move(clusters).status();\n std::cout \u003c\u003c \"Cluster Name List\\n\";\n for (auto const& cluster : clusters-\u003eclusters()) {\n std::cout \u003c\u003c \"Cluster Name:\" \u003c\u003c cluster.name() \u003c\u003c \"\\n\";\n }\n if (!clusters-\u003efailed_locations().empty()) {\n std::cout \u003c\u003c \"The Cloud Bigtable service reports that the following \"\n \"locations are temporarily unavailable and no information \"\n \"about clusters in these locations can be obtained:\\n\";\n for (auto const& failed_location : clusters-\u003efailed_locations()) {\n std::cout \u003c\u003c failed_location \u003c\u003c \"\\n\";\n }\n }\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n try {\n List\u003cCluster\u003e clusters = adminClient.listClusters(instanceId);\n for (Cluster cluster : clusters) {\n System.out.println(cluster.getId());\n }\n } catch (NotFoundException e) {\n System.err.println(\"Failed to list clusters from a non-existent instance: \" + e.getMessage());\n }\n\nNode.js\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const instance3 = bigtable.instance(instanceID);\n const [clusters] = await instance3.getClusters();\n clusters.forEach(cluster =\u003e {\n console.log(cluster.id);\n });\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\ListClustersRequest;\n\n /**\n * List clusters of an instance\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n */\n function list_instance_clusters(\n string $projectId,\n string $instanceId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n\n $projectName = $instanceAdminClient-\u003eprojectName($projectId);\n $instanceName = $instanceAdminClient-\u003einstanceName($projectId, $instanceId);\n\n printf('Listing Clusters:' . PHP_EOL);\n $listClustersRequest = (new ListClustersRequest())\n -\u003esetParent($instanceName);\n $getClusters = $instanceAdminClient-\u003elistClusters($listClustersRequest)-\u003egetClusters();\n $clusters = $getClusters-\u003egetIterator();\n\n foreach ($clusters as $cluster) {\n print($cluster-\u003egetName() . PHP_EOL);\n }\n }\n\nPython\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n print(\"\\nListing clusters...\")\n for cluster in instance.list_clusters()[0]:\n print(cluster.cluster_id)\n\nRuby\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # instance_id = \"my-instance\"\n bigtable.instance(instance_id).clusters.all do |cluster|\n puts \"Cluster: #{cluster.cluster_id}\"\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]