1
|
package com.monitor.cmdb.ctrl;
|
1
|
package com.monitor.cmdb.ctrl;
|
2
|
|
2
|
|
|
|
3
|
+import com.monitor.model.response.BaseResponse;
|
3
|
import com.yoho.ops.cmdb.aws.autoscaling.AutoScalingFetcher;
|
4
|
import com.yoho.ops.cmdb.aws.autoscaling.AutoScalingFetcher;
|
4
|
-import com.yoho.ops.cmdb.domain.BaseResponse;
|
|
|
5
|
import com.yoho.ops.cmdb.models.AutoScalingGroup;
|
5
|
import com.yoho.ops.cmdb.models.AutoScalingGroup;
|
6
|
import com.yoho.ops.cmdb.models.AutoScalingHost;
|
6
|
import com.yoho.ops.cmdb.models.AutoScalingHost;
|
7
|
import com.yoho.ops.cmdb.models.CommAutoModifyScalingGroupReq;
|
7
|
import com.yoho.ops.cmdb.models.CommAutoModifyScalingGroupReq;
|
|
@@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
@@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping; |
16
|
import org.springframework.web.bind.annotation.ResponseBody;
|
16
|
import org.springframework.web.bind.annotation.ResponseBody;
|
17
|
|
17
|
|
18
|
import java.util.ArrayList;
|
18
|
import java.util.ArrayList;
|
|
|
19
|
+import java.util.HashMap;
|
19
|
import java.util.List;
|
20
|
import java.util.List;
|
|
|
21
|
+import java.util.Map;
|
20
|
|
22
|
|
21
|
/**
|
23
|
/**
|
22
|
* 对外提供接口
|
24
|
* 对外提供接口
|
|
@@ -59,33 +61,68 @@ public class AutoScalingCtrl { |
|
@@ -59,33 +61,68 @@ public class AutoScalingCtrl { |
59
|
}
|
61
|
}
|
60
|
|
62
|
|
61
|
/**
|
63
|
/**
|
62
|
- * 腾讯云:根据组id获取instanceIP
|
|
|
63
|
- * 亚马逊云:待定
|
64
|
+ * 获取伸缩组内机器的ips
|
64
|
* @param groupId 伸缩组id
|
65
|
* @param groupId 伸缩组id
|
65
|
* @return
|
66
|
* @return
|
66
|
*/
|
67
|
*/
|
67
|
@RequestMapping("/getIpsByScalingGroupId")
|
68
|
@RequestMapping("/getIpsByScalingGroupId")
|
68
|
@ResponseBody
|
69
|
@ResponseBody
|
69
|
- public com.monitor.model.response.BaseResponse getIpsByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
70
|
- com.monitor.model.response.BaseResponse response = new com.monitor.model.response.BaseResponse();
|
|
|
71
|
- List<String> ipList =new ArrayList<String>();;
|
70
|
+ public BaseResponse getIpsByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
71
|
+ BaseResponse response = new BaseResponse();
|
|
|
72
|
+ List<String> ipList =new ArrayList<String>();
|
|
|
73
|
+ AutoScalingGroup group=this.getGroup(cloudType, groupName , groupId);
|
|
|
74
|
+ if(group!=null&&group.getAutoScalingHosts()!=null){
|
|
|
75
|
+ for(AutoScalingHost host:group.getAutoScalingHosts()){
|
|
|
76
|
+ ipList.add(host.getIp());
|
|
|
77
|
+ }
|
|
|
78
|
+ }
|
|
|
79
|
+ response.setData(ipList);
|
|
|
80
|
+ return response;
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ private AutoScalingGroup getGroup(int cloudType, String groupName , String groupId){
|
72
|
AutoScalingGroup group=null;
|
84
|
AutoScalingGroup group=null;
|
73
|
if(1==cloudType){
|
85
|
if(1==cloudType){
|
74
|
if(groupName==null||groupName.length()<=0){
|
86
|
if(groupName==null||groupName.length()<=0){
|
75
|
- response.setCode(300);
|
|
|
76
|
- response.setMessage("aws伸缩组名字为空");
|
|
|
77
|
- return response;
|
87
|
+ return null;
|
78
|
}
|
88
|
}
|
79
|
group=awsFetcher.getAutoScalingByGroupName(groupName);
|
89
|
group=awsFetcher.getAutoScalingByGroupName(groupName);
|
80
|
}else if(2==cloudType){
|
90
|
}else if(2==cloudType){
|
|
|
91
|
+ if(groupId==null||groupId.length()<=0){
|
|
|
92
|
+ return null;
|
|
|
93
|
+ }
|
81
|
group=qcloudFetcher.getAutoScalingGroupByScalingGroupId(groupId);
|
94
|
group=qcloudFetcher.getAutoScalingGroupByScalingGroupId(groupId);
|
82
|
}
|
95
|
}
|
|
|
96
|
+ return group;
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ /**
|
|
|
100
|
+ * 获取伸缩组内的机器ips
|
|
|
101
|
+ * 并按照保护和非保护分类
|
|
|
102
|
+ * @param groupId 伸缩组id
|
|
|
103
|
+ * @return
|
|
|
104
|
+ */
|
|
|
105
|
+ @RequestMapping("/getIpsProtectedAndNoneByScalingGroupId")
|
|
|
106
|
+ @ResponseBody
|
|
|
107
|
+ public BaseResponse getIpsProtectedAndNoneByScalingGroupId(int cloudType, String groupName , String groupId){
|
|
|
108
|
+ BaseResponse response = new BaseResponse();
|
|
|
109
|
+ List<String> ipList_protected =new ArrayList<String>();
|
|
|
110
|
+ List<String> ipList_none_protected =new ArrayList<String>();
|
|
|
111
|
+ AutoScalingGroup group=this.getGroup(cloudType, groupName , groupId);
|
83
|
if(group!=null&&group.getAutoScalingHosts()!=null){
|
112
|
if(group!=null&&group.getAutoScalingHosts()!=null){
|
84
|
for(AutoScalingHost host:group.getAutoScalingHosts()){
|
113
|
for(AutoScalingHost host:group.getAutoScalingHosts()){
|
85
|
- ipList.add(host.getIp());
|
114
|
+ if(host.isProtected()){
|
|
|
115
|
+ ipList_protected.add(host.getIp());
|
|
|
116
|
+ }else{
|
|
|
117
|
+ ipList_none_protected.add(host.getIp());
|
|
|
118
|
+ }
|
|
|
119
|
+
|
86
|
}
|
120
|
}
|
87
|
}
|
121
|
}
|
88
|
- response.setData(ipList);
|
122
|
+ Map<String,List<String>> map=new HashMap<>();
|
|
|
123
|
+ map.put("protected",ipList_protected);
|
|
|
124
|
+ map.put("noneProtected",ipList_none_protected);
|
|
|
125
|
+ response.setData(map);
|
89
|
return response;
|
126
|
return response;
|
90
|
}
|
127
|
}
|
91
|
|
128
|
|