-
Notifications
You must be signed in to change notification settings - Fork 87
feat: integrate disable Lifecycle rule api for to remove lifecycle rule of bucket #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a73af3e
22351d8
2332a13
e1bc3ab
42c932c
f635369
bd15eed
32a716e
1e4b71c
affa5e1
08e5c39
5918c7e
398a771
d48d6b6
9e4d3fe
57045a3
dd3a276
f722f70
4d273fe
c3b1e81
6a9da63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ | |
| import com.google.cloud.storage.Storage.BlobField; | ||
| import com.google.cloud.storage.Storage.BlobWriteOption; | ||
| import com.google.cloud.storage.Storage.BucketField; | ||
| import com.google.cloud.storage.Storage.BucketGetOption; | ||
| import com.google.cloud.storage.StorageBatch; | ||
| import com.google.cloud.storage.StorageBatchResult; | ||
| import com.google.cloud.storage.StorageClass; | ||
|
|
@@ -3273,4 +3274,36 @@ public void testBlobReload() throws Exception { | |
| updated.delete(); | ||
| assertNull(updated.reload()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeleteLifecycleRules() throws ExecutionException, InterruptedException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following up, did you try deleting a single lifecycle rule?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to find the feasible way to delete a single lifecycle rule but its look like there is no possible way to do that and also found that across all the languages have same behavior which we have currently implemented. Suggestion
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @athakor, apologies for the delay. String lifecycleTestBucketName = RemoteStorageHelper.generateBucketName();
storage.create(
BucketInfo.newBuilder(lifecycleTestBucketName)
.setLocation("us")
.setLifecycleRules(
ImmutableList.of(
new LifecycleRule(
LifecycleAction.newSetStorageClassAction(StorageClass.COLDLINE),
LifecycleCondition.newBuilder()
.setAge(1)
.setNumberOfNewerVersions(3)
.setIsLive(false)
.setCreatedBefore(new DateTime(System.currentTimeMillis()))
.setMatchesStorageClass(ImmutableList.of(StorageClass.COLDLINE))
.build()),
new LifecycleRule(
LifecycleAction.newDeleteAction(),
LifecycleCondition.newBuilder()
.setAge(1)
.build()
)))
.build());
// Delete OLM rule.
Bucket remoteBucket =
storage.get(lifecycleTestBucketName, Storage.BucketGetOption.fields(BucketField.LIFECYCLE));
int priorSize = remoteBucket.getLifecycleRules().size();
ArrayList<LifecycleRule> lifecycleRules = new ArrayList(remoteBucket.getLifecycleRules());
Iterator<LifecycleRule> iterator = lifecycleRules.iterator();
while(iterator.hasNext()) {
LifecycleRule rule = iterator.next();
if (rule.getAction().getActionType().equals(LifecycleRule.DeleteLifecycleAction.TYPE)) {
iterator.remove();
}
}
remoteBucket.toBuilder().setLifecycleRules(lifecycleRules).build().update();
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this help? I think we can merge this change once you add a helper to Storage interface but no change is required for StorageRpc.java.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @frankyn thanks for this, I tried your sample code but its not working please check the below response. [
LifecycleRule{
lifecycleAction=DeleteLifecycleAction{
actionType=Delete
},
lifecycleCondition=LifecycleCondition{
age=1,
createBefore=null,
numberofNewerVersions=null,
isLive=null,
matchesStorageClass=null
}
},
LifecycleRule{
lifecycleAction=SetStorageClassLifecycleAction{
actionType=SetStorageClass,
storageClass=COLDLINE
},
lifecycleCondition=LifecycleCondition{
age=1,
createBefore=2020-05-15,
numberofNewerVersions=3,
isLive=false,
matchesStorageClass=[
COLDLINE
]
}
}
]does it works on your end? i think bucket lifecycle rule's not updated properly.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please let me know if there is still confusion with the workaround. In short, the library should not require the workaround.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @frankyn thanks for the clarification. It's works i will raise separate PR by adding these helper to Storage interface. Thank you for your help.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I appreciate your patience.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @athakor I might be confused, you're going to close this PR and make another right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, will close this once newly created PR gets Approved |
||
| String lifeCycleRuleBucket = RemoteStorageHelper.generateBucketName(); | ||
| List<LifecycleRule> lifecycleRules = | ||
| ImmutableList.of( | ||
| new LifecycleRule( | ||
| LifecycleAction.newDeleteAction(), | ||
| LifecycleCondition.newBuilder().setAge(2).setIsLive(Boolean.TRUE).build())); | ||
| try { | ||
| Bucket bucket = | ||
| storage.create( | ||
| BucketInfo.newBuilder(lifeCycleRuleBucket) | ||
| .setStorageClass(StorageClass.COLDLINE) | ||
| .setLocation("us-central1") | ||
| .setLifecycleRules(lifecycleRules) | ||
| .build()); | ||
| assertEquals(lifeCycleRuleBucket, bucket.getName()); | ||
| assertEquals(StorageClass.COLDLINE, bucket.getStorageClass()); | ||
| assertEquals(lifecycleRules, bucket.getLifecycleRules()); | ||
| assertNotNull(bucket.getLifecycleRules()); | ||
| boolean rulesDeleted = bucket.deleteLifecycleRules(); | ||
| assertTrue(rulesDeleted); | ||
| bucket = | ||
| storage.get(lifeCycleRuleBucket, BucketGetOption.fields(Storage.BucketField.values())); | ||
| assertNull(bucket.getLifecycleRules()); | ||
| } catch (StorageException ex) { | ||
| throw ex; | ||
| } finally { | ||
| RemoteStorageHelper.forceDelete(storage, lifeCycleRuleBucket, 5, TimeUnit.SECONDS); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.