-
Notifications
You must be signed in to change notification settings - Fork 1k
BigTable Admin Samples #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
dbb8f07
BigTable Admin Samples
4f63e67
Set some changes to the Google Bigtable Admin Samples
ee0faf2
Setting Format of some print functions
d8e963e
Divided the InstanceAdmin in Snippets Files
77f3a4a
InstanceAdmin Test completed
22beb1a
Divided TableAdmin in Snippets Files & TableAdmin Test completed
b285266
Changed the README to set the Snippets
aabfb4c
changed 'Instance' to 'instance'
a45b2d3
All samples on /bigtable/api/src
070a85d
Argv in Bigtable samples
adaa040
Move the START tag before the use statements.
c276da1
Split the Table Admin file and create all the test of the snippet files
7794250
Tested all the snippets
924f96e
Admin format
866dc61
Deleting unused variables
0a0299d
Removed the comment in clear_instance
21f92c1
Resolved Review
8914702
Formatting & Conflict Resolve
4e5af77
Delete Cluster & Delete Family Conflicts
c6201e8
Creating a Test Sample
8f12807
Create Cluster
18a0ecb
Created Test Snippets
5a70628
Throwing an exception when the instances is already exists.
6b49ed7
Delete Instance and Delete Table
3f75614
Delete Table
1017060
Bigtable Update Gc Rule
3b99938
UpdateGcRule - CheckRule Function
9ca0797
a
5ef8f5f
create a function for the try/catch
9fa6d12
Check in Delete Instance and Delete Table
6372e28
Generate Dynamic Instance Name
c279f9e
Generate Dynamic Instance Name
0033754
Deleted the Test File
19399ed
Create Cluster Try Catch Throw other Status.
83e0200
Delete all the other test
raelcorrales 5b6b6cd
Deleting the iterator_to_array
3f11972
Update bigtable to 0.9.1 in composer and set the setUpBeforeClass
5a88736
Changed setupUpBeforeClass to static
c666340
List errors
8e70951
List error changed
4108d26
Getting the Key File
7cfe24c
Setting the ProjectID variable
81ce228
Test Listing
9c51b31
Checking the List Instance Cluster
cbe478d
Checking the Segmentation Fault in the GetCluster()->getIterator()
eee2b72
Segmentation Fault GetInstance
28450f5
Formatted Code Test
b73a2cd
Changed the code to get the Instance and Cluster List, Issue: SegFault
ae4d904
Running test in docker
6a0609b
Test runs successfully
e5d09cc
Test phpunit.xml.dist ConvertErrors and PHP 5.6 return types
0a4ba3d
Adding Bigtable to Run Test Suite
1313502
TestTrait added
e33c07e
projectId in line 77
1cc1dca
projectId in line 47 and 59
c16bd2a
Added Exponential Backoff Trait
656bfee
Added try/catch to delete_instance
ea45f7f
Adding TestTrait again
fe17217
Changed runSnippet to static
6679d99
Removed the tearDownAfterClass method
e0782c3
Changed Test structure, to use less instances
b086efc
Added Delete Test
ea030c8
Resolve errors of typing
a02432f
create_cluster test setting other region cluster
9091e2a
create_cluster test setting other region cluster
fcde4c9
created the testCreateProdution
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Google BigTable Sample | ||
|
|
||
| ## Description | ||
|
|
||
| All code in the `src` directory demonstrates how to connect to Cloud Bigtable and run some basic operations to create instance, create cluster, delete instance and delete cluster. | ||
|
|
||
| ## Build and Run | ||
| 1. **Enable APIs** - [Enable the BigTable API](https://console.cloud.google.com/flows/enableapi?apiid=bigtable) | ||
| and create a new project or select an existing project. | ||
| 2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials" | ||
| and select "Service Account Key". Create a new service account, use the JSON key type, and | ||
| select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` | ||
| to the path of the JSON key that was downloaded. | ||
| 3. **Clone the repo** and cd into this directory | ||
| ```sh | ||
| $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples | ||
| $ cd php-docs-samples/bigtable/api | ||
| ``` | ||
|
|
||
| 4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). | ||
| Run `php composer.phar install` (if composer is installed locally) or `composer install` | ||
| (if composer is installed globally). | ||
| 5. Run `php SNIPPET_NAME.php`. The usage will print for each if no arguments | ||
| are provided: | ||
| ```sh | ||
| $ php src/run_instance_operations.php | ||
| Usage: php src/run_instance_operations.php PROJECT_ID INSTANCE_ID TABLE_ID | ||
|
|
||
| $ php src/run_instance_operations.php your-project-id your-instance-id your-table-id | ||
| ``` | ||
|
|
||
| ## Contributing changes | ||
|
|
||
| * See [CONTRIBUTING.md](../../CONTRIBUTING.md) | ||
|
|
||
| ## Licensing | ||
|
|
||
| * See [LICENSE](../../LICENSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "require": { | ||
| "google/cloud-bigtable": "^0.9.1" | ||
| }, | ||
| "require-dev": { | ||
| "google/cloud-tools": "^0.8", | ||
| "phpunit/phpunit": "^5.0" | ||
| } | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2018 Google LLC. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
| <phpunit backupGlobals="false" | ||
| strict="true" | ||
| backupStaticAttributes="false" | ||
| bootstrap="vendor/autoload.php" | ||
| colors="true" | ||
| processIsolation="false" | ||
| stopOnFailure="false" | ||
| syntaxCheck="false" | ||
| timeoutForSmallTests="10" | ||
| timeoutForMediumTests="30" | ||
| timeoutForLargeTests="120"> | ||
| <testsuites> | ||
| <testsuite name="PHP bigtable Instance test"> | ||
| <file>./test/bigtableTest.php</file> | ||
| </testsuite> | ||
| </testsuites> | ||
| <logging> | ||
| <log type="coverage-clover" target="./build/logs/clover.xml"/> | ||
| </logging> | ||
| <filter> | ||
| <whitelist addUncoveredFilesFromWhitelist="true"> | ||
| <directory>./src</directory> | ||
| </whitelist> | ||
| </filter> | ||
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2018 Google LLC. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * For instructions on how to run the full sample: | ||
| * | ||
| * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md | ||
| */ | ||
|
|
||
| // Include Google Cloud dependendencies using Composer | ||
| require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| if (count($argv) < 3 || count($argv) > 5) { | ||
| return printf("Usage: php %s PROJECT_ID INSTANCE_ID CLUSTER_ID [LOCATION_ID]" . PHP_EOL, __FILE__); | ||
| } | ||
| list($_, $project_id, $instance_id, $cluster_id) = $argv; | ||
| $location_id = isset($argv[4]) ? $argv[4] : 'us-east1-b'; | ||
|
|
||
| // [START bigtable_create_cluster] | ||
|
|
||
| use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; | ||
| use Google\Cloud\Bigtable\Admin\V2\Cluster; | ||
| use Google\Cloud\Bigtable\Admin\V2\StorageType; | ||
| use Google\ApiCore\ApiException; | ||
|
|
||
|
|
||
| /** Uncomment and populate these variables in your code */ | ||
| // $project_id = 'The Google project ID'; | ||
| // $instance_id = 'The Bigtable instance ID'; | ||
| // $cluster_id = 'The Bigtable cluster ID'; | ||
| // $location_id = 'The Bigtable region ID'; | ||
|
|
||
|
|
||
| $instanceAdminClient = new BigtableInstanceAdminClient(); | ||
|
|
||
| $instanceName = $instanceAdminClient->instanceName($project_id, $instance_id); | ||
| $clusterName = $instanceAdminClient->clusterName($project_id, $instance_id, $cluster_id); | ||
|
|
||
| printf("Adding Cluster to Instance %s" . PHP_EOL, $instance_id); | ||
| try { | ||
| $instanceAdminClient->getInstance($instanceName); | ||
| } catch (ApiException $e) { | ||
| if ($e->getStatus() === 'NOT_FOUND') { | ||
| printf("Instance %s does not exists." . PHP_EOL, $instance_id); | ||
| return; | ||
| } else { | ||
| throw $e; | ||
| } | ||
juan-rael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| printf("Listing Clusters:" . PHP_EOL); | ||
|
|
||
| $storage_type = StorageType::SSD; | ||
| $serve_nodes = 3; | ||
|
|
||
| $clustersBefore = $instanceAdminClient->listClusters($instanceName)->getClusters(); | ||
| $clusters = $clustersBefore->getIterator(); | ||
| foreach ($clusters as $cluster) { | ||
| print($cluster->getName() . PHP_EOL); | ||
| } | ||
|
|
||
| $cluster = new Cluster(); | ||
| $cluster->setServeNodes($serve_nodes); | ||
| $cluster->setDefaultStorageType($storage_type); | ||
| $cluster->setLocation( | ||
| $instanceAdminClient->locationName( | ||
| $project_id, | ||
| $location_id | ||
| ) | ||
| ); | ||
| try { | ||
| $instanceAdminClient->getCluster($clusterName); | ||
| printf("Cluster %s already exists, aborting...", $cluster_id); | ||
| } catch (ApiException $e) { | ||
| if ($e->getStatus() === 'NOT_FOUND') { | ||
| $operationResponse = $instanceAdminClient->createCluster($instanceName, $cluster_id, $cluster); | ||
|
|
||
| $operationResponse->pollUntilComplete(); | ||
| if ($operationResponse->operationSucceeded()) { | ||
| $result = $operationResponse->getResult(); | ||
| printf("Cluster created: %s", $cluster_id); | ||
| } else { | ||
| $error = $operationResponse->getError(); | ||
| printf("Cluster not created: %s", $error); | ||
| } | ||
| } else { | ||
| throw $e; | ||
| } | ||
juan-rael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| // [END bigtable_create_cluster] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2018 Google LLC. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * For instructions on how to run the full sample: | ||
| * | ||
| * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md | ||
| */ | ||
|
|
||
| // Include Google Cloud dependendencies using Composer | ||
| require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| if (count($argv) < 3 || count($argv) > 5) { | ||
| return printf("Usage: php %s PROJECT_ID INSTANCE_ID CLUSTER_ID [LOCATION_ID]" . PHP_EOL, __FILE__); | ||
| } | ||
| list($_, $project_id, $instance_id, $cluster_id) = $argv; | ||
| $location_id = isset($argv[4]) ? $argv[4] : 'us-east1-b'; | ||
|
|
||
| // [START bigtable_create_dev_instance] | ||
|
|
||
| use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; | ||
juan-rael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use Google\Cloud\Bigtable\Admin\V2\Instance; | ||
| use Google\Cloud\Bigtable\Admin\V2\Cluster; | ||
| use Google\Cloud\Bigtable\Admin\V2\StorageType; | ||
| use Google\Cloud\Bigtable\Admin\V2\Instance\Type as InstanceType; | ||
| use Google\ApiCore\ApiException; | ||
|
|
||
| /** Uncomment and populate these variables in your code */ | ||
| // $project_id = 'The Google project ID'; | ||
| // $instance_id = 'The Bigtable instance ID'; | ||
| // $cluster_id = 'The Bigtable cluster ID'; | ||
| // $location_id = 'The Bigtable region ID'; | ||
|
|
||
|
|
||
| $instanceAdminClient = new BigtableInstanceAdminClient(); | ||
|
|
||
| $projectName = $instanceAdminClient->projectName($project_id); | ||
| $instanceName = $instanceAdminClient->instanceName($project_id, $instance_id); | ||
|
|
||
|
|
||
| printf("Creating a DEVELOPMENT Instance" . PHP_EOL); | ||
| // Set options to create an Instance | ||
|
|
||
| $storage_type = StorageType::HDD; | ||
| $development = InstanceType::DEVELOPMENT; | ||
| $labels = ['dev-label' => 'dev-label']; | ||
|
|
||
|
|
||
| # Create instance with given options | ||
| $instance = new Instance(); | ||
| $instance->setDisplayName($instance_id); | ||
| $instance->setLabels($labels); | ||
| $instance->setType($development); | ||
|
|
||
| // Create cluster with given options | ||
| $cluster = new Cluster(); | ||
| $cluster->setDefaultStorageType($storage_type); | ||
| $cluster->setLocation( | ||
| $instanceAdminClient->locationName( | ||
| $project_id, | ||
| $location_id | ||
| ) | ||
| ); | ||
| $clusters = [ | ||
| $cluster_id => $cluster | ||
| ]; | ||
| // Create development instance with given options | ||
| try { | ||
| $instanceAdminClient->getInstance($instanceName); | ||
juan-rael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| printf("Instance %s already exists." . PHP_EOL, $instance_id); | ||
| } catch (ApiException $e) { | ||
juan-rael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ($e->getStatus() === 'NOT_FOUND') { | ||
| printf("Creating a development Instance: %s" . PHP_EOL, $instance_id); | ||
| $operationResponse = $instanceAdminClient->createInstance( | ||
| $projectName, | ||
| $instance_id, | ||
| $instance, | ||
| $clusters | ||
| ); | ||
| $operationResponse->pollUntilComplete(); | ||
| if (!$operationResponse->operationSucceeded()) { | ||
| $error = $operationResponse->getError(); | ||
| throw $error; | ||
| } else { | ||
| printf("Instance %s created.", $instance_id); | ||
| } | ||
| } else { | ||
| throw $e; | ||
| } | ||
| } | ||
| // [END bigtable_create_dev_instance] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Copyright 2018 Google LLC. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * For instructions on how to run the full sample: | ||
| * | ||
| * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md | ||
| */ | ||
|
|
||
| // Include Google Cloud dependendencies using Composer | ||
| require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| if (count($argv) != 4) { | ||
| return printf("Usage: php %s PROJECT_ID INSTANCE_ID TABLE_ID" . PHP_EOL, __FILE__); | ||
| } | ||
| list($_, $project_id, $instance_id, $table_id) = $argv; | ||
|
|
||
| // [START bigtable_create_family_gc_intersection] | ||
| use Google\Cloud\Bigtable\Admin\V2\GcRule\Intersection as GcRuleIntersection; | ||
| use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification; | ||
| use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; | ||
| use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient; | ||
| use Google\Cloud\Bigtable\Admin\V2\ColumnFamily; | ||
| use Google\Cloud\Bigtable\Admin\V2\GcRule; | ||
| use Google\Protobuf\Duration; | ||
|
|
||
|
|
||
| /** Uncomment and populate these variables in your code */ | ||
| // $project_id = 'The Google project ID'; | ||
| // $instance_id = 'The Bigtable instance ID'; | ||
| // $table_id = 'The Bigtable table ID'; | ||
|
|
||
| $tableAdminClient = new BigtableTableAdminClient(); | ||
|
|
||
| $tableName = $tableAdminClient->tableName($project_id, $instance_id, $table_id); | ||
|
|
||
| print('Creating column family cf4 with Intersection GC rule...' . PHP_EOL); | ||
| $columnFamily4 = new ColumnFamily(); | ||
|
|
||
| $intersection_rule = new GcRuleIntersection(); | ||
| $intersection_array = [ | ||
| (new GcRule)->setMaxAge((new Duration())->setSeconds(3600 * 24 * 5)), | ||
| (new GcRule)->setMaxNumVersions(2) | ||
| ]; | ||
| $intersection_rule->setRules($intersection_array); | ||
|
|
||
| $intersection = new GcRule(); | ||
| $intersection->setIntersection($intersection_rule); | ||
|
|
||
| $columnFamily4->setGCRule($intersection); | ||
|
|
||
| $columnModification = new Modification(); | ||
| $columnModification->setId('cf4'); | ||
| $columnModification->setCreate($columnFamily4); | ||
| $tableAdminClient->modifyColumnFamilies($tableName, [$columnModification]); | ||
|
|
||
| print('Created column family cf4 with Union GC rule' . PHP_EOL); | ||
|
|
||
| // [END bigtable_create_family_gc_intersection] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.