Skip to content

Dev 2411 #550

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

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
14 changes: 14 additions & 0 deletions src/main/java/com/aliyun/oss/OSS.java
Original file line number Diff line number Diff line change
Expand Up @@ -5659,4 +5659,18 @@ public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdf
*/
public ListAccessPointsResult listBucketAccessPoints(ListBucketAccessPointsRequest listBucketAccessPointsRequest) throws OSSException, ClientException;

/**
* Cold archiving, deep cold archiving supports users to actively call cleanRestore to clean up replicas in advance
* @param genericRequest
* A {@link GenericRequest} instance.
* @return A {@link VoidResult} instance wrapped void return and
* contains some basic response options, such as requestId.
*
* @throws OSSException
* If any errors are encountered in the client while making the
* request or handling the response.
* @throws ClientException
* If any errors occurred in OSS while processing the request.
*/
public VoidResult cleanRestoredObject(GenericRequest genericRequest) throws OSSException, ClientException;
}
5 changes: 5 additions & 0 deletions src/main/java/com/aliyun/oss/OSSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,11 @@ public ListAccessPointsResult listBucketAccessPoints(ListBucketAccessPointsReque
return bucketOperation.listBucketAccessPoints(listBucketAccessPointsRequest);
}

@Override
public VoidResult cleanRestoredObject(GenericRequest genericRequest) throws OSSException, ClientException {
return objectOperation.cleanRestoredObject(genericRequest);
}

@Override
public void shutdown() {
try {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ public static OSSException createInvalidResponseException(String requestId, Thro
COMMON_RESOURCE_MANAGER.getFormattedString("FailedToParseResponse", cause.getMessage()));
}

public static OSSException createInvalidResponseException(String requestId, String rawResponseError,
Throwable cause) {
return createInvalidResponseException(requestId,
COMMON_RESOURCE_MANAGER.getFormattedString("FailedToParseResponse", cause.getMessage()),
rawResponseError);
public static OSSException createInvalidResponseException(String requestId, String rawResponseError, Throwable cause) {
return createOSSException(requestId, OSSErrorCode.INVALID_RESPONSE, COMMON_RESOURCE_MANAGER.getFormattedString("FailedToParseResponse", cause.getMessage()), rawResponseError, cause, null);
}

public static OSSException createInvalidResponseException(String requestId, String message) {
Expand Down Expand Up @@ -113,6 +110,10 @@ public static OSSException createOSSException(String requestId, String errorCode
return new OSSException(message, errorCode, requestId, null, null, null, null, rawResponseError);
}

public static OSSException createOSSException(String requestId, String errorCode, String message, String rawResponseError, Throwable cause, String ec) {
return new OSSException(message, errorCode, requestId, null, null, null, null, rawResponseError, cause, ec);
}

public static OSSException createUnknownOSSException(String requestId, int statusCode) {
String message = "No body in response, http status code " + Integer.toString(statusCode);
return new OSSException(message, ClientErrorCode.UNKNOWN, requestId, null, null, null, null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/aliyun/oss/common/utils/HttpHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ public interface HttpHeaders {
public static final String RANGE = "Range";
public static final String LOCATION = "Location";
public static final String CONNECTION = "Connection";

public static final String TRANSITION_TIME = "x-oss-transition-time";
}
23 changes: 23 additions & 0 deletions src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,29 @@ public URL generatePresignedUrl(GeneratePresignedUrlRequest request) throws Clie
}
}

public VoidResult cleanRestoredObject(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
String key = genericRequest.getKey();

assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(key);

Map<String, String> params = new HashMap<String, String>();
params.put(CLEAN_RESTORE_OBJECT, null);

Map<String, String> headers = new HashMap<String, String>();
populateRequestPayerHeader(headers, genericRequest.getRequestPayer());

RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(genericRequest))
.setMethod(HttpMethod.POST).setBucket(bucketName).setKey(key).setParameters(params).setHeaders(headers)
.setInputStream(new ByteArrayInputStream(new byte[0])).setInputSize(0)
.setOriginalRequest(genericRequest).build();

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

public String calculatePostSignature(String postPolicy, Date date) throws ClientException {
try {
byte[] binaryData = postPolicy.getBytes(DEFAULT_CHARSET_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ public final class RequestParameters {
public static final String X_OSS_REDUNDANCY_TRANSITION_TASK_ID = "x-oss-redundancy-transition-taskid";
public static final String SUBRESOURCE_ACCESS_POINT = "accessPoint";
public static final String SUBRESOURCE_ACCESS_POINT_POLICY = "accessPointPolicy";
public static final String CLEAN_RESTORE_OBJECT = "cleanRestoredObject";
}
11 changes: 9 additions & 2 deletions src/main/java/com/aliyun/oss/internal/ResponseParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,9 @@ public static ObjectListing parseListObjects(InputStream responseBody) throws Re
String id = elem.getChild("Owner").getChildText("ID");
String displayName = elem.getChild("Owner").getChildText("DisplayName");
ossObjectSummary.setOwner(new Owner(id, displayName));

if (elem.getChild("TransitionTime") != null) {
ossObjectSummary.setTransitionTime(DateUtil.parseIso8601Date(elem.getChildText("TransitionTime")));
}
objectListing.addObjectSummary(ossObjectSummary);
}

Expand Down Expand Up @@ -1402,7 +1404,9 @@ public static ListObjectsV2Result parseListObjectsV2(InputStream responseBody) t
String displayName = elem.getChild("Owner").getChildText("DisplayName");
ossObjectSummary.setOwner(new Owner(id, displayName));
}

if (elem.getChild("TransitionTime") != null) {
ossObjectSummary.setTransitionTime(DateUtil.parseIso8601Date(elem.getChildText("TransitionTime")));
}
result.addObjectSummary(ossObjectSummary);
}

Expand Down Expand Up @@ -1499,6 +1503,9 @@ public static VersionListing parseListVersions(InputStream responseBody) throws
String displayName = elem.getChild("Owner").getChildText("DisplayName");
ossVersionSummary.setOwner(new Owner(id, displayName));

if (elem.getChild("TransitionTime") != null) {
ossVersionSummary.setTransitionTime(DateUtil.parseIso8601Date(elem.getChildText("TransitionTime")));
}
versionListing.getVersionSummaries().add(ossVersionSummary);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/aliyun/oss/internal/SignParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public class SignParameters {
X_OSS_AC_SOURCE_IP, X_OSS_AC_SUBNET_MASK, X_OSS_AC_VPC_ID, X_OSS_AC_FORWARD_ALLOW, META_QUERY, SUBRESOURCE_RESOURCE_GROUP,
SUBRESOURCE_REGION_LIST, X_OSS_ASYNC_PROCESS, WRITE_GET_OBJECT_RESPONSE, ARCHIVE_DIRECT_READ, HTTPS_CONFIG,
PUBLIC_ACCESS_BLOCK, POLICY_STATUS, REDUNDANCY_TRANSITION, X_OSS_TARGET_REDUNDANCY_TYPE, X_OSS_REDUNDANCY_TRANSITION_TASK_ID,
SUBRESOURCE_ACCESS_POINT, SUBRESOURCE_ACCESS_POINT_POLICY});
SUBRESOURCE_ACCESS_POINT, SUBRESOURCE_ACCESS_POINT_POLICY, CLEAN_RESTORE_OBJECT});

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface InventoryOptionalFields {
public static final String IsMultipartUploaded = "IsMultipartUploaded";

public static final String EncryptionStatus = "EncryptionStatus";

public static final String TransitionTime = "TransitionTime";
}
22 changes: 22 additions & 0 deletions src/main/java/com/aliyun/oss/model/OSSObjectSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class OSSObjectSummary {
/** The restore info status of the object */
private String restoreInfo;

/** The transition time of the object */
private Date transitionTime;

/**
* Constructor.
*/
Expand Down Expand Up @@ -224,4 +227,23 @@ public String getRestoreInfo() {
public void setRestoreInfo(String restoreInfo) {
this.restoreInfo = restoreInfo;
}

/**
* Gets the transition time.
*
* @return Object transition time.
*/
public Date getTransitionTime() {
return transitionTime;
}

/**
* Sets the transition time of the object.
*
* @param transitionTime
* object transition time
*/
public void setTransitionTime(Date transitionTime) {
this.transitionTime = transitionTime;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/aliyun/oss/model/OSSVersionSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class OSSVersionSummary implements Serializable {
/** The restore info status of the object */
private String restoreInfo;

/** The transition time of the object */
private Date transitionTime;

/**
* Gets the name of the OSS bucket in which this version is stored.
Expand Down Expand Up @@ -357,4 +359,23 @@ public String getRestoreInfo() {
public void setRestoreInfo(String restoreInfo) {
this.restoreInfo = restoreInfo;
}

/**
* Gets the transition time.
*
* @return Object transition time.
*/
public Date getTransitionTime() {
return transitionTime;
}

/**
* Sets the transition time of the object.
*
* @param transitionTime
* object transition time
*/
public void setTransitionTime(Date transitionTime) {
this.transitionTime = transitionTime;
}
}
27 changes: 26 additions & 1 deletion src/main/java/com/aliyun/oss/model/ObjectMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,30 @@ public void setObjectTagging(Map<String, String> tags) {
metadata.put(OSSHeaders.OSS_TAGGING, builder.toString());
}
}


/**
* Sets the x-oss-transition-time header.
*
* @param transitionTime
* transition time.
*/
public void setTransitionTime(Date transitionTime) {
metadata.put(OSSHeaders.TRANSITION_TIME, DateUtil.formatRfc822Date(transitionTime));
}

/**
* Gets the value of x-oss-transition-time header, which means the transition
* time of the object.
*
* @return Object's transition time.
*/
public Date getTransitionTime() throws ParseException {
String transitionTime = (String) metadata.get(OSSHeaders.TRANSITION_TIME);

if (transitionTime != null)
return DateUtil.parseRfc822Date((String) metadata.get(OSSHeaders.TRANSITION_TIME));

return null;

}
}
43 changes: 43 additions & 0 deletions src/samples/CleanRestoreSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package samples;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.GenericRequest;

public class CleanRestoreSample {

private static String endpoint = "*** Provide OSS endpoint ***";
private static String accessKeyId = "*** Provide your AccessKeyId ***";
private static String accessKeySecret = "*** Provide your AccessKeySecret ***";
private static String bucketName = "*** Provide bucket name ***";
private static String objectName = "*** Provide object name ***";

public static void main(String[] args) {
// Create an OSSClient instance.
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

try {
GenericRequest genericRequest = new GenericRequest()
.withBucketName(bucketName)
.withKey(objectName);

// clean restore.
ossClient.cleanRestore(genericRequest);

} catch (OSSException oe) {
System.out.println("Error Message: " + oe.getErrorMessage());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
/*
* Do not forget to shut down the client finally to release all allocated resources.
*/
ossClient.shutdown();
}
}
}
Loading