...
|
...
|
@@ -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;
|
|
|
}
|
|
|
}
|
...
|
...
|
|