-
Notifications
You must be signed in to change notification settings - Fork 225
version 8: uc query v3 to v4 #411
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ecc730
uc query api to v4
3fa23ce
优化 dns prefetch
097df4d
modify dns cache file create logic and optimize dns cache info create…
bf758bc
upload manager complete func add sync logic
d64abc2
modify dns cache logic
13eef78
modify dns cache logic
2edc81b
Merge branch 'refactor' into uc_query_v4
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,49 +22,39 @@ public class ZoneInfo { | |
|
|
||
| private static int DOMAIN_FROZEN_SECONDS = 10 * 60; | ||
|
|
||
| private int ttl; | ||
| public UploadServerGroup acc; | ||
| public UploadServerGroup src; | ||
| public UploadServerGroup old_acc; | ||
| public UploadServerGroup old_src; | ||
|
|
||
| public String regionId; | ||
| public ArrayList<String> allHosts; | ||
| public final int ttl; | ||
| public final List<String> domains; | ||
| public final List<String> old_domains; | ||
|
|
||
| public final String regionId; | ||
| public List<String> allHosts; | ||
| public JSONObject detailInfo; | ||
|
|
||
| public static ZoneInfo buildInfo(List<String> mainHosts, | ||
| List<String> ioHosts){ | ||
| return buildInfo(mainHosts, null, ioHosts); | ||
| String regionId){ | ||
| return buildInfo(mainHosts, null, regionId); | ||
| } | ||
|
|
||
| public static ZoneInfo buildInfo(List<String> mainHosts, | ||
| List<String> oldHosts, | ||
| List<String> ioHosts){ | ||
| String regionId){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 公开接口变更,应该有文档注明 |
||
| if (mainHosts == null){ | ||
| return null; | ||
| } | ||
|
|
||
| HashMap<String, Object> up = new HashMap<>(); | ||
|
|
||
| HashMap<String, Object> up_acc = new HashMap<>(); | ||
| up_acc.put("main", mainHosts); | ||
| up.put("acc", up_acc); | ||
|
|
||
| up.put("domains", mainHosts); | ||
| if (oldHosts != null){ | ||
| HashMap<String, Object> up_old_acc = new HashMap<>(); | ||
| up_old_acc.put("main", oldHosts); | ||
| up.put("old_acc", up_old_acc); | ||
| up.put("old", oldHosts); | ||
| } | ||
|
|
||
| HashMap<String, Object> io_src = new HashMap<>(); | ||
| HashMap<String, Object> io = new HashMap<>(); | ||
| io_src.put("main", (ioHosts != null ? ioHosts : new ArrayList<String>())); | ||
| io.put("src", io_src); | ||
|
|
||
| if (regionId == null){ | ||
| regionId = EmptyRegionId; | ||
| } | ||
| HashMap<String, Object> info = new HashMap<>(); | ||
| info.put("ttl", 86400*1000); | ||
| info.put("region", regionId); | ||
| info.put("up", up); | ||
| info.put("io", io); | ||
|
|
||
| JSONObject object = new JSONObject(info); | ||
|
|
||
|
|
@@ -76,16 +66,13 @@ public static ZoneInfo buildInfo(List<String> mainHosts, | |
| } | ||
|
|
||
| private ZoneInfo(int ttl, | ||
| UploadServerGroup acc, | ||
| UploadServerGroup src, | ||
| UploadServerGroup old_acc, | ||
| UploadServerGroup old_src) { | ||
|
|
||
| String regionId, | ||
| List<String> domains, | ||
| List<String> old_domains) { | ||
| this.ttl = ttl; | ||
| this.acc = acc; | ||
| this.src = src; | ||
| this.old_acc = old_acc; | ||
| this.old_src = old_src; | ||
| this.regionId = regionId; | ||
| this.domains = domains; | ||
| this.old_domains = old_domains; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -99,73 +86,49 @@ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException { | |
| return null; | ||
| } | ||
|
|
||
| int ttl = obj.getInt("ttl"); | ||
| List<String> domainsList = new ArrayList<>(); | ||
| ConcurrentHashMap<String, Long> domainsMap = new ConcurrentHashMap<>(); | ||
| int ttl = obj.optInt("ttl"); | ||
| String regionId = obj.optString("region"); | ||
| if (regionId == null){ | ||
| regionId = EmptyRegionId; | ||
| } | ||
|
|
||
| String io_host = "null"; | ||
| try { | ||
| JSONObject io = obj.getJSONObject("io"); | ||
| JSONObject io_src = io.getJSONObject("src"); | ||
| JSONArray io_main = io_src.getJSONArray("main"); | ||
| io_host = io_main.length() > 0 ? io_main.getString(0) : "null"; | ||
| } catch (JSONException e){} | ||
|
|
||
| String zoneRegion = "unknown"; | ||
| if (io_host.equals("iovip.qbox.me")){ | ||
| zoneRegion = "z0"; | ||
| } else if (io_host.equals("iovip-z1.qbox.me")){ | ||
| zoneRegion = "z1"; | ||
| } else if (io_host.equals("iovip-z2.qbox.me")){ | ||
| zoneRegion = "z2"; | ||
| } else if (io_host.equals("iovip-na0.qbox.me")){ | ||
| zoneRegion = "na0"; | ||
| } else if (io_host.equals("iovip-as0.qbox.me")){ | ||
| zoneRegion = "as0"; | ||
| } else if (io_host.equals(SDKDefaultIOHost)){ | ||
| zoneRegion = EmptyRegionId; | ||
| JSONObject up = obj.optJSONObject("up"); | ||
| if (up == null){ | ||
| return null; | ||
| } | ||
|
|
||
| JSONObject up = obj.getJSONObject("up"); | ||
| List<String> allHosts = new ArrayList<>(); | ||
| List<String> domains = new ArrayList<>(); | ||
| JSONArray domainsJson = up.optJSONArray("domains"); | ||
| if (domainsJson != null && domainsJson.length() > 0){ | ||
| for (int i=0; i< domainsJson.length(); i++) { | ||
| String domain = domainsJson.optString(i); | ||
| if (domain != null && domain.length() > 0){ | ||
| domains.add(domain); | ||
| allHosts.add(domain); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| JSONObject acc = null; | ||
| JSONObject src = null; | ||
| JSONObject old_acc = null; | ||
| JSONObject old_src = null; | ||
| try { | ||
| acc = up.getJSONObject("acc");; | ||
| } catch (JSONException e) {} | ||
| try { | ||
| src = up.getJSONObject("src");; | ||
| } catch (JSONException e) {} | ||
| try { | ||
| old_acc = up.getJSONObject("old_acc");; | ||
| } catch (JSONException e) {} | ||
| try { | ||
| old_src = up.getJSONObject("old_src");; | ||
| } catch (JSONException e) {} | ||
| List<String> old_domains = new ArrayList<>(); | ||
| JSONArray old_domainsJson = up.optJSONArray("old"); | ||
| if (old_domainsJson != null && old_domainsJson.length() > 0){ | ||
| for (int i=0; i< old_domainsJson.length(); i++) { | ||
| String domain = old_domainsJson.optString(i); | ||
| if (domain != null && domain.length() > 0){ | ||
| old_domains.add(domain); | ||
| allHosts.add(domain); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ZoneInfo zoneInfo = new ZoneInfo(ttl, | ||
| UploadServerGroup.buildInfoFromJson(acc), | ||
| UploadServerGroup.buildInfoFromJson(src), | ||
| UploadServerGroup.buildInfoFromJson(old_acc), | ||
| UploadServerGroup.buildInfoFromJson(old_src)); | ||
| zoneInfo.regionId = zoneRegion; | ||
| if (domains.size() == 0 && old_domains.size() == 0){ | ||
| return null; | ||
| } | ||
|
|
||
| ZoneInfo zoneInfo = new ZoneInfo(ttl, regionId, domains, old_domains); | ||
| zoneInfo.detailInfo = obj; | ||
|
|
||
| ArrayList<String> allHosts = new ArrayList<>(); | ||
| if (zoneInfo.acc != null && zoneInfo.acc.allHosts != null){ | ||
| allHosts.addAll(zoneInfo.acc.allHosts); | ||
| } | ||
| if (zoneInfo.src != null && zoneInfo.src.allHosts != null){ | ||
| allHosts.addAll(zoneInfo.src.allHosts); | ||
| } | ||
| if (zoneInfo.old_acc != null && zoneInfo.old_acc.allHosts != null){ | ||
| allHosts.addAll(zoneInfo.old_acc.allHosts); | ||
| } | ||
| if (zoneInfo.old_src != null && zoneInfo.old_src.allHosts != null){ | ||
| allHosts.addAll(zoneInfo.old_src.allHosts); | ||
| } | ||
| zoneInfo.allHosts = allHosts; | ||
|
|
||
| return zoneInfo; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
公开接口变更,应该有文档注明