Skip to content

Commit

Permalink
feat: restore support DeepColdArchive type (#1337)
Browse files Browse the repository at this point in the history
* feat: restore support DeepColdArchive type

* feat: restore support DeepColdArchive type

* feat: restore support DeepColdArchive type

* feat: restore support DeepColdArchive type

---------

Co-authored-by: 孟凡荣 <[email protected]>
  • Loading branch information
mzy-1120 and 孟凡荣 authored Nov 21, 2024
1 parent 986b743 commit ac500d3
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 11 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,33 @@ const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2
console.log(result.status);
```
- JobParameters for unfreezing Specifies the JobParameters for unfreezing
```js
const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2, JobParameters: 'Standard' });
console.log(result.status);
```
- Restore an object with DeepColdArchive type
```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive' });
console.log(result.status);
```
- Days for unfreezing Specifies the days for unfreezing
```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2 });
console.log(result.status);
```
- JobParameters for unfreezing Specifies the JobParameters for unfreezing
```js
const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2, JobParameters: 'Standard' });
console.log(result.status);
```
- Restore an history object
```js
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ proto.restore = async function restore(name, options = { type: 'Archive' }) {
options.subres.versionId = options.versionId;
}
const params = this._objectRequestParams('POST', name, options);
if (options.type === 'ColdArchive') {
if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') {
const paramsXMLObj = {
RestoreRequest: {
Days: options.Days ? options.Days : 2,
Expand Down
2 changes: 1 addition & 1 deletion lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ proto.restore = async function restore(name, options = { type: 'Archive' }) {
options.subres.versionId = options.versionId;
}
const params = this._objectRequestParams('POST', name, options);
if (options.type === 'ColdArchive') {
if (options.type === 'ColdArchive' || options.type === 'DeepColdArchive') {
const paramsXMLObj = {
RestoreRequest: {
Days: options.Days ? options.Days : 2,
Expand Down
63 changes: 62 additions & 1 deletion test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ describe('browser', () => {
});

it('ColdArchive choice Days', async () => {
const name = '/oss/daysRestore.js';
const name = '/oss/daysColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'ColdArchive'
Expand All @@ -2707,6 +2707,22 @@ describe('browser', () => {
assert.equal(result.res.status, 202);
});

it('ColdArchive choice JobParameters', async () => {
const name = '/oss/JobParametersColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'ColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'ColdArchive',
Days: 2,
JobParameters: 'Standard'
});
assert.equal(result.res.status, 202);
});

it('ColdArchive is Accepted', async () => {
const name = '/oss/coldRestore.js';
const options = {
Expand All @@ -2720,6 +2736,51 @@ describe('browser', () => {
});
assert.equal(result.res.status, 202);
});

it('DeepColdArchive choice Days', async () => {
const name = '/oss/daysDeepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'DeepColdArchive',
Days: 2
});
assert.equal(result.res.status, 202);
});

it('DeepColdArchive choice JobParameters', async () => {
const name = '/oss/JobParametersDeepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'DeepColdArchive',
Days: 2,
JobParameters: 'Standard'
});
assert.equal(result.res.status, 202);
});

it('DeepColdArchive is Accepted', async () => {
const name = '/oss/deepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from(__filename), options);
const result = await store.restore(name, {
type: 'DeepColdArchive'
});
assert.equal(result.res.status, 202);
});
});

describe('multipartCopy()', () => {
Expand Down
11 changes: 5 additions & 6 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('test/bucket.test.js', () => {
const { prefix, includesConf } = utils;
let store;
let bucket;
const bucketRegion = 'oss-ap-southeast-1'; // oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive
const { accountId } = config;
[
{
Expand All @@ -25,7 +24,7 @@ describe('test/bucket.test.js', () => {
].forEach((moreConfigs, idx) => {
describe(`test bucket in iterate ${idx}`, () => {
before(async () => {
store = oss({ ...config, ...moreConfigs, region: bucketRegion });
store = oss({ ...config, ...moreConfigs });
bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}${idx}`;

const result = await store.putBucket(bucket, { timeout });
Expand Down Expand Up @@ -134,9 +133,9 @@ describe('test/bucket.test.js', () => {
const result = await store.getBucketInfo(bucket);
assert.equal(result.res.status, 200);

assert.equal(result.bucket.Location, `${bucketRegion}`);
assert.equal(result.bucket.ExtranetEndpoint, `${bucketRegion}.aliyuncs.com`);
assert.equal(result.bucket.IntranetEndpoint, `${bucketRegion}-internal.aliyuncs.com`);
assert.equal(result.bucket.Location, `${config.region}`);
assert.equal(result.bucket.ExtranetEndpoint, `${config.region}.aliyuncs.com`);
assert.equal(result.bucket.IntranetEndpoint, `${config.region}-internal.aliyuncs.com`);
assert.equal(result.bucket.AccessControlList.Grant, 'private');
assert.equal(result.bucket.StorageClass, 'Standard');
});
Expand All @@ -151,7 +150,7 @@ describe('test/bucket.test.js', () => {
describe('getBucketLoaction', () => {
it('it should return loaction this.region', async () => {
const result = await store.getBucketLocation(bucket);
assert.equal(result.location, bucketRegion);
assert.equal(result.location, config.region);
});

it('it should return NoSuchBucketError when bucket not exist', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('test/multiversion.test.js', () => {
describe(`test multiversion in iterate ${idx}`, () => {
before(async () => {
// oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive
store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' });
store = oss({ ...config, ...moreConfigs });
bucket = `ali-oss-test-bucket-version-${prefix.replace(/[/.]/g, '-')}${idx}`;

const result = await store.putBucket(bucket);
Expand Down
81 changes: 80 additions & 1 deletion test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,13 @@ describe('test/object.test.js', () => {
});

it('ColdArchive choice Days', async () => {
const name = '/oss/daysRestore.js';
const name = '/oss/daysColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'ColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'ColdArchive',
Days: 2
Expand All @@ -2486,6 +2492,25 @@ describe('test/object.test.js', () => {
);
});

it('ColdArchive choice JobParameters', async () => {
const name = '/oss/JobParametersColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'ColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'ColdArchive',
Days: 2,
JobParameters: 'Standard'
});
assert.equal(
['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']),
true
);
});

it('ColdArchive is Accepted', async () => {
const name = '/oss/coldRestore.js';
const result = await store.restore(name, {
Expand All @@ -2496,6 +2521,60 @@ describe('test/object.test.js', () => {
true
);
});

it('DeepColdArchive choice Days', async () => {
const name = '/oss/daysDeepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'DeepColdArchive',
Days: 2
});
assert.equal(
['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']),
true
);
});

it('DeepColdArchive choice JobParameters', async () => {
const name = '/oss/JobParametersDeepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from('abc'), options);
const result = await store.restore(name, {
type: 'DeepColdArchive',
Days: 2,
JobParameters: 'Standard'
});
assert.equal(
['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']),
true
);
});

it('DeepColdArchive is Accepted', async () => {
const name = '/oss/deepColdRestore.js';
const options = {
headers: {
'x-oss-storage-class': 'DeepColdArchive'
}
};
await store.put(name, Buffer.from(__filename), options);
const result = await store.restore(name, {
type: 'DeepColdArchive'
});
assert.equal(
['Expedited', 'Standard', 'Bulk'].includes(result.res.headers['x-oss-object-restore-priority']),
true
);
});
});

describe('symlink()', () => {
Expand Down

0 comments on commit ac500d3

Please sign in to comment.