Mendapatkan detail cluster

Mendapatkan detail cluster dengan ID instance dalam project saat ini.

Contoh kode

C++

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Bigtable, lihat Library klien Bigtable.

Untuk melakukan autentikasi ke Bigtable, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Bigtable, lihat Library klien Bigtable.

Untuk melakukan autentikasi ke Bigtable, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

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);
}

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.