获取集群详情

根据当前项目中的实例 ID 获取集群详情。

代码示例

C++

如需了解如何安装和使用 Bigtable 客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id, std::string const& instance_id,
   std::string const& cluster_id) {
  std::string cluster_name =
      cbt::ClusterName(project_id, instance_id, cluster_id);
  StatusOr<google::bigtable::admin::v2::Cluster> cluster =
      instance_admin.GetCluster(cluster_name);
  if (!cluster) throw std::move(cluster).status();
  std::cout << "GetCluster details : " << cluster->DebugString() << "\n";
}

PHP

如需了解如何安装和使用 Bigtable 客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\GetClusterRequest;
use Google\Cloud\Bigtable\Admin\V2\Instance\State;
use Google\Cloud\Bigtable\Admin\V2\StorageType;

/**
 * Get a Bigtable cluster
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 * @param string $clusterId The ID of the cluster to fetch
 */
function get_cluster(
    string $projectId,
    string $instanceId,
    string $clusterId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();

    printf('Fetching the Cluster %s' . PHP_EOL, $clusterId);
    try {
        $clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);
        $getClusterRequest = (new GetClusterRequest())
            ->setName($clusterName);
        $cluster = $instanceAdminClient->getCluster($getClusterRequest);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Cluster %s does not exists.' . PHP_EOL, $clusterId);
            return;
        }
        throw $e;
    }

    printf('Printing Details:' . PHP_EOL);

    // Fetch some commonly used metadata
    printf('Name: ' . $cluster->getName() . PHP_EOL);
    printf('Location: ' . $cluster->getLocation() . PHP_EOL);
    printf('State: ' . State::name($cluster->getState()) . PHP_EOL);
    printf('Default Storage Type: ' . StorageType::name($cluster->getDefaultStorageType()) . PHP_EOL);
    printf('Nodes: ' . $cluster->getServeNodes() . PHP_EOL);
    printf('Encryption Config: ' . ($cluster->hasEncryptionConfig() ? $cluster->getEncryptionConfig()->getKmsKeyName() : 'N/A') . PHP_EOL);
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器