TopoSwitchCtrl.java
5.96 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.ui.ctrl;
import com.alibaba.fastjson.JSONObject;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 限流调整
*
* @author bblu 2016-10-26
*/
@Controller
@RequestMapping("topoSwitch")
public class TopoSwitchCtrl {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
HttpRestClient httpRestClient;
@RequestMapping(value = "toTopoSwitch")
public ModelAndView toTopoSwitch() {
ModelAndView mdv = new ModelAndView("switch/switch_topology");
return mdv;
}
@RequestMapping(value = "toAppTopoSwitch")
public ModelAndView toAppTopoSwitch() {
ModelAndView mdv = new ModelAndView("switch/switch_topology_app");
return mdv;
}
/**
* 展示当前配置
*
* @return ModelAndView
*/
@RequestMapping(value = "getNgixnStatus")
@ResponseBody
public BaseResponse getNgixnStatus() {
Map<String, Object> resultMap = new HashMap<>();
try{
//lua
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";
}
}
//nginx
BaseResponse<Map<String, List<Map<String, Object>>>> response = httpRestClient.exchangeForget(HttpUriContants.VIEW_NGINX_CONF, new ParameterizedTypeReference<BaseResponse<Map<String, List<Map<String, Object>>>>>() {
}, null);
Map<String, List<Map<String, Object>>> map = response.getData();
List<Map<String, Object>> awsList = map.get("awsList");
List<Map<String, Object>> qcloudList = map.get("qcloudList");
String awsApiNginx = "aws";
String awsGrayNginx = "aws";
String qqApiNginx = "qq";
String qqGrayNginx = "qq";
for (Map<String, Object> apiMap : awsList) {
if (StringUtils.equals("apigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
if (serverList.get(0).startsWith("10")) {
awsApiNginx = "qq";
}
}
if (StringUtils.equals("grayapigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
if (serverList.get(0).startsWith("10")) {
awsGrayNginx = "qq";
}
}
}
for (Map<String, Object> apiMap : qcloudList) {
if (StringUtils.equals("apigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
if (serverList.get(0).startsWith("172")) {
qqApiNginx = "aws";
}
}
if (StringUtils.equals("grayapigateway", String.valueOf(apiMap.get("name")))) {
List<String> serverList = (List<String>) apiMap.get("server");
if (serverList.get(0).startsWith("172")) {
qqGrayNginx = "aws";
}
}
}
//dns
String defaultDns = "";
MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
requestEntity.add("login_token", "31578,5f5402160468dc375159e2e94eeef1da");
requestEntity.add("format","json");
requestEntity.add("domain_id", "16862974");
requestEntity.add("record_id","293178513");
try{
String requestResponse = httpRestClient.post("https://dnsapi.cn/Record.Info", requestEntity, String.class);
JSONObject responseJSON = JSONObject.parseObject(requestResponse);
JSONObject responseStatus = JSONObject.parseObject(responseJSON.getString("status"));
if ("1".equals(responseStatus.getString("code"))){
if (requestResponse.indexOf("amazonaws") == -1){
defaultDns = "qq";
}else{
defaultDns = "aws";
}
}else{
logger.error(" TopoSwitchCtrl - getNgixnStatus - JSON - err:" + responseJSON.getString("message"));
}
}catch (Exception e){
logger.error(" TopoSwitchCtrl - getNgixnStatus - https://dnsapi.cn/Record.Info - err", e);
}
resultMap.put("luaType", luaType);
resultMap.put("awsApiNginx", awsApiNginx);
resultMap.put("awsGrayNginx", awsGrayNginx);
resultMap.put("qqApiNginx", qqApiNginx);
resultMap.put("qqGrayNginx", qqGrayNginx);
resultMap.put("defaultDns", defaultDns);
}catch (Exception e){
logger.error(" TopoSwitchCtrl - getNgixnStatus - err", e);
}
return new BaseResponse(resultMap);
}
}