Authored by qinchao

nginx切换

... ... @@ -155,22 +155,25 @@ public class NginxSwitchCtrl {
/**
* 修改配置
* type:环境类型 1:线上 2:灰度
* cloudName : 操作的云
* target : 切线目标(其它云或者灰度云)
* onlineOrGray:环境类型 1:线上 2:灰度
*
* @return 2016年5月12日下午1:49:48
*/
@RequestMapping(value = "viewToChangeNginxConf")
@ResponseBody
public BaseResponse viewToChangeNginxConf(String cloudName, String target, String ips, String onlineOrGray) {
public BaseResponse viewToChangeNginxConf(String cloudName, String target, String onlineOrGray) {
try{
//线上切换
String tag = StringUtils.equals("gray", target) ? HostTagConstant.tag_huidu_cn : HostTagConstant.tag_gateway;
/*String tag = StringUtils.equals("gray", target) ? HostTagConstant.tag_huidu_cn : HostTagConstant.tag_gateway;
//需要查询的gateway机子
int gatewayCloudType = StringUtils.equals("aws", target) ? 1 : 2;
//获取gateway或graygateway服务器
List<HostInfo> gatewayHosts = hostInfoMapper.selectHostInfosByTagAndCloudType(tag, gatewayCloudType);
if (CollectionUtils.isEmpty(gatewayHosts)) {
return new BaseResponse(500, cloudName + "在cmdb中未找到对应" + tag + "的服务器!");
}
... ... @@ -184,6 +187,21 @@ public class NginxSwitchCtrl {
} else if (hostInfo.getTags().indexOf(HostTagConstant.tag_gateway) == -1) {
infoIterator.remove();
}
}*/
List<String> gatewayHostIps=new ArrayList<>();
if(StringUtils.equals("gray", target)){
gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_huidu_cn);
}else{
if(target.contains("az2")){
gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_az2);
}else{
gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_az1);
}
}
if (CollectionUtils.isEmpty(gatewayHostIps)) {
return new BaseResponse(500, target + "在cmdb中未找到对应gateway的服务器!");
}
StringBuilder commond = new StringBuilder();
... ... @@ -192,8 +210,12 @@ public class NginxSwitchCtrl {
commond.append(" -o" + onlineOrGray);
commond.append(" -c");
for (HostInfo hostInfo : gatewayHosts) {
/*for (HostInfo hostInfo : gatewayHosts) {
commond.append("server\\t" + hostInfo.getHostIp() + ":8080\\tmax_fails=5\\tfail_timeout=3s\\;\\n");
}*/
for (String hostIp : gatewayHostIps) {
commond.append("server\\t" + hostIp+ ":8080\\tmax_fails=5\\tfail_timeout=3s\\;\\n");
}
commond.append("keepalive\\t32\\;\\n");
... ...