...
|
...
|
@@ -7,10 +7,13 @@ import com.monitor.compare.service.GatewayCompare; |
|
|
import com.monitor.compare.service.NignxCompare;
|
|
|
import com.monitor.compare.service.ServiceCompare;
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -20,6 +23,8 @@ import java.util.*; |
|
|
@RequestMapping(value = "/compareIps")
|
|
|
public class CompareCtrl {
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(CompareCtrl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private NignxCompare nignxCompare;
|
|
|
|
...
|
...
|
@@ -32,7 +37,7 @@ public class CompareCtrl { |
|
|
@RequestMapping(value = "/compare")
|
|
|
public BaseResponse compare(@RequestBody CompareRequest request) {
|
|
|
|
|
|
CompareResponse compareResponse=new CompareResponse();
|
|
|
CompareResponse compareResponse = new CompareResponse();
|
|
|
|
|
|
Map<String, List<String>> configMap = new HashMap<>();
|
|
|
|
...
|
...
|
@@ -72,8 +77,7 @@ public class CompareCtrl { |
|
|
}
|
|
|
compareResponse.setIps(resultList);
|
|
|
|
|
|
if(!checkConfig(configMap))
|
|
|
{
|
|
|
if (!checkConfig(configMap)) {
|
|
|
compareResponse.setStatus(1);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -113,6 +117,7 @@ public class CompareCtrl { |
|
|
|
|
|
/**
|
|
|
* 在线ip对比--对比所有的服务
|
|
|
*
|
|
|
* @param cloud
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -120,20 +125,34 @@ public class CompareCtrl { |
|
|
public BaseResponse compareAll(@RequestBody String cloud) {
|
|
|
BaseResponse resp = new BaseResponse();
|
|
|
List<String> serviceList = IpCompareSeviceType.getAllServices();
|
|
|
List<CompareResponse> compareResults = new ArrayList<>();
|
|
|
for(String s : serviceList){
|
|
|
CompareRequest compareRequest = new CompareRequest(s,cloud);
|
|
|
CompareResponse result = compareService(compareRequest);
|
|
|
result.setServiceName(s);
|
|
|
compareResults.add(result);
|
|
|
|
|
|
ExecutorService serversExecutor = Executors.newFixedThreadPool(10);
|
|
|
List<CompareResponse> compareResults = new CopyOnWriteArrayList<>();
|
|
|
for (String s : serviceList) {
|
|
|
CompareRequest compareRequest = new CompareRequest(s, cloud);
|
|
|
serversExecutor.submit(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
CompareResponse result = compareService(compareRequest);
|
|
|
result.setServiceName(s);
|
|
|
compareResults.add(result);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
serversExecutor.shutdown();
|
|
|
try {
|
|
|
serversExecutor.awaitTermination(50, TimeUnit.SECONDS);
|
|
|
} catch (InterruptedException e) {
|
|
|
LOGGER.error("check tasks time out ....");
|
|
|
if (!serversExecutor.isShutdown()) {
|
|
|
serversExecutor.shutdownNow();
|
|
|
}
|
|
|
}
|
|
|
resp.setData(compareResults);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -162,8 +181,7 @@ public class CompareCtrl { |
|
|
|
|
|
compareResponse.setIpMaps(configMap);
|
|
|
|
|
|
if(!checkConfig(configMap))
|
|
|
{
|
|
|
if (!checkConfig(configMap)) {
|
|
|
compareResponse.setStatus(1);
|
|
|
}
|
|
|
|
...
|
...
|
|