@@ -22,49 +22,39 @@ public class ZoneInfo {
2222
2323 private static int DOMAIN_FROZEN_SECONDS = 10 * 60 ;
2424
25- private int ttl ;
26- public UploadServerGroup acc ;
27- public UploadServerGroup src ;
28- public UploadServerGroup old_acc ;
29- public UploadServerGroup old_src ;
30-
31- public String regionId ;
32- public ArrayList <String > allHosts ;
25+ public final int ttl ;
26+ public final List <String > domains ;
27+ public final List <String > old_domains ;
28+
29+ public final String regionId ;
30+ public List <String > allHosts ;
3331 public JSONObject detailInfo ;
3432
3533 public static ZoneInfo buildInfo (List <String > mainHosts ,
36- List < String > ioHosts ){
37- return buildInfo (mainHosts , null , ioHosts );
34+ String regionId ){
35+ return buildInfo (mainHosts , null , regionId );
3836 }
3937
4038 public static ZoneInfo buildInfo (List <String > mainHosts ,
4139 List <String > oldHosts ,
42- List < String > ioHosts ){
40+ String regionId ){
4341 if (mainHosts == null ){
4442 return null ;
4543 }
4644
4745 HashMap <String , Object > up = new HashMap <>();
48-
49- HashMap <String , Object > up_acc = new HashMap <>();
50- up_acc .put ("main" , mainHosts );
51- up .put ("acc" , up_acc );
52-
46+ up .put ("domains" , mainHosts );
5347 if (oldHosts != null ){
54- HashMap <String , Object > up_old_acc = new HashMap <>();
55- up_old_acc .put ("main" , oldHosts );
56- up .put ("old_acc" , up_old_acc );
48+ up .put ("old" , oldHosts );
5749 }
5850
59- HashMap <String , Object > io_src = new HashMap <>();
60- HashMap <String , Object > io = new HashMap <>();
61- io_src .put ("main" , (ioHosts != null ? ioHosts : new ArrayList <String >()));
62- io .put ("src" , io_src );
63-
51+ if (regionId == null ){
52+ regionId = EmptyRegionId ;
53+ }
6454 HashMap <String , Object > info = new HashMap <>();
6555 info .put ("ttl" , 86400 *1000 );
56+ info .put ("region" , regionId );
6657 info .put ("up" , up );
67- info .put ("io" , io );
6858
6959 JSONObject object = new JSONObject (info );
7060
@@ -76,16 +66,13 @@ public static ZoneInfo buildInfo(List<String> mainHosts,
7666 }
7767
7868 private ZoneInfo (int ttl ,
79- UploadServerGroup acc ,
80- UploadServerGroup src ,
81- UploadServerGroup old_acc ,
82- UploadServerGroup old_src ) {
83-
69+ String regionId ,
70+ List <String > domains ,
71+ List <String > old_domains ) {
8472 this .ttl = ttl ;
85- this .acc = acc ;
86- this .src = src ;
87- this .old_acc = old_acc ;
88- this .old_src = old_src ;
73+ this .regionId = regionId ;
74+ this .domains = domains ;
75+ this .old_domains = old_domains ;
8976 }
9077
9178 /**
@@ -99,73 +86,49 @@ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException {
9986 return null ;
10087 }
10188
102- int ttl = obj .getInt ("ttl" );
103- List <String > domainsList = new ArrayList <>();
104- ConcurrentHashMap <String , Long > domainsMap = new ConcurrentHashMap <>();
89+ int ttl = obj .optInt ("ttl" );
90+ String regionId = obj .optString ("region" );
91+ if (regionId == null ){
92+ regionId = EmptyRegionId ;
93+ }
10594
106- String io_host = "null" ;
107- try {
108- JSONObject io = obj .getJSONObject ("io" );
109- JSONObject io_src = io .getJSONObject ("src" );
110- JSONArray io_main = io_src .getJSONArray ("main" );
111- io_host = io_main .length () > 0 ? io_main .getString (0 ) : "null" ;
112- } catch (JSONException e ){}
113-
114- String zoneRegion = "unknown" ;
115- if (io_host .equals ("iovip.qbox.me" )){
116- zoneRegion = "z0" ;
117- } else if (io_host .equals ("iovip-z1.qbox.me" )){
118- zoneRegion = "z1" ;
119- } else if (io_host .equals ("iovip-z2.qbox.me" )){
120- zoneRegion = "z2" ;
121- } else if (io_host .equals ("iovip-na0.qbox.me" )){
122- zoneRegion = "na0" ;
123- } else if (io_host .equals ("iovip-as0.qbox.me" )){
124- zoneRegion = "as0" ;
125- } else if (io_host .equals (SDKDefaultIOHost )){
126- zoneRegion = EmptyRegionId ;
95+ JSONObject up = obj .optJSONObject ("up" );
96+ if (up == null ){
97+ return null ;
12798 }
12899
129- JSONObject up = obj .getJSONObject ("up" );
100+ List <String > allHosts = new ArrayList <>();
101+ List <String > domains = new ArrayList <>();
102+ JSONArray domainsJson = up .optJSONArray ("domains" );
103+ if (domainsJson != null && domainsJson .length () > 0 ){
104+ for (int i =0 ; i < domainsJson .length (); i ++) {
105+ String domain = domainsJson .optString (i );
106+ if (domain != null && domain .length () > 0 ){
107+ domains .add (domain );
108+ allHosts .add (domain );
109+ }
110+ }
111+ }
130112
131- JSONObject acc = null ;
132- JSONObject src = null ;
133- JSONObject old_acc = null ;
134- JSONObject old_src = null ;
135- try {
136- acc = up .getJSONObject ("acc" );;
137- } catch (JSONException e ) {}
138- try {
139- src = up .getJSONObject ("src" );;
140- } catch (JSONException e ) {}
141- try {
142- old_acc = up .getJSONObject ("old_acc" );;
143- } catch (JSONException e ) {}
144- try {
145- old_src = up .getJSONObject ("old_src" );;
146- } catch (JSONException e ) {}
113+ List <String > old_domains = new ArrayList <>();
114+ JSONArray old_domainsJson = up .optJSONArray ("old" );
115+ if (old_domainsJson != null && old_domainsJson .length () > 0 ){
116+ for (int i =0 ; i < old_domainsJson .length (); i ++) {
117+ String domain = old_domainsJson .optString (i );
118+ if (domain != null && domain .length () > 0 ){
119+ old_domains .add (domain );
120+ allHosts .add (domain );
121+ }
122+ }
123+ }
147124
148- ZoneInfo zoneInfo = new ZoneInfo (ttl ,
149- UploadServerGroup .buildInfoFromJson (acc ),
150- UploadServerGroup .buildInfoFromJson (src ),
151- UploadServerGroup .buildInfoFromJson (old_acc ),
152- UploadServerGroup .buildInfoFromJson (old_src ));
153- zoneInfo .regionId = zoneRegion ;
125+ if (domains .size () == 0 && old_domains .size () == 0 ){
126+ return null ;
127+ }
128+
129+ ZoneInfo zoneInfo = new ZoneInfo (ttl , regionId , domains , old_domains );
154130 zoneInfo .detailInfo = obj ;
155131
156- ArrayList <String > allHosts = new ArrayList <>();
157- if (zoneInfo .acc != null && zoneInfo .acc .allHosts != null ){
158- allHosts .addAll (zoneInfo .acc .allHosts );
159- }
160- if (zoneInfo .src != null && zoneInfo .src .allHosts != null ){
161- allHosts .addAll (zoneInfo .src .allHosts );
162- }
163- if (zoneInfo .old_acc != null && zoneInfo .old_acc .allHosts != null ){
164- allHosts .addAll (zoneInfo .old_acc .allHosts );
165- }
166- if (zoneInfo .old_src != null && zoneInfo .old_src .allHosts != null ){
167- allHosts .addAll (zoneInfo .old_src .allHosts );
168- }
169132 zoneInfo .allHosts = allHosts ;
170133
171134 return zoneInfo ;
0 commit comments