Skip to content

Commit

Permalink
fix: 主机AgentId更新后,小概率出现使用旧AgentId下发任务 TencentBlueKing#2142
Browse files Browse the repository at this point in the history
1.去除主机数据更新与主机关系数据更新间的耦合;
2.全量更新改为增量更新;
3.去除对主机表中拓扑数据的引用,后续去除冗余拓扑字段。
  • Loading branch information
jsonwan committed Jun 29, 2023
1 parent b6a498b commit b4cfca5
Show file tree
Hide file tree
Showing 30 changed files with 1,517 additions and 829 deletions.
Expand Up @@ -43,11 +43,11 @@ public class FindModuleHostRelationReq extends EsbReq {
private List<Long> moduleIdList;

@JsonProperty("module_fields")
private List<String> moduleFields = Arrays.asList("bk_module_id", "bk_set_id");
private List<String> moduleFields = Arrays.asList("bk_module_id", "bk_set_id", "last_time");

@JsonProperty("host_fields")
private List<String> hostFields = Arrays.asList("bk_host_id", "bk_host_innerip", "bk_host_innerip_v6",
"bk_agent_id", "bk_host_name", "bk_os_name", "bk_cloud_id", "bk_os_type", "bk_cloud_vendor");
"bk_agent_id", "bk_host_name", "bk_os_name", "bk_cloud_id", "bk_os_type", "bk_cloud_vendor", "last_time");

private Page page;
}

This file was deleted.

Expand Up @@ -24,11 +24,7 @@

package com.tencent.bk.job.common.cc.model.result;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

Expand All @@ -39,47 +35,4 @@ public class FindModuleHostRelationResult {

private List<HostWithModules> relation;

@Getter
@Setter
@ToString
public static class HostWithModules {
private HostProp host;
private List<ModuleProp> modules;
}

@Getter
@Setter
@ToString
public static class HostProp {
@JsonProperty("bk_host_id")
private Long hostId;
@JsonProperty("bk_host_innerip")
private String ip;
@JsonProperty("bk_host_innerip_v6")
private String ipv6;
@JsonProperty("bk_agent_id")
private String agentId;
@JsonProperty("bk_host_name")
private String hostName;
@JsonProperty("bk_os_name")
private String osName;
@JsonProperty("bk_os_type")
private String osType;
@JsonProperty("bk_cloud_id")
private Long cloudAreaId = 0L;
@JsonProperty("bk_cloud_vendor")
private String cloudVendorId;
}

@Getter
@Setter
@ToString
public static class ModuleProp {
@JsonProperty("bk_module_id")
private Long moduleId;
@JsonProperty("bk_set_id")
private Long setId;
@JsonProperty("bk_module_type")
private String moduleType;
}
}
Expand Up @@ -28,6 +28,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.model.dto.ApplicationHostDTO;
import com.tencent.bk.job.common.util.StringUtil;
import com.tencent.bk.job.common.util.TimeUtil;
import lombok.Data;

import java.util.List;
Expand Down Expand Up @@ -62,6 +63,9 @@ public class HostEventDetail {
@JsonProperty("bk_cloud_vendor")
private String cloudVendorId;

@JsonProperty("last_time")
private String lastTime;

public static ApplicationHostDTO toHostInfoDTO(HostEventDetail eventDetail) {
ApplicationHostDTO hostInfoDTO = new ApplicationHostDTO();
hostInfoDTO.setHostId(eventDetail.hostId);
Expand All @@ -78,6 +82,7 @@ public static ApplicationHostDTO toHostInfoDTO(HostEventDetail eventDetail) {
hostInfoDTO.setOsType(eventDetail.osType);
hostInfoDTO.setCloudAreaId(Long.parseLong(eventDetail.getCloudId()));
hostInfoDTO.setCloudVendorId(eventDetail.cloudVendorId);
hostInfoDTO.setLastTime(TimeUtil.parseZonedTime(eventDetail.getLastTime()));
return hostInfoDTO;
}
}
@@ -0,0 +1,85 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.cc.model.result;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.model.dto.ApplicationHostDTO;
import com.tencent.bk.job.common.util.StringUtil;
import com.tencent.bk.job.common.util.TimeUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

@Getter
@Setter
@ToString
public class HostProp {
@JsonProperty("bk_host_id")
private Long hostId;
@JsonProperty("bk_host_innerip")
private String ip;
@JsonProperty("bk_host_innerip_v6")
private String ipv6;
@JsonProperty("bk_agent_id")
private String agentId;
@JsonProperty("bk_host_name")
private String hostName;
@JsonProperty("bk_os_name")
private String osName;
@JsonProperty("bk_os_type")
private String osType;
@JsonProperty("bk_cloud_id")
private Long cloudAreaId = 0L;
@JsonProperty("bk_cloud_vendor")
private String cloudVendorId;
@JsonProperty("last_time")
private String lastTime;

public ApplicationHostDTO toApplicationHostDTO() {
ApplicationHostDTO applicationHostDTO = new ApplicationHostDTO();
applicationHostDTO.setHostId(hostId);
List<String> ipList = StringUtil.strToList(ip, String.class, ",");
applicationHostDTO.setIpList(ipList);
if (ipList != null && !ipList.isEmpty()) {
applicationHostDTO.setIp(ipList.get(0));
}
applicationHostDTO.setDisplayIp(ip);
applicationHostDTO.setIpv6(ipv6);
applicationHostDTO.setAgentId(agentId);
int hostNameMaxLength = 2000;
int osNameMaxLength = 512;
int osTypeNameMaxLength = 32;
applicationHostDTO.setHostName(StringUtil.substring(hostName, hostNameMaxLength));
applicationHostDTO.setOsName(StringUtil.substring(osName, osNameMaxLength));
applicationHostDTO.setOsType(StringUtil.substring(osType, osTypeNameMaxLength));
applicationHostDTO.setCloudAreaId(cloudAreaId);
applicationHostDTO.setCloudVendorId(cloudVendorId);
applicationHostDTO.setLastTime(TimeUtil.parseZonedTime(lastTime));
return applicationHostDTO;
}
}
Expand Up @@ -42,4 +42,7 @@ public class HostRelationEventDetail {

@JsonProperty("bk_module_id")
private Long moduleId;

@JsonProperty("last_time")
private String lastTime;
}
@@ -0,0 +1,40 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.cc.model.result;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;


@Getter
@Setter
@ToString
public class HostWithModules {
private HostProp host;
private List<ModuleProp> modules;
}
@@ -0,0 +1,45 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.cc.model.result;


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class ModuleProp {
@JsonProperty("bk_module_id")
private Long moduleId;
@JsonProperty("bk_set_id")
private Long setId;
@JsonProperty("bk_module_type")
private String moduleType;
@JsonProperty("last_time")
private String lastTime;
}

0 comments on commit b4cfca5

Please sign in to comment.