TopoSwitchUtil.java
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.ui.ctrl;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class TopoSwitchUtil {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
HttpRestClient httpRestClient;
public String getLuaType(){
String luaResponse = httpRestClient.defaultGet(HttpUriContants.VIEW_LUA_CONF, String.class, null);
String luaType = "";
if(StringUtils.isNotBlank(luaResponse)){
if (luaResponse.matches(".*context.cloud_flag\\s*=\\s*2.*")) {
luaType = "qq";
} else if (luaResponse.matches(".*context.cloud_flag\\s*=\\s*3.*")) {
luaType = "aws+qq";
} else{
luaType = "aws";
}
}
return luaType;
}
public List<String> getNginxLocationType(List<String> az1HostIps ,List<String> az2HostIps ,
List<String> grayHostIps,List<Map<String, Object>> qcloudList){
List<String> ls=new ArrayList<>();
String qqApiNginx = "";
String qqGrayNginx = "";
for (Map<String, Object> apiMap : qcloudList) {
if (StringUtils.equals("apigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
String tmpServerRecord=serverList.get(0);
String tmpServerIp=tmpServerRecord.substring(0,tmpServerRecord.indexOf(":"));
if(az1HostIps.contains(tmpServerIp)){
qqApiNginx = "qq";
}else if(az2HostIps.contains(tmpServerIp)){
qqApiNginx = "az2";
}
}
if (StringUtils.equals("grayapigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
logger.error("qqgrayapigateway is === "+serverList.get(0));
String tmpServerRecord=serverList.get(0);
String tmpServerIp=tmpServerRecord.substring(0,tmpServerRecord.indexOf(":"));
boolean grayFlag=false;
for(String grayIp:grayHostIps){
if(tmpServerIp.startsWith(grayIp)){
grayFlag=true;
break;
}
}
if(grayFlag){
qqGrayNginx = "gray";
}else{
if(az1HostIps.contains(tmpServerIp)){
qqGrayNginx = "qq";
}else if(az2HostIps.contains(tmpServerIp)){
qqGrayNginx = "az2";
}
}
}
}
ls.add(qqApiNginx);
ls.add(qqGrayNginx);
return ls;
}
}