|
|
package com.monitor.cmdb.ctrl;
|
|
|
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.yoho.ops.cmdb.aws.autoscaling.AutoScalingFetcher;
|
|
|
import com.yoho.ops.cmdb.domain.BaseResponse;
|
|
|
import com.yoho.ops.cmdb.models.AutoScalingGroup;
|
|
|
import com.yoho.ops.cmdb.models.AutoScalingHost;
|
|
|
import com.yoho.ops.cmdb.models.CommAutoModifyScalingGroupReq;
|
...
|
...
|
@@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 对外提供接口
|
...
|
...
|
@@ -59,33 +61,68 @@ public class AutoScalingCtrl { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 腾讯云:根据组id获取instanceIP
|
|
|
* 亚马逊云:待定
|
|
|
* 获取伸缩组内机器的ips
|
|
|
* @param groupId 伸缩组id
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/getIpsByScalingGroupId")
|
|
|
@ResponseBody
|
|
|
public com.monitor.model.response.BaseResponse getIpsByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
com.monitor.model.response.BaseResponse response = new com.monitor.model.response.BaseResponse();
|
|
|
List<String> ipList =new ArrayList<String>();;
|
|
|
public BaseResponse getIpsByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
List<String> ipList =new ArrayList<String>();
|
|
|
AutoScalingGroup group=this.getGroup(cloudType, groupName , groupId);
|
|
|
if(group!=null&&group.getAutoScalingHosts()!=null){
|
|
|
for(AutoScalingHost host:group.getAutoScalingHosts()){
|
|
|
ipList.add(host.getIp());
|
|
|
}
|
|
|
}
|
|
|
response.setData(ipList);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
private AutoScalingGroup getGroup(int cloudType, String groupName , String groupId){
|
|
|
AutoScalingGroup group=null;
|
|
|
if(1==cloudType){
|
|
|
if(groupName==null||groupName.length()<=0){
|
|
|
response.setCode(300);
|
|
|
response.setMessage("aws伸缩组名字为空");
|
|
|
return response;
|
|
|
return null;
|
|
|
}
|
|
|
group=awsFetcher.getAutoScalingByGroupName(groupName);
|
|
|
}else if(2==cloudType){
|
|
|
if(groupId==null||groupId.length()<=0){
|
|
|
return null;
|
|
|
}
|
|
|
group=qcloudFetcher.getAutoScalingGroupByScalingGroupId(groupId);
|
|
|
}
|
|
|
return group;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取伸缩组内的机器ips
|
|
|
* 并按照保护和非保护分类
|
|
|
* @param groupId 伸缩组id
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/getIpsProtectedAndNoneByScalingGroupId")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getIpsProtectedAndNoneByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
List<String> ipList_protected =new ArrayList<String>();
|
|
|
List<String> ipList_none_protected =new ArrayList<String>();
|
|
|
AutoScalingGroup group=this.getGroup(cloudType, groupName , groupId);
|
|
|
if(group!=null&&group.getAutoScalingHosts()!=null){
|
|
|
for(AutoScalingHost host:group.getAutoScalingHosts()){
|
|
|
ipList.add(host.getIp());
|
|
|
if(host.isProtected()){
|
|
|
ipList_protected.add(host.getIp());
|
|
|
}else{
|
|
|
ipList_none_protected.add(host.getIp());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
response.setData(ipList);
|
|
|
Map<String,List<String>> map=new HashMap<>();
|
|
|
map.put("protected",ipList_protected);
|
|
|
map.put("noneProtected",ipList_none_protected);
|
|
|
response.setData(map);
|
|
|
return response;
|
|
|
}
|
|
|
|
...
|
...
|
|