Skip to content

Commit 75cc785

Browse files
chore(bigtable): new sample format for write and delete samples (GoogleCloudPlatform#1450)
1 parent 0340e40 commit 75cc785

25 files changed

+412
-372
lines changed

bigtable/src/create_cluster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_dev_instance.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_family_gc_intersection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_family_gc_max_age.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_family_gc_max_versions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_family_gc_nested.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_family_gc_union.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_production_instance.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/create_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*

bigtable/src/delete_cluster.php

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Google\Cloud\Samples\Bigtable;
4+
35
/**
46
* Copyright 2019 Google LLC.
57
*
@@ -22,39 +24,38 @@
2224
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2325
*/
2426

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-
3327
// [START bigtable_delete_cluster]
34-
3528
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3629
use Google\ApiCore\ApiException;
3730

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+
}
5855
}
5956
}
6057
// [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

Comments
 (0)