Skip to content

Commit 5bb135c

Browse files
liyanzhang505huiguangjun
authored andcommitted
1, Support object versions lifecycle.
2, Fix resumable download file checkpoint filename and tmp filename with versionid if it specified.
1 parent e6ac6b7 commit 5bb135c

File tree

11 files changed

+500
-92
lines changed

11 files changed

+500
-92
lines changed

src/main/java/com/aliyun/oss/OSSClient.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,32 +1242,32 @@ public void deleteBucketEncryption(GenericRequest genericRequest) throws OSSExce
12421242

12431243
@Override
12441244
public void setBucketPolicy(String bucketName, String policyText) throws OSSException, ClientException {
1245-
this.bucketOperation.setBucketPolicy(new SetBucketPolicyRequest(bucketName, policyText));
1245+
this.setBucketPolicy(new SetBucketPolicyRequest(bucketName, policyText));
12461246
}
12471247

12481248
@Override
12491249
public void setBucketPolicy(SetBucketPolicyRequest setBucketPolicyRequest) throws OSSException, ClientException {
1250-
this.bucketOperation.setBucketPolicy(setBucketPolicyRequest);
1250+
this.bucketOperation.setBucketPolicy(setBucketPolicyRequest);
12511251
}
12521252

12531253
@Override
12541254
public GetBucketPolicyResult getBucketPolicy(GenericRequest genericRequest) throws OSSException, ClientException {
1255-
return bucketOperation.getBucketPolicy(genericRequest);
1255+
return this.bucketOperation.getBucketPolicy(genericRequest);
12561256
}
12571257

12581258
@Override
12591259
public GetBucketPolicyResult getBucketPolicy(String bucketName) throws OSSException, ClientException {
1260-
return bucketOperation.getBucketPolicy(new GenericRequest(bucketName));
1260+
return this.getBucketPolicy(new GenericRequest(bucketName));
12611261
}
12621262

12631263
@Override
12641264
public void deleteBucketPolicy(GenericRequest genericRequest) throws OSSException, ClientException {
1265-
bucketOperation.deleteBucketPolicy(genericRequest);
1265+
this.bucketOperation.deleteBucketPolicy(genericRequest);
12661266
}
12671267

12681268
@Override
12691269
public void deleteBucketPolicy(String bucketName) throws OSSException, ClientException {
1270-
bucketOperation.deleteBucketPolicy(new GenericRequest(bucketName));
1270+
this.deleteBucketPolicy(new GenericRequest(bucketName));
12711271
}
12721272

12731273
@Override
@@ -1420,7 +1420,7 @@ public GenericResult processObject(ProcessObjectRequest processObjectRequest) th
14201420

14211421
@Override
14221422
public void setBucketRequestPayment(String bucketName, Payer payer) throws OSSException, ClientException {
1423-
this.bucketOperation.setBucketRequestPayment(new SetBucketRequestPaymentRequest(bucketName, payer));
1423+
this.setBucketRequestPayment(new SetBucketRequestPaymentRequest(bucketName, payer));
14241424
}
14251425

14261426
@Override
@@ -1430,7 +1430,7 @@ public void setBucketRequestPayment(SetBucketRequestPaymentRequest setBucketRequ
14301430

14311431
@Override
14321432
public GetBucketRequestPaymentResult getBucketRequestPayment(String bucketName) throws OSSException, ClientException {
1433-
return this.bucketOperation.getBucketRequestPayment(new GenericRequest(bucketName));
1433+
return this.getBucketRequestPayment(new GenericRequest(bucketName));
14341434
}
14351435

14361436
@Override
@@ -1440,7 +1440,7 @@ public GetBucketRequestPaymentResult getBucketRequestPayment(GenericRequest gene
14401440

14411441
@Override
14421442
public void setBucketQosInfo(String bucketName, BucketQosInfo bucketQosInfo) throws OSSException, ClientException {
1443-
this.bucketOperation.setBucketQosInfo(new SetBucketQosInfoRequest(bucketName, bucketQosInfo));
1443+
this.setBucketQosInfo(new SetBucketQosInfoRequest(bucketName, bucketQosInfo));
14441444
}
14451445

14461446
@Override
@@ -1450,7 +1450,7 @@ public void setBucketQosInfo(SetBucketQosInfoRequest setBucketQosInfoRequest) th
14501450

14511451
@Override
14521452
public BucketQosInfo getBucketQosInfo(String bucketName) throws OSSException, ClientException {
1453-
return this.bucketOperation.getBucketQosInfo(new GenericRequest(bucketName));
1453+
return this.getBucketQosInfo(new GenericRequest(bucketName));
14541454
}
14551455

14561456
@Override
@@ -1460,7 +1460,7 @@ public BucketQosInfo getBucketQosInfo(GenericRequest genericRequest) throws OSSE
14601460

14611461
@Override
14621462
public void deleteBucketQosInfo(String bucketName) throws OSSException, ClientException {
1463-
this.bucketOperation.deleteBucketQosInfo(new GenericRequest(bucketName));
1463+
this.deleteBucketQosInfo(new GenericRequest(bucketName));
14641464
}
14651465

14661466
@Override

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import com.aliyun.oss.model.LifecycleRule.AbortMultipartUpload;
4141
import com.aliyun.oss.model.LifecycleRule.RuleStatus;
4242
import com.aliyun.oss.model.LifecycleRule.StorageTransition;
43+
import com.aliyun.oss.model.LifecycleRule.NoncurrentVersionStorageTransition;
44+
import com.aliyun.oss.model.LifecycleRule.NoncurrentVersionExpiration;
4345
import com.aliyun.oss.model.SetBucketCORSRequest.CORSRule;
4446

4547
/**
@@ -401,6 +403,9 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) {
401403
String formatDate = DateUtil.formatIso8601Date(rule.getCreatedBeforeDate());
402404
xmlBody.append(
403405
"<Expiration><CreatedBeforeDate>" + formatDate + "</CreatedBeforeDate></Expiration>");
406+
} else if (rule.getExpiredDeleteMarker() != null) {
407+
xmlBody.append("<Expiration><ExpiredObjectDeleteMarker>" + rule.getExpiredDeleteMarker() +
408+
"</ExpiredObjectDeleteMarker></Expiration>");
404409
}
405410

406411
if (rule.hasAbortMultipartUpload()) {
@@ -429,6 +434,23 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) {
429434
}
430435
}
431436

437+
if (rule.hasNoncurrentVersionExpiration()) {
438+
NoncurrentVersionExpiration expiration = rule.getNoncurrentVersionExpiration();
439+
if (expiration.hasNoncurrentDays()) {
440+
xmlBody.append("<NoncurrentVersionExpiration><NoncurrentDays>" + expiration.getNoncurrentDays() +
441+
"</NoncurrentDays></NoncurrentVersionExpiration>");
442+
}
443+
}
444+
445+
if (rule.hasNoncurrentVersionStorageTransitions()) {
446+
for (NoncurrentVersionStorageTransition transition : rule.getNoncurrentVersionStorageTransitions()) {
447+
xmlBody.append("<NoncurrentVersionTransition>");
448+
xmlBody.append("<NoncurrentDays>" + transition.getNoncurrentDays() + "</NoncurrentDays>");
449+
xmlBody.append("<StorageClass>" + transition.getStorageClass() + "</StorageClass>");
450+
xmlBody.append("</NoncurrentVersionTransition>");
451+
}
452+
}
453+
432454
xmlBody.append("</Rule>");
433455
}
434456
xmlBody.append("</LifecycleConfiguration>");

src/main/java/com/aliyun/oss/internal/OSSDownloadOperation.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.concurrent.TimeUnit;
5050

5151
import com.aliyun.oss.InconsistentException;
52+
import com.aliyun.oss.common.utils.BinaryUtil;
5253
import com.aliyun.oss.common.utils.CRC64;
5354
import com.aliyun.oss.common.utils.IOUtils;
5455
import com.aliyun.oss.event.ProgressEventType;
@@ -111,13 +112,24 @@ public synchronized void update(int index, boolean completed) throws IOException
111112
/**
112113
* Check if the object matches the checkpoint information.
113114
*/
114-
public synchronized boolean isValid(OSSObjectOperation objectOperation) {
115+
public synchronized boolean isValid(OSSObjectOperation objectOperation, DownloadFileRequest downloadFileRequest) {
115116
// 比较checkpoint的magic和md5
116117
if (this.magic == null || !this.magic.equals(DOWNLOAD_MAGIC) || this.md5 != hashCode()) {
117118
return false;
118119
}
119120

120121
GenericRequest genericRequest = new GenericRequest(bucketName, objectKey);
122+
123+
Payer payer = downloadFileRequest.getRequestPayer();
124+
if (payer != null) {
125+
genericRequest.setRequestPayer(payer);
126+
}
127+
128+
String versionId = downloadFileRequest.getVersionId();
129+
if (versionId != null) {
130+
genericRequest.setVersionId(versionId);
131+
}
132+
121133
SimplifiedObjectMeta meta = objectOperation.getSimplifiedObjectMeta(genericRequest);
122134

123135
// Object's size, last modified time or ETAG are not same as the one
@@ -363,7 +375,13 @@ public DownloadFileResult downloadFile(DownloadFileRequest downloadFileRequest)
363375
// checkpoint file name.
364376
if (downloadFileRequest.isEnableCheckpoint()) {
365377
if (downloadFileRequest.getCheckpointFile() == null || downloadFileRequest.getCheckpointFile().isEmpty()) {
366-
downloadFileRequest.setCheckpointFile(downloadFileRequest.getDownloadFile() + ".dcp");
378+
String versionId = downloadFileRequest.getVersionId();
379+
if (versionId != null) {
380+
downloadFileRequest.setCheckpointFile(downloadFileRequest.getDownloadFile() + "."
381+
+ BinaryUtil.encodeMD5(versionId.getBytes()) + ".dcp");
382+
} else {
383+
downloadFileRequest.setCheckpointFile(downloadFileRequest.getDownloadFile() + ".dcp");
384+
}
367385
}
368386
}
369387

@@ -387,7 +405,7 @@ private DownloadFileResult downloadFileWithCheckpoint(DownloadFileRequest downlo
387405
}
388406

389407
// The download checkpoint is corrupted, download again.
390-
if (!downloadCheckPoint.isValid(objectOperation)) {
408+
if (!downloadCheckPoint.isValid(objectOperation, downloadFileRequest)) {
391409
prepare(downloadCheckPoint, downloadFileRequest);
392410
remove(downloadFileRequest.getCheckpointFile());
393411
}

src/main/java/com/aliyun/oss/internal/OSSUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class OSSUtils {
5252
public static final ResourceManager OSS_RESOURCE_MANAGER = ResourceManager.getInstance(RESOURCE_NAME_OSS);
5353
public static final ResourceManager COMMON_RESOURCE_MANAGER = ResourceManager.getInstance(RESOURCE_NAME_COMMON);
5454

55-
private static final String BUCKET_NAMING_REGEX = "^[a-z0-9][a-z0-9_\\-]{1,61}[a-z0-9]$";
55+
private static final String BUCKET_NAMING_REGEX = "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$";
5656

5757
/**
5858
* Validate bucket name.

src/main/java/com/aliyun/oss/internal/ResponseParsers.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
import com.aliyun.oss.model.VersionListing;
129129
import com.aliyun.oss.model.GetBucketPolicyResult;
130130
import com.aliyun.oss.model.GetBucketRequestPaymentResult;
131+
import com.aliyun.oss.model.LifecycleRule.NoncurrentVersionStorageTransition;
132+
import com.aliyun.oss.model.LifecycleRule.NoncurrentVersionExpiration;
131133

132134
/*
133135
* A collection of parsers that parse HTTP reponses into corresponding human-readable results.
@@ -2798,10 +2800,12 @@ public static List<LifecycleRule> parseGetBucketLifecycle(InputStream responseBo
27982800
rule.setExpirationTime(expirationDate);
27992801
} else if (ruleElem.getChild("Expiration").getChild("Days") != null) {
28002802
rule.setExpirationDays(Integer.parseInt(ruleElem.getChild("Expiration").getChildText("Days")));
2801-
} else {
2803+
} else if (ruleElem.getChild("Expiration").getChild("CreatedBeforeDate") != null) {
28022804
Date createdBeforeDate = DateUtil
28032805
.parseIso8601Date(ruleElem.getChild("Expiration").getChildText("CreatedBeforeDate"));
28042806
rule.setCreatedBeforeDate(createdBeforeDate);
2807+
} else if (ruleElem.getChild("Expiration").getChild("ExpiredObjectDeleteMarker") != null) {
2808+
rule.setExpiredDeleteMarker(Boolean.valueOf(ruleElem.getChild("Expiration").getChildText("ExpiredObjectDeleteMarker")));
28052809
}
28062810
}
28072811

@@ -2837,6 +2841,28 @@ public static List<LifecycleRule> parseGetBucketLifecycle(InputStream responseBo
28372841
}
28382842
rule.setStorageTransition(storageTransitions);
28392843

2844+
if (ruleElem.getChild("NoncurrentVersionExpiration") != null) {
2845+
NoncurrentVersionExpiration expiration = new NoncurrentVersionExpiration();
2846+
if (ruleElem.getChild("NoncurrentVersionExpiration").getChild("NoncurrentDays") != null) {
2847+
expiration.setNoncurrentDays(Integer.parseInt(ruleElem.getChild("NoncurrentVersionExpiration").getChildText("NoncurrentDays")));
2848+
rule.setNoncurrentVersionExpiration(expiration);
2849+
}
2850+
}
2851+
2852+
List<Element> versionTansitionElements = ruleElem.getChildren("NoncurrentVersionTransition");
2853+
List<NoncurrentVersionStorageTransition> noncurrentVersionTransitions = new ArrayList<NoncurrentVersionStorageTransition>();
2854+
for (Element transitionElem : versionTansitionElements) {
2855+
NoncurrentVersionStorageTransition transition = new NoncurrentVersionStorageTransition();
2856+
if (transitionElem.getChild("NoncurrentDays") != null) {
2857+
transition.setNoncurrentDays(Integer.parseInt(transitionElem.getChildText("NoncurrentDays")));
2858+
}
2859+
if (transitionElem.getChild("StorageClass") != null) {
2860+
transition.setStorageClass(StorageClass.parse(transitionElem.getChildText("StorageClass")));
2861+
}
2862+
noncurrentVersionTransitions.add(transition);
2863+
}
2864+
rule.setNoncurrentVersionStorageTransitions(noncurrentVersionTransitions);
2865+
28402866
lifecycleRules.add(rule);
28412867
}
28422868

src/main/java/com/aliyun/oss/model/DownloadFileRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.aliyun.oss.model;
2121

22+
import com.aliyun.oss.common.utils.BinaryUtil;
23+
2224
import java.util.ArrayList;
2325
import java.util.Date;
2426
import java.util.List;
@@ -75,7 +77,11 @@ public String getDownloadFile() {
7577
}
7678

7779
public String getTempDownloadFile() {
78-
return downloadFile + ".tmp";
80+
if (getVersionId() != null) {
81+
return downloadFile + "." + BinaryUtil.encodeMD5(getVersionId().getBytes()) + ".tmp";
82+
} else {
83+
return downloadFile + ".tmp";
84+
}
7985
}
8086

8187
public void setDownloadFile(String downloadFile) {

0 commit comments

Comments
 (0)