Skip to content

Commit

Permalink
bugfix: 纯IPv6环境分发本地文件/第三方文件一直卡住 TencentBlueKing#1530
Browse files Browse the repository at this point in the history
更改CMDB自定义查询规则,减少嵌套深度,补充查询字段
  • Loading branch information
jsonwan committed Nov 25, 2022
1 parent db905a6 commit 709adc8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ListHostsWithoutBizReq extends EsbReq {
"bk_host_id",
"bk_host_innerip",
"bk_host_innerip_v6",
"bk_agent_id",
"bk_host_name",
"bk_os_name",
"bk_cloud_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,30 +662,32 @@ private List<ApplicationHostDTO> convertToHostInfoDTOList(
return applicationHostDTOList;
}

private ApplicationHostDTO convertHost(long bizId, CcHostInfoDTO hostInfo) {
ApplicationHostDTO ipInfo = new ApplicationHostDTO();
ipInfo.setHostId(hostInfo.getHostId());
// 部分从cmdb同步过来的资源没有ip,需要过滤掉
if (StringUtils.isBlank(hostInfo.getIp())) {
private ApplicationHostDTO convertHost(long bizId, CcHostInfoDTO ccHostInfo) {
// 部分从cmdb同步过来的资源没有hostId,需要过滤掉
if (ccHostInfo.getHostId() == null) {
return null;
}
ApplicationHostDTO hostDTO = new ApplicationHostDTO();
hostDTO.setHostId(ccHostInfo.getHostId());

if (hostInfo.getOs() != null && hostInfo.getOs().length() > 512) {
ipInfo.setOsName(hostInfo.getOs().substring(0, 512));
if (ccHostInfo.getOs() != null && ccHostInfo.getOs().length() > 512) {
log.warn("osName truncated to 512, host={}", ccHostInfo);
hostDTO.setOsName(ccHostInfo.getOs().substring(0, 512));
} else {
ipInfo.setOsName(hostInfo.getOs());
hostDTO.setOsName(ccHostInfo.getOs());
}
if (hostInfo.getCloudId() != null) {
ipInfo.setCloudAreaId(hostInfo.getCloudId());
if (ccHostInfo.getCloudId() != null) {
hostDTO.setCloudAreaId(ccHostInfo.getCloudId());
} else {
log.warn("Host does not have cloud area id!|{}", hostInfo);
log.warn("Host does not have cloud area id!|{}", ccHostInfo);
return null;
}
ipInfo.setIp(hostInfo.getIp());
ipInfo.setBizId(bizId);
ipInfo.setHostName(hostInfo.getHostName());

return ipInfo;
hostDTO.setIp(ccHostInfo.getIp());
hostDTO.setIpv6(ccHostInfo.getIpv6());
hostDTO.setAgentId(ccHostInfo.getAgentId());
hostDTO.setBizId(bizId);
hostDTO.setHostName(ccHostInfo.getHostName());
return hostDTO;
}

@Override
Expand Down Expand Up @@ -1036,33 +1038,27 @@ public List<ApplicationHostDTO> listHostsByCloudIpv6s(List<String> cloudIpv6s) {
PropertyFilterDTO condition = new PropertyFilterDTO();
condition.setCondition("OR");
Map<Long, List<String>> hostGroups = groupHostsByBkCloudId(cloudIpv6s);
hostGroups.forEach((bkCloudId, ipv6s) -> {
ComposeRuleDTO hostRule = new ComposeRuleDTO();
hostRule.setCondition("AND");
hostRule.addRule(buildCloudIdRule(bkCloudId));

ComposeRuleDTO multiIpv6Rule = buildMultiIpv6LikeRule(ipv6s);
hostRule.addRule(multiIpv6Rule);

condition.addRule(hostRule);
});
hostGroups.forEach((bkCloudId, ipv6s) ->
ipv6s.forEach(ipv6 -> {
ComposeRuleDTO hostRule = new ComposeRuleDTO();
hostRule.setCondition("AND");
hostRule.addRule(buildCloudIdRule(bkCloudId));

BaseRuleDTO ipv6Rule = buildIpv6Rule(ipv6);
hostRule.addRule(ipv6Rule);
condition.addRule(hostRule);
}));
req.setCondition(condition);

return listHostsWithoutBiz(req);
}

private ComposeRuleDTO buildMultiIpv6LikeRule(List<String> ipv6s) {
ComposeRuleDTO multiIpv6Rule = new ComposeRuleDTO();
multiIpv6Rule.setCondition("OR");
ipv6s.forEach(ipv6 -> {
BaseRuleDTO ipv6Rule = new BaseRuleDTO();
// ipv6字段可能包含多个IPv6地址,故此处使用contains
ipv6Rule.setField("bk_host_innerip_v6");
ipv6Rule.setOperator("contains");
ipv6Rule.setValue(ipv6);
multiIpv6Rule.addRule(ipv6Rule);
});
return multiIpv6Rule;
private BaseRuleDTO buildIpv6Rule(String ipv6) {
BaseRuleDTO ipv6Rule = new BaseRuleDTO();
// ipv6字段可能包含多个IPv6地址,故此处使用contains
ipv6Rule.setField("bk_host_innerip_v6");
ipv6Rule.setOperator("contains");
ipv6Rule.setValue(ipv6);
return ipv6Rule;
}

private BaseRuleDTO buildCloudIdRule(Long bkCloudId) {
Expand Down

0 comments on commit 709adc8

Please sign in to comment.