Skip to content

Commit ac4d1fd

Browse files
authored
Add archive ir (#598)
1 parent ad6a208 commit ac4d1fd

File tree

8 files changed

+90
-34
lines changed

8 files changed

+90
-34
lines changed

src/main/java/com/qiniu/storage/AutoRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private UCRet queryRegionInfoFromServerIfNeeded(RegionIndex index) throws QiniuE
8383
}
8484

8585
String[] ucHosts = getUcHostArray();
86-
String address = getUcServer() + "/v3/query?ak=" + index.accessKey + "&bucket=" + index.bucket;
86+
String address = UrlUtils.setHostScheme(getUcServer(), true) + "/v3/query?ak=" + index.accessKey + "&bucket=" + index.bucket;
8787
Api api = new Api(client, new Api.Config.Builder()
8888
.setSingleHostRetryMax(retryMax)
8989
.setRetryInterval(retryInterval)

src/main/java/com/qiniu/storage/BucketManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public Response changeHeaders(String bucket, String key, Map<String, String> hea
389389
*
390390
* @param bucket 空间名称
391391
* @param key 文件名称
392-
* @param type type=0 表示普通存储,type=1 表示低频存存储, type=2 表示归档存储, type=3 表示深度归档存储
392+
* @param type 存储类型
393393
* @return Response
394394
* @throws QiniuException 异常
395395
*/

src/main/java/com/qiniu/storage/model/BucketLifeCycleRule.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public class BucketLifeCycleRule {
4141
@SerializedName("to_line_after_days")
4242
int toLineAfterDays;
4343

44+
/**
45+
* 指定文件上传多少天后转归档直读存储。
46+
* 0 表示不转归档直读存储,
47+
* < 0 表示上传的文件立即变归档直读存储
48+
* > 0 表示多少天后转归档直读存储
49+
*/
50+
@SerializedName("to_archive_ir_after_days")
51+
int toArchiveIRAfterDays;
52+
4453
/**
4554
* 指定文件上传多少天后转归档存储。
4655
* 0 表示不转归档存储,
@@ -141,17 +150,36 @@ public int getToLineAfterDays() {
141150
/**
142151
* 在多少天后转低频存储<br>
143152
*
144-
* @param toLineAfterDays
145-
* 0 - 表示不转低频<br>
146-
* 小于 0 表示上传的文件立即使用低频存储<br>
147-
* 大于 0 表示转低频的天数
153+
* @param toLineAfterDays 0 - 表示不转低频<br>
154+
* 大于 0 表示转低频的天数
148155
* @return 规则信息
149156
*/
150157
public BucketLifeCycleRule setToLineAfterDays(int toLineAfterDays) {
151158
this.toLineAfterDays = toLineAfterDays;
152159
return this;
153160
}
154161

162+
/**
163+
* 获得在多少天后转归档直读存储
164+
*
165+
* @return 多少天后转归档直读存储
166+
*/
167+
public int getToArchiveIRAfterDays() {
168+
return toArchiveIRAfterDays;
169+
}
170+
171+
/**
172+
* 在多少天后转归档直读存储<br>
173+
*
174+
* @param toArchiveIRAfterDays 0 - 表示不转归档直读存储<br>
175+
* 大于 0 表示多少天后转归档直读存储
176+
* @return 规则信息
177+
*/
178+
public BucketLifeCycleRule setToArchiveIRAfterDays(int toArchiveIRAfterDays) {
179+
this.toArchiveIRAfterDays = toArchiveIRAfterDays;
180+
return this;
181+
}
182+
155183
/**
156184
* 获得在多少天后转归档存储
157185
*
@@ -164,10 +192,8 @@ public int getToArchiveAfterDays() {
164192
/**
165193
* 在多少天后转归档存储<br>
166194
*
167-
* @param toArchiveAfterDays
168-
* 0 - 表示不转归档存储<br>
169-
* 小于 0 表示上传的文件立即使用归档存储<br>
170-
* 大于 0 表示多少天后转归档存储
195+
* @param toArchiveAfterDays 0 - 表示不转归档存储<br>
196+
* 大于 0 表示多少天后转归档存储
171197
* @return 规则信息
172198
*/
173199
public BucketLifeCycleRule setToArchiveAfterDays(int toArchiveAfterDays) {
@@ -187,10 +213,8 @@ public int getToDeepArchiveAfterDays() {
187213
/**
188214
* 在多少天后转深度归档存储<br>
189215
*
190-
* @param toDeepArchiveAfterDays
191-
* 0 - 表示不转深度归档存储<br>
192-
* 小于 0 表示上传的文件立即使用深度归档存储<br>
193-
* 大于 0 表示多少天后转深度归档存储
216+
* @param toDeepArchiveAfterDays 0 - 表示不转深度归档存储<br>
217+
* 大于 0 表示多少天后转深度归档存储
194218
* @return 规则信息
195219
*/
196220
public BucketLifeCycleRule setToDeepArchiveAfterDays(int toDeepArchiveAfterDays) {
@@ -204,11 +228,12 @@ public BucketLifeCycleRule setToDeepArchiveAfterDays(int toDeepArchiveAfterDays)
204228
* @return query
205229
*/
206230
public String asQueryString() {
207-
return String.format("name=%s&prefix=%s&delete_after_days=%d&to_line_after_days=%d&to_archive_after_days=%d&to_deep_archive_after_days=%d",
231+
return String.format("name=%s&prefix=%s&delete_after_days=%d&to_line_after_days=%d&to_archive_ir_after_days=%d&to_archive_after_days=%d&to_deep_archive_after_days=%d",
208232
null == name ? "" : name,
209233
null == prefix ? "" : prefix,
210234
deleteAfterDays,
211235
toLineAfterDays,
236+
toArchiveIRAfterDays,
212237
toArchiveAfterDays,
213238
toDeepArchiveAfterDays
214239
);

src/main/java/com/qiniu/storage/model/FileInfo.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class FileInfo {
5353
* 1 表示低频存存储
5454
* 2 表示归档存储
5555
* 3 表示深度归档存储
56+
* 4 表示归档直读存储
5657
*/
5758
public int type;
5859

@@ -73,7 +74,7 @@ public final class FileInfo {
7374
* 文件在设置过期时间后才会返回该字段(通过生命周期规则设置文件过期时间,仅对该功能发布后满足规则条件新上传文件返回该字段;
7475
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件过期删除时间 API 或者 修改文件生命周期 API 指定过期时间;对于已
7576
* 经设置过过期时间的历史文件,到期都会正常过期删除,只是服务端没有该字段返回)
76-
*
77+
* <p>
7778
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天内删除。
7879
*/
7980
public Long expiration;
@@ -84,7 +85,7 @@ public final class FileInfo {
8485
* 文件在设置转低频后才会返回该字段(通过生命周期规则设置文件转低频,仅对该功能发布后满足规则条件新上传文件返回该字段;
8586
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转低频时间;对于已经设置过转低频时间的历史文
8687
* 件,到期都会正常执行,只是服务端没有该字段返回)
87-
*
88+
* <p>
8889
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为低频存储类型。
8990
*/
9091
public Long transitionToIA;
@@ -94,7 +95,17 @@ public final class FileInfo {
9495
* 文件在设置转归档后才会返回该字段(通过生命周期规则设置文件转归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
9596
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转归档时间;对于已经设置过转归档时间的历史文
9697
* 件,到期都会正常执行,只是服务端没有该字段返回)
97-
*
98+
* <p>
99+
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为归档存储类型。
100+
*/
101+
public Long transitionToArchiveIR;
102+
103+
/**
104+
* 文件生命周期中转为归档存储的日期,int64 类型,Unix 时间戳格式 ,具体日期计算参考 生命周期管理。
105+
* 文件在设置转归档后才会返回该字段(通过生命周期规则设置文件转归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
106+
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转归档时间;对于已经设置过转归档时间的历史文
107+
* 件,到期都会正常执行,只是服务端没有该字段返回)
108+
* <p>
98109
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为归档存储类型。
99110
*/
100111
@SerializedName("transitionToARCHIVE")
@@ -105,7 +116,7 @@ public final class FileInfo {
105116
* 文件在设置转深度归档后才会返回该字段(通过生命周期规则设置文件转深度归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
106117
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转深度归档时间;对于已经设置过转深度归档时间的历史文
107118
* 件,到期都会正常执行,只是服务端没有该字段返回)
108-
*
119+
* <p>
109120
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为深度归档存储类型。
110121
*/
111122
public Long transitionToDeepArchive;

src/main/java/com/qiniu/storage/model/StorageType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public enum StorageType {
2222
/**
2323
* 深度归档存储
2424
*/
25-
DeepArchive
25+
DeepArchive,
26+
27+
/**
28+
* 归档直读存储
29+
*/
30+
ArchiveIR,
2631
}

src/main/java/com/qiniu/storage/model/UploadPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.qiniu.storage.model;
22

3+
import com.qiniu.util.StringMap;
4+
35
/**
46
* 该类封装了上传策略
7+
* 废弃,构造上传 Token 使用 StringMap 承载上传 Policy 信息,详细见 {@link com.qiniu.util.Auth#uploadToken(String, String, long, StringMap)}
58
* 参考文档:<a href="https://developer.qiniu.com/kodo/manual/put-policy">上传策略</a>
69
*/
10+
@Deprecated
711
public final class UploadPolicy {
812

913
/**
@@ -143,6 +147,7 @@ public final class UploadPolicy {
143147
* 1 表示低频存储
144148
* 2 表示归档存储
145149
* 3 表示深度归档存储
150+
* 4 表示归档直读存储
146151
*/
147152
public int fileType;
148153

src/main/java/com/qiniu/util/Auth.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ public final class Auth {
3838

3939
"endUser",
4040
"saveKey",
41+
"forceSaveKey",
4142
"insertOnly",
4243
"isPrefixalScope",
4344

4445
"detectMime",
4546
"mimeLimit",
4647
"fsizeLimit",
4748
"fsizeMin",
49+
"trafficLimit",
4850

4951
"persistentOps",
5052
"persistentNotifyUrl",
@@ -328,6 +330,7 @@ public String uploadToken(String bucket, String key) {
328330
* @param expires 有效时长,单位秒
329331
* @param policy 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
330332
* scope通过 bucket、key间接设置,deadline 通过 expires 间接设置
333+
* 具体参考: <a href="https://developer.qiniu.com/kodo/manual/put-policy"> 上传策略 </a>
331334
* @return 生成的上传token
332335
*/
333336
public String uploadToken(String bucket, String key, long expires, StringMap policy) {
@@ -342,6 +345,7 @@ public String uploadToken(String bucket, String key, long expires, StringMap pol
342345
* @param expires 有效时长,单位秒。默认3600s
343346
* @param policy 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
344347
* scope通过 bucket、key间接设置,deadline 通过 expires 间接设置
348+
* 具体参考: <a href="https://developer.qiniu.com/kodo/manual/put-policy"> 上传策略 </a>
345349
* @param strict 是否去除非限定的策略字段,默认true
346350
* @return 生成的上传token
347351
*/

src/test/java/test/com/qiniu/storage/BucketTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.qiniu.http.Response;
77
import com.qiniu.storage.BucketManager;
88
import com.qiniu.storage.Configuration;
9+
import com.qiniu.storage.Region;
910
import com.qiniu.storage.model.*;
11+
import com.qiniu.util.Auth;
1012
import com.qiniu.util.Json;
1113
import com.qiniu.util.StringUtils;
1214
import okhttp3.Call;
@@ -634,10 +636,11 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
634636

635637
// 追加规则
636638
rule = new BucketLifeCycleRule("aa", "x")
637-
.setToLineAfterDays(1)
638-
.setToArchiveAfterDays(2)
639-
.setToDeepArchiveAfterDays(3)
640-
.setDeleteAfterDays(4);
639+
.setToLineAfterDays(10)
640+
.setToArchiveIRAfterDays(20)
641+
.setToArchiveAfterDays(30)
642+
.setToDeepArchiveAfterDays(40)
643+
.setDeleteAfterDays(50);
641644
System.out.println(rule.asQueryString());
642645
response = bucketManager.putBucketLifecycleRule(bucket, rule);
643646
assertEquals(200, response.statusCode);
@@ -646,10 +649,11 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
646649
for (BucketLifeCycleRule r : rules) {
647650
if (r.getName().equals("aa")
648651
&& r.getPrefix().equals("x")
649-
&& r.getToLineAfterDays() == 1
650-
&& r.getToArchiveAfterDays() == 2
651-
&& r.getToDeepArchiveAfterDays() == 3
652-
&& r.getDeleteAfterDays() == 4) {
652+
&& r.getToLineAfterDays() == 10
653+
&& r.getToArchiveIRAfterDays() == 20
654+
&& r.getToArchiveAfterDays() == 30
655+
&& r.getToDeepArchiveAfterDays() == 40
656+
&& r.getDeleteAfterDays() == 50) {
653657
exist = true;
654658
}
655659
}
@@ -667,9 +671,10 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
667671
// 更新规则
668672
rule = new BucketLifeCycleRule("aa", "x")
669673
.setToLineAfterDays(11)
670-
.setToArchiveAfterDays(12)
671-
.setToDeepArchiveAfterDays(13)
672-
.setDeleteAfterDays(14);
674+
.setToArchiveIRAfterDays(12)
675+
.setToArchiveAfterDays(13)
676+
.setToDeepArchiveAfterDays(14)
677+
.setDeleteAfterDays(15);
673678
System.out.println(rule.asQueryString());
674679
response = bucketManager.updateBucketLifeCycleRule(bucket, rule);
675680
assertEquals(200, response.statusCode);
@@ -680,9 +685,10 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
680685
if (r.getName().equals("aa")
681686
&& r.getPrefix().equals("x")
682687
&& r.getToLineAfterDays() == 11
683-
&& r.getToArchiveAfterDays() == 12
684-
&& r.getToDeepArchiveAfterDays() == 13
685-
&& r.getDeleteAfterDays() == 14) {
688+
&& r.getToArchiveIRAfterDays() == 12
689+
&& r.getToArchiveAfterDays() == 13
690+
&& r.getToDeepArchiveAfterDays() == 14
691+
&& r.getDeleteAfterDays() == 15) {
686692
exist = true;
687693
}
688694
}

0 commit comments

Comments
 (0)