FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: Refactor Custom Dual Region sample to work with API changes by sydney-munro · Pull Request #1516 · googleapis/java-storage · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
Expand Up @@ -20,35 +20,59 @@

import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.BucketInfo.CustomPlacementConfig;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import java.util.Arrays;

public class CreateBucketDualRegion {

public static void createBucketDualRegion(
String projectId, String bucketName, String firstRegion, String secondRegion) {
// The ID of your GCP project
String projectId,
String bucketName,
String location,
String firstRegion,
String secondRegion) {
// The ID of your GCP project.
// String projectId = "your-project-id";

// The ID to give your GCS bucket
// The ID to give your GCS bucket.
// String bucketName = "your-unique-bucket-name";

// The location your dual regions will be located in.
// String location = "US";

// One of the regions the dual region bucket is to be created in.
// String firstRegion = "US-EAST1";

// The second region the dual region bucket is to be created in.
// String secondRegion = "US-WEST1";

// Construct the dual region ie. "US-EAST1+US-WEST1"
String dualRegion = firstRegion + "+" + secondRegion;
// See this documentation for other valid locations and regions:
// https://cloud.google.com/storage/docs/locations

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();

Bucket bucket =
storage.create(BucketInfo.newBuilder(bucketName).setLocation(dualRegion).build());
CustomPlacementConfig config =
CustomPlacementConfig.newBuilder()
.setDataLocations(Arrays.asList(firstRegion, secondRegion))
.build();

BucketInfo bucketInfo =
BucketInfo.newBuilder(bucketName)
.setLocation(location)
.setCustomPlacementConfig(config)
.build();

Bucket bucket = storage.create(bucketInfo);

System.out.println(
"Created bucket " + bucket.getName() + " in location " + bucket.getLocation());
"Created bucket "
+ bucket.getName()
+ " in location "
+ bucket.getLocation()
+ " with regions "
+ bucket.getCustomPlacementConfig().getDataLocations().toString());
}
}
// [END storage_create_bucket_dual_region]
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
Expand Up @@ -31,7 +31,8 @@ public class CreateBucketDualRegionTest extends TestBase {
public void testCreateBucketDualRegion() {
assertNotNull("Unable to determine Project ID", PROJECT_ID);
String newBucket = RemoteStorageHelper.generateBucketName();
CreateBucketDualRegion.createBucketDualRegion(PROJECT_ID, newBucket, "US-EAST1", "US-WEST1");
CreateBucketDualRegion.createBucketDualRegion(
PROJECT_ID, newBucket, "US", "US-EAST1", "US-WEST1");
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("US-WEST1");
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("US-EAST1");
assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("Created bucket");
Expand Down

Back | FazBrowse Home | New Git URL