...
|
...
|
@@ -13,6 +13,7 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
...
|
...
|
@@ -42,12 +43,12 @@ public class NginxLimit { |
|
|
*/
|
|
|
@RequestMapping(value = "viewConf")
|
|
|
@ResponseBody
|
|
|
public Map<String,Object> viewConf() throws Exception {
|
|
|
public BaseResponse viewConf() throws Exception {
|
|
|
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("限流");
|
|
|
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
|
|
|
throw new Exception("没有找到限流nginx服务器");
|
|
|
}
|
|
|
return analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null));
|
|
|
return new BaseResponse(200,"success",analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null)));
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -57,11 +58,11 @@ public class NginxLimit { |
|
|
*/
|
|
|
@RequestMapping(value = "viewToChangeLimitConf")
|
|
|
@ResponseBody
|
|
|
public BaseResponse viewToChangeLuaConf(String limitFlow, String apiConfs, String serviceConfs, HttpServletRequest request) {
|
|
|
logger.info("limitFlow {} apiConfig {} serviceCong {}", limitFlow,apiConfs,serviceConfs);
|
|
|
public BaseResponse viewToChangeLuaConf(@RequestBody Map<String,String> params, HttpServletRequest request) {
|
|
|
logger.info("params {}", params);
|
|
|
Map<String, Object> map = new HashMap();
|
|
|
map.put("open_limit_flow", limitFlow);
|
|
|
List apiConfigList = JSON.parseArray(apiConfs,String.class);
|
|
|
map.put("open_limit_flow", params.get("limitFlow"));
|
|
|
List apiConfigList = JSON.parseArray(params.get("apiConfs"),String.class);
|
|
|
int apiConfigSize = apiConfigList.size();
|
|
|
for(int i = 0;i< apiConfigSize;i++){
|
|
|
if(i == (apiConfigSize -1)){
|
...
|
...
|
@@ -70,7 +71,7 @@ public class NginxLimit { |
|
|
apiConfigList.set(i,apiConfigList.get(i)+",");
|
|
|
}
|
|
|
map.put("limit_config", apiConfigList);
|
|
|
List serviceConfList = JSON.parseArray(serviceConfs,String.class);
|
|
|
List serviceConfList = JSON.parseArray(params.get("serviceConfs"),String.class);
|
|
|
int serviceConfSize = serviceConfList.size();
|
|
|
for(int i = 0;i< serviceConfSize;i++){
|
|
|
if(i == (serviceConfSize -1)){
|
...
|
...
|
@@ -117,7 +118,7 @@ public class NginxLimit { |
|
|
public String exe(String commod, String host, String templatePath) {
|
|
|
StringBuilder commond = new StringBuilder();
|
|
|
commond.append(" " + commod).append(" " + host).append(" " + templatePath);
|
|
|
return CommodUtil.exe(CommodUtil.NGINX_SWITCH_SH, commond.toString());
|
|
|
return CommodUtil.exe(CommodUtil.LIMIT_SWITCH_SH, commond.toString());
|
|
|
}
|
|
|
|
|
|
private Map<String,Object> analyseConfigFile(String str) throws IOException {
|
...
|
...
|
@@ -128,7 +129,7 @@ public class NginxLimit { |
|
|
break;
|
|
|
}
|
|
|
if(strs[i].contains("open_limit_flow")){
|
|
|
map.put("limit_flow",strs[i].trim());
|
|
|
map.put("open_limit_flow",strs[i].trim().split("=")[1]);
|
|
|
continue;
|
|
|
}
|
|
|
if(strs[i].contains("limit_config") || strs[i].contains("limit_service_config")){
|
...
|
...
|
@@ -139,7 +140,7 @@ public class NginxLimit { |
|
|
if(!strs[i].trim().startsWith("[") && strs[i].trim().endsWith("}")){
|
|
|
break;
|
|
|
}
|
|
|
if(strs[i].trim().startsWith("--")){
|
|
|
if(StringUtils.isEmpty(strs[i].trim()) || strs[i].trim().startsWith("--")){
|
|
|
continue;
|
|
|
}
|
|
|
limitConf.add(strs[i].trim().replace(",",""));
|
...
|
...
|
|