Supprimer un cluster

Restez organisé à l'aide des collections Enregistrez et classez les contenus selon vos préférences.

Supprimer un cluster, à partir d'un ID de projet et un ID d'instance.

Exemple de code

C++

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes Bigtable.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Status;
[](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);
  Status status = instance_admin.DeleteCluster(cluster_name);
  if (!status.ok()) throw std::runtime_error(status.message());
}

C#

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes 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);
}

Java

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes 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

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes Bigtable.

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

PHP

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes 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

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes 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

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la page Bibliothèques clientes Bigtable.

cluster.delete

Étapes suivantes

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'exemple de navigateur Google Cloud.