Authored by zhouxiang

no message

... ... @@ -16,11 +16,11 @@ default_err_code=9999991
default_err_msg="系统正忙,请稍后重试!"
--limit interface
limit_config={
{@{#each limit_config}@}{@{this}@}
{@{#each limit_config}@}{@{{this}}@}
{@{/each}@}
}
limit_service_config={
{@{#each limit_service_config}@}{@{this}@}
{@{#each limit_service_config}@}{@{{this}}@}
{@{/each}@}
}
... ...
... ... @@ -10,6 +10,7 @@ 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.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
... ... @@ -22,6 +23,8 @@ import java.util.Map;
/**
* Created by zhouxiang on 2016/10/25.
*/
@Controller
@RequestMapping("lbswitch")
public class LbSwitchCtrl {
private Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -40,9 +43,9 @@ public class LbSwitchCtrl {
@ResponseBody
public Map<String,String> viewConf() throws Exception {
//直连的配置放在腾讯云nginx上
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", 2);
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("直连");
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
throw new Exception("没有找到nginx服务器");
throw new Exception("没有找到直连nginx服务器");
}
return analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null));
}
... ... @@ -52,15 +55,15 @@ public class LbSwitchCtrl {
*
* @return 2016年5月12日下午1:49:48
*/
@RequestMapping(value = "viewToChangeLuaConf")
@RequestMapping(value = "viewToChangeLbConf")
@ResponseBody
public BaseResponse viewToChangeLuaConf(String status, HttpServletRequest request) throws Exception {
logger.info("will change status {}", status);
if(!StringUtils.equals("open", status) && !StringUtils.equals("close", status)){
if(!StringUtils.equals("1", status) && !StringUtils.equals("0", status)){
throw new Exception("切换状态参数不正确!");
}
Map<String, Object> map = new HashMap();
map.put("open_dl", StringUtils.equals("open", status) ? OPENDL : CLOSEDL);
map.put("open_dl", StringUtils.equals("1", status) ? OPENDL : CLOSEDL);
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
String result = HandlebarsUtils.replace(map, "template/lb", path);
return new BaseResponse(200, "success", result);
... ... @@ -76,7 +79,7 @@ public class LbSwitchCtrl {
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
logger.info("lb.lua template path {}", path);
//lua dns 只放在腾讯云nginx服务器上
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", 2);
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTag("直连");
if (CollectionUtils.isEmpty(nginxHosts)) {
return new BaseResponse(500, "在cmdb中未找到直连对应的nginx服务器!");
}
... ... @@ -117,11 +120,11 @@ public class LbSwitchCtrl {
result.put("conf",sb.toString());
String dl = str[i].substring(str[i].indexOf("\"")).replaceAll("\"","").trim();
if(StringUtils.equals(OPENDL,dl)){
result.put("status","open");
result.put("status","1");
return result;
}
if(StringUtils.equals(CLOSEDL,dl)){
result.put("status","close");
result.put("status","0");
return result;
}
}
... ...
... ... @@ -12,6 +12,7 @@ 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.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
... ... @@ -25,6 +26,8 @@ import java.util.Map;
/**
* Created by zhouxiang on 2016/10/25.
*/
@Controller
@RequestMapping("limitswitch")
public class NginxLimit {
private Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -40,7 +43,7 @@ public class NginxLimit {
@RequestMapping(value = "viewConf")
@ResponseBody
public Map<String,Object> viewConf() throws Exception {
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", 2);
List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("限流");
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
throw new Exception("没有找到限流nginx服务器");
}
... ... @@ -52,7 +55,7 @@ public class NginxLimit {
*
* @return 2016年5月12日下午1:49:48
*/
@RequestMapping(value = "viewToChangeLuaConf")
@RequestMapping(value = "viewToChangeLimitConf")
@ResponseBody
public BaseResponse viewToChangeLuaConf(String limitFlow, String apiConfs, String serviceConfs, HttpServletRequest request) {
logger.info("limitFlow {} apiConfig {} serviceCong {}", limitFlow,apiConfs,serviceConfs);
... ... @@ -87,11 +90,11 @@ public class NginxLimit {
*
* @return 2016年5月12日下午1:49:48
*/
@RequestMapping(value = "switchLuaConf")
@RequestMapping(value = "switchConf")
@ResponseBody
public BaseResponse switchNginxConf(HttpServletRequest httpRequest) {
//获取对应cloud的机器 aws 1 qcloud 2
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTag("nginx_limit");
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTag("限流");
if (CollectionUtils.isEmpty(nginxHosts)) {
return new BaseResponse(500, "在cmdb中未找到限流对应的nginx服务器!");
}
... ...