Skip to content

Commit 97edb9a

Browse files
sample: add turbo replication samples (#1618)
* sample: add turbo replication samples * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add storage system-test * change name of sample test bucket * fix dual region bucket in samples test * add rpo to getMetadata sample, change error handling * feedback from canonical sample document * fix readme names * fix naming in tests * change dual region to dual-region * add comment about name being a dual-region bucket name * set rpo in test, do not allow as argument * add clarifying comment about undefined value * update header copyright year to 2022 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 809bf11 commit 97edb9a

9 files changed

+399
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-storage/tre
115115
| Copy File | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/copyFile.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/copyFile.js,samples/README.md) |
116116
| Copy Old Version Of File. | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/copyOldVersionOfFile.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/copyOldVersionOfFile.js,samples/README.md) |
117117
| Create Bucket With Storage Class and Location. | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createBucketWithStorageClassAndLocation.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/createBucketWithStorageClassAndLocation.js,samples/README.md) |
118+
| Create Bucket With Turbo Replication | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createBucketWithTurboReplication.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/createBucketWithTurboReplication.js,samples/README.md) |
118119
| Create New Bucket | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createNewBucket.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/createNewBucket.js,samples/README.md) |
119120
| Create Notification | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createNotification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/createNotification.js,samples/README.md) |
120121
| Delete Bucket | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/deleteBucket.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/deleteBucket.js,samples/README.md) |
@@ -149,6 +150,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-storage/tre
149150
| Get Metadata | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getMetadata.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getMetadata.js,samples/README.md) |
150151
| Get Metadata Notifications | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getMetadataNotifications.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getMetadataNotifications.js,samples/README.md) |
151152
| Get Public Access Prevention | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getPublicAccessPrevention.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getPublicAccessPrevention.js,samples/README.md) |
153+
| Get RPO | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getRPO.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getRPO.js,samples/README.md) |
152154
| Get Requester Pays Status | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getRequesterPaysStatus.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getRequesterPaysStatus.js,samples/README.md) |
153155
| Get Retention Policy | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getRetentionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getRetentionPolicy.js,samples/README.md) |
154156
| Storage Get Service Account. | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getServiceAccount.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getServiceAccount.js,samples/README.md) |
@@ -190,6 +192,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-storage/tre
190192
| Set Event Based Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setEventBasedHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setEventBasedHold.js,samples/README.md) |
191193
| Set Public Access Prevention Enforced | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionEnforced.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionEnforced.js,samples/README.md) |
192194
| Set Public Access Prevention Inherited | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionInherited.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionInherited.js,samples/README.md) |
195+
| Set RPO Async Turbo | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRPOAsyncTurbo.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRPOAsyncTurbo.js,samples/README.md) |
196+
| Set RPO Default | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRPODefault.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRPODefault.js,samples/README.md) |
193197
| Set Retention Policy | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRetentionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRetentionPolicy.js,samples/README.md) |
194198
| Set Temporary Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setTemporaryHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setTemporaryHold.js,samples/README.md) |
195199
| Stream File Download | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/streamFileDownload.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/streamFileDownload.js,samples/README.md) |

samples/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ objects to users via direct download.
3434
* [Copy File](#copy-file)
3535
* [Copy Old Version Of File.](#copy-old-version-of-file.)
3636
* [Create Bucket With Storage Class and Location.](#create-bucket-with-storage-class-and-location.)
37+
* [Create Bucket With Turbo Replication](#create-bucket-with-turbo-replication)
3738
* [Create New Bucket](#create-new-bucket)
3839
* [Create Notification](#create-notification)
3940
* [Delete Bucket](#delete-bucket)
@@ -68,6 +69,7 @@ objects to users via direct download.
6869
* [Get Metadata](#get-metadata)
6970
* [Get Metadata Notifications](#get-metadata-notifications)
7071
* [Get Public Access Prevention](#get-public-access-prevention)
72+
* [Get RPO](#get-rpo)
7173
* [Get Requester Pays Status](#get-requester-pays-status)
7274
* [Get Retention Policy](#get-retention-policy)
7375
* [Storage Get Service Account.](#storage-get-service-account.)
@@ -109,6 +111,8 @@ objects to users via direct download.
109111
* [Set Event Based Hold](#set-event-based-hold)
110112
* [Set Public Access Prevention Enforced](#set-public-access-prevention-enforced)
111113
* [Set Public Access Prevention Inherited](#set-public-access-prevention-inherited)
114+
* [Set RPO Async Turbo](#set-rpo-async-turbo)
115+
* [Set RPO Default](#set-rpo-default)
112116
* [Set Retention Policy](#set-retention-policy)
113117
* [Set Temporary Hold](#set-temporary-hold)
114118
* [Stream File Download](#stream-file-download)
@@ -427,6 +431,23 @@ __Usage:__
427431

428432

429433

434+
### Create Bucket With Turbo Replication
435+
436+
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createBucketWithTurboReplication.js).
437+
438+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/createBucketWithTurboReplication.js,samples/README.md)
439+
440+
__Usage:__
441+
442+
443+
`node samples/createBucketWithTurboReplication.js`
444+
445+
446+
-----
447+
448+
449+
450+
430451
### Create New Bucket
431452

432453
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/createNewBucket.js).
@@ -1017,6 +1038,23 @@ __Usage:__
10171038

10181039

10191040

1041+
### Get RPO
1042+
1043+
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getRPO.js).
1044+
1045+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/getRPO.js,samples/README.md)
1046+
1047+
__Usage:__
1048+
1049+
1050+
`node samples/getRPO.js`
1051+
1052+
1053+
-----
1054+
1055+
1056+
1057+
10201058
### Get Requester Pays Status
10211059

10221060
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/getRequesterPaysStatus.js).
@@ -1738,6 +1776,40 @@ __Usage:__
17381776

17391777

17401778

1779+
### Set RPO Async Turbo
1780+
1781+
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRPOAsyncTurbo.js).
1782+
1783+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRPOAsyncTurbo.js,samples/README.md)
1784+
1785+
__Usage:__
1786+
1787+
1788+
`node samples/setRPOAsyncTurbo.js`
1789+
1790+
1791+
-----
1792+
1793+
1794+
1795+
1796+
### Set RPO Default
1797+
1798+
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRPODefault.js).
1799+
1800+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRPODefault.js,samples/README.md)
1801+
1802+
__Usage:__
1803+
1804+
1805+
`node samples/setRPODefault.js`
1806+
1807+
1808+
-----
1809+
1810+
1811+
1812+
17411813
### Set Retention Policy
17421814

17431815
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRetentionPolicy.js).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* This application demonstrates how to perform basic operations on buckets with
19+
* the Google Cloud Storage API.
20+
*
21+
* For more information, see the README.md under /storage and the documentation
22+
* at https://cloud.google.com/storage/docs.
23+
*/
24+
25+
function main(bucketName = 'my-bucket', location = 'NAM4') {
26+
// [START storage_create_bucket_turbo_replication]
27+
/**
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// The ID of your GCS bucket
31+
// const bucketName = 'your-unique-bucket-name';
32+
33+
// The name of a dual-region location
34+
// See this documentation for other valid locations:
35+
// https://cloud.google.com/storage/docs/locations#location-dr
36+
// const location = 'NAM4';
37+
38+
// Flag to enable turbo replication for this bucket
39+
const rpo = 'ASYNC_TURBO';
40+
41+
// Imports the Google Cloud client library
42+
const {Storage} = require('@google-cloud/storage');
43+
44+
// Creates a client
45+
// The bucket in the sample below will be created in the project associated with this client.
46+
// For more information, please see https://cloud.google.com/docs/authentication/production or https://googleapis.dev/nodejs/storage/latest/Storage.html
47+
const storage = new Storage();
48+
49+
async function createBucketWithTurboReplication() {
50+
// For default values see: https://cloud.google.com/storage/docs/locations and
51+
// https://cloud.google.com/storage/docs/storage-classes
52+
const [bucket] = await storage.createBucket(bucketName, {
53+
location,
54+
rpo,
55+
});
56+
57+
console.log(
58+
`${bucket.name} created with turbo replication ${rpo} class in ${location}.`
59+
);
60+
}
61+
62+
createBucketWithTurboReplication();
63+
// [END storage_create_bucket_turbo_replication]
64+
}
65+
process.on('unhandledRejection', err => {
66+
console.error(err.message);
67+
process.exitCode = 1;
68+
});
69+
main(...process.argv.slice(2));

samples/getMetadata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function main(bucketName = 'my-bucket', fileName = 'test.txt') {
6565
console.log(`StorageClass: ${metadata.storageClass}`);
6666
console.log(`TimeCreated: ${new Date(metadata.timeCreated)}`);
6767
console.log(`Last Metadata Update: ${new Date(metadata.updated)}`);
68+
console.log(`TurboReplication: ${metadata.rpo}`);
6869
console.log(
6970
`temporaryHold: ${metadata.temporaryHold ? 'enabled' : 'disabled'}`
7071
);

samples/getRPO.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* This application demonstrates how to perform basic operations on buckets with
17+
* the Google Cloud Storage API.
18+
*
19+
* For more information, see the README.md under /storage and the documentation
20+
* at https://cloud.google.com/storage/docs.
21+
*/
22+
23+
function main(bucketName = 'my-bucket') {
24+
// [START storage_get_rpo]
25+
/**
26+
* TODO(developer): Uncomment the following lines before running the sample.
27+
*/
28+
// The name of your GCS bucket in a dual-region
29+
// const bucketName = 'Name of a bucket, e.g. my-bucket';
30+
31+
// Imports the Google Cloud client library
32+
const {Storage} = require('@google-cloud/storage');
33+
34+
// Creates a client
35+
const storage = new Storage();
36+
37+
async function getRPO() {
38+
// Gets Bucket Metadata and prints RPO value (either 'default' or 'async_turbo').
39+
// If RPO is undefined, the bucket is a single region bucket
40+
const [metadata] = await storage.bucket(bucketName).getMetadata();
41+
console.log(`RPO is ${metadata.rpo} for ${bucketName}.`);
42+
}
43+
44+
getRPO();
45+
46+
// [END storage_get_rpo]
47+
}
48+
process.on('unhandledRejection', err => {
49+
console.error(err.message);
50+
process.exitCode = 1;
51+
});
52+
main(...process.argv.slice(2));

samples/setRPOAsyncTurbo.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* This application demonstrates how to perform basic operations on buckets with
17+
* the Google Cloud Storage API.
18+
*
19+
* For more information, see the README.md under /storage and the documentation
20+
* at https://cloud.google.com/storage/docs.
21+
*/
22+
23+
function main(bucketName = 'my-bucket') {
24+
// [START storage_set_rpo_async_turbo]
25+
/**
26+
* TODO(developer): Uncomment the following lines before running the sample.
27+
*/
28+
// The name of your GCS bucket in a dual-region
29+
// const bucketName = 'Name of a bucket, e.g. my-bucket';
30+
31+
// Imports the Google Cloud client library
32+
const {Storage} = require('@google-cloud/storage');
33+
34+
// Creates a client
35+
const storage = new Storage();
36+
37+
// Enable turbo replication for the bucket by setting rpo to ASYNC_TURBO.
38+
// The bucket must be a dual-region bucket.
39+
async function setRPOAsyncTurbo() {
40+
await storage.bucket(bucketName).setMetadata({
41+
rpo: 'ASYNC_TURBO',
42+
});
43+
44+
console.log(`Turbo replication enabled for ${bucketName}.`);
45+
}
46+
47+
setRPOAsyncTurbo();
48+
// [END storage_set_rpo_async_turbo]
49+
}
50+
51+
process.on('unhandledRejection', err => {
52+
console.error(err.message);
53+
process.exitCode = 1;
54+
});
55+
main(...process.argv.slice(2));

samples/setRPODefault.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* This application demonstrates how to perform basic operations on buckets with
17+
* the Google Cloud Storage API.
18+
*
19+
* For more information, see the README.md under /storage and the documentation
20+
* at https://cloud.google.com/storage/docs.
21+
*/
22+
23+
function main(bucketName = 'my-bucket') {
24+
// [START storage_set_rpo_default]
25+
/**
26+
* TODO(developer): Uncomment the following lines before running the sample.
27+
*/
28+
// The name of your GCS bucket in a dual-region
29+
// const bucketName = 'Name of a bucket, e.g. my-bucket';
30+
31+
// Imports the Google Cloud client library
32+
const {Storage} = require('@google-cloud/storage');
33+
34+
// Creates a client
35+
const storage = new Storage();
36+
37+
// Disable turbo replication for the bucket by setting RPO to default.
38+
// The bucket must be a dual-region bucket.
39+
async function setRPODefault() {
40+
await storage.bucket(bucketName).setMetadata({
41+
rpo: 'DEFAULT',
42+
});
43+
44+
console.log(`Turbo replication disabled for ${bucketName}.`);
45+
}
46+
47+
setRPODefault();
48+
// [END storage_set_rpo_default]
49+
}
50+
51+
process.on('unhandledRejection', err => {
52+
console.error(err.message);
53+
process.exitCode = 1;
54+
});
55+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)