|
|
package com.monitor.compare.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.model.HostInfo;
|
|
|
import com.monitor.cmdb.service.IHostInfoService;
|
|
|
import com.monitor.compare.comparator.IpComparator;
|
|
|
import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
|
|
|
import org.apache.commons.lang.StringUtils;
|
...
|
...
|
@@ -15,6 +17,7 @@ import org.gitlab.api.TokenType; |
|
|
import org.gitlab.api.models.GitlabProject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -37,6 +40,9 @@ public class ServiceCompare { |
|
|
@Value("${qcloud_zk_address}")
|
|
|
private String qcloud_zk_address;
|
|
|
|
|
|
@Autowired
|
|
|
private IHostInfoService hostInfoService;
|
|
|
|
|
|
public Map<String, List<String>> compare(String net, String service) {
|
|
|
Map<String, List<String>> configMap = new HashMap<>();
|
|
|
|
...
|
...
|
@@ -53,7 +59,7 @@ public class ServiceCompare { |
|
|
DEBUG.error("Failed to query net {} service {} form ip-tables in gitlab, error {} ", net, service, e);
|
|
|
}
|
|
|
|
|
|
configMap.put("iptables", ipsInIptables);
|
|
|
configMap.put("ip-tables", ipsInIptables);
|
|
|
|
|
|
List<String> ipsInZK;
|
|
|
|
...
|
...
|
@@ -66,7 +72,19 @@ public class ServiceCompare { |
|
|
DEBUG.error("Failed to query net {} service {} form zk register service, error {} ", net, service, e);
|
|
|
}
|
|
|
|
|
|
configMap.put("zk", ipsInZK);
|
|
|
configMap.put("zk-instaces", ipsInZK);
|
|
|
|
|
|
List<String> ipsInCMDB;
|
|
|
try {
|
|
|
ipsInCMDB=queryServiceCMDBIps(net,service);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
ipsInCMDB=new ArrayList<>(0);
|
|
|
DEBUG.error("Failed to query net {} service {} form cmdb, error {} ", net, service, e);
|
|
|
}
|
|
|
|
|
|
configMap.put("cmdb",ipsInCMDB);
|
|
|
|
|
|
return configMap;
|
|
|
}
|
...
|
...
|
@@ -113,8 +131,7 @@ public class ServiceCompare { |
|
|
|
|
|
String[] ipArray = ips.split("master@");
|
|
|
|
|
|
if(null==ipArray)
|
|
|
{
|
|
|
if (null == ipArray) {
|
|
|
return ipList;
|
|
|
}
|
|
|
for (String ip : ipArray) {
|
...
|
...
|
@@ -328,7 +345,7 @@ public class ServiceCompare { |
|
|
return serviceIps;
|
|
|
}
|
|
|
|
|
|
private CuratorFramework createClinet(String address) throws InterruptedException {
|
|
|
private CuratorFramework createClinet(String address) throws Exception {
|
|
|
CuratorFramework client = CuratorFrameworkFactory.newClient(address, new RetryOneTime(2000));
|
|
|
|
|
|
client.blockUntilConnected(2, TimeUnit.SECONDS);
|
...
|
...
|
@@ -336,4 +353,24 @@ public class ServiceCompare { |
|
|
return client;
|
|
|
}
|
|
|
|
|
|
public List<String> queryServiceCMDBIps(String net, String service) {
|
|
|
List<String> cmdbIpList = new ArrayList<>();
|
|
|
int netType = 1;
|
|
|
if (StringUtils.equals(QCLOUD_TYPE, net)) {
|
|
|
netType = 2;
|
|
|
}
|
|
|
for (HostInfo hostInfo : hostInfoService.getHostInfosByTag(service)) {
|
|
|
//1 aws 2 qcloud
|
|
|
if (netType == hostInfo.getCloudType()) {
|
|
|
cmdbIpList.add(hostInfo.getHostIp());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!cmdbIpList.isEmpty()) {
|
|
|
Collections.sort(cmdbIpList, new IpComparator());
|
|
|
}
|
|
|
|
|
|
return cmdbIpList;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|