Skip to content
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

Dev 2107-lifecycle-overlap #373

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@
import static com.aliyun.oss.internal.ResponseParsers.getBucketTransferAccelerationResponseParser;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.HttpMethod;
Expand Down Expand Up @@ -855,6 +851,10 @@ public VoidResult setBucketLifecycle(SetBucketLifecycleRequest setBucketLifecycl
.setInputStreamWithLength(setBucketLifecycleRequestMarshaller.marshall(setBucketLifecycleRequest))
.setOriginalRequest(setBucketLifecycleRequest).build();

if(!setBucketLifecycleRequest.getHeaders().isEmpty()){
request.addHeader(OSSHeaders.OSS_HEADER_LIFECYCLE_OVERLAP, setBucketLifecycleRequest.getHeaders().get(OSSHeaders.OSS_HEADER_LIFECYCLE_OVERLAP));
}

return doOperation(request, requestIdResponseParser, bucketName, null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/aliyun/oss/internal/OSSHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ public interface OSSHeaders extends HttpHeaders {
static final String OSS_RENAME_SOURCE = "x-oss-rename-source";

static final String OSS_RESOURCE_GROUP_ID = "x-oss-resource-group-id";

static final String OSS_HEADER_LIFECYCLE_OVERLAP = "x-oss-allow-same-action-overlap";
}
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,59 @@ public void testUnormalDeleteBucketLifecycle() {
ossClient.deleteBucket(bucketWithoutLifecycleConfiguration);
}
}

@Test
public void testLifecycleOverlap() throws ParseException {
final String bucketName = super.bucketName + "normal-set-bucket-lifecycle";
final String ruleId1 = "overlap/";
final String matchPrefix1 = "Prefix";
final String ruleId2 = "overlap/a";
final String matchPrefix2 = "Prefix/SubPrefix";

try {
SetBucketLifecycleRequest request = new SetBucketLifecycleRequest(bucketName);
ossClient.createBucket(bucketName);


LifecycleRule rule = new LifecycleRule(ruleId1, matchPrefix1, RuleStatus.Enabled,
DateUtil.parseIso8601Date("2022-10-12T00:00:00.000Z"));
request.AddLifecycleRule(rule);

rule = new LifecycleRule(ruleId2, matchPrefix2, RuleStatus.Enabled,
DateUtil.parseIso8601Date("2022-10-12T00:00:00.000Z"));
request.AddLifecycleRule(rule);

try {
ossClient.setBucketLifecycle(request);
} catch (OSSException e){
Assert.assertEquals("Overlap for same action type Expiration",e.getErrorMessage());
}
request.addHeader("x-oss-allow-same-action-overlap", "true");
ossClient.setBucketLifecycle(request);

List<LifecycleRule> rules = ossClient.getBucketLifecycle(bucketName);
Assert.assertEquals(rules.size(), 2);

LifecycleRule r1 = rules.get(0);
Assert.assertEquals(r1.getId(), ruleId1);
Assert.assertEquals(r1.getPrefix(), matchPrefix1);
Assert.assertEquals(r1.getStatus(), RuleStatus.Enabled);
Assert.assertFalse(r1.hasCreatedBeforeDate());
Assert.assertEquals(DateUtil.formatIso8601Date(r1.getExpirationTime()),
"2022-10-12T00:00:00.000Z");

LifecycleRule r2 = rules.get(1);
Assert.assertEquals(r2.getId(), ruleId2);
Assert.assertEquals(r2.getPrefix(), matchPrefix2);
Assert.assertEquals(r2.getStatus(), RuleStatus.Enabled);
Assert.assertFalse(r2.hasCreatedBeforeDate());
Assert.assertEquals(DateUtil.formatIso8601Date(r2.getExpirationTime()),
"2022-10-12T00:00:00.000Z");

} catch (OSSException e) {
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
}