|
|
package com.monitor.cmdb.ctrl;
|
|
|
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.yoho.ops.cmdb.aws.lb.AwsLoadBalance;
|
|
|
import com.yoho.ops.cmdb.models.Host;
|
|
|
import com.yoho.ops.cmdb.models.LoadBalance;
|
|
|
import com.yoho.ops.cmdb.qcloud.lb.QcloudLoadBalance;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 对外提供接口
|
|
|
* Created by craig.qin on 2017/7/7.
|
|
|
*/
|
|
|
@Controller
|
|
|
@RequestMapping("/lb")
|
|
|
public class LbCtrl {
|
|
|
//AWS 负载均衡器
|
|
|
@Value("${yoho_search_service_aws_lb}")
|
|
|
private String YOHO_SEARCH_SERVICE_AWS_ALB;
|
|
|
@Value("${yoho_search_service_aws__lb_target}")
|
|
|
private String YOHO_SEARCH_SERVICE_AWS_ALB_GROUP;
|
|
|
|
|
|
//QQ 传统负载均衡器
|
|
|
@Value("${yoho_search_service_qcloud_lb}")
|
|
|
private String YOHO_SEARCH_SERVICE_QCLOUD_CLB;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private AwsLoadBalance awsLoadBalance;
|
|
|
@Autowired
|
|
|
private QcloudLoadBalance qcloudLoadBalance;
|
|
|
/**
|
|
|
* 查询伸缩组信息,返回列表
|
|
|
* @param cloudType 1:aws ; 2:qcloud
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getLb/yohoSearchService")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getLb_yohoSearchService(String cloudType){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
LoadBalance lb=null;
|
|
|
if("aws".equals(cloudType)){
|
|
|
lb=awsLoadBalance.getAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP);
|
|
|
}else if("qcloud".equals(cloudType)){
|
|
|
lb=qcloudLoadBalance.getAlbLoadBalancesById(YOHO_SEARCH_SERVICE_QCLOUD_CLB);
|
|
|
}
|
|
|
if(lb!=null){
|
|
|
Map<String,String> hostIdAndIpMap=new LinkedHashMap<>();
|
|
|
for(Host host:lb.getHosts()){
|
|
|
hostIdAndIpMap.put(host.getId(),host.getIp());
|
|
|
}
|
|
|
response.setData(hostIdAndIpMap);
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 卸载
|
|
|
*/
|
|
|
@RequestMapping(value = "/deregisterHostFromLb/yohoSearchService")
|
|
|
@ResponseBody
|
|
|
public BaseResponse deregisterHostFromLb_yohoSearchService(String cloudType,String instIds){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
String[] idArray=instIds.split(",");
|
|
|
List<String> idList= Arrays.asList(idArray);
|
|
|
LoadBalance lb=null;
|
|
|
if("aws".equals(cloudType)){
|
|
|
awsLoadBalance.deregisterTargetFromAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP,idList);
|
|
|
}else if("qcloud".equals(cloudType)){
|
|
|
qcloudLoadBalance.deregisterInstancesWithLoadBalancer(YOHO_SEARCH_SERVICE_QCLOUD_CLB,idList);
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 挂载
|
|
|
*/
|
|
|
@RequestMapping(value = "/registerHostFromLb/yohoSearchService")
|
|
|
@ResponseBody
|
|
|
public BaseResponse registerHostFromLb_yohoSearchService(String cloudType,String instIds){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
String[] idArray=instIds.split(",");
|
|
|
List<String> idList= Arrays.asList(idArray);
|
|
|
LoadBalance lb=null;
|
|
|
if("aws".equals(cloudType)){
|
|
|
awsLoadBalance.registerTargetFromAlbsByNameWithTargetGroup(YOHO_SEARCH_SERVICE_AWS_ALB,YOHO_SEARCH_SERVICE_AWS_ALB_GROUP,idList);
|
|
|
}else if("qcloud".equals(cloudType)){
|
|
|
qcloudLoadBalance.registerInstancesWithLoadBalancer(YOHO_SEARCH_SERVICE_QCLOUD_CLB,idList);
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|