Showing
1 changed file
with
26 additions
and
4 deletions
@@ -155,22 +155,25 @@ public class NginxSwitchCtrl { | @@ -155,22 +155,25 @@ public class NginxSwitchCtrl { | ||
155 | 155 | ||
156 | /** | 156 | /** |
157 | * 修改配置 | 157 | * 修改配置 |
158 | - * type:环境类型 1:线上 2:灰度 | 158 | + * cloudName : 操作的云 |
159 | + * target : 切线目标(其它云或者灰度云) | ||
160 | + * onlineOrGray:环境类型 1:线上 2:灰度 | ||
159 | * | 161 | * |
160 | * @return 2016年5月12日下午1:49:48 | 162 | * @return 2016年5月12日下午1:49:48 |
161 | */ | 163 | */ |
162 | @RequestMapping(value = "viewToChangeNginxConf") | 164 | @RequestMapping(value = "viewToChangeNginxConf") |
163 | @ResponseBody | 165 | @ResponseBody |
164 | - public BaseResponse viewToChangeNginxConf(String cloudName, String target, String ips, String onlineOrGray) { | 166 | + public BaseResponse viewToChangeNginxConf(String cloudName, String target, String onlineOrGray) { |
165 | try{ | 167 | try{ |
166 | //线上切换 | 168 | //线上切换 |
167 | - String tag = StringUtils.equals("gray", target) ? HostTagConstant.tag_huidu_cn : HostTagConstant.tag_gateway; | 169 | + /*String tag = StringUtils.equals("gray", target) ? HostTagConstant.tag_huidu_cn : HostTagConstant.tag_gateway; |
168 | 170 | ||
169 | //需要查询的gateway机子 | 171 | //需要查询的gateway机子 |
170 | int gatewayCloudType = StringUtils.equals("aws", target) ? 1 : 2; | 172 | int gatewayCloudType = StringUtils.equals("aws", target) ? 1 : 2; |
171 | 173 | ||
172 | //获取gateway或graygateway服务器 | 174 | //获取gateway或graygateway服务器 |
173 | List<HostInfo> gatewayHosts = hostInfoMapper.selectHostInfosByTagAndCloudType(tag, gatewayCloudType); | 175 | List<HostInfo> gatewayHosts = hostInfoMapper.selectHostInfosByTagAndCloudType(tag, gatewayCloudType); |
176 | + | ||
174 | if (CollectionUtils.isEmpty(gatewayHosts)) { | 177 | if (CollectionUtils.isEmpty(gatewayHosts)) { |
175 | return new BaseResponse(500, cloudName + "在cmdb中未找到对应" + tag + "的服务器!"); | 178 | return new BaseResponse(500, cloudName + "在cmdb中未找到对应" + tag + "的服务器!"); |
176 | } | 179 | } |
@@ -184,6 +187,21 @@ public class NginxSwitchCtrl { | @@ -184,6 +187,21 @@ public class NginxSwitchCtrl { | ||
184 | } else if (hostInfo.getTags().indexOf(HostTagConstant.tag_gateway) == -1) { | 187 | } else if (hostInfo.getTags().indexOf(HostTagConstant.tag_gateway) == -1) { |
185 | infoIterator.remove(); | 188 | infoIterator.remove(); |
186 | } | 189 | } |
190 | + }*/ | ||
191 | + | ||
192 | + List<String> gatewayHostIps=new ArrayList<>(); | ||
193 | + if(StringUtils.equals("gray", target)){ | ||
194 | + gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_huidu_cn); | ||
195 | + }else{ | ||
196 | + if(target.contains("az2")){ | ||
197 | + gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_az2); | ||
198 | + }else{ | ||
199 | + gatewayHostIps = getGatewayHostIPs(HostTagConstant.tag_az1); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + if (CollectionUtils.isEmpty(gatewayHostIps)) { | ||
204 | + return new BaseResponse(500, target + "在cmdb中未找到对应gateway的服务器!"); | ||
187 | } | 205 | } |
188 | 206 | ||
189 | StringBuilder commond = new StringBuilder(); | 207 | StringBuilder commond = new StringBuilder(); |
@@ -192,8 +210,12 @@ public class NginxSwitchCtrl { | @@ -192,8 +210,12 @@ public class NginxSwitchCtrl { | ||
192 | commond.append(" -o" + onlineOrGray); | 210 | commond.append(" -o" + onlineOrGray); |
193 | commond.append(" -c"); | 211 | commond.append(" -c"); |
194 | 212 | ||
195 | - for (HostInfo hostInfo : gatewayHosts) { | 213 | + /*for (HostInfo hostInfo : gatewayHosts) { |
196 | commond.append("server\\t" + hostInfo.getHostIp() + ":8080\\tmax_fails=5\\tfail_timeout=3s\\;\\n"); | 214 | commond.append("server\\t" + hostInfo.getHostIp() + ":8080\\tmax_fails=5\\tfail_timeout=3s\\;\\n"); |
215 | + }*/ | ||
216 | + | ||
217 | + for (String hostIp : gatewayHostIps) { | ||
218 | + commond.append("server\\t" + hostIp+ ":8080\\tmax_fails=5\\tfail_timeout=3s\\;\\n"); | ||
197 | } | 219 | } |
198 | commond.append("keepalive\\t32\\;\\n"); | 220 | commond.append("keepalive\\t32\\;\\n"); |
199 | 221 |
-
Please register or login to post a comment