删除集群

根据项目 ID 和实例 ID 删除集群。

代码示例

C#

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

// Deltes cluster "ssd-cluster2" from instance.
// At least one cluster must remain on an instance.
// Initialize request argument(s)
DeleteClusterRequest request = new DeleteClusterRequest
{
    ClusterName = new ClusterName(projectId, instanceId, "ssd-cluster2")
};
try
{
    // Make the request
    Console.WriteLine("Waiting for operation to complete...");
    bigtableInstanceAdminClient.DeleteCluster(request);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception deleting cluster {request.ClusterName.ClusterId} from instance {instanceId}");
    Console.WriteLine(ex.Message);
}

C++

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

namespace cbt = ::google::cloud::bigtable;
[](cbt::InstanceAdmin instance_admin, std::string const& instance_id,
   std::string const& cluster_id) {
  google::cloud::Status status =
      instance_admin.DeleteCluster(instance_id, cluster_id);
  if (!status.ok()) throw std::runtime_error(status.message());
}

Java

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

try {
  adminClient.deleteCluster(instanceId, CLUSTER);
  System.out.printf("Cluster: %s deleted successfully%n", CLUSTER);
} catch (NotFoundException e) {
  System.err.println("Failed to delete a non-existent cluster: " + e.getMessage());
}

Node.js

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

console.log(); //for just a new-line
console.log('Deleting Cluster');
await cluster.delete();
console.log(`Cluster deleted: ${cluster.id}`);

PHP

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

use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
use Google\ApiCore\ApiException;

/**
 * Delete a 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 be deleted
 */
function delete_cluster(
    string $projectId,
    string $instanceId,
    string $clusterId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);

    printf('Deleting Cluster' . PHP_EOL);
    try {
        $instanceAdminClient->deleteCluster($clusterName);
        printf('Cluster %s deleted.' . PHP_EOL, $clusterId);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Cluster %s does not exist.' . PHP_EOL, $clusterId);
        } else {
            throw $e;
        }
    }
}

Python

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

print("\nDeleting cluster")
if cluster.exists():
    cluster.delete()
    print("Cluster deleted: {}".format(cluster_id))
else:
    print("\nCluster {} does not exist.".format(cluster_id))

Ruby

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

cluster.delete

后续步骤

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