yoho-search-service发布特殊流程
Showing
5 changed files
with
164 additions
and
8 deletions
1 | +package com.monitor.cmdb.ctrl; | ||
2 | + | ||
3 | +import com.monitor.model.response.BaseResponse; | ||
4 | +import com.yoho.ops.cmdb.aws.lb.AwsLoadBalance; | ||
5 | +import com.yoho.ops.cmdb.models.Host; | ||
6 | +import com.yoho.ops.cmdb.models.LoadBalance; | ||
7 | +import com.yoho.ops.cmdb.qcloud.lb.QcloudLoadBalance; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.beans.factory.annotation.Value; | ||
10 | +import org.springframework.stereotype.Controller; | ||
11 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
12 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
13 | + | ||
14 | +import java.util.Arrays; | ||
15 | +import java.util.LinkedHashMap; | ||
16 | +import java.util.List; | ||
17 | +import java.util.Map; | ||
18 | + | ||
19 | +/** | ||
20 | + * 对外提供接口 | ||
21 | + * Created by craig.qin on 2017/7/7. | ||
22 | + */ | ||
23 | +@Controller | ||
24 | +@RequestMapping("/lb") | ||
25 | +public class LbCtrl { | ||
26 | + //AWS 负载均衡器 | ||
27 | + @Value("${yoho_search_service_aws_lb}") | ||
28 | + private String YOHO_SEARCH_SERVICE_AWS_ALB; | ||
29 | + @Value("${yoho_search_service_aws__lb_target}") | ||
30 | + private String YOHO_SEARCH_SERVICE_AWS_ALB_GROUP; | ||
31 | + | ||
32 | + //QQ 传统负载均衡器 | ||
33 | + @Value("${yoho_search_service_qcloud_lb}") | ||
34 | + private String YOHO_SEARCH_SERVICE_QCLOUD_CLB; | ||
35 | + | ||
36 | + | ||
37 | + @Autowired | ||
38 | + private AwsLoadBalance awsLoadBalance; | ||
39 | + @Autowired | ||
40 | + private QcloudLoadBalance qcloudLoadBalance; | ||
41 | + /** | ||
42 | + * 查询伸缩组信息,返回列表 | ||
43 | + * @param cloudType 1:aws ; 2:qcloud | ||
44 | + * @return | ||
45 | + */ | ||
46 | + @RequestMapping(value = "/getLb/yohoSearchService") | ||
47 | + @ResponseBody | ||
48 | + public BaseResponse getLb_yohoSearchService(String cloudType){ | ||
49 | + BaseResponse response = new BaseResponse(); | ||
50 | + LoadBalance lb=null; | ||
51 | + if("aws".equals(cloudType)){ | ||
52 | + lb=awsLoadBalance.getAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP); | ||
53 | + }else if("qcloud".equals(cloudType)){ | ||
54 | + lb=qcloudLoadBalance.getAlbLoadBalancesById(YOHO_SEARCH_SERVICE_QCLOUD_CLB); | ||
55 | + } | ||
56 | + if(lb!=null){ | ||
57 | + Map<String,String> hostIdAndIpMap=new LinkedHashMap<>(); | ||
58 | + for(Host host:lb.getHosts()){ | ||
59 | + hostIdAndIpMap.put(host.getId(),host.getIp()); | ||
60 | + } | ||
61 | + response.setData(hostIdAndIpMap); | ||
62 | + } | ||
63 | + return response; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * 卸载 | ||
68 | + */ | ||
69 | + @RequestMapping(value = "/deregisterHostFromLb/yohoSearchService") | ||
70 | + @ResponseBody | ||
71 | + public BaseResponse deregisterHostFromLb_yohoSearchService(String cloudType,String instIds){ | ||
72 | + BaseResponse response = new BaseResponse(); | ||
73 | + String[] idArray=instIds.split(","); | ||
74 | + List<String> idList= Arrays.asList(idArray); | ||
75 | + LoadBalance lb=null; | ||
76 | + if("aws".equals(cloudType)){ | ||
77 | + awsLoadBalance.deregisterTargetFromAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP,idList); | ||
78 | + }else if("qcloud".equals(cloudType)){ | ||
79 | + qcloudLoadBalance.deregisterInstancesWithLoadBalancer(YOHO_SEARCH_SERVICE_QCLOUD_CLB,idList); | ||
80 | + } | ||
81 | + return response; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * 挂载 | ||
86 | + */ | ||
87 | + @RequestMapping(value = "/registerHostFromLb/yohoSearchService") | ||
88 | + @ResponseBody | ||
89 | + public BaseResponse registerHostFromLb_yohoSearchService(String cloudType,String instIds){ | ||
90 | + BaseResponse response = new BaseResponse(); | ||
91 | + String[] idArray=instIds.split(","); | ||
92 | + List<String> idList= Arrays.asList(idArray); | ||
93 | + LoadBalance lb=null; | ||
94 | + if("aws".equals(cloudType)){ | ||
95 | + awsLoadBalance.registerTargetFromAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP,idList); | ||
96 | + }else if("qcloud".equals(cloudType)){ | ||
97 | + qcloudLoadBalance.registerInstancesWithLoadBalancer(YOHO_SEARCH_SERVICE_QCLOUD_CLB,idList); | ||
98 | + } | ||
99 | + return response; | ||
100 | + } | ||
101 | + | ||
102 | +} |
@@ -81,28 +81,28 @@ public class AwsLoadBalance { | @@ -81,28 +81,28 @@ public class AwsLoadBalance { | ||
81 | * 卸载机器 | 81 | * 卸载机器 |
82 | * @param albName | 82 | * @param albName |
83 | * @param targetGroupName | 83 | * @param targetGroupName |
84 | - * @param ips | 84 | + * @param instIdList |
85 | */ | 85 | */ |
86 | - public void deregisterTargetFromAlbsByNameWithTargetGroup(String albName,String targetGroupName,List<String> ips){ | ||
87 | - if(ips==null||ips.size()<=0){ | 86 | + public void deregisterTargetFromAlbsByNameWithTargetGroup(String albName,String targetGroupName,List<String> instIdList){ |
87 | + if(instIdList==null||instIdList.size()<=0){ | ||
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | int flag=-1;//卸载 | 90 | int flag=-1;//卸载 |
91 | - this.alb.registerOrDeregisterTargetFromAlbsByNameWithTargetGroup(albName,targetGroupName,flag,ips); | 91 | + this.alb.registerOrDeregisterTargetFromAlbsByNameWithTargetGroup(albName,targetGroupName,flag,instIdList); |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * 挂载机器 | 95 | * 挂载机器 |
96 | * @param albName | 96 | * @param albName |
97 | * @param targetGroupName | 97 | * @param targetGroupName |
98 | - * @param ips | 98 | + * @param instIdList |
99 | */ | 99 | */ |
100 | - public void registerTargetFromAlbsByNameWithTargetGroup(String albName,String targetGroupName,List<String> ips){ | ||
101 | - if(ips==null||ips.size()<=0){ | 100 | + public void registerTargetFromAlbsByNameWithTargetGroup(String albName,String targetGroupName,List<String> instIdList){ |
101 | + if(instIdList==null||instIdList.size()<=0){ | ||
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | int flag=1;//挂载 | 104 | int flag=1;//挂载 |
105 | - this.alb.registerOrDeregisterTargetFromAlbsByNameWithTargetGroup(albName,targetGroupName,flag,ips); | 105 | + this.alb.registerOrDeregisterTargetFromAlbsByNameWithTargetGroup(albName,targetGroupName,flag,instIdList); |
106 | } | 106 | } |
107 | 107 | ||
108 | private void updateHostInfo(final List<LoadBalance> loadBalances){ | 108 | private void updateHostInfo(final List<LoadBalance> loadBalances){ |
1 | +package com.yoho.ops.cmdb.qcloud.lb; | ||
2 | + | ||
3 | +import com.yoho.ops.cmdb.models.DataCenter; | ||
4 | +import com.yoho.ops.cmdb.models.Host; | ||
5 | +import com.yoho.ops.cmdb.models.LoadBalance; | ||
6 | +import com.yoho.ops.cmdb.qcloud.model.QcloudCLBModel; | ||
7 | +import com.yoho.ops.cmdb.qcloud.util.QcloudSdkUtil; | ||
8 | +import org.springframework.stereotype.Service; | ||
9 | + | ||
10 | +import java.util.List; | ||
11 | + | ||
12 | +@Service | ||
13 | +public class QcloudLoadBalance { | ||
14 | + /** | ||
15 | + * 获取指定的负载均衡器器信息 | ||
16 | + * @return 负载均衡器信息 | ||
17 | + */ | ||
18 | + public LoadBalance getAlbLoadBalancesById(String lbId){ | ||
19 | + QcloudCLBModel model=QcloudSdkUtil.describeLoadBalancerBackends(lbId); | ||
20 | + if(model!=null){ | ||
21 | + LoadBalance lb=new LoadBalance("", DataCenter.qcloud,""); | ||
22 | + for(int i=0;i<model.getBackendSet().size();i++){ | ||
23 | + Host host=new Host(DataCenter.qcloud,model.getBackendSet().get(i).getUnInstanceId(),model.getBackendSet().get(i).getLanIp(),model.getBackendSet().get(i).getInstanceName()); | ||
24 | + lb.getHosts().add(host); | ||
25 | + } | ||
26 | + return lb; | ||
27 | + } | ||
28 | + return null; | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * 卸载机器 | ||
33 | + */ | ||
34 | + public void deregisterInstancesWithLoadBalancer(String lbId, List<String> instIdList){ | ||
35 | + QcloudSdkUtil.deRegisterInstancesWithLoadBalancer(lbId,instIdList); | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 挂载机器 | ||
40 | + */ | ||
41 | + public void registerInstancesWithLoadBalancer(String lbId, List<String> instIdList){ | ||
42 | + QcloudSdkUtil.registerInstancesWithLoadBalancer(lbId,instIdList); | ||
43 | + } | ||
44 | +} |
@@ -2,3 +2,8 @@ nginx_elb_aws=app-java-v2 | @@ -2,3 +2,8 @@ nginx_elb_aws=app-java-v2 | ||
2 | nginx_clb_qcloud=lb-09g87u8f | 2 | nginx_clb_qcloud=lb-09g87u8f |
3 | aws_zk_address=172.31.50.193:2181 | 3 | aws_zk_address=172.31.50.193:2181 |
4 | qcloud_zk_address=10.66.4.3:2181 | 4 | qcloud_zk_address=10.66.4.3:2181 |
5 | + | ||
6 | +#yoho-search-serviceڵĸؾ | ||
7 | +yoho_search_service_aws_lb=search | ||
8 | +yoho_search_service_aws__lb_target=search-intenel | ||
9 | +yoho_search_service_qcloud_lb=lb-14k30u8z |
@@ -2,3 +2,8 @@ nginx_elb_aws=app-java-v2 | @@ -2,3 +2,8 @@ nginx_elb_aws=app-java-v2 | ||
2 | nginx_clb_qcloud=lb-09g87u8f | 2 | nginx_clb_qcloud=lb-09g87u8f |
3 | aws_zk_address=192.168.102.45:2181 | 3 | aws_zk_address=192.168.102.45:2181 |
4 | qcloud_zk_address=192.168.102.45:2181 | 4 | qcloud_zk_address=192.168.102.45:2181 |
5 | + | ||
6 | +#yoho-search-serviceڵĸؾ | ||
7 | +yoho_search_service_aws_lb=search-test | ||
8 | +yoho_search_service_aws__lb_target=search-v2 | ||
9 | +yoho_search_service_qcloud_lb=lb-471bd4jl |
-
Please register or login to post a comment