...
|
...
|
@@ -14,6 +14,9 @@ import org.springframework.stereotype.Controller; |
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -31,10 +34,15 @@ public class Pch5DockerSwitchCtrl { |
|
|
//pch5 pc\wap负载均衡,应用型
|
|
|
private final String ELB_PCH5_ID="lb-7cowsd61";
|
|
|
|
|
|
//用来做灰度的nginx机器
|
|
|
private final List<String> gray_nginx_hosts=Arrays.asList("10.66.103.13");
|
|
|
|
|
|
//pc node 对于域名
|
|
|
private final List<String> elb_pch5_pc_domain=Arrays.asList("*.yohobuy.com","activity.yoho.cn");
|
|
|
private final List<String> elb_pch5_wap_domain=Arrays.asList("m.yohobuy.com","*.m.yohobuy.com");
|
|
|
|
|
|
private static final String COMMON_SWITCH_PY = "/usr/bin/python /home/master/ops_sh/pch5-az2-node-host-switch/switch.py ";
|
|
|
|
|
|
|
|
|
//当前环境
|
|
|
@Value("${system.envi}")
|
...
|
...
|
@@ -166,10 +174,64 @@ public class Pch5DockerSwitchCtrl { |
|
|
@RequestMapping(value = "/switchDockerAz2")
|
|
|
@ResponseBody
|
|
|
public BaseResponse switchDockerAz2(String projectType,String onlineOrGray) {
|
|
|
int weight=10;
|
|
|
if("gray".equals(onlineOrGray)){
|
|
|
weight=0;
|
|
|
}else if("online".equals(onlineOrGray)){
|
|
|
weight=10;
|
|
|
}
|
|
|
|
|
|
if(projectType.contains("blk")){
|
|
|
//elb传统型
|
|
|
QcloudCLBModel clb=QcloudSdkUtil.describeLoadBalancerBackends(ELB_BLK_ID);
|
|
|
|
|
|
List<String> unInstIdList=new ArrayList<>();
|
|
|
List<Integer> weightList=new ArrayList<>();
|
|
|
for(QcloudCLBModel.Backend beckend:clb.getBackendSet()){
|
|
|
if(gray_nginx_hosts.contains(beckend.getLanIp())&&weight!=beckend.getWeight()){
|
|
|
unInstIdList.add(beckend.getUnInstanceId());
|
|
|
weightList.add(weight);
|
|
|
}
|
|
|
}
|
|
|
//开始切换
|
|
|
QcloudSdkUtil.modifyLoadBalancerBackends(ELB_BLK_ID,unInstIdList,weightList);
|
|
|
}else {
|
|
|
//elb 应用型
|
|
|
QcloudForwardLbModel forwardlb= QcloudSdkUtil.describeForwardLBBackends(ELB_PCH5_ID);
|
|
|
for(QcloudForwardLbModelData forwardLbModelData:forwardlb.getData()){
|
|
|
String listenerId=forwardLbModelData.getListenerId();
|
|
|
for(QcloudForwardLbModelDataRule rule:forwardLbModelData.getRules()){
|
|
|
String domain=rule.getDomain();
|
|
|
|
|
|
if(projectType.contains("pc")&&elb_pch5_pc_domain.contains(domain)){
|
|
|
modifyAlbWeight(weight,listenerId,domain,rule.getBackends());
|
|
|
}else if(projectType.contains("wap")&&elb_pch5_wap_domain.contains(domain)){
|
|
|
modifyAlbWeight(weight,listenerId,domain,rule.getBackends());
|
|
|
}
|
|
|
|
|
|
return new BaseResponse(201,"开发中");
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return new BaseResponse();
|
|
|
}
|
|
|
|
|
|
//修改权重
|
|
|
private void modifyAlbWeight(int weight ,String listenerId,String domain,List<QcloudForwardLbModelDataRule.Backend> backendList){
|
|
|
List<String> unInstIdList=new ArrayList<>();
|
|
|
List<Integer> portList=new ArrayList<>();
|
|
|
List<Integer> weightList=new ArrayList<>();
|
|
|
|
|
|
|
|
|
for(QcloudForwardLbModelDataRule.Backend forwardBackend:backendList){
|
|
|
if(gray_nginx_hosts.contains(forwardBackend.getLanIp())&&weight!=forwardBackend.getWeight()){
|
|
|
unInstIdList.add(forwardBackend.getUnInstanceId());
|
|
|
portList.add(forwardBackend.getPort());
|
|
|
weightList.add(weight);
|
|
|
}
|
|
|
}
|
|
|
QcloudSdkUtil.modifyForwardSeventhBackends(ELB_PCH5_ID,listenerId,domain,unInstIdList,portList,weightList);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|