|
|
package com.monitor.javaserver.client;
|
|
|
|
|
|
import com.model.HostInfo;
|
|
|
import com.model.JavaApiInfo;
|
|
|
import com.model.MObjectDetails;
|
|
|
import com.model.MObjectInfo;
|
|
|
import com.monitor.cmdb.service.IHostInfoService;
|
|
|
import com.monitor.cmdb.service.IJavaApiInfoService;
|
|
|
import com.monitor.cmdb.service.IMObjectInfoService;
|
|
|
import com.monitor.javaserver.common.JavaApiStatics;
|
|
|
import com.monitor.javaserver.common.JavaApiStatus;
|
|
|
import com.monitor.javaserver.common.JavaApiTask;
|
|
|
import com.monitor.javaserver.common.JavaApiThreadFactory;
|
|
|
import com.monitor.javaserver.handle.IJavaApiHadnler;
|
|
|
import com.monitor.model.request.HostInfoReq;
|
|
|
import com.monitor.model.response.PageResponse;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Component;
|
...
|
...
|
@@ -17,6 +24,7 @@ import org.springframework.util.LinkedMultiValueMap; |
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.*;
|
...
|
...
|
@@ -36,6 +44,9 @@ public class JavaApiClient { |
|
|
private IMObjectInfoService mObjectInfoService;
|
|
|
|
|
|
@Autowired
|
|
|
private IHostInfoService hostInfoService;
|
|
|
|
|
|
@Autowired
|
|
|
@Qualifier("javaapiRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
//
|
...
|
...
|
@@ -46,11 +57,14 @@ public class JavaApiClient { |
|
|
@Autowired
|
|
|
private List<IJavaApiHadnler> javaApiHadnlerList;
|
|
|
|
|
|
@Autowired
|
|
|
JavaApiStatus javaApiStatus;
|
|
|
|
|
|
|
|
|
//TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
|
|
|
private Map<String, JavaApiInfo> javaApimap;
|
|
|
|
|
|
private MultiValueMap<Integer, MObjectInfo> mObjInfoMap;
|
|
|
private MultiValueMap<Integer, MObjectDetails> mObjInfoMap;
|
|
|
|
|
|
private ExecutorService executorService;
|
|
|
|
...
|
...
|
@@ -64,21 +78,48 @@ public class JavaApiClient { |
|
|
completionService = new ExecutorCompletionService<JavaApiStatics>(executorService);
|
|
|
|
|
|
javaApimap = new ConcurrentHashMap<String, JavaApiInfo>();
|
|
|
mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectInfo>();
|
|
|
mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectDetails>();
|
|
|
|
|
|
//清理本次统计信息
|
|
|
javaApiStatus.clear();
|
|
|
}
|
|
|
|
|
|
public void initApiMonitor() {
|
|
|
//获取JAVA服务信息
|
|
|
List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo();
|
|
|
|
|
|
for (JavaApiInfo javaApiInfo : apiInfos) {
|
|
|
javaApimap.put(javaApiInfo.getApiName(), javaApiInfo);
|
|
|
}
|
|
|
|
|
|
//获取云类型
|
|
|
HostInfoReq req = new HostInfoReq();
|
|
|
req.setPageSize(1000);
|
|
|
req.setCurrentPage(0);
|
|
|
PageResponse<HostInfo> hostInfos = hostInfoService.getHostInfos(req);
|
|
|
Map<String, Integer> ipCloudMap = new HashMap<String, Integer>();
|
|
|
|
|
|
if (hostInfos.getTotal() > 0) {
|
|
|
for (HostInfo hostInfo : hostInfos.getRows()) {
|
|
|
ipCloudMap.put(hostInfo.getHostIp().trim(), hostInfo.getCloudType());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//获取部署java服务的服务对象
|
|
|
//TODO 需要删选java服务
|
|
|
List<MObjectInfo> mObjectInfos = mObjectInfoService.queryMObjectsInfo();
|
|
|
|
|
|
for (MObjectInfo mObjInfo : mObjectInfos) {
|
|
|
mObjInfoMap.add(mObjInfo.getMoTypeId(), mObjInfo);
|
|
|
MObjectDetails mObjectDetails = new MObjectDetails();
|
|
|
BeanUtils.copyProperties(mObjInfo, mObjectDetails);
|
|
|
|
|
|
if (ipCloudMap.containsKey(mObjInfo.getMoHostIp())) {
|
|
|
mObjectDetails.setCloudType(ipCloudMap.get(mObjInfo.getMoHostIp().trim()));
|
|
|
} else {
|
|
|
mObjectDetails.setCloudType(0);
|
|
|
}
|
|
|
mObjInfoMap.add(mObjInfo.getMoTypeId(), mObjectDetails);
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -89,12 +130,12 @@ public class JavaApiClient { |
|
|
int tastNum = 0;
|
|
|
for (JavaApiInfo javaApiInfo : javaApimap.values()) {
|
|
|
|
|
|
List<MObjectInfo> mObjectInfos = mObjInfoMap.get(javaApiInfo.getServiceType());
|
|
|
List<MObjectDetails> mObjectInfos = mObjInfoMap.get(javaApiInfo.getServiceType());
|
|
|
if (mObjectInfos == null) {
|
|
|
log.warn("type {} has no service object", javaApiInfo.getServiceType());
|
|
|
continue;
|
|
|
}
|
|
|
for (MObjectInfo mObjectInfo : mObjectInfos) {
|
|
|
for (MObjectDetails mObjectInfo : mObjectInfos) {
|
|
|
completionService.submit(new JavaApiTask(restTemplate, javaApiInfo, mObjectInfo));
|
|
|
tastNum++;
|
|
|
}
|
...
|
...
|
@@ -135,9 +176,9 @@ public class JavaApiClient { |
|
|
completionService = new ExecutorCompletionService<JavaApiStatics>(executorService);
|
|
|
|
|
|
javaApimap = new ConcurrentHashMap<String, JavaApiInfo>();
|
|
|
mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectInfo>();
|
|
|
mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectDetails>();
|
|
|
|
|
|
MObjectInfo mObj1 = new MObjectInfo();
|
|
|
MObjectDetails mObj1 = new MObjectDetails();
|
|
|
mObj1.setMoId(1);
|
|
|
mObj1.setMoHostIp("192.168.102.205");
|
|
|
mObj1.setMoTags("8080");
|
...
|
...
|
@@ -155,7 +196,7 @@ public class JavaApiClient { |
|
|
//
|
|
|
// mObjInfoMap.add(1, mObj2);
|
|
|
|
|
|
MObjectInfo mObj2 = new MObjectInfo();
|
|
|
MObjectDetails mObj2 = new MObjectDetails();
|
|
|
mObj2.setMoId(0);
|
|
|
mObj2.setMoHostIp("localhost");
|
|
|
mObj2.setMoTags("10080");
|
...
|
...
|
|