Authored by qinchao

在线ip比较

package com.monitor.compare.service;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.model.MObjectInfo;
import com.model.TypeInfo;
import com.monitor.cmdb.service.impl.TypeInfoServiceImpl;
import com.monitor.common.util.ZkOnlineClientUtil;
import com.monitor.compare.comparator.IpComparator;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import com.monitor.mysql.mapper.MTypeInfoMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.utils.ZKPaths;
... ... @@ -28,7 +31,10 @@ public class ServiceCompare {
public static final Logger DEBUG = LoggerFactory.getLogger(ServiceCompare.class);
@Autowired
private IHostInfoService hostInfoService;
TypeInfoServiceImpl typeInfoService;
@Autowired
MObjectInfoMapper mObjectInfoMapper;
@Autowired
private ZkOnlineClientUtil zkOnlineClientUtil;
... ... @@ -353,15 +359,25 @@ public class ServiceCompare {
public List<String> queryServiceCMDBIps(String net, String service) {
String pathStr="YOHO,yohobuy-app";
List<String> cmdbIpList = new ArrayList<>();
int netType = 1;
if (StringUtils.equals(QCLOUD_TYPE, net)) {
netType = 2;
pathStr += ",qcloud";
}else{
pathStr += ",aws";
}
for (HostInfo hostInfo : hostInfoService.getHostInfosByTag(service)) {
//1 aws 2 qcloud
if (netType == hostInfo.getCloudType()) {
cmdbIpList.add(hostInfo.getHostIp());
pathStr += ",service";
pathStr += ","+service;
String[] pathArray=pathStr.split(",");
TypeInfo typeInfo=typeInfoService.getTypeByMobjectPathArray(pathArray);
if(typeInfo!=null){
List<MObjectInfo> mObjectInfoList=mObjectInfoMapper.selectMObjectsInfoByTypeId(typeInfo.getTypeId());
if(mObjectInfoList!=null&&mObjectInfoList.size()>0){
for(MObjectInfo mo:mObjectInfoList){
cmdbIpList.add(mo.getMoHostIp());
}
}
}
... ...