|
@@ -10,6 +10,7 @@ import org.apache.commons.lang.StringUtils; |
|
@@ -10,6 +10,7 @@ import org.apache.commons.lang.StringUtils; |
10
|
import org.slf4j.Logger;
|
10
|
import org.slf4j.Logger;
|
11
|
import org.slf4j.LoggerFactory;
|
11
|
import org.slf4j.LoggerFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13
|
+import org.springframework.stereotype.Controller;
|
13
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
import org.springframework.web.bind.annotation.ResponseBody;
|
15
|
import org.springframework.web.bind.annotation.ResponseBody;
|
15
|
|
16
|
|
|
@@ -22,6 +23,8 @@ import java.util.Map; |
|
@@ -22,6 +23,8 @@ import java.util.Map; |
22
|
/**
|
23
|
/**
|
23
|
* Created by zhouxiang on 2016/10/25.
|
24
|
* Created by zhouxiang on 2016/10/25.
|
24
|
*/
|
25
|
*/
|
|
|
26
|
+@Controller
|
|
|
27
|
+@RequestMapping("lbswitch")
|
25
|
public class LbSwitchCtrl {
|
28
|
public class LbSwitchCtrl {
|
26
|
|
29
|
|
27
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
30
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
@@ -40,9 +43,9 @@ public class LbSwitchCtrl { |
|
@@ -40,9 +43,9 @@ public class LbSwitchCtrl { |
40
|
@ResponseBody
|
43
|
@ResponseBody
|
41
|
public Map<String,String> viewConf() throws Exception {
|
44
|
public Map<String,String> viewConf() throws Exception {
|
42
|
//直连的配置放在腾讯云nginx上
|
45
|
//直连的配置放在腾讯云nginx上
|
43
|
- List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", 2);
|
46
|
+ List<HostInfo> qcloudNginxHosts = hostInfoMapper.selectHostInfosByTag("直连");
|
44
|
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
|
47
|
if (CollectionUtils.isEmpty(qcloudNginxHosts)) {
|
45
|
- throw new Exception("没有找到nginx服务器");
|
48
|
+ throw new Exception("没有找到直连nginx服务器");
|
46
|
}
|
49
|
}
|
47
|
return analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null));
|
50
|
return analyseConfigFile(exe("view", qcloudNginxHosts.get(0).getHostIp(),null));
|
48
|
}
|
51
|
}
|
|
@@ -52,15 +55,15 @@ public class LbSwitchCtrl { |
|
@@ -52,15 +55,15 @@ public class LbSwitchCtrl { |
52
|
*
|
55
|
*
|
53
|
* @return 2016年5月12日下午1:49:48
|
56
|
* @return 2016年5月12日下午1:49:48
|
54
|
*/
|
57
|
*/
|
55
|
- @RequestMapping(value = "viewToChangeLuaConf")
|
58
|
+ @RequestMapping(value = "viewToChangeLbConf")
|
56
|
@ResponseBody
|
59
|
@ResponseBody
|
57
|
public BaseResponse viewToChangeLuaConf(String status, HttpServletRequest request) throws Exception {
|
60
|
public BaseResponse viewToChangeLuaConf(String status, HttpServletRequest request) throws Exception {
|
58
|
logger.info("will change status {}", status);
|
61
|
logger.info("will change status {}", status);
|
59
|
- if(!StringUtils.equals("open", status) && !StringUtils.equals("close", status)){
|
62
|
+ if(!StringUtils.equals("1", status) && !StringUtils.equals("0", status)){
|
60
|
throw new Exception("切换状态参数不正确!");
|
63
|
throw new Exception("切换状态参数不正确!");
|
61
|
}
|
64
|
}
|
62
|
Map<String, Object> map = new HashMap();
|
65
|
Map<String, Object> map = new HashMap();
|
63
|
- map.put("open_dl", StringUtils.equals("open", status) ? OPENDL : CLOSEDL);
|
66
|
+ map.put("open_dl", StringUtils.equals("1", status) ? OPENDL : CLOSEDL);
|
64
|
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
|
67
|
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
|
65
|
String result = HandlebarsUtils.replace(map, "template/lb", path);
|
68
|
String result = HandlebarsUtils.replace(map, "template/lb", path);
|
66
|
return new BaseResponse(200, "success", result);
|
69
|
return new BaseResponse(200, "success", result);
|
|
@@ -76,7 +79,7 @@ public class LbSwitchCtrl { |
|
@@ -76,7 +79,7 @@ public class LbSwitchCtrl { |
76
|
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
|
79
|
String path = request.getSession().getServletContext().getRealPath("/") + "lua/lb.lua";
|
77
|
logger.info("lb.lua template path {}", path);
|
80
|
logger.info("lb.lua template path {}", path);
|
78
|
//lua dns 只放在腾讯云nginx服务器上
|
81
|
//lua dns 只放在腾讯云nginx服务器上
|
79
|
- List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", 2);
|
82
|
+ List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTag("直连");
|
80
|
if (CollectionUtils.isEmpty(nginxHosts)) {
|
83
|
if (CollectionUtils.isEmpty(nginxHosts)) {
|
81
|
return new BaseResponse(500, "在cmdb中未找到直连对应的nginx服务器!");
|
84
|
return new BaseResponse(500, "在cmdb中未找到直连对应的nginx服务器!");
|
82
|
}
|
85
|
}
|
|
@@ -117,11 +120,11 @@ public class LbSwitchCtrl { |
|
@@ -117,11 +120,11 @@ public class LbSwitchCtrl { |
117
|
result.put("conf",sb.toString());
|
120
|
result.put("conf",sb.toString());
|
118
|
String dl = str[i].substring(str[i].indexOf("\"")).replaceAll("\"","").trim();
|
121
|
String dl = str[i].substring(str[i].indexOf("\"")).replaceAll("\"","").trim();
|
119
|
if(StringUtils.equals(OPENDL,dl)){
|
122
|
if(StringUtils.equals(OPENDL,dl)){
|
120
|
- result.put("status","open");
|
123
|
+ result.put("status","1");
|
121
|
return result;
|
124
|
return result;
|
122
|
}
|
125
|
}
|
123
|
if(StringUtils.equals(CLOSEDL,dl)){
|
126
|
if(StringUtils.equals(CLOSEDL,dl)){
|
124
|
- result.put("status","close");
|
127
|
+ result.put("status","0");
|
125
|
return result;
|
128
|
return result;
|
126
|
}
|
129
|
}
|
127
|
}
|
130
|
}
|