本文整理了Java中com.google.cloud.storage.Bucket.retentionPolicyIsLocked()
方法的一些代码示例,展示了Bucket.retentionPolicyIsLocked()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.retentionPolicyIsLocked()
方法的具体详情如下:
包路径:com.google.cloud.storage.Bucket
类名称:Bucket
方法名:retentionPolicyIsLocked
暂无
代码示例来源:origin: googleapis/google-cloud-java
/** Example of how to get a bucket's retention policy */
public Bucket getRetentionPolicy(String bucketName) throws StorageException {
// [START storage_get_retention_policy]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of a bucket, e.g. "my-bucket"
// String bucketName = "my-bucket";
Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.RETENTION_POLICY));
System.out.println("Retention Policy for " + bucketName);
System.out.println("Retention Period: " + bucket.getRetentionPeriod());
if (bucket.retentionPolicyIsLocked() != null && bucket.retentionPolicyIsLocked()) {
System.out.println("Retention Policy is locked");
}
if (bucket.getRetentionEffectiveTime() != null) {
System.out.println("Effective Time: " + new Date(bucket.getRetentionEffectiveTime()));
}
// [END storage_get_retention_policy]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of removing a retention policy on a bucket */
public Bucket removeRetentionPolicy(String bucketName)
throws StorageException, IllegalArgumentException {
// [START storage_remove_retention_policy]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of a bucket, e.g. "my-bucket"
// String bucketName = "my-bucket";
Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.RETENTION_POLICY));
if (bucket.retentionPolicyIsLocked() != null && bucket.retentionPolicyIsLocked()) {
throw new IllegalArgumentException(
"Unable to remove retention period as retention policy is locked.");
}
Bucket bucketWithoutRetentionPolicy =
bucket.toBuilder().setRetentionPeriod(null).build().update();
System.out.println("Retention period for " + bucketName + " has been removed");
// [END storage_remove_retention_policy]
return bucketWithoutRetentionPolicy;
}
代码示例来源:origin: googleapis/google-cloud-java
assertNull(remoteBucket.retentionPolicyIsLocked());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNotNull(remoteBucket.getMetageneration());
remoteBucket, Storage.BucketTargetOption.metagenerationMatch());
assertTrue(remoteBucket.retentionPolicyIsLocked());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
} finally {
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRetentionPolicyNoLock() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket remoteBucket =
storage.create(
BucketInfo.newBuilder(bucketName).setRetentionPeriod(RETENTION_PERIOD).build());
try {
assertEquals(RETENTION_PERIOD, remoteBucket.getRetentionPeriod());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNull(remoteBucket.retentionPolicyIsLocked());
remoteBucket =
storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.RETENTION_POLICY));
assertEquals(RETENTION_PERIOD, remoteBucket.getRetentionPeriod());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNull(remoteBucket.retentionPolicyIsLocked());
String blobName = "test-create-with-retention-policy-hold";
BlobInfo blobInfo = BlobInfo.newBuilder(bucketName, blobName).build();
Blob remoteBlob = storage.create(blobInfo);
assertNotNull(remoteBlob.getRetentionExpirationTime());
remoteBucket = remoteBucket.toBuilder().setRetentionPeriod(null).build().update();
assertNull(remoteBucket.getRetentionPeriod());
remoteBucket = remoteBucket.toBuilder().setRetentionPeriod(null).build().update();
assertNull(remoteBucket.getRetentionPeriod());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(RETENTION_EFFECTIVE_TIME, bucket.getRetentionEffectiveTime());
assertEquals(RETENTION_PERIOD, bucket.getRetentionPeriod());
assertEquals(RETENTION_POLICY_IS_LOCKED, bucket.retentionPolicyIsLocked());
assertEquals(storage.getOptions(), bucket.getStorage().getOptions());
内容来源于网络,如有侵权,请联系作者删除!