获取集群详情
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
根据当前项目中的实例 ID 获取集群详情。
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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 page provides code samples in C++ and PHP to retrieve cluster details using the Bigtable client library within the current project.\u003c/p\u003e\n"],["\u003cp\u003eThe code demonstrates how to use the \u003ccode\u003eGetCluster\u003c/code\u003e method to fetch specific information about a cluster, given the project ID, instance ID, and cluster ID.\u003c/p\u003e\n"],["\u003cp\u003eThe PHP example shows how to handle potential errors, such as a \u003ccode\u003eNOT_FOUND\u003c/code\u003e status, and prints essential cluster metadata like name, location, state, storage type, nodes, and encryption configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe page provides links to the Bigtable client libraries and guides on setting up Application Default Credentials for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThe page shows the user how to search and filter code samples for other google cloud products using the sample browser.\u003c/p\u003e\n"]]],[],null,["Get cluster details given the instance ID in the current project.\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 const& cluster_id) {\n std::string cluster_name =\n cbt::ClusterName(project_id, instance_id, cluster_id);\n StatusOr\u003cgoogle::bigtable::admin::v2::Cluster\u003e cluster =\n instance_admin.GetCluster(cluster_name);\n if (!cluster) throw std::move(cluster).status();\n std::cout \u003c\u003c \"GetCluster details : \" \u003c\u003c cluster-\u003eDebugString() \u003c\u003c \"\\n\";\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\\ApiCore\\ApiException;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\GetClusterRequest;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Instance\\State;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\StorageType;\n\n /**\n * Get a Bigtable cluster\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n * @param string $clusterId The ID of the cluster to fetch\n */\n function get_cluster(\n string $projectId,\n string $instanceId,\n string $clusterId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n\n printf('Fetching the Cluster %s' . PHP_EOL, $clusterId);\n try {\n $clusterName = $instanceAdminClient-\u003eclusterName($projectId, $instanceId, $clusterId);\n $getClusterRequest = (new GetClusterRequest())\n -\u003esetName($clusterName);\n $cluster = $instanceAdminClient-\u003egetCluster($getClusterRequest);\n } catch (ApiException $e) {\n if ($e-\u003egetStatus() === 'NOT_FOUND') {\n printf('Cluster %s does not exists.' . PHP_EOL, $clusterId);\n return;\n }\n throw $e;\n }\n\n printf('Printing Details:' . PHP_EOL);\n\n // Fetch some commonly used metadata\n printf('Name: ' . $cluster-\u003egetName() . PHP_EOL);\n printf('Location: ' . $cluster-\u003egetLocation() . PHP_EOL);\n printf('State: ' . State::name($cluster-\u003egetState()) . PHP_EOL);\n printf('Default Storage Type: ' . StorageType::name($cluster-\u003egetDefaultStorageType()) . PHP_EOL);\n printf('Nodes: ' . $cluster-\u003egetServeNodes() . PHP_EOL);\n printf('Encryption Config: ' . ($cluster-\u003ehasEncryptionConfig() ? $cluster-\u003egetEncryptionConfig()-\u003egetKmsKeyName() : 'N/A') . PHP_EOL);\n }\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)."]]