Skip to content

Commit ae2a7af

Browse files
authored
Merge pull request #557 from YangSen-qn/master
add region:ap-northeast-1
2 parents 8b8c4b5 + 37b928c commit ae2a7af

File tree

5 files changed

+114
-61
lines changed

5 files changed

+114
-61
lines changed

src/main/java/com/qiniu/common/Zone.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,6 @@ public static Zone xinjiapo() {
179179
return zoneAs0();
180180
}
181181

182-
/**
183-
* 雾存储 华东-1
184-
*/
185-
public static Zone zoneFogCnEast1() {
186-
return new Builder()
187-
.region("fog-cn-east-1")
188-
.upHttp("http://upload-fog-cn-east-1.qiniup.com").upHttps("https://upload-fog-cn-east-1.qiniup.com")
189-
.upBackupHttp("http://up-fog-cn-east-1.qiniup.com").upBackupHttps("https://up-fog-cn-east-1.qiniup.com")
190-
.iovipHttp("http://iovip-fog-cn-east-1.qbox.me").iovipHttps("https://iovip-fog-cn-east-1.qbox.me")
191-
.rsHttp("http://rs-fog-cn-east-1.qbox.me").rsHttps("https://rs-fog-cn-east-1.qbox.me")
192-
.rsfHttp("http://rsf-fog-cn-east-1.qbox.me").rsfHttps("https://rsf-fog-cn-east-1.qbox.me")
193-
.apiHttp("http://api-fog-cn-east-1.qiniuapi.com").apiHttps("https://api-fog-cn-east-1.qiniuapi.com")
194-
.build();
195-
}
196-
197182
/**
198183
* 自动根据AccessKey和Bucket来判断所在机房,并获取相关的域名
199184
* 空间所在的对应机房可以在空间创建的时候选择,或者创建完毕之后,从后台查看

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public String[] domainList(String bucket) throws QiniuException {
144144
}
145145

146146
public Response domainListResponse(String bucket) throws QiniuException {
147-
String url = String.format("%s/v6/domain/list?tbl=%s", configHelper.apiHost(), bucket);
147+
String url = String.format("%s/v6/domain/list?tbl=%s", configHelper.apiHost(auth.accessKey, bucket), bucket);
148148
Response res = get(url);
149149
if (!res.isOK()) {
150150
throw new QiniuException(res);
@@ -1022,7 +1022,7 @@ public Response setBucketAcl(String bucket, AclType acl) throws QiniuException {
10221022
*/
10231023
public Response putBucketQuota(String bucket, BucketQuota bucketQuota) throws QiniuException {
10241024
String url = String.format("%s/setbucketquota/%s/size/%d/count/%d",
1025-
configHelper.apiHost(), bucket, bucketQuota.getSize(), bucketQuota.getCount());
1025+
configHelper.apiHost(auth.accessKey, bucket), bucket, bucketQuota.getSize(), bucketQuota.getCount());
10261026
Response res = post(url, null);
10271027
if (!res.isOK()) {
10281028
throw new QiniuException(res);
@@ -1044,7 +1044,7 @@ public BucketQuota getBucketQuota(String bucket) throws QiniuException {
10441044
}
10451045

10461046
public Response getBucketQuotaResponse(String bucket) throws QiniuException {
1047-
String url = String.format("%s/getbucketquota/%s", configHelper.apiHost(), bucket);
1047+
String url = String.format("%s/getbucketquota/%s", configHelper.apiHost(auth.accessKey, bucket), bucket);
10481048
Response res = post(url, null);
10491049
if (!res.isOK()) {
10501050
throw new QiniuException(res);
@@ -1096,13 +1096,21 @@ private void check(String bucket) throws QiniuException {
10961096

10971097
/**
10981098
* 批量文件管理请求
1099+
* <p>
1100+
* 如果遇到超时比较多,可减小单次 batch 操作的数量,或者在创建 BucketManager 时尝试增加超时时间;
1101+
* 增加超时时间的具体方式如下:
1102+
* Configuration cfg = new Configuration();
1103+
* cfg.readTimeout = 120;
1104+
* BucketManager bucketManager = new BucketManager(auth, cfg);
1105+
* <p>
1106+
* 如果 BucketManager 定义了 Client ,可以指定 Client 的超时时间。
10991107
*/
11001108
public Response batch(BatchOperations operations) throws QiniuException {
11011109
return rsPost(operations.execBucket(), "/batch", operations.toBody());
11021110
}
11031111

11041112
/**
1105-
* 文件管理批量操作指令构建对象
1113+
* 文件管理批量操作指令构建对象,单次 BatchOperations 的操作数最多为 1000(即 add 最多 1000 个),如果遇到超时,需要调小操作数量
11061114
*/
11071115
public static class BatchOperations {
11081116
private ArrayList<String> ops;

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static Region regionCnEast2() {
8080
accUpHost("upload-cn-east-2.qiniup.com").
8181
iovipHost("iovip-cn-east-2.qiniuio.com").
8282
rsHost("rs-cn-east-2.qiniuapi.com").
83-
rsfHost("rsf-cn-east-2-qiniuapi.com").
83+
rsfHost("rsf-cn-east-2.qiniuapi.com").
8484
apiHost("api-cn-east-2.qiniuapi.com").
8585
build();
8686
}
@@ -181,6 +181,21 @@ public static Region huanan() {
181181
return region2();
182182
}
183183

184+
/**
185+
* 亚太-首尔机房相关域名
186+
*/
187+
public static Region regionApNorthEast1() {
188+
return new Builder().
189+
region("ap-northeast-1").
190+
srcUpHost("up-ap-northeast-1.qiniup.com").
191+
accUpHost("upload-ap-northeast-1.qiniup.com").
192+
iovipHost("iovip-ap-northeast-1.qiniuio.com").
193+
rsHost("rs-ap-northeast-1.qiniuapi.com").
194+
rsfHost("rsf-ap-northeast-1.qiniuapi.com").
195+
apiHost("api-ap-northeast-1.qiniuapi.com").
196+
build();
197+
}
198+
184199
/**
185200
* 北美机房相关域名
186201
*/
@@ -225,21 +240,6 @@ public static Region xinjiapo() {
225240
return regionAs0();
226241
}
227242

228-
/**
229-
* 雾存储 华东-1
230-
*/
231-
public static Region regionFogCnEast1() {
232-
return new Builder()
233-
.region("fog-cn-east-1")
234-
.srcUpHost("up-fog-cn-east-1.qiniup.com")
235-
.accUpHost("upload-fog-cn-east-1.qiniup.com")
236-
.iovipHost("iovip-fog-cn-east-1.qbox.me")
237-
.rsHost("rs-fog-cn-east-1.qbox.me")
238-
.rsfHost("rsf-fog-cn-east-1.qbox.me")
239-
.apiHost("api-fog-cn-east-1.qiniuapi.com")
240-
.build();
241-
}
242-
243243
/*
244244
* 自动根据AccessKey和Bucket来判断所在机房,并获取相关的域名
245245
* 空间所在的对应机房可以在空间创建的时候选择,或者创建完毕之后,从后台查看

src/test/java/test/com/qiniu/TestConfig.java

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,76 @@ public static TestFile[] getTestFileArray(String fileSaveKey, String fileMimeTyp
121121
z0_auto.regionId = "z0";
122122
z0_auto.region = Region.region0();
123123

124-
TestFile fog = new TestFile();
125-
fog.key = fileSaveKey;
126-
fog.mimeType = fileMimeType;
127-
fog.bucketName = "java-sdk-fog-cn-east1";
128-
fog.testDomain = "javasdk-fog-cn-east1.peterpy.cn";
129-
fog.testUrl = "http://" + fog.testDomain + "/" + fileSaveKey;
130-
fog.testDomainTimeStamp = "javasdk-fog-cn-east1-timestamp.peterpy.cn";
131-
fog.testUrlTimeStamp = "http://" + fog.testDomainTimeStamp + "/" + fileSaveKey;
132-
fog.regionId = "fog-cn-east-1";
133-
fog.region = Region.regionFogCnEast1();
134-
135-
TestFile fog1 = new TestFile();
136-
fog1.key = fileSaveKey;
137-
fog1.mimeType = fileMimeType;
138-
fog1.bucketName = "java-sdk-fog-cn-east1";
139-
fog1.testDomain = "javasdk-fog-cn-east1.peterpy.cn";
140-
fog1.testUrl = "http://" + fog.testDomain + "/" + fileSaveKey;
141-
fog1.testDomainTimeStamp = "javasdk-fog-cn-east1-timestamp.peterpy.cn";
142-
fog1.testUrlTimeStamp = "http://" + fog.testDomainTimeStamp + "/" + fileSaveKey;
143-
fog1.regionId = "fog-cn-east-1";
144-
fog1.region = toRegion(Zone.zoneFogCnEast1());
145-
146-
return new TestFile[] { z0 };
124+
return new TestFile[]{z0};
125+
}
126+
127+
public static TestFile[] getAllRegionTestFileArray() {
128+
return getAllRegionTestFileArray(testDefaultKey, "image/png");
129+
}
130+
131+
public static TestFile[] getAllRegionTestFileArray(String fileSaveKey, String fileMimeType) {
132+
if (StringUtils.isNullOrEmpty(fileSaveKey)) {
133+
fileSaveKey = testDefaultKey;
134+
}
135+
if (StringUtils.isNullOrEmpty(fileMimeType)) {
136+
fileMimeType = "application/octet-stream";
137+
}
138+
139+
TestFile na0 = new TestFile();
140+
na0.key = fileSaveKey;
141+
na0.mimeType = fileMimeType;
142+
na0.bucketName = testBucket_na0;
143+
na0.testDomain = testDomain_na0;
144+
na0.testUrl = "http://" + testDomain_na0 + "/" + fileSaveKey;
145+
na0.testDomainTimeStamp = testDomain_na0_timeStamp;
146+
na0.testUrlTimeStamp = "http://" + testDomain_na0_timeStamp + "/" + fileSaveKey;
147+
na0.regionId = "na0";
148+
na0.region = Region.regionNa0();
149+
150+
TestFile z0 = new TestFile();
151+
z0.key = fileSaveKey;
152+
z0.mimeType = fileMimeType;
153+
z0.bucketName = testBucket_z0;
154+
z0.testDomain = testDomain_z0;
155+
z0.testUrl = "http://" + testDomain_z0 + "/" + fileSaveKey;
156+
z0.testDomainTimeStamp = testDomain_z0_timeStamp;
157+
z0.testUrlTimeStamp = "http://" + testDomain_z0_timeStamp + "/" + fileSaveKey;
158+
z0.regionId = "z0";
159+
z0.region = Region.region0();
160+
161+
TestFile z1 = new TestFile();
162+
z1.key = fileSaveKey;
163+
z1.mimeType = fileMimeType;
164+
z1.bucketName = testBucket_z1;
165+
z1.regionId = "z1";
166+
z1.region = Region.region1();
167+
168+
TestFile z2 = new TestFile();
169+
z2.key = fileSaveKey;
170+
z2.mimeType = fileMimeType;
171+
z2.bucketName = "sdk-z2";
172+
z2.regionId = "z2";
173+
z2.region = Region.region2();
174+
175+
TestFile as0 = new TestFile();
176+
as0.key = fileSaveKey;
177+
as0.mimeType = fileMimeType;
178+
as0.bucketName = "sdk-as0";
179+
as0.regionId = "as0";
180+
as0.region = Region.regionAs0();
181+
182+
TestFile z0_auto = new TestFile();
183+
z0_auto.key = fileSaveKey;
184+
z0_auto.mimeType = fileMimeType;
185+
z0_auto.bucketName = testBucket_z0;
186+
z0_auto.testDomain = testDomain_z0;
187+
z0_auto.testUrl = "http://" + testDomain_z0 + "/" + fileSaveKey;
188+
z0_auto.testDomainTimeStamp = testDomain_z0_timeStamp;
189+
z0_auto.testUrlTimeStamp = "http://" + testDomain_z0_timeStamp + "/" + fileSaveKey;
190+
z0_auto.regionId = "z0";
191+
z0_auto.region = Region.region0();
192+
193+
return new TestFile[]{z0, z1, z2, as0, na0};
147194
}
148195

149196
private static Region toRegion(Zone zone) {
@@ -169,9 +216,9 @@ private static String[] getHosts(String https, String http) {
169216
String s1 = toDomain(http);
170217
String s2 = toDomain(https);
171218
if (s2 != null && !s2.equalsIgnoreCase(s1)) {
172-
return new String[] { s1, s2 };
219+
return new String[]{s1, s2};
173220
}
174-
return new String[] { s1 };
221+
return new String[]{s1};
175222
}
176223

177224
private static String toDomain(String d1) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
7474
@Test
7575
@Tag("IntegrationTest")
7676
public void testDomains() throws Exception {
77-
testFileWithHandler(new TestFileHandler() {
77+
testAllRegionFileWithHandler(new TestFileHandler() {
7878
@Override
7979
public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException {
8080
try {
@@ -1817,6 +1817,19 @@ private void testFileWithHandler(TestFileHandler handler) throws Exception {
18171817
}
18181818
}
18191819

1820+
private void testAllRegionFileWithHandler(TestFileHandler handler) throws Exception {
1821+
if (handler == null) {
1822+
return;
1823+
}
1824+
1825+
TestConfig.TestFile[] files = TestConfig.getAllRegionTestFileArray();
1826+
for (TestConfig.TestFile file : files) {
1827+
Configuration cfg = new Configuration(file.getRegion());
1828+
BucketManager bucketManager = new BucketManager(TestConfig.testAuth, cfg);
1829+
handler.testFile(file, bucketManager);
1830+
}
1831+
}
1832+
18201833
private interface TestFileHandler {
18211834
void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws Exception;
18221835
}

0 commit comments

Comments
 (0)