Authored by qinchao

接口更改

... ... @@ -132,6 +132,16 @@ public class HostInfoCtrl {
}
/**
* 从标签获取机器信息
* @return
*/
@RequestMapping("/getHostIpByTags")
@ResponseBody
public List<String> getHostIpByTags(String tags){
return hostInfoService.getHostIpByTags(tags);
}
/**
* 获取所有具有nginx标签的主机信息,返回给外系统(恶意ip捕获)调用
... ...
... ... @@ -27,6 +27,8 @@ public interface IHostInfoService {
List<HostInfo> getHostInfosByTag(String tag);
List<String> getHostIpByTags(String tags);
List<HostInfo> getHostInfosByTagList(List<String> tagList);
List<HostInfo> getHostInfoByIps(List<String> ids);
... ...
... ... @@ -23,10 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Created by yoho on 2016/6/14.
... ... @@ -235,6 +232,19 @@ public class HostInfoServiceImpl implements IHostInfoService {
}
@Override
public List<String> getHostIpByTags(String tags){
List<String> ips=new ArrayList<>();
if(StringUtils.isNotBlank(tags)){
List<HostInfo> hostInfos = this.getHostInfosByTagList(Arrays.asList(tags.split(",")));
if(hostInfos!=null&&hostInfos.size()>0){
for(HostInfo hostInfo:hostInfos){
ips.add(hostInfo.getHostIp());
}
}
}
return ips;
}
@Override
public List<HostInfo> getHostInfosByTagList(List<String> tagList){
return hostInfoMapper.selectHostInfosByTagList(tagList);
}
... ...
package com.monitor.switchs;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.monitor.model.response.BaseResponse;
import com.yoho.ops.cmdb.models.Host;
... ... @@ -45,29 +44,11 @@ public class Pch5SwitchCtrl {
private final String const_az1_host_under_prod_elb="az1_host_under_prod_elb";
private final String const_az2_host_under_prod_elb="az2_host_under_prod_elb";
private final String const_az2_in_gray="const_az2_in_gray";
private final List<String> const_tags_for_nginx_az1=new ArrayList<String>(){
{
add("pch5");
add("nginx");
add("az1");
}
};
private final String const_tags_for_nginx_az1="pch5,nginx,az1";
private final List<String> const_tags_for_nginx_az2=new ArrayList<String>(){
{
add("pch5");
add("nginx");
add("az2");
}
};
private final String const_tags_for_nginx_az2="pch5,nginx,az2";
private final List<String> const_tags_for_nginx_node_az2=new ArrayList<String>(){
{
add("pch5");
add("node");
add("az2");
}
};
private final String const_tags_for_nginx_node_az2="pch5,node,az2";
@Autowired
private QcloudLoadBalance qcloudLoadBalance;
... ... @@ -80,8 +61,8 @@ public class Pch5SwitchCtrl {
public BaseResponse getElbStatus() {
BaseResponse response = new BaseResponse();
//az1 ,az2机器
List<String> az1_host_cmdb=getHostByType(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=getHostByType(const_tags_for_nginx_az2);
List<String> az1_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az2);
BaseResponse checkAzResponse=checkAzCmdb(az1_host_cmdb,az2_host_cmdb);
if(checkAzResponse==null||checkAzResponse.getCode()!=200){
return checkAzResponse;
... ... @@ -228,22 +209,6 @@ public class Pch5SwitchCtrl {
return baseResponse;
}
/**
* 从标签获取机器信息
* @return
*/
private List<String> getHostByType(List<String> tagList){
List<HostInfo> hostInfos = hostInfoService.getHostInfosByTagList(tagList);
List<String> ips=new ArrayList<>();
if(hostInfos!=null&&hostInfos.size()>0){
for(HostInfo hostInfo:hostInfos){
ips.add(hostInfo.getHostIp());
}
}
return ips;
}
/**
* 可用区切换
... ... @@ -254,8 +219,8 @@ public class Pch5SwitchCtrl {
public BaseResponse switchArea(String area) {
//az1 ,az2机器,及对应instanceId
List<String> az1_host_cmdb=getHostByType(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=getHostByType(const_tags_for_nginx_az2);
List<String> az1_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az2);
BaseResponse checkAzResponse=checkAzCmdb(az1_host_cmdb,az2_host_cmdb);
if(checkAzResponse==null||checkAzResponse.getCode()!=200){
return checkAzResponse;
... ... @@ -334,7 +299,7 @@ public class Pch5SwitchCtrl {
@RequestMapping(value = "/getPch5NodeHostUnderAz2")
@ResponseBody
public List<String> getPch5NodeHostIPs() {
return getHostByType(const_tags_for_nginx_node_az2);
return hostInfoService.getHostIpByTags(const_tags_for_nginx_node_az2);
}
... ... @@ -352,8 +317,8 @@ public class Pch5SwitchCtrl {
}
//az1 ,az2机器,及对应instanceId
List<String> az1_host_cmdb=getHostByType(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=getHostByType(const_tags_for_nginx_az2);
List<String> az1_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az1);
List<String> az2_host_cmdb=hostInfoService.getHostIpByTags(const_tags_for_nginx_az2);
BaseResponse checkAzResponse=checkAzCmdb(az1_host_cmdb,az2_host_cmdb);
if(checkAzResponse==null||checkAzResponse.getCode()!=200){
return checkAzResponse;
... ...