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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ static LifecycleRule fromPb(Rule rule) {
LifecycleAction.newSetStorageClassAction(
StorageClass.valueOf(action.getStorageClass()));
break;
case AbortIncompleteMPUAction.TYPE:
lifecycleAction = LifecycleAction.newAbortIncompleteMPUploadAction();
break;
default:
log.warning(
"The lifecycle action "
Expand Down Expand Up @@ -845,6 +848,15 @@ public static SetStorageClassLifecycleAction newSetStorageClassAction(
return new SetStorageClassLifecycleAction(storageClass);
}

/**
* Create a new {@code AbortIncompleteMPUAction}. An incomplete multipart upload will be
* aborted when the multipart upload meets the specified condition. Age is the only condition
* supported for this action. See: https://cloud.google.com/storage/docs/lifecycle##abort-mpu
*/
public static LifecycleAction newAbortIncompleteMPUploadAction() {
return new AbortIncompleteMPUAction();
}

/**
* Creates a new {@code LifecycleAction , with no specific supported action associated with it. This
* is only intended as a "backup" for when the library doesn't recognize the type, and should
Expand Down Expand Up @@ -888,6 +900,15 @@ public StorageClass getStorageClass() {
return storageClass;
}
}

public static class AbortIncompleteMPUAction extends LifecycleAction {
public static final String TYPE = "AbortIncompleteMultipartUpload";
private static final long serialVersionUID = -1072182310389348060L;

private AbortIncompleteMPUAction() {
super(TYPE);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
import com.google.cloud.storage.BucketInfo.IamConfiguration;
import com.google.cloud.storage.BucketInfo.IsLiveDeleteRule;
import com.google.cloud.storage.BucketInfo.LifecycleRule;
import com.google.cloud.storage.BucketInfo.LifecycleRule.AbortIncompleteMPUAction;
import com.google.cloud.storage.BucketInfo.LifecycleRule.DeleteLifecycleAction;
import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction;
import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition;
import com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction;
import com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule;
import com.google.cloud.storage.BucketInfo.PublicAccessPrevention;
import com.google.cloud.storage.BucketInfo.RawDeleteRule;
Expand Down Expand Up @@ -331,6 +334,8 @@ public void testLifecycleRules() {
assertEquals(
LifecycleRule.DeleteLifecycleAction.TYPE, deleteLifecycleRule.getAction().getType());
assertEquals(10, deleteLifecycleRule.getCondition().getAge().intValue());
assertTrue(
LifecycleRule.fromPb(deleteLifecycleRule).getAction() instanceof DeleteLifecycleAction);

Rule setStorageClassLifecycleRule =
new LifecycleRule(
Expand All @@ -346,6 +351,9 @@ public void testLifecycleRules() {
setStorageClassLifecycleRule.getAction().getStorageClass());
assertTrue(setStorageClassLifecycleRule.getCondition().getIsLive());
assertEquals(10, setStorageClassLifecycleRule.getCondition().getNumNewerVersions().intValue());
assertTrue(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added these in since I didn't see us testing all the cases of the fromPb switch statement.

LifecycleRule.fromPb(setStorageClassLifecycleRule).getAction()
instanceof SetStorageClassLifecycleAction);

Rule lifecycleRule =
new LifecycleRule(
Expand All @@ -367,6 +375,19 @@ public void testLifecycleRules() {
assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
assertEquals(30, lifecycleRule.getCondition().getDaysSinceCustomTime().intValue());
assertNotNull(lifecycleRule.getCondition().getCustomTimeBefore());
assertTrue(
LifecycleRule.fromPb(lifecycleRule).getAction() instanceof SetStorageClassLifecycleAction);

Rule abortMpuLifecycleRule =
new LifecycleRule(
LifecycleAction.newAbortIncompleteMPUploadAction(),
LifecycleCondition.newBuilder().setAge(10).build())
.toPb();
assertEquals(AbortIncompleteMPUAction.TYPE, abortMpuLifecycleRule.getAction().getType());
assertEquals(10, abortMpuLifecycleRule.getCondition().getAge().intValue());
assertTrue(
LifecycleRule.fromPb(abortMpuLifecycleRule).getAction()
instanceof AbortIncompleteMPUAction);

Rule unsupportedRule =
new LifecycleRule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.BucketInfo.LifecycleRule;
import com.google.cloud.storage.BucketInfo.LifecycleRule.AbortIncompleteMPUAction;
import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction;
import com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition;
import com.google.cloud.storage.CopyWriter;
Expand Down Expand Up @@ -547,6 +548,29 @@ public void testGetBucketLifecycleRules() {
}
}

@Test
public void testGetBucketAbortMPULifecycle() {
String lifecycleTestBucketName = RemoteStorageHelper.generateBucketName();
storage.create(
BucketInfo.newBuilder(lifecycleTestBucketName)
.setLocation("us")
.setLifecycleRules(
ImmutableList.of(
new LifecycleRule(
LifecycleAction.newAbortIncompleteMPUploadAction(),
LifecycleCondition.newBuilder().setAge(1).build())))
.build());
Bucket remoteBucket =
storage.get(lifecycleTestBucketName, Storage.BucketGetOption.fields(BucketField.LIFECYCLE));
LifecycleRule lifecycleRule = remoteBucket.getLifecycleRules().get(0);
try {
assertEquals(AbortIncompleteMPUAction.TYPE, lifecycleRule.getAction().getActionType());
assertEquals(1, lifecycleRule.getCondition().getAge().intValue());
} finally {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah interesting; didn't think of wrapping asserts with a try {} so you can do clean up afterwards, clever.

storage.delete(lifecycleTestBucketName);
}
}

@Test
public void testClearBucketDefaultKmsKeyName() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Expand Down