diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java index 80cd5a8a02..55eb4d1067 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/service/impl/ApplicationServiceImpl.java @@ -789,19 +789,9 @@ public List getHostInfoById(String username, Long appId, return hostInfoList; } - @Override - public List getHostsByIp( - String username, - Long appId, - ActionScopeEnum actionScope, - List checkIpList - ) { - log.info("Input=({},{},{})", username, appId, checkIpList); - if (checkIpList == null || checkIpList.isEmpty()) { - return Collections.emptyList(); - } - checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); + private List parseInputCloudIPList(List checkIpList) { List inputCloudIPList = new ArrayList<>(); + checkIpList = checkIpList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList()); for (int i = 0; i < checkIpList.size(); i++) { String ip = checkIpList.get(i); if (!StringUtils.isBlank(ip)) { @@ -821,26 +811,16 @@ public List getHostsByIp( } } } - //1.先查IP白名单中是否存在该IP - List appWhiteIPList = whiteIPService.listWhiteIP(appId, actionScope); - //生成IP为索引的Map - Map> whiteIPMap = new HashMap<>(); - appWhiteIPList.forEach(cloudIPDTO -> { - String ip = cloudIPDTO.getIp(); - if (whiteIPMap.containsKey(ip)) { - List list = whiteIPMap.get(ip); - list.add(cloudIPDTO); - whiteIPMap.put(ip, list); - } else { - List list = new ArrayList<>(); - list.add(cloudIPDTO); - whiteIPMap.put(ip, list); - } - }); + return inputCloudIPList; + } + + private void separateWhiteIP( + List inputCloudIPList, + List inputWhiteIPList, + List inputNotWhiteIPList, + Map> whiteIPMap + ) { Set whiteIPSet = whiteIPMap.keySet(); - //找出输入IP中的白名单IP - List inputWhiteIPList = new ArrayList<>(); - List inputNotWhiteIPList = new ArrayList<>(); inputCloudIPList.forEach(cloudIPDTO -> { String ip = cloudIPDTO.getIp(); Long cloudId = cloudIPDTO.getCloudAreaId(); @@ -864,6 +844,41 @@ public List getHostsByIp( inputNotWhiteIPList.add(cloudIPDTO); } }); + } + + @Override + public List getHostsByIp( + String username, + Long appId, + ActionScopeEnum actionScope, + List checkIpList + ) { + log.info("Input=({},{},{})", username, appId, checkIpList); + if (checkIpList == null || checkIpList.isEmpty()) { + return Collections.emptyList(); + } + List inputCloudIPList = parseInputCloudIPList(checkIpList); + //1.先查IP白名单中是否存在该IP + List appWhiteIPList = whiteIPService.listWhiteIP(appId, actionScope); + //生成IP为索引的Map + Map> whiteIPMap = new HashMap<>(); + appWhiteIPList.forEach(cloudIPDTO -> { + String ip = cloudIPDTO.getIp(); + if (whiteIPMap.containsKey(ip)) { + List list = whiteIPMap.get(ip); + list.add(cloudIPDTO); + whiteIPMap.put(ip, list); + } else { + List list = new ArrayList<>(); + list.add(cloudIPDTO); + whiteIPMap.put(ip, list); + } + }); + + //找出输入IP中的白名单IP + List inputWhiteIPList = new ArrayList<>(); + List inputNotWhiteIPList = new ArrayList<>(); + separateWhiteIP(inputCloudIPList,inputWhiteIPList,inputNotWhiteIPList,whiteIPMap); //使用不带业务信息接口查询白名单IP对应的主机详情 //仅根据IP查询,查出后再根据指定云区域过滤 //根据IP查主机(缺少业务信息)本地