|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +namespace Google\Cloud\Samples\Bigtable; |
| 4 | + |
3 | 5 | /** |
4 | 6 | * Copyright 2019 Google LLC. |
5 | 7 | * |
|
22 | 24 | * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md |
23 | 25 | */ |
24 | 26 |
|
25 | | -// Include Google Cloud dependencies using Composer |
26 | | -require_once __DIR__ . '/../vendor/autoload.php'; |
27 | | - |
28 | | -if (count($argv) != 4) { |
29 | | - return printf("Usage: php %s PROJECT_ID INSTANCE_ID CLUSTER_ID" . PHP_EOL, __FILE__); |
30 | | -} |
31 | | -list($_, $projectId, $instanceId, $clusterId) = $argv; |
32 | | - |
33 | 27 | // [START bigtable_delete_cluster] |
34 | | - |
35 | 28 | use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; |
36 | 29 | use Google\ApiCore\ApiException; |
37 | 30 |
|
38 | | -/** Uncomment and populate these variables in your code */ |
39 | | -// $projectId = 'The Google project ID'; |
40 | | -// $instanceId = 'The Bigtable instance ID'; |
41 | | -// $clusterId = 'The Bigtable cluster ID'; |
42 | | - |
43 | | - |
44 | | -$instanceAdminClient = new BigtableInstanceAdminClient(); |
45 | | - |
46 | | -$clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId); |
47 | | - |
48 | | - |
49 | | -printf("Deleting Cluster" . PHP_EOL); |
50 | | -try { |
51 | | - $instanceAdminClient->deleteCluster($clusterName); |
52 | | - printf("Cluster %s deleted." . PHP_EOL, $clusterId); |
53 | | -} catch (ApiException $e) { |
54 | | - if ($e->getStatus() === 'NOT_FOUND') { |
55 | | - printf("Cluster %s does not exist." . PHP_EOL, $clusterId); |
56 | | - } else { |
57 | | - throw $e; |
| 31 | +/** |
| 32 | + * Delete a cluster |
| 33 | + * @param string $projectId The Google Cloud project ID |
| 34 | + * @param string $instanceId The ID of the Bigtable instance |
| 35 | + * @param string $clusterId The ID of the cluster to be deleted |
| 36 | + */ |
| 37 | +function delete_cluster( |
| 38 | + string $projectId, |
| 39 | + string $instanceId, |
| 40 | + string $clusterId |
| 41 | +): void { |
| 42 | + $instanceAdminClient = new BigtableInstanceAdminClient(); |
| 43 | + $clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId); |
| 44 | + |
| 45 | + printf("Deleting Cluster" . PHP_EOL); |
| 46 | + try { |
| 47 | + $instanceAdminClient->deleteCluster($clusterName); |
| 48 | + printf("Cluster %s deleted." . PHP_EOL, $clusterId); |
| 49 | + } catch (ApiException $e) { |
| 50 | + if ($e->getStatus() === 'NOT_FOUND') { |
| 51 | + printf("Cluster %s does not exist." . PHP_EOL, $clusterId); |
| 52 | + } else { |
| 53 | + throw $e; |
| 54 | + } |
58 | 55 | } |
59 | 56 | } |
60 | 57 | // [END bigtable_delete_cluster] |
| 58 | + |
| 59 | +// The following 2 lines are only needed to run the samples |
| 60 | +require_once __DIR__ . '/../../testing/sample_helpers.php'; |
| 61 | +\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); |
0 commit comments