Authored by zhouxiang

直连 限流

... ... @@ -9,7 +9,7 @@ local redis1=redis_util:new(redis_config1)
lua_context={}
lua_context["redises"]={redis1}
open_limit_flow=false
open_limit_flow={@{open_limit_flow}@}
api_default_max_per_sencond=1000
service_default_max_per_sencond=1000
default_err_code=9999991
... ...
... ... @@ -6,7 +6,7 @@ local icutil = require "iconfig_util"
--5b2d8b4b242e067616c6cd98851b2306 close
--2a90dfa0f37b92aaebf369e9a4d38ba4 open
local open_dl = {@{open_dl}@}
local open_dl = "{@{open_dl}@}"
local close_dl = "5b2d8b4b242e067616c6cd98851b2306"
... ...
... ... @@ -39,6 +39,16 @@ public class CommodUtil {
*/
public static final String LUA_SWITCH_SH = "switch_lua.sh";
/**
* 直连lua
*/
public static final String LB_SWITCH_SH = "switch_lb.sh";
/**
* 限流
*/
public static final String LIMIT_SWITCH_SH = "nginx_limit.sh";
public static String exe(String commond, String param) {
logger.info("start to exe commond:{},param:{}",commond,param);
Process process = null;
... ...
... ... @@ -41,13 +41,13 @@ public class LbSwitchCtrl {
*/
@RequestMapping(value = "viewConf")
@ResponseBody
public Map<String,String> viewConf() throws Exception {
public BaseResponse viewConf() throws Exception {
//直连的配置放在腾讯云nginx上
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)));
}
/**
... ... @@ -101,7 +101,7 @@ public class LbSwitchCtrl {
public String exe(String commod, String host, String templatePath) {
StringBuilder commond = new StringBuilder();
commond.append(" " + commod).append(" " + host).append(" " + templatePath);
return CommodUtil.exe(CommodUtil.LUA_SWITCH_SH, commond.toString());
return CommodUtil.exe(CommodUtil.LB_SWITCH_SH, commond.toString());
}
private Map<String,String> analyseConfigFile(String rlt) {
... ...
... ... @@ -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(",",""));
... ...