Authored by qinchao

aws和qcloud伸缩接口.。。。3333

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;
}
... ...
package com.monitor.cmdb.ctrl;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.autoscaling.AmazonAutoScaling;
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
import com.amazonaws.services.elasticloadbalancingv2.model.SetSecurityGroupsRequest;
import com.monitor.model.response.BaseResponse;
import com.yoho.ops.cmdb.aws.AwsClientFactory;
import com.yoho.ops.cmdb.aws.lb.AwsApplicationLoadBalanceFetcher;
import com.yoho.ops.cmdb.domain.BaseResponse;
import com.yoho.ops.cmdb.models.LoadBalance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
... ...
package com.yoho.ops.cmdb.domain;
/**
* service返回信息对象
* @author hp
* 2014-03-11
*/
public class BaseResponse<T> {
private int code = 200;
private String message = "success";
private T data;
public BaseResponse() {}
public BaseResponse(ErrorCode errorCode) {
this.code = errorCode.getCode();
this.message = errorCode.getMessage();
}
public BaseResponse(int code, String message) {
this.code = code;
this.message = message;
}
public BaseResponse(String message) {//Exception
this.code = 201;
this.message = message;
}
public BaseResponse(T data) {
this.data = data;
}
public BaseResponse(int code, String message, T data) {
this(code, message);
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
/**
*
*/
package com.yoho.ops.cmdb.domain;
import lombok.Data;
/**
* 描述:
*
* @author ping.huang
* 2016年3月31日
*/
@Data
public class ErrorCode {
public ErrorCode(int code, String message) {
super();
this.code = code;
this.message = message;
}
private int code;
private String message;
}