diff --git a/src/main/java/com/aliyun/oss/OSS.java b/src/main/java/com/aliyun/oss/OSS.java index 11638447..80eebdef 100644 --- a/src/main/java/com/aliyun/oss/OSS.java +++ b/src/main/java/com/aliyun/oss/OSS.java @@ -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; } diff --git a/src/main/java/com/aliyun/oss/OSSClient.java b/src/main/java/com/aliyun/oss/OSSClient.java index a77a01d5..e197b803 100644 --- a/src/main/java/com/aliyun/oss/OSSClient.java +++ b/src/main/java/com/aliyun/oss/OSSClient.java @@ -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 { diff --git a/src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java b/src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java index ebb496ad..2e506e43 100644 --- a/src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java +++ b/src/main/java/com/aliyun/oss/common/utils/ExceptionFactory.java @@ -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) { @@ -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); diff --git a/src/main/java/com/aliyun/oss/common/utils/HttpHeaders.java b/src/main/java/com/aliyun/oss/common/utils/HttpHeaders.java index 7cfdfd70..b0b50649 100644 --- a/src/main/java/com/aliyun/oss/common/utils/HttpHeaders.java +++ b/src/main/java/com/aliyun/oss/common/utils/HttpHeaders.java @@ -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"; } diff --git a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java index 4cc0e266..7f762930 100644 --- a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java +++ b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java @@ -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 params = new HashMap(); + params.put(CLEAN_RESTORE_OBJECT, null); + + Map headers = new HashMap(); + 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); diff --git a/src/main/java/com/aliyun/oss/internal/RequestParameters.java b/src/main/java/com/aliyun/oss/internal/RequestParameters.java index 49f6548a..3d006751 100644 --- a/src/main/java/com/aliyun/oss/internal/RequestParameters.java +++ b/src/main/java/com/aliyun/oss/internal/RequestParameters.java @@ -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"; } diff --git a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java index 4892738c..a6e846cd 100644 --- a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java +++ b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java @@ -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); } @@ -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); } @@ -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); } diff --git a/src/main/java/com/aliyun/oss/internal/SignParameters.java b/src/main/java/com/aliyun/oss/internal/SignParameters.java index 2c141575..1598717c 100644 --- a/src/main/java/com/aliyun/oss/internal/SignParameters.java +++ b/src/main/java/com/aliyun/oss/internal/SignParameters.java @@ -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}); } diff --git a/src/main/java/com/aliyun/oss/model/InventoryOptionalFields.java b/src/main/java/com/aliyun/oss/model/InventoryOptionalFields.java index 10d919dc..6fa04ec7 100644 --- a/src/main/java/com/aliyun/oss/model/InventoryOptionalFields.java +++ b/src/main/java/com/aliyun/oss/model/InventoryOptionalFields.java @@ -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"; } diff --git a/src/main/java/com/aliyun/oss/model/OSSObjectSummary.java b/src/main/java/com/aliyun/oss/model/OSSObjectSummary.java index 6b777144..e5f85fe0 100644 --- a/src/main/java/com/aliyun/oss/model/OSSObjectSummary.java +++ b/src/main/java/com/aliyun/oss/model/OSSObjectSummary.java @@ -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. */ @@ -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; + } } diff --git a/src/main/java/com/aliyun/oss/model/OSSVersionSummary.java b/src/main/java/com/aliyun/oss/model/OSSVersionSummary.java index 7f09f899..28ff8fa6 100644 --- a/src/main/java/com/aliyun/oss/model/OSSVersionSummary.java +++ b/src/main/java/com/aliyun/oss/model/OSSVersionSummary.java @@ -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. @@ -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; + } } diff --git a/src/main/java/com/aliyun/oss/model/ObjectMetadata.java b/src/main/java/com/aliyun/oss/model/ObjectMetadata.java index 019181de..35bbe1ca 100644 --- a/src/main/java/com/aliyun/oss/model/ObjectMetadata.java +++ b/src/main/java/com/aliyun/oss/model/ObjectMetadata.java @@ -466,5 +466,30 @@ public void setObjectTagging(Map 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; + + } } diff --git a/src/samples/CleanRestoreSample.java b/src/samples/CleanRestoreSample.java new file mode 100644 index 00000000..fa6ec69c --- /dev/null +++ b/src/samples/CleanRestoreSample.java @@ -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(); + } + } +} diff --git a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java index 79a7834f..7c3fb4b0 100644 --- a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java +++ b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java @@ -6561,4 +6561,141 @@ public void testParseGetBucketStatWithDeepCold() { Assert.assertTrue(false); } } + + @Test + public void testParseListObjectsWithTransitionTime() throws Exception{ + InputStream instream = null; + String respBody; + + respBody = "" + + "\n" + + " oss-java-sdk-1667542813\n" + + " \n" + + " \n" + + " 100\n" + + " \n" + + " false\n" + + " \n" + + " object-with-special-restore\n" + + " 2022-11-04T05:23:18.000Z\n" + + " \"AB56B4D92B40713ACC5AF89985D4B786\"\n" + + " Normal\n" + + " 5\n" + + " Archive\n" + + " \n" + + " 1283641064516515\n" + + " 1283641064516515\n" + + " \n" + + " ongoing-request=\"true\"\n" + + " 2021-09-15T02:35:07.000Z\n" + + " \n" + + ""; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + ObjectListing result = null; + try { + result = ResponseParsers.parseListObjects(instream); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertTrue(false); + } + Assert.assertEquals("object-with-special-restore", result.getObjectSummaries().get(0).getKey()); + Assert.assertEquals("ongoing-request=\"true\"", result.getObjectSummaries().get(0).getRestoreInfo()); + Assert.assertEquals(DateUtil.parseIso8601Date("2021-09-15T02:35:07.000Z"), result.getObjectSummaries().get(0).getTransitionTime()); + } + + @Test + public void testParseListObjectsV2WithTransitionTime() throws Exception{ + InputStream instream = null; + String respBody; + + respBody = "" + + "\n" + + " oss-java-sdk-1667548362-list-v2\n" + + " \n" + + " 100\n" + + " \n" + + " false\n" + + " \n" + + " object-with-special-restore\n" + + " 2022-11-04T07:37:25.000Z\n" + + " \"AB56B4D92B40713ACC5AF89985D4B786\"\n" + + " Normal\n" + + " 5\n" + + " Archive\n" + + " ongoing-request=\"false\", expiry-date=\"Sat, 05 Nov 2022 07:38:08 GMT\"\n" + + " 2021-09-15T02:35:07.000Z\n" + + " \n" + + " 1\n" + + "\n"; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + ListObjectsV2Result result = null; + try { + result = ResponseParsers.parseListObjectsV2(instream); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertTrue(false); + } + Assert.assertEquals("object-with-special-restore", result.getObjectSummaries().get(0).getKey()); + Assert.assertEquals("ongoing-request=\"false\", expiry-date=\"Sat, 05 Nov 2022 07:38:08 GMT\"", result.getObjectSummaries().get(0).getRestoreInfo()); + Assert.assertEquals(DateUtil.parseIso8601Date("2021-09-15T02:35:07.000Z"), result.getObjectSummaries().get(0).getTransitionTime()); + } + + @Test + public void testParseListVersionsWithTransitionTime() throws Exception{ + InputStream instream = null; + String respBody; + + respBody = "" + + "\n" + + " oss-java-sdk-1667549556-list-versions\n" + + " \n" + + " \n" + + " \n" + + " 100\n" + + " \n" + + " false\n" + + " \n" + + " object-with-special-restore\n" + + " CAEQDxiBgID78pyGohgiIDFhNWM0ODYxMDcyNTQ0ODJiZDJjZDlmNjRhZmU5MWEy\n" + + " true\n" + + " 2022-11-04T07:32:45.000Z\n" + + " \"AB56B4D92B40713ACC5AF89985D4B786\"\n" + + " Normal\n" + + " 5\n" + + " Archive\n" + + " ongoing-request=\"true\"\n" + + " \n" + + " 1283641064516515\n" + + " 1283641064516515\n" + + " \n" + + " 2021-09-15T02:35:07.000Z\n" + + " \n" + + ""; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + VersionListing result = null; + try { + result = ResponseParsers.parseListVersions(instream); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertTrue(false); + } + Assert.assertEquals("object-with-special-restore", result.getVersionSummaries().get(0).getKey()); + Assert.assertEquals("ongoing-request=\"true\"", result.getVersionSummaries().get(0).getRestoreInfo()); + Assert.assertEquals(DateUtil.parseIso8601Date("2021-09-15T02:35:07.000Z"), result.getVersionSummaries().get(0).getTransitionTime()); + } } diff --git a/src/test/java/com/aliyun/oss/common/utils/ExceptionFactoryTest.java b/src/test/java/com/aliyun/oss/common/utils/ExceptionFactoryTest.java index b6707518..71851e27 100644 --- a/src/test/java/com/aliyun/oss/common/utils/ExceptionFactoryTest.java +++ b/src/test/java/com/aliyun/oss/common/utils/ExceptionFactoryTest.java @@ -74,4 +74,13 @@ public void testCreateNetworkException() { ose = ExceptionFactory.createOSSException(new OSSErrorResult()); assertNotNull(ose); } + + @Test + public void testCreateExceptionWithThrowable() { + OSSException ose = ExceptionFactory.createInvalidResponseException("request id", "rawResponseError", new ConnectTimeoutException()); + assertNotNull(ose); + assertEquals("request id", ose.getRequestId()); + assertEquals("rawResponseError", ose.getRawResponseError()); + assertNotNull(ose.getCause()); + } } diff --git a/src/test/java/com/aliyun/oss/integrationtests/BucketInventoryTest.java b/src/test/java/com/aliyun/oss/integrationtests/BucketInventoryTest.java index d8bc8022..a6a853c8 100644 --- a/src/test/java/com/aliyun/oss/integrationtests/BucketInventoryTest.java +++ b/src/test/java/com/aliyun/oss/integrationtests/BucketInventoryTest.java @@ -187,6 +187,75 @@ public void testBucketInventoryNormal() { } } + @Test + public void testBucketInventoryNormalWithTransitionTime() { + String inventoryId = "testid-transition-time"; + // fields + List fields = new ArrayList(); + fields.add(InventoryOptionalFields.Size); + fields.add(InventoryOptionalFields.LastModifiedDate); + fields.add(InventoryOptionalFields.ETag); + fields.add(InventoryOptionalFields.StorageClass); + fields.add(InventoryOptionalFields.IsMultipartUploaded); + fields.add(InventoryOptionalFields.EncryptionStatus); + fields.add(InventoryOptionalFields.TransitionTime); + + // schedule + InventorySchedule inventorySchedule = new InventorySchedule().withFrequency(InventoryFrequency.Weekly); + + // filter + InventoryFilter inventoryFilter = new InventoryFilter().withPrefix("testPrefix"); + + // destination + InventoryEncryption inventoryEncryption = new InventoryEncryption(); + inventoryEncryption.setServerSideOssEncryption(new InventoryServerSideEncryptionOSS()); + InventoryOSSBucketDestination ossBucketDestin = new InventoryOSSBucketDestination() + .withFormat(InventoryFormat.CSV) + .withPrefix("bucket-prefix") + .withAccountId(TestConfig.RAM_UID) + .withRoleArn(TestConfig.RAM_ROLE_ARN) + .withBucket(destinBucket) + .withEncryption(inventoryEncryption); + + InventoryDestination destination = new InventoryDestination().withOSSBucketDestination(ossBucketDestin); + + InventoryConfiguration inventoryConfiguration = new InventoryConfiguration() + .withInventoryId(inventoryId) + .withEnabled(false) + .withIncludedObjectVersions(InventoryIncludedObjectVersions.All) + .withOptionalFields(fields) + .withFilter(inventoryFilter) + .withSchedule(inventorySchedule) + .withDestination(destination); + + // put + try { + ossClient.setBucketInventoryConfiguration(bucketName, inventoryConfiguration); + } catch (ClientException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + // get and delete + try { + GetBucketInventoryConfigurationResult result = ossClient.getBucketInventoryConfiguration( + new GetBucketInventoryConfigurationRequest(bucketName, inventoryId)); + + InventoryConfiguration actualConfig = result.getInventoryConfiguration(); + Assert.assertEquals(inventoryId, actualConfig.getInventoryId()); + Assert.assertEquals(InventoryIncludedObjectVersions.All.toString(), actualConfig.getIncludedObjectVersions()); + Assert.assertEquals("testPrefix", actualConfig.getInventoryFilter().getPrefix()); + Assert.assertEquals(InventoryFrequency.Weekly.toString(), actualConfig.getSchedule().getFrequency()); + Assert.assertEquals(7, actualConfig.getOptionalFields().size()); + + } catch (ClientException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } finally { + ossClient.deleteBucketInventoryConfiguration(new DeleteBucketInventoryConfigurationRequest(bucketName, inventoryId)); + } + } + @Test public void testErrorInventoryEncryption() { try { diff --git a/src/test/java/com/aliyun/oss/integrationtests/CleanRestoredObjectTest.java b/src/test/java/com/aliyun/oss/integrationtests/CleanRestoredObjectTest.java new file mode 100644 index 00000000..01619dfa --- /dev/null +++ b/src/test/java/com/aliyun/oss/integrationtests/CleanRestoredObjectTest.java @@ -0,0 +1,68 @@ +package com.aliyun.oss.integrationtests; + +import com.aliyun.oss.OSSException; +import com.aliyun.oss.internal.OSSHeaders; +import com.aliyun.oss.model.*; +import junit.framework.Assert; +import org.junit.Test; +import java.io.ByteArrayInputStream; + +public class CleanRestoredObjectTest extends TestBase { + + @Test + public void testCleanRestoreException() { + String objectNameEXample1 = "testCleanRestore-1.txt"; + String objectNameEXample2 = "testCleanRestore-2.txt"; + + try { + GenericRequest genericRequest = new GenericRequest() + .withBucketName(bucketName) + .withKey(objectNameEXample1); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectNameEXample1, + new ByteArrayInputStream("ColdArchive file".getBytes())); + + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.ColdArchive.toString()); + putObjectRequest.setMetadata(metadata); + ossClient.putObject(putObjectRequest); + + metadata = ossClient.getObjectMetadata(bucketName, objectNameEXample1); + Assert.assertEquals(StorageClass.ColdArchive, metadata.getObjectStorageClass()); + + ossClient.cleanRestoredObject(genericRequest); + } catch (OSSException e1) { + Assert.assertEquals("ArchiveRestoreFileStale", e1.getErrorCode()); + } + + + try { + GenericRequest genericRequest = new GenericRequest() + .withBucketName(bucketName) + .withKey(objectNameEXample2); + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectNameEXample2, + new ByteArrayInputStream("ColdArchive file".getBytes())); + + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.ColdArchive.toString()); + putObjectRequest.setMetadata(metadata); + ossClient.putObject(putObjectRequest); + + metadata = ossClient.getObjectMetadata(bucketName, objectNameEXample2); + Assert.assertEquals(StorageClass.ColdArchive, metadata.getObjectStorageClass()); + + + RestoreJobParameters jobParameters = new RestoreJobParameters(RestoreTier.RESTORE_TIER_EXPEDITED); + RestoreConfiguration configuration = new RestoreConfiguration(1, jobParameters); + ossClient.restoreObject(bucketName, objectNameEXample2, configuration); + + Thread.sleep(1000); + + ossClient.cleanRestoredObject(genericRequest); + } catch (OSSException e1) { + Assert.assertEquals("ArchiveRestoreNotFinished", e1.getErrorCode()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/com/aliyun/oss/integrationtests/GetObjectMetadataTest.java b/src/test/java/com/aliyun/oss/integrationtests/GetObjectMetadataTest.java index f346ba39..3073eed5 100644 --- a/src/test/java/com/aliyun/oss/integrationtests/GetObjectMetadataTest.java +++ b/src/test/java/com/aliyun/oss/integrationtests/GetObjectMetadataTest.java @@ -23,12 +23,16 @@ import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSErrorCode; import com.aliyun.oss.OSSException; +import com.aliyun.oss.common.utils.DateUtil; import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.PutObjectRequest; +import com.aliyun.oss.model.StorageClass; import org.junit.Assert; import org.junit.Test; import java.io.ByteArrayInputStream; +import java.text.ParseException; +import java.util.Date; public class GetObjectMetadataTest extends TestBase { @@ -83,4 +87,18 @@ public void testGetObjectUnNormal() { client.shutdown(); } } + + @Test + public void testGetObjectMetaWithTransitionTime() throws ParseException { + ObjectMetadata objectMetadata = new ObjectMetadata(); + Date date = new Date(); + objectMetadata.setTransitionTime(date); + Date date2 = objectMetadata.getTransitionTime(); + Assert.assertEquals(date.toString(), date2.toString()); + + ObjectMetadata objectMetadata2 = new ObjectMetadata(); + String dateStr = "Wed, 13 Nov 2024 00:18:12 GMT"; + objectMetadata2.setHeader("x-oss-transition-time", "Wed, 13 Nov 2024 00:18:12 GMT"); + Assert.assertEquals(DateUtil.parseRfc822Date(dateStr).toString(), objectMetadata2.getTransitionTime().toString()); + } }