Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add storage RPO samples (#7700)
* feat: add storage RPO samples * update dependnecy * format
- Loading branch information
1 parent
eb84e2e
commit 7f00aa8
Showing
6 changed files
with
147 additions
and
1 deletion.
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
40 changes: 40 additions & 0 deletions
40
...main/java/com/google/cloud/examples/storage/buckets/CreateBucketWithTurboReplication.java
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,40 @@ | ||
package com.google.cloud.examples.storage.buckets; | ||
|
||
// [START storage_create_bucket_turbo_replication] | ||
import com.google.cloud.storage.Bucket; | ||
import com.google.cloud.storage.BucketInfo; | ||
import com.google.cloud.storage.Rpo; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
public class CreateBucketWithTurboReplication { | ||
public static void createBucketWithTurboReplication( | ||
String projectId, String bucketName, String location) { | ||
// The ID of your GCP project | ||
// String projectId = "your-project-id"; | ||
|
||
// The ID to give your GCS bucket | ||
// String bucketName = "your-unique-bucket-name"; | ||
|
||
// The dual-region location to create your bucket in | ||
// String location = "NAM4" | ||
|
||
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
|
||
Bucket bucket = | ||
storage.create( | ||
BucketInfo.newBuilder(bucketName) | ||
.setLocation(location) | ||
.setRpo(Rpo.ASYNC_TURBO) | ||
.build()); | ||
|
||
System.out.println( | ||
"Created bucket " | ||
+ bucket.getName() | ||
+ " in " | ||
+ bucket.getLocation() | ||
+ " with RPO setting" | ||
+ bucket.getRpo()); | ||
} | ||
} | ||
// [END storage_create_bucket_turbo_replication] |
23 changes: 23 additions & 0 deletions
23
...-cloud-examples/src/main/java/com/google/cloud/examples/storage/buckets/GetBucketRpo.java
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,23 @@ | ||
package com.google.cloud.examples.storage.buckets; | ||
|
||
// [START storage_get_rpo] | ||
import com.google.cloud.storage.Bucket; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
public class GetBucketRpo { | ||
public static void getBucketRpo(String projectId, String bucketName) { | ||
// The ID of your GCP project | ||
// String projectId = "your-project-id"; | ||
|
||
// The ID of your GCS bucket | ||
// String bucketName = "your-unique-bucket-name"; | ||
|
||
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
Bucket bucket = storage.get(bucketName); | ||
String rpo = bucket.getRpo().toString(); | ||
|
||
System.out.println("The RPO setting of bucket " + bucketName + " is " + rpo); | ||
} | ||
} | ||
// [END storage_get_rpo] |
25 changes: 25 additions & 0 deletions
25
...ud-examples/src/main/java/com/google/cloud/examples/storage/buckets/SetAsyncTurboRpo.java
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,25 @@ | ||
package com.google.cloud.examples.storage.buckets; | ||
|
||
// [START storage_set_rpo_async_turbo] | ||
import com.google.cloud.storage.Bucket; | ||
import com.google.cloud.storage.Rpo; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
public class SetAsyncTurboRpo { | ||
public static void setAsyncTurboRpo(String projectId, String bucketName) { | ||
// The ID of your GCP project | ||
// String projectId = "your-project-id"; | ||
|
||
// The ID of your GCS bucket | ||
// String bucketName = "your-unique-bucket-name"; | ||
|
||
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
Bucket bucket = storage.get(bucketName); | ||
|
||
bucket.toBuilder().setRpo(Rpo.ASYNC_TURBO).build().update(); | ||
|
||
System.out.println("Turbo replication was enabled for " + bucketName); | ||
} | ||
} | ||
// [END storage_set_rpo_async_turbo] |
25 changes: 25 additions & 0 deletions
25
...cloud-examples/src/main/java/com/google/cloud/examples/storage/buckets/SetDefaultRpo.java
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,25 @@ | ||
package com.google.cloud.examples.storage.buckets; | ||
|
||
// [START storage_set_rpo_default] | ||
import com.google.cloud.storage.Bucket; | ||
import com.google.cloud.storage.Rpo; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
public class SetDefaultRpo { | ||
public static void setDefaultRpo(String projectId, String bucketName) { | ||
// The ID of your GCP project | ||
// String projectId = "your-project-id"; | ||
|
||
// The ID of your GCS bucket | ||
// String bucketName = "your-unique-bucket-name"; | ||
|
||
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
Bucket bucket = storage.get(bucketName); | ||
|
||
bucket.toBuilder().setRpo(Rpo.DEFAULT).build().update(); | ||
|
||
System.out.println("Replication was set to default for " + bucketName); | ||
} | ||
} | ||
// [END storage_set_rpo_default] |
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