|
@@ -13,6 +13,7 @@ import org.slf4j.Logger; |
|
@@ -13,6 +13,7 @@ import org.slf4j.Logger; |
13
|
import org.slf4j.LoggerFactory;
|
13
|
import org.slf4j.LoggerFactory;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.stereotype.Controller;
|
15
|
import org.springframework.stereotype.Controller;
|
|
|
16
|
+import org.springframework.web.bind.annotation.RequestBody;
|
16
|
import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
import org.springframework.web.bind.annotation.ResponseBody;
|
18
|
import org.springframework.web.bind.annotation.ResponseBody;
|
18
|
|
19
|
|
|
@@ -42,12 +43,12 @@ public class NginxLimit { |
|
@@ -42,12 +43,12 @@ public class NginxLimit { |
42
|
*/
|
43
|
*/
|
43
|
@RequestMapping(value = "viewConf")
|
44
|
@RequestMapping(value = "viewConf")
|
44
|
@ResponseBody
|
45
|
@ResponseBody
|
45
|
- public Map<String,Object> viewConf() throws Exception {
|
46
|
+ public BaseResponse viewConf() throws Exception {
|
46
|
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("限流");
|
47
|
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("限流");
|
47
|
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
|
48
|
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
|
48
|
throw new Exception("没有找到限流nginx服务器");
|
49
|
throw new Exception("没有找到限流nginx服务器");
|
49
|
}
|
50
|
}
|
50
|
- return analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null));
|
51
|
+ return new BaseResponse(200,"success",analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null)));
|
51
|
}
|
52
|
}
|
52
|
|
53
|
|
53
|
/**
|
54
|
/**
|
|
@@ -57,11 +58,11 @@ public class NginxLimit { |
|
@@ -57,11 +58,11 @@ public class NginxLimit { |
57
|
*/
|
58
|
*/
|
58
|
@RequestMapping(value = "viewToChangeLimitConf")
|
59
|
@RequestMapping(value = "viewToChangeLimitConf")
|
59
|
@ResponseBody
|
60
|
@ResponseBody
|
60
|
- public BaseResponse viewToChangeLuaConf(String limitFlow, String apiConfs, String serviceConfs, HttpServletRequest request) {
|
|
|
61
|
- logger.info("limitFlow {} apiConfig {} serviceCong {}", limitFlow,apiConfs,serviceConfs);
|
61
|
+ public BaseResponse viewToChangeLuaConf(@RequestBody Map<String,String> params, HttpServletRequest request) {
|
|
|
62
|
+ logger.info("params {}", params);
|
62
|
Map<String, Object> map = new HashMap();
|
63
|
Map<String, Object> map = new HashMap();
|
63
|
- map.put("open_limit_flow", limitFlow);
|
|
|
64
|
- List apiConfigList = JSON.parseArray(apiConfs,String.class);
|
64
|
+ map.put("open_limit_flow", params.get("limitFlow"));
|
|
|
65
|
+ List apiConfigList = JSON.parseArray(params.get("apiConfs"),String.class);
|
65
|
int apiConfigSize = apiConfigList.size();
|
66
|
int apiConfigSize = apiConfigList.size();
|
66
|
for(int i = 0;i< apiConfigSize;i++){
|
67
|
for(int i = 0;i< apiConfigSize;i++){
|
67
|
if(i == (apiConfigSize -1)){
|
68
|
if(i == (apiConfigSize -1)){
|
|
@@ -70,7 +71,7 @@ public class NginxLimit { |
|
@@ -70,7 +71,7 @@ public class NginxLimit { |
70
|
apiConfigList.set(i,apiConfigList.get(i)+",");
|
71
|
apiConfigList.set(i,apiConfigList.get(i)+",");
|
71
|
}
|
72
|
}
|
72
|
map.put("limit_config", apiConfigList);
|
73
|
map.put("limit_config", apiConfigList);
|
73
|
- List serviceConfList = JSON.parseArray(serviceConfs,String.class);
|
74
|
+ List serviceConfList = JSON.parseArray(params.get("serviceConfs"),String.class);
|
74
|
int serviceConfSize = serviceConfList.size();
|
75
|
int serviceConfSize = serviceConfList.size();
|
75
|
for(int i = 0;i< serviceConfSize;i++){
|
76
|
for(int i = 0;i< serviceConfSize;i++){
|
76
|
if(i == (serviceConfSize -1)){
|
77
|
if(i == (serviceConfSize -1)){
|
|
@@ -117,7 +118,7 @@ public class NginxLimit { |
|
@@ -117,7 +118,7 @@ public class NginxLimit { |
117
|
public String exe(String commod, String host, String templatePath) {
|
118
|
public String exe(String commod, String host, String templatePath) {
|
118
|
StringBuilder commond = new StringBuilder();
|
119
|
StringBuilder commond = new StringBuilder();
|
119
|
commond.append(" " + commod).append(" " + host).append(" " + templatePath);
|
120
|
commond.append(" " + commod).append(" " + host).append(" " + templatePath);
|
120
|
- return CommodUtil.exe(CommodUtil.NGINX_SWITCH_SH, commond.toString());
|
121
|
+ return CommodUtil.exe(CommodUtil.LIMIT_SWITCH_SH, commond.toString());
|
121
|
}
|
122
|
}
|
122
|
|
123
|
|
123
|
private Map<String,Object> analyseConfigFile(String str) throws IOException {
|
124
|
private Map<String,Object> analyseConfigFile(String str) throws IOException {
|
|
@@ -128,7 +129,7 @@ public class NginxLimit { |
|
@@ -128,7 +129,7 @@ public class NginxLimit { |
128
|
break;
|
129
|
break;
|
129
|
}
|
130
|
}
|
130
|
if(strs[i].contains("open_limit_flow")){
|
131
|
if(strs[i].contains("open_limit_flow")){
|
131
|
- map.put("limit_flow",strs[i].trim());
|
132
|
+ map.put("open_limit_flow",strs[i].trim().split("=")[1]);
|
132
|
continue;
|
133
|
continue;
|
133
|
}
|
134
|
}
|
134
|
if(strs[i].contains("limit_config") || strs[i].contains("limit_service_config")){
|
135
|
if(strs[i].contains("limit_config") || strs[i].contains("limit_service_config")){
|
|
@@ -139,7 +140,7 @@ public class NginxLimit { |
|
@@ -139,7 +140,7 @@ public class NginxLimit { |
139
|
if(!strs[i].trim().startsWith("[") && strs[i].trim().endsWith("}")){
|
140
|
if(!strs[i].trim().startsWith("[") && strs[i].trim().endsWith("}")){
|
140
|
break;
|
141
|
break;
|
141
|
}
|
142
|
}
|
142
|
- if(strs[i].trim().startsWith("--")){
|
143
|
+ if(StringUtils.isEmpty(strs[i].trim()) || strs[i].trim().startsWith("--")){
|
143
|
continue;
|
144
|
continue;
|
144
|
}
|
145
|
}
|
145
|
limitConf.add(strs[i].trim().replace(",",""));
|
146
|
limitConf.add(strs[i].trim().replace(",",""));
|