From f1b2932451ff126f4b0d0b5d73d153ed5fbd0af4 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Wed, 28 Jul 2021 17:23:04 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E7=99=BD=E5=90=8D=E5=8D=95IP?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=AF=B9=E2=80=9C?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=96=B9=E5=BC=8F=E2=80=9D=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E5=A6=82=E4=BB=85=E5=BC=80=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E5=8F=91=E5=88=99=E5=9C=A8=E8=84=9A=E6=9C=AC=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E4=B8=8D=E5=8F=AF=E9=80=89=E4=B8=AD=20#115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ApplicationServiceImpl.java | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) 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查主机(缺少业务信息)本地