-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
809bf11
commit 97edb9a
Showing
9 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,69 @@ | ||
/** | ||
* Copyright 2022 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. | ||
*/ | ||
|
||
/** | ||
* This application demonstrates how to perform basic operations on buckets with | ||
* the Google Cloud Storage API. | ||
* | ||
* For more information, see the README.md under /storage and the documentation | ||
* at https://cloud.google.com/storage/docs. | ||
*/ | ||
|
||
function main(bucketName = 'my-bucket', location = 'NAM4') { | ||
// [START storage_create_bucket_turbo_replication] | ||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// The ID of your GCS bucket | ||
// const bucketName = 'your-unique-bucket-name'; | ||
|
||
// The name of a dual-region location | ||
// See this documentation for other valid locations: | ||
// https://cloud.google.com/storage/docs/locations#location-dr | ||
// const location = 'NAM4'; | ||
|
||
// Flag to enable turbo replication for this bucket | ||
const rpo = 'ASYNC_TURBO'; | ||
|
||
// Imports the Google Cloud client library | ||
const {Storage} = require('@google-cloud/storage'); | ||
|
||
// Creates a client | ||
// The bucket in the sample below will be created in the project associated with this client. | ||
// For more information, please see https://cloud.google.com/docs/authentication/production or https://googleapis.dev/nodejs/storage/latest/Storage.html | ||
const storage = new Storage(); | ||
|
||
async function createBucketWithTurboReplication() { | ||
// For default values see: https://cloud.google.com/storage/docs/locations and | ||
// https://cloud.google.com/storage/docs/storage-classes | ||
const [bucket] = await storage.createBucket(bucketName, { | ||
location, | ||
rpo, | ||
}); | ||
|
||
console.log( | ||
`${bucket.name} created with turbo replication ${rpo} class in ${location}.` | ||
); | ||
} | ||
|
||
createBucketWithTurboReplication(); | ||
// [END storage_create_bucket_turbo_replication] | ||
} | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains 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
This file contains 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,52 @@ | ||
// Copyright 2022 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. | ||
|
||
/** | ||
* This application demonstrates how to perform basic operations on buckets with | ||
* the Google Cloud Storage API. | ||
* | ||
* For more information, see the README.md under /storage and the documentation | ||
* at https://cloud.google.com/storage/docs. | ||
*/ | ||
|
||
function main(bucketName = 'my-bucket') { | ||
// [START storage_get_rpo] | ||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// The name of your GCS bucket in a dual-region | ||
// const bucketName = 'Name of a bucket, e.g. my-bucket'; | ||
|
||
// Imports the Google Cloud client library | ||
const {Storage} = require('@google-cloud/storage'); | ||
|
||
// Creates a client | ||
const storage = new Storage(); | ||
|
||
async function getRPO() { | ||
// Gets Bucket Metadata and prints RPO value (either 'default' or 'async_turbo'). | ||
// If RPO is undefined, the bucket is a single region bucket | ||
const [metadata] = await storage.bucket(bucketName).getMetadata(); | ||
console.log(`RPO is ${metadata.rpo} for ${bucketName}.`); | ||
} | ||
|
||
getRPO(); | ||
|
||
// [END storage_get_rpo] | ||
} | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains 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,55 @@ | ||
// Copyright 2022 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. | ||
|
||
/** | ||
* This application demonstrates how to perform basic operations on buckets with | ||
* the Google Cloud Storage API. | ||
* | ||
* For more information, see the README.md under /storage and the documentation | ||
* at https://cloud.google.com/storage/docs. | ||
*/ | ||
|
||
function main(bucketName = 'my-bucket') { | ||
// [START storage_set_rpo_async_turbo] | ||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// The name of your GCS bucket in a dual-region | ||
// const bucketName = 'Name of a bucket, e.g. my-bucket'; | ||
|
||
// Imports the Google Cloud client library | ||
const {Storage} = require('@google-cloud/storage'); | ||
|
||
// Creates a client | ||
const storage = new Storage(); | ||
|
||
// Enable turbo replication for the bucket by setting rpo to ASYNC_TURBO. | ||
// The bucket must be a dual-region bucket. | ||
async function setRPOAsyncTurbo() { | ||
await storage.bucket(bucketName).setMetadata({ | ||
rpo: 'ASYNC_TURBO', | ||
}); | ||
|
||
console.log(`Turbo replication enabled for ${bucketName}.`); | ||
} | ||
|
||
setRPOAsyncTurbo(); | ||
// [END storage_set_rpo_async_turbo] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains 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,55 @@ | ||
// Copyright 2022 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. | ||
|
||
/** | ||
* This application demonstrates how to perform basic operations on buckets with | ||
* the Google Cloud Storage API. | ||
* | ||
* For more information, see the README.md under /storage and the documentation | ||
* at https://cloud.google.com/storage/docs. | ||
*/ | ||
|
||
function main(bucketName = 'my-bucket') { | ||
// [START storage_set_rpo_default] | ||
/** | ||
* TODO(developer): Uncomment the following lines before running the sample. | ||
*/ | ||
// The name of your GCS bucket in a dual-region | ||
// const bucketName = 'Name of a bucket, e.g. my-bucket'; | ||
|
||
// Imports the Google Cloud client library | ||
const {Storage} = require('@google-cloud/storage'); | ||
|
||
// Creates a client | ||
const storage = new Storage(); | ||
|
||
// Disable turbo replication for the bucket by setting RPO to default. | ||
// The bucket must be a dual-region bucket. | ||
async function setRPODefault() { | ||
await storage.bucket(bucketName).setMetadata({ | ||
rpo: 'DEFAULT', | ||
}); | ||
|
||
console.log(`Turbo replication disabled for ${bucketName}.`); | ||
} | ||
|
||
setRPODefault(); | ||
// [END storage_set_rpo_default] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
Oops, something went wrong.