Skip to content

Commit

Permalink
fix: IP选择器对搜索后进行全选时,错误将全部数据给全选了 TencentBlueKing#2076
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed May 23, 2023
1 parent be278ce commit d93cd95
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public Response<PageData<HostIdWithMeta>> listHostIdByBizTopologyNodes(String us
req.getNodeList(),
req.getSearchContent(),
req.getAlive(),
req.getIpKeyList(),
req.getIpv6KeyList(),
req.getHostNameKeyList(),
req.getOsNameKeyList(),
pagePair.getLeft(),
pagePair.getRight()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ Long countHostInfoByMultiKeys(Collection<Long> bizIds,

/**
* 批量更新主机状态
* @param status 主机状态
*
* @param status 主机状态
* @param hostIdList 主机id列表
* @return 成功更新的条数
*/
Expand Down Expand Up @@ -233,8 +234,10 @@ Long countHostInfoByMultiKeys(Collection<Long> bizIds,
* @return 删除的主机数量
*/
int deleteBizHostInfoByBizId(long bizId);

/**
* 根据业务id统计主机状态数量
*
* @param bizIds 业务id
* @return 状态数量
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,20 @@ public List<ApplicationHostDTO> listHostInfoByHostNames(Collection<String> hostN
}

@Override
public Long countHostInfoBySearchContents(Collection<Long> bizIds, Collection<Long> moduleIds,
Collection<Long> cloudAreaIds, List<String> searchContents,
public Long countHostInfoBySearchContents(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentStatus) {
List<Long> hostIdList = getHostIdListBySearchContents(bizIds, moduleIds, cloudAreaIds, searchContents,
agentStatus, null, null);
List<Long> hostIdList = getHostIdListBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentStatus,
null,
null
);
return (long) (hostIdList.size());
}

Expand Down Expand Up @@ -563,17 +572,41 @@ private List<Condition> buildMultiKeysConditions(Collection<Long> bizIds,
if (cloudAreaIds != null) {
conditions.add(tHost.CLOUD_AREA_ID.in(cloudAreaIds));
}
if (ipKeys != null) {
conditions.add(tHost.IP.in(ipKeys));
if (CollectionUtils.isNotEmpty(ipKeys)) {
List<String> ipList = new ArrayList<>(ipKeys);
String firstContent = ipList.get(0);
Condition condition = tHost.IP.like("%" + firstContent + "%");
for (int i = 1; i < ipList.size(); i++) {
condition = condition.or(tHost.IP.like("%" + ipList.get(i) + "%"));
}
conditions.add(condition);
}
if (ipv6Keys != null) {
conditions.add(tHost.IP_V6.in(ipv6Keys));
if (CollectionUtils.isNotEmpty(ipv6Keys)) {
List<String> ipv6List = new ArrayList<>(ipv6Keys);
String firstContent = ipv6List.get(0);
Condition condition = tHost.IP_V6.like("%" + firstContent + "%");
for (int i = 1; i < ipv6List.size(); i++) {
condition = condition.or(tHost.IP_V6.like("%" + ipv6List.get(i) + "%"));
}
conditions.add(condition);
}
if (hostNameKeys != null) {
conditions.add(tHost.IP_DESC.in(hostNameKeys));
if (CollectionUtils.isNotEmpty(hostNameKeys)) {
List<String> hostNameList = new ArrayList<>(hostNameKeys);
String firstContent = hostNameList.get(0);
Condition condition = tHost.IP_DESC.like("%" + firstContent + "%");
for (int i = 1; i < hostNameList.size(); i++) {
condition = condition.or(tHost.IP_DESC.like("%" + hostNameList.get(i) + "%"));
}
conditions.add(condition);
}
if (osNameKeys != null) {
conditions.add(tHost.OS.in(osNameKeys));
if (CollectionUtils.isNotEmpty(osNameKeys)) {
List<String> osNameList = new ArrayList<>(osNameKeys);
String firstContent = osNameList.get(0);
Condition condition = tHost.OS.like("%" + firstContent + "%");
for (int i = 1; i < osNameList.size(); i++) {
condition = condition.or(tHost.OS.like("%" + osNameList.get(i) + "%"));
}
conditions.add(condition);
}
return conditions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,28 @@ List<ApplicationHostDTO> getHostsByBizAndHostNames(Collection<Long> bizIds,
/**
* 根据条件查询主机ID
*
* @param bizIds 业务ID集合
* @param moduleIds 模块ID集合
* @param cloudAreaIds 云区域ID集合
* @param searchContents 搜索关键字列表
* @param agentAlive agent是否正常
* @param start 数据起始位置
* @param limit 查询数据条数
* @param bizIds 业务ID集合
* @param moduleIds 模块ID集合
* @param cloudAreaIds 云区域ID集合
* @param searchContents 搜索关键字列表
* @param agentAlive agent是否正常
* @param ipKeyList IP关键字列表
* @param ipv6KeyList IPv6关键字列表
* @param hostNameKeyList 主机名关键字列表
* @param osNameKeyList 系统名关键字列表
* @param start 数据起始位置
* @param limit 查询数据条数
* @return 主机列表
*/
PageData<Long> pageListHostId(Collection<Long> bizIds,
Collection<Long> moduleIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ List<ApplicationHostDTO> getScopeHostsByHostNames(AppResourceScope appResourceSc
* @param appTopoNodeList 拓扑节点列表
* @param searchContent 模糊搜索关键字(同时对主机IP/主机名/操作系统/云区域名称进行模糊搜索)
* @param agentAlive 筛选条件:agentAlive:0为异常,1为正常
* @param ipKeyList IP关键字列表
* @param ipv6KeyList IPv6关键字列表
* @param hostNameKeyList 主机名称关键字列表
* @param osNameKeyList 操作系统名称关键字列表
* @param start 数据起始位置
* @param pageSize 拉取数量
* @return hostId列表
Expand All @@ -102,6 +106,10 @@ PageData<Long> listHostIdByBizTopologyNodes(AppResourceScope appResourceScope,
List<BizTopoNode> appTopoNodeList,
String searchContent,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long pageSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,67 @@ public PageData<Long> pageListHostId(Collection<Long> bizIds,
Collection<Long> cloudAreaIds,
List<String> searchContents,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long limit) {
List<Long> hostIdList;
Long count;
StopWatch watch = new StopWatch("pageListHostId");
watch.start("listHostInfoBySearchContents");
List<Long> hostIdList = applicationHostDAO.getHostIdListBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentAlive,
start,
limit
);
watch.stop();
watch.start("countHostInfoBySearchContents");
Long count = applicationHostDAO.countHostInfoBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentAlive
);
watch.stop();
if (searchContents != null) {
watch.start("getHostIdListBySearchContents");
hostIdList = applicationHostDAO.getHostIdListBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentAlive,
start,
limit
);
watch.stop();
watch.start("countHostInfoBySearchContents");
count = applicationHostDAO.countHostInfoBySearchContents(
bizIds,
moduleIds,
cloudAreaIds,
searchContents,
agentAlive
);
watch.stop();
} else {
watch.start("getHostIdListByMultiKeys");
hostIdList = applicationHostDAO.getHostIdListByMultiKeys(
bizIds,
moduleIds,
cloudAreaIds,
ipKeyList,
ipv6KeyList,
hostNameKeyList,
osNameKeyList,
agentAlive,
start,
limit
);
watch.stop();
watch.start("countHostInfoByMultiKeys");
count = applicationHostDAO.countHostInfoByMultiKeys(
bizIds,
moduleIds,
cloudAreaIds,
ipKeyList,
ipv6KeyList,
hostNameKeyList,
osNameKeyList,
agentAlive
);
watch.stop();
}
if (watch.getTotalTimeMillis() > 3000) {
log.warn("pageListHostId slow:" + watch.prettyPrint());
}
return new PageData<>(start.intValue(), limit.intValue(), count, hostIdList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ public PageData<Long> listHostIdByBizTopologyNodes(AppResourceScope appResourceS
List<BizTopoNode> appTopoNodeList,
String searchContent,
Integer agentAlive,
List<String> ipKeyList,
List<String> ipv6KeyList,
List<String> hostNameKeyList,
List<String> osNameKeyList,
Long start,
Long pageSize) {
StopWatch watch = new StopWatch("listHostByBizTopologyNodes");
Expand All @@ -181,6 +185,10 @@ public PageData<Long> listHostIdByBizTopologyNodes(AppResourceScope appResourceS
basicConditions.getCloudAreaIds(),
basicConditions.getSearchContents(),
agentAlive,
ipKeyList,
ipv6KeyList,
hostNameKeyList,
osNameKeyList,
start,
pageSize
);
Expand Down

0 comments on commit d93cd95

Please sign in to comment.