From 109f8685461abe063a9f286f81ffe0b15b34aeff Mon Sep 17 00:00:00 2001 From: yangsen Date: Mon, 5 Aug 2024 15:34:43 +0800 Subject: [PATCH] delete fog east host (#606) Co-authored-by: YangSen-qn --- examples/upload_v1_api.java | 1 - examples/upload_v2_api.java | 1 - src/main/java/com/qiniu/storage/Api.java | 16 ++++++--- .../java/com/qiniu/storage/UpHostHelper.java | 1 - src/main/java/com/qiniu/util/UrlUtils.java | 15 ++++++++ src/test/java/test/com/qiniu/TestConfig.java | 4 --- .../test/com/qiniu/processing/PfopTest.java | 8 ++--- .../test/com/qiniu/storage/BucketTest.java | 15 -------- .../com/qiniu/storage/RecordUploadTest.java | 4 --- .../com/qiniu/storage/ResumeUploadTest.java | 36 ++++++++----------- .../com/qiniu/storage/StreamUploadTest.java | 6 ++-- .../com/qiniu/storage/SwitchRegionTest.java | 32 ++++++++--------- 12 files changed, 61 insertions(+), 78 deletions(-) diff --git a/examples/upload_v1_api.java b/examples/upload_v1_api.java index 360edf73..853b8754 100644 --- a/examples/upload_v1_api.java +++ b/examples/upload_v1_api.java @@ -28,7 +28,6 @@ public class UploadDemo { * 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com * 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com * 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com - * 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com */ String urlPrefix = "urlPrefix"; // http://up.qiniup.com //要上传的空间 diff --git a/examples/upload_v2_api.java b/examples/upload_v2_api.java index 648a76b3..749a3e9b 100644 --- a/examples/upload_v2_api.java +++ b/examples/upload_v2_api.java @@ -24,7 +24,6 @@ public class UploadDemo { * 华南机房(region2): up-z2.qiniup.com 或 upload-z2.qiniup.com * 北美机房(regionNa0): up-na0.qiniup.com 或 upload-na0.qiniup.com * 新加坡机房(regionAs0): up-as0.qiniup.com 或 upload-as0.qiniup.com - * 雾存储华东一区(regionFogCnEast1): up-fog-cn-east-1.qiniup.com 或 upload-fog-cn-east-1.qiniup.com */ String urlPrefix = "urlPrefix" // http://up.qiniup.com"; // 要上传的空间 diff --git a/src/main/java/com/qiniu/storage/Api.java b/src/main/java/com/qiniu/storage/Api.java index 35280fda..763b9c14 100644 --- a/src/main/java/com/qiniu/storage/Api.java +++ b/src/main/java/com/qiniu/storage/Api.java @@ -4,10 +4,7 @@ import com.qiniu.http.Client; import com.qiniu.http.MethodType; import com.qiniu.http.RequestStreamBody; -import com.qiniu.util.Auth; -import com.qiniu.util.Json; -import com.qiniu.util.StringMap; -import com.qiniu.util.StringUtils; +import com.qiniu.util.*; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.RequestBody; @@ -461,7 +458,16 @@ public String getHost() throws QiniuException { } void setHost(String host) { - this.host = host; + URL tmpUrl = UrlUtils.parseHost(host); + if (tmpUrl == null) { + this.host = null; + return; + } + + this.host = tmpUrl.getHost(); + if (tmpUrl.getPort() >= 0) { + this.port = tmpUrl.getPort(); + } } /** diff --git a/src/main/java/com/qiniu/storage/UpHostHelper.java b/src/main/java/com/qiniu/storage/UpHostHelper.java index 70f3185e..5725b6e6 100644 --- a/src/main/java/com/qiniu/storage/UpHostHelper.java +++ b/src/main/java/com/qiniu/storage/UpHostHelper.java @@ -67,7 +67,6 @@ private String failedUpHost(String regionKey) { this.add("upload-z2.qiniup.com"); this.add("upload-na0.qiniup.com"); this.add("upload-as0.qiniup.com"); - this.add("upload-fog-cn-east-1.qiniup.com"); } }; Collections.shuffle(accHosts); // ? diff --git a/src/main/java/com/qiniu/util/UrlUtils.java b/src/main/java/com/qiniu/util/UrlUtils.java index f5b8e83e..f39ac88f 100644 --- a/src/main/java/com/qiniu/util/UrlUtils.java +++ b/src/main/java/com/qiniu/util/UrlUtils.java @@ -1,6 +1,8 @@ package com.qiniu.util; import java.io.CharArrayWriter; +import java.net.MalformedURLException; +import java.net.URL; import java.nio.charset.Charset; import java.util.BitSet; @@ -191,6 +193,19 @@ public static String removeHostScheme(String host) { return host; } + public static URL parseHost(String host) { + if (StringUtils.isNullOrEmpty(host)) { + return null; + } + + String tmpHost = setHostScheme(host, true); + try { + return new URL(tmpHost); + } catch (MalformedURLException e) { + return null; + } + } + /** * 如果 host 包含 scheme 则优先使用 host 中包含的 scheme diff --git a/src/test/java/test/com/qiniu/TestConfig.java b/src/test/java/test/com/qiniu/TestConfig.java index 26aaf593..64c5f3bd 100644 --- a/src/test/java/test/com/qiniu/TestConfig.java +++ b/src/test/java/test/com/qiniu/TestConfig.java @@ -346,10 +346,6 @@ public String getRegionId() { public Region getRegion() { return region; } - - public boolean isFog() { - return regionId.equals("fog-cn-east-1"); - } } } diff --git a/src/test/java/test/com/qiniu/processing/PfopTest.java b/src/test/java/test/com/qiniu/processing/PfopTest.java index b1e5a74f..ec6aaf01 100644 --- a/src/test/java/test/com/qiniu/processing/PfopTest.java +++ b/src/test/java/test/com/qiniu/processing/PfopTest.java @@ -13,7 +13,9 @@ import org.junit.jupiter.api.Test; import test.com.qiniu.ResCode; import test.com.qiniu.TestConfig; + import java.util.*; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,9 +33,7 @@ public void testPfop() throws QiniuException { Map bucketKeyMap = new HashMap(); TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile testFile : files) { - if (!testFile.isFog()) { - bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); - } + bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); } List ids = new ArrayList<>(); @@ -55,7 +55,7 @@ public void testPfop() throws QiniuException { String fopMp4 = String.format("avthumb/mp4/vcodec/libx264/s/320x240|saveas/%s", UrlSafeBase64.encodeToString(mp4SaveEntry)); - String fops = StringUtils.join(new String[] { fopM3u8, fopMp4 }, ";"); + String fops = StringUtils.join(new String[]{fopM3u8, fopMp4}, ";"); System.out.println(fops); try { diff --git a/src/test/java/test/com/qiniu/storage/BucketTest.java b/src/test/java/test/com/qiniu/storage/BucketTest.java index 01ac6115..540c3181 100644 --- a/src/test/java/test/com/qiniu/storage/BucketTest.java +++ b/src/test/java/test/com/qiniu/storage/BucketTest.java @@ -509,11 +509,6 @@ public void testFetch() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储不支持 fetch - if (file.isFog()) { - return; - } - try { String resUrl = "http://devtools.qiniu.com/qiniu.png"; String resKey = "qiniu.png"; @@ -972,11 +967,6 @@ public void testPutBucketAccessStyleMode() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储没有域名 - if (file.isFog()) { - return; - } - String bucket = file.getBucketName(); String url = file.getTestUrl(); System.out.println(bucket + " -- " + url); @@ -1590,11 +1580,6 @@ public void testChangeFileType() throws Exception { testFileWithHandler(new TestFileHandler() { @Override public void testFile(TestConfig.TestFile file, BucketManager bucketManager) throws IOException { - // 雾存储不支持 changeType - if (file.isFog()) { - return; - } - String bucket = file.getBucketName(); String key = file.getKey(); String keyToChangeType = "keyToChangeType" + Math.random(); diff --git a/src/test/java/test/com/qiniu/storage/RecordUploadTest.java b/src/test/java/test/com/qiniu/storage/RecordUploadTest.java index 0cd9314e..a38942b6 100644 --- a/src/test/java/test/com/qiniu/storage/RecordUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/RecordUploadTest.java @@ -52,10 +52,6 @@ private void template(final int size, boolean isResumeV2, boolean isConcurrent) TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && !isResumeV2) { - continue; - } String bucket = file.getBucketName(); final Region region = file.getRegion(); diff --git a/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java b/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java index e545607f..505539d1 100644 --- a/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/ResumeUploadTest.java @@ -14,10 +14,12 @@ import org.junit.jupiter.api.Test; import test.com.qiniu.TempFile; import test.com.qiniu.TestConfig; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -33,12 +35,12 @@ public class ResumeUploadTest { private static boolean[][] testConfigList = { // isHttps, isResumeV2, isStream, isConcurrent - { false, true, false, false }, { false, false, false, true }, { false, false, true, false }, - { false, false, true, true }, { false, true, false, false }, { false, true, false, true }, - { false, true, true, false }, { false, true, true, true }, { true, false, false, false }, - { true, false, false, true }, { true, false, true, false }, { true, false, true, true }, - { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, - { true, true, true, true } }; + {false, true, false, false}, {false, false, false, true}, {false, false, true, false}, + {false, false, true, true}, {false, true, false, false}, {false, true, false, true}, + {false, true, true, false}, {false, true, true, true}, {true, false, false, false}, + {true, false, false, true}, {true, false, true, false}, {true, false, true, true}, + {true, true, false, false}, {true, true, false, true}, {true, true, true, false}, + {true, true, true, true}}; /** * 检测自定义变量foo是否生效 @@ -51,10 +53,6 @@ public void testXVar() throws IOException { TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog()) { - continue; - } String bucket = file.getBucketName(); Region region = file.getRegion(); final String expectKey = "世/界"; @@ -99,10 +97,6 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS throws IOException { TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && !isResumeV2) { - continue; - } String bucket = file.getBucketName(); Region region = file.getRegion(); Configuration config = new Configuration(region); @@ -169,14 +163,12 @@ private void template(int size, boolean isHttps, boolean isResumeV2, boolean isS checkMd5 = true; } if (checkMd5) { - if (!file.isFog()) { - String md5 = Md5.md5(f); - String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); - System.out.println(" md5:" + md5); - System.out.println("serverMd5:" + serverMd5); - assertNotNull(serverMd5); - assertEquals(md5, serverMd5); - } + String md5 = Md5.md5(f); + String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); + System.out.println(" md5:" + md5); + System.out.println("serverMd5:" + serverMd5); + assertNotNull(serverMd5); + assertEquals(md5, serverMd5); } else { final String etag = Etag.file(f); System.out.println(" etag:" + etag); diff --git a/src/test/java/test/com/qiniu/storage/StreamUploadTest.java b/src/test/java/test/com/qiniu/storage/StreamUploadTest.java index 3fb42cb0..b72b55d6 100644 --- a/src/test/java/test/com/qiniu/storage/StreamUploadTest.java +++ b/src/test/java/test/com/qiniu/storage/StreamUploadTest.java @@ -14,8 +14,10 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import test.com.qiniu.TestConfig; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -73,9 +75,7 @@ private void template(int size, boolean https) throws IOException { Map bucketKeyMap = new HashMap(); TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile testFile : files) { - if (!testFile.isFog()) { - bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); - } + bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion()); } for (Map.Entry entry : bucketKeyMap.entrySet()) { diff --git a/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java b/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java index 0c42271b..1231c55a 100644 --- a/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java +++ b/src/test/java/test/com/qiniu/storage/SwitchRegionTest.java @@ -15,10 +15,12 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.IOException; import java.net.URLEncoder; @@ -36,13 +38,13 @@ public class SwitchRegionTest { private static final int serialType = 1; private static final int concurrentType = 2; - private static int[][] testConfigList = { { httpType, -1, formType }, { httpType, resumableV1Type, serialType }, - { httpType, resumableV1Type, concurrentType }, { httpType, resumableV2Type, serialType }, - { httpType, resumableV2Type, concurrentType }, + private static int[][] testConfigList = {{httpType, -1, formType}, {httpType, resumableV1Type, serialType}, + {httpType, resumableV1Type, concurrentType}, {httpType, resumableV2Type, serialType}, + {httpType, resumableV2Type, concurrentType}, - { httpsType, -1, formType }, { httpsType, resumableV1Type, serialType }, - { httpsType, resumableV1Type, concurrentType }, { httpsType, resumableV2Type, serialType }, - { httpsType, resumableV2Type, concurrentType }, }; + {httpsType, -1, formType}, {httpsType, resumableV1Type, serialType}, + {httpsType, resumableV1Type, concurrentType}, {httpsType, resumableV2Type, serialType}, + {httpsType, resumableV2Type, concurrentType}}; /** * 分片上传 检测key、hash、fszie、fname是否符合预期 @@ -59,10 +61,6 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t TestConfig.TestFile[] files = TestConfig.getTestFileArray(); for (TestConfig.TestFile file : files) { - // 雾存储不支持 v1 - if (file.isFog() && uploadType == resumableV1Type) { - continue; - } String bucket = file.getBucketName(); Region mockRegion = new Region.Builder().region("custom").srcUpHost("mock.src.host.com") @@ -139,14 +137,12 @@ private void template(int size, int httpType, int uploadType, int uploadStyle) t checkMd5 = true; } if (checkMd5) { - if (!file.isFog()) { - String md5 = Md5.md5(f); - String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); - System.out.println(" md5:" + md5); - System.out.println("serverMd5:" + serverMd5); - assertNotNull(serverMd5); - assertEquals(md5, serverMd5); - } + String md5 = Md5.md5(f); + String serverMd5 = getFileMD5(file.getTestDomain(), expectKey); + System.out.println(" md5:" + md5); + System.out.println("serverMd5:" + serverMd5); + assertNotNull(serverMd5); + assertEquals(md5, serverMd5); } else { final String etag = Etag.file(f); System.out.println(" etag:" + etag);