...
|
...
|
@@ -247,21 +247,34 @@ public class Pch5SwitchCtrl { |
|
|
if("all".equals(area)){
|
|
|
//指向all,挂载
|
|
|
List<String> addIds=new ArrayList<>();
|
|
|
for(String ip:hostMap.keySet()){
|
|
|
//if(!allHostIps_under_prod.contains(ip)){
|
|
|
addIds.add(hostMap.get(ip).getId());
|
|
|
//}
|
|
|
//挂载az1
|
|
|
for(String ip:az1_host_cmdb){
|
|
|
addIds.add(hostMap.get(ip).getId());
|
|
|
}
|
|
|
qcloudLoadBalance.registerInstancesWithLoadBalancer(ELB_PCH5_ID,addIds);
|
|
|
|
|
|
//挂载az2 ,需要指定权重
|
|
|
List<Integer> weights=new ArrayList<>();
|
|
|
addIds=new ArrayList<>();
|
|
|
for(String ip:az2_host_cmdb){
|
|
|
addIds.add(hostMap.get(ip).getId());
|
|
|
weights.add(5);
|
|
|
}
|
|
|
qcloudLoadBalance.registerInstancesAndWeightWithLoadBalancer(ELB_PCH5_ID,addIds,weights);
|
|
|
|
|
|
} else if("az1".equals(area)){
|
|
|
//指向az1 ,把az2卸载
|
|
|
//首先要确保az1,至少有一个host,才能卸载az2机器
|
|
|
pch5ElbChangeHost(az1_host_cmdb,az2_host_cmdb,hostMap);
|
|
|
pch5ElbChangeHost(az1_host_cmdb,az2_host_cmdb,hostMap,null);
|
|
|
} else if("az2".equals(area)){
|
|
|
//指向az2,把az1卸载
|
|
|
//先把az2挂载上
|
|
|
//卸载az1
|
|
|
pch5ElbChangeHost(az2_host_cmdb,az1_host_cmdb,hostMap);
|
|
|
List<Integer> weights=new ArrayList<>();
|
|
|
for(int i=0;i<az2_host_cmdb.size();i++){
|
|
|
weights.add(5);
|
|
|
}
|
|
|
pch5ElbChangeHost(az2_host_cmdb,az1_host_cmdb,hostMap,weights);
|
|
|
}
|
|
|
return new BaseResponse();
|
|
|
}
|
...
|
...
|
@@ -272,13 +285,13 @@ public class Pch5SwitchCtrl { |
|
|
* @param removeIps
|
|
|
* @param hostMap
|
|
|
*/
|
|
|
private void pch5ElbChangeHost(List<String> addOrKeepIps,List<String> removeIps,Map<String,Host> hostMap){
|
|
|
private void pch5ElbChangeHost(List<String> addOrKeepIps,List<String> removeIps,Map<String,Host> hostMap,List<Integer> weights){
|
|
|
//先把az1挂载上
|
|
|
List<String> addIds=new ArrayList<>();
|
|
|
for(String ip:addOrKeepIps){
|
|
|
addIds.add(hostMap.get(ip).getId());
|
|
|
}
|
|
|
qcloudLoadBalance.registerInstancesWithLoadBalancer(ELB_PCH5_ID,addIds);
|
|
|
qcloudLoadBalance.registerInstancesAndWeightWithLoadBalancer(ELB_PCH5_ID,addIds,weights);
|
|
|
|
|
|
//中间等待10秒钟
|
|
|
try {
|
...
|
...
|
@@ -327,9 +340,12 @@ public class Pch5SwitchCtrl { |
|
|
Map<String,Object> rntData=(Map<String, Object>) checkAzResponse.getData();
|
|
|
Map<String,Host> hostMap=(Map<String,Host>)(rntData.get(const_host_cvm_map));
|
|
|
List<Host> current_host_prodElb=(List<Host>)rntData.get(const_current_host_under_prod_elb);
|
|
|
|
|
|
List<Integer> weights=new ArrayList<>();
|
|
|
List<String> az2HostIds=new ArrayList<>();
|
|
|
for(String ip:az2_host_cmdb){
|
|
|
az2HostIds.add(hostMap.get(ip).getId());
|
|
|
weights.add(5);
|
|
|
}
|
|
|
if("online".equals(onlineOrGray)){
|
|
|
//az2用作生产,productElb挂载 ,然后修改host
|
...
|
...
|
@@ -337,7 +353,7 @@ public class Pch5SwitchCtrl { |
|
|
//TODO 修改host
|
|
|
exe("pch5_prod.py");
|
|
|
|
|
|
qcloudLoadBalance.registerInstancesWithLoadBalancer(ELB_PCH5_ID,az2HostIds);
|
|
|
qcloudLoadBalance.registerInstancesAndWeightWithLoadBalancer(ELB_PCH5_ID,az2HostIds,weights);
|
|
|
|
|
|
}else if("gray".equals(onlineOrGray)){
|
|
|
//卸载之前先检查是否存在az1机器,否则不允许卸载
|
...
|
...
|
|