Cluster auflisten
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Alle Clusternamen in einer Instanz auflisten
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","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)."]]