Skip to content
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

Add archive ir #598

Merged
merged 7 commits into from
Dec 5, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/AutoRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private UCRet queryRegionInfoFromServerIfNeeded(RegionIndex index) throws QiniuE
}

String[] ucHosts = getUcHostArray();
String address = getUcServer() + "/v3/query?ak=" + index.accessKey + "&bucket=" + index.bucket;
String address = UrlUtils.setHostScheme(getUcServer(), true) + "/v3/query?ak=" + index.accessKey + "&bucket=" + index.bucket;
Api api = new Api(client, new Api.Config.Builder()
.setSingleHostRetryMax(retryMax)
.setRetryInterval(retryInterval)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public Response changeHeaders(String bucket, String key, Map<String, String> hea
*
* @param bucket 空间名称
* @param key 文件名称
* @param type type=0 表示普通存储,type=1 表示低频存存储, type=2 表示归档存储, type=3 表示深度归档存储
* @param type 存储类型
* @return Response
* @throws QiniuException 异常
*/
Expand Down
51 changes: 38 additions & 13 deletions src/main/java/com/qiniu/storage/model/BucketLifeCycleRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public class BucketLifeCycleRule {
@SerializedName("to_line_after_days")
int toLineAfterDays;

/**
* 指定文件上传多少天后转归档直读存储。
* 0 表示不转归档直读存储,
* < 0 表示上传的文件立即变归档直读存储
* > 0 表示多少天后转归档直读存储
*/
@SerializedName("to_archive_ir_after_days")
int toArchiveIRAfterDays;

/**
* 指定文件上传多少天后转归档存储。
* 0 表示不转归档存储,
Expand Down Expand Up @@ -141,17 +150,36 @@ public int getToLineAfterDays() {
/**
* 在多少天后转低频存储<br>
*
* @param toLineAfterDays
* 0 - 表示不转低频<br>
* 小于 0 表示上传的文件立即使用低频存储<br>
* 大于 0 表示转低频的天数
* @param toLineAfterDays 0 - 表示不转低频<br>
* 大于 0 表示转低频的天数
* @return 规则信息
*/
public BucketLifeCycleRule setToLineAfterDays(int toLineAfterDays) {
this.toLineAfterDays = toLineAfterDays;
return this;
}

/**
* 获得在多少天后转归档直读存储
*
* @return 多少天后转归档直读存储
*/
public int getToArchiveIRAfterDays() {
return toArchiveIRAfterDays;
}

/**
* 在多少天后转归档直读存储<br>
*
* @param toArchiveIRAfterDays 0 - 表示不转归档直读存储<br>
* 大于 0 表示多少天后转归档直读存储
* @return 规则信息
*/
public BucketLifeCycleRule setToArchiveIRAfterDays(int toArchiveIRAfterDays) {
this.toArchiveIRAfterDays = toArchiveIRAfterDays;
return this;
}

/**
* 获得在多少天后转归档存储
*
Expand All @@ -164,10 +192,8 @@ public int getToArchiveAfterDays() {
/**
* 在多少天后转归档存储<br>
*
* @param toArchiveAfterDays
* 0 - 表示不转归档存储<br>
* 小于 0 表示上传的文件立即使用归档存储<br>
* 大于 0 表示多少天后转归档存储
* @param toArchiveAfterDays 0 - 表示不转归档存储<br>
* 大于 0 表示多少天后转归档存储
* @return 规则信息
*/
public BucketLifeCycleRule setToArchiveAfterDays(int toArchiveAfterDays) {
Expand All @@ -187,10 +213,8 @@ public int getToDeepArchiveAfterDays() {
/**
* 在多少天后转深度归档存储<br>
*
* @param toDeepArchiveAfterDays
* 0 - 表示不转深度归档存储<br>
* 小于 0 表示上传的文件立即使用深度归档存储<br>
* 大于 0 表示多少天后转深度归档存储
* @param toDeepArchiveAfterDays 0 - 表示不转深度归档存储<br>
* 大于 0 表示多少天后转深度归档存储
* @return 规则信息
*/
public BucketLifeCycleRule setToDeepArchiveAfterDays(int toDeepArchiveAfterDays) {
Expand All @@ -204,11 +228,12 @@ public BucketLifeCycleRule setToDeepArchiveAfterDays(int toDeepArchiveAfterDays)
* @return query
*/
public String asQueryString() {
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",
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",
null == name ? "" : name,
null == prefix ? "" : prefix,
deleteAfterDays,
toLineAfterDays,
toArchiveIRAfterDays,
toArchiveAfterDays,
toDeepArchiveAfterDays
);
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/qiniu/storage/model/FileInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class FileInfo {
* 1 表示低频存存储
* 2 表示归档存储
* 3 表示深度归档存储
* 4 表示归档直读存储
*/
public int type;

Expand All @@ -73,7 +74,7 @@ public final class FileInfo {
* 文件在设置过期时间后才会返回该字段(通过生命周期规则设置文件过期时间,仅对该功能发布后满足规则条件新上传文件返回该字段;
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件过期删除时间 API 或者 修改文件生命周期 API 指定过期时间;对于已
* 经设置过过期时间的历史文件,到期都会正常过期删除,只是服务端没有该字段返回)
*
* <p>
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天内删除。
*/
public Long expiration;
Expand All @@ -84,7 +85,7 @@ public final class FileInfo {
* 文件在设置转低频后才会返回该字段(通过生命周期规则设置文件转低频,仅对该功能发布后满足规则条件新上传文件返回该字段;
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转低频时间;对于已经设置过转低频时间的历史文
* 件,到期都会正常执行,只是服务端没有该字段返回)
*
* <p>
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为低频存储类型。
*/
public Long transitionToIA;
Expand All @@ -94,7 +95,17 @@ public final class FileInfo {
* 文件在设置转归档后才会返回该字段(通过生命周期规则设置文件转归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转归档时间;对于已经设置过转归档时间的历史文
* 件,到期都会正常执行,只是服务端没有该字段返回)
*
* <p>
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为归档存储类型。
*/
public Long transitionToArchiveIR;

/**
* 文件生命周期中转为归档存储的日期,int64 类型,Unix 时间戳格式 ,具体日期计算参考 生命周期管理。
* 文件在设置转归档后才会返回该字段(通过生命周期规则设置文件转归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转归档时间;对于已经设置过转归档时间的历史文
* 件,到期都会正常执行,只是服务端没有该字段返回)
* <p>
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为归档存储类型。
*/
@SerializedName("transitionToARCHIVE")
Expand All @@ -105,7 +116,7 @@ public final class FileInfo {
* 文件在设置转深度归档后才会返回该字段(通过生命周期规则设置文件转深度归档,仅对该功能发布后满足规则条件新上传文件返回该字段;
* 历史文件想要返回该字段需要在功能发布后可通过 修改文件生命周期 API 指定转深度归档时间;对于已经设置过转深度归档时间的历史文
* 件,到期都会正常执行,只是服务端没有该字段返回)
*
* <p>
* 例如:值为1568736000的时间,表示文件会在2019/9/18当天转为深度归档存储类型。
*/
public Long transitionToDeepArchive;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/qiniu/storage/model/StorageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public enum StorageType {
/**
* 深度归档存储
*/
DeepArchive
DeepArchive,

/**
* 归档直读存储
*/
ArchiveIR,
}
5 changes: 5 additions & 0 deletions src/main/java/com/qiniu/storage/model/UploadPolicy.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.qiniu.storage.model;

import com.qiniu.util.StringMap;

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

/**
Expand Down Expand Up @@ -143,6 +147,7 @@ public final class UploadPolicy {
* 1 表示低频存储
* 2 表示归档存储
* 3 表示深度归档存储
* 4 表示归档直读存储
*/
public int fileType;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/qiniu/util/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public final class Auth {

"endUser",
"saveKey",
"forceSaveKey",
"insertOnly",
"isPrefixalScope",

"detectMime",
"mimeLimit",
"fsizeLimit",
"fsizeMin",
"trafficLimit",

"persistentOps",
"persistentNotifyUrl",
Expand Down Expand Up @@ -328,6 +330,7 @@ public String uploadToken(String bucket, String key) {
* @param expires 有效时长,单位秒
* @param policy 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
* scope通过 bucket、key间接设置,deadline 通过 expires 间接设置
* 具体参考: <a href="https://developer.qiniu.com/kodo/manual/put-policy"> 上传策略 </a>
* @return 生成的上传token
*/
public String uploadToken(String bucket, String key, long expires, StringMap policy) {
Expand All @@ -342,6 +345,7 @@ public String uploadToken(String bucket, String key, long expires, StringMap pol
* @param expires 有效时长,单位秒。默认3600s
* @param policy 上传策略的其它参数,如 new StringMap().put("endUser", "uid").putNotEmpty("returnBody", "")。
* scope通过 bucket、key间接设置,deadline 通过 expires 间接设置
* 具体参考: <a href="https://developer.qiniu.com/kodo/manual/put-policy"> 上传策略 </a>
* @param strict 是否去除非限定的策略字段,默认true
* @return 生成的上传token
*/
Expand Down
34 changes: 20 additions & 14 deletions src/test/java/test/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.model.*;
import com.qiniu.util.Auth;
import com.qiniu.util.Json;
import com.qiniu.util.StringUtils;
import okhttp3.Call;
Expand Down Expand Up @@ -634,10 +636,11 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro

// 追加规则
rule = new BucketLifeCycleRule("aa", "x")
.setToLineAfterDays(1)
.setToArchiveAfterDays(2)
.setToDeepArchiveAfterDays(3)
.setDeleteAfterDays(4);
.setToLineAfterDays(10)
.setToArchiveIRAfterDays(20)
.setToArchiveAfterDays(30)
.setToDeepArchiveAfterDays(40)
.setDeleteAfterDays(50);
System.out.println(rule.asQueryString());
response = bucketManager.putBucketLifecycleRule(bucket, rule);
assertEquals(200, response.statusCode);
Expand All @@ -646,10 +649,11 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
for (BucketLifeCycleRule r : rules) {
if (r.getName().equals("aa")
&& r.getPrefix().equals("x")
&& r.getToLineAfterDays() == 1
&& r.getToArchiveAfterDays() == 2
&& r.getToDeepArchiveAfterDays() == 3
&& r.getDeleteAfterDays() == 4) {
&& r.getToLineAfterDays() == 10
&& r.getToArchiveIRAfterDays() == 20
&& r.getToArchiveAfterDays() == 30
&& r.getToDeepArchiveAfterDays() == 40
&& r.getDeleteAfterDays() == 50) {
exist = true;
}
}
Expand All @@ -667,9 +671,10 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
// 更新规则
rule = new BucketLifeCycleRule("aa", "x")
.setToLineAfterDays(11)
.setToArchiveAfterDays(12)
.setToDeepArchiveAfterDays(13)
.setDeleteAfterDays(14);
.setToArchiveIRAfterDays(12)
.setToArchiveAfterDays(13)
.setToDeepArchiveAfterDays(14)
.setDeleteAfterDays(15);
System.out.println(rule.asQueryString());
response = bucketManager.updateBucketLifeCycleRule(bucket, rule);
assertEquals(200, response.statusCode);
Expand All @@ -680,9 +685,10 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
if (r.getName().equals("aa")
&& r.getPrefix().equals("x")
&& r.getToLineAfterDays() == 11
&& r.getToArchiveAfterDays() == 12
&& r.getToDeepArchiveAfterDays() == 13
&& r.getDeleteAfterDays() == 14) {
&& r.getToArchiveIRAfterDays() == 12
&& r.getToArchiveAfterDays() == 13
&& r.getToDeepArchiveAfterDays() == 14
&& r.getDeleteAfterDays() == 15) {
exist = true;
}
}
Expand Down
Loading