Skip to content

Commit 8f2471c

Browse files
authored
doc(storage): add custom-dual regions example (#8595)
1 parent 5308f1c commit 8f2471c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

google/cloud/storage/examples/storage_bucket_samples.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ void CreateBucketWithStorageClassLocation(
137137
(std::move(client), argv.at(0), argv.at(1), argv.at(2));
138138
}
139139

140+
void CreateBucketDualRegion(google::cloud::storage::Client client,
141+
std::vector<std::string> const& argv) {
142+
// [START storage_create_bucket_dual_region]
143+
namespace gcs = ::google::cloud::storage;
144+
using ::google::cloud::StatusOr;
145+
[](gcs::Client client, std::string const& bucket_name,
146+
std::string const& region_a, std::string const& region_b) {
147+
auto metadata = client.CreateBucket(
148+
bucket_name,
149+
gcs::BucketMetadata().set_location(region_a + '+' + region_b));
150+
if (!metadata) throw std::runtime_error(metadata.status().message());
151+
152+
std::cout << "Bucket " << metadata->name() << " created."
153+
<< "\nFull Metadata: " << *metadata << "\n";
154+
}
155+
// [END storage_create_bucket_dual_region]
156+
(std::move(client), argv.at(0), argv.at(1), argv.at(2));
157+
}
158+
140159
void GetBucketMetadata(google::cloud::storage::Client client,
141160
std::vector<std::string> const& argv) {
142161
//! [get bucket metadata]
@@ -596,6 +615,7 @@ void RunAll(std::vector<std::string> const& argv) {
596615
auto generator = google::cloud::internal::DefaultPRNG(std::random_device{}());
597616
auto const bucket_name = examples::MakeRandomBucketName(generator);
598617
auto const rpo_bucket_name = examples::MakeRandomBucketName(generator);
618+
auto const dual_bucket_name = examples::MakeRandomBucketName(generator);
599619
auto client = gcs::Client();
600620

601621
// This is the only example that cleans up stale buckets. The examples run in
@@ -690,6 +710,11 @@ void RunAll(std::vector<std::string> const& argv) {
690710
std::cout << "\nRunning DeleteBucket() example [2]" << std::endl;
691711
DeleteBucket(client, {bucket_name});
692712

713+
std::cout << "\nRunning CreateBucketDualRegion example" << std::endl;
714+
CreateBucketDualRegion(client, {dual_bucket_name, "us-east1", "us-central1"});
715+
716+
(void)client.DeleteBucket(dual_bucket_name);
717+
693718
std::cout << "\nRunning CreateBucketWithStorageClassLocation() example"
694719
<< std::endl;
695720
CreateBucketWithStorageClassLocation(client, {bucket_name, "STANDARD", "US"});
@@ -722,6 +747,8 @@ int main(int argc, char* argv[]) {
722747
make_entry("create-bucket-with-storage-class-location",
723748
{"<storage-class>", "<location>"},
724749
CreateBucketWithStorageClassLocation),
750+
make_entry("create-bucket-dual-region", {"<region-a>", "<region-b>"},
751+
CreateBucketDualRegion),
725752
make_entry("get-bucket-metadata", {}, GetBucketMetadata),
726753
make_entry("delete-bucket", {}, DeleteBucket),
727754
make_entry("change-default-storage-class", {"<new-class>"},

0 commit comments

Comments
 (0)