Skip to content

Commit

Permalink
feature: 3.6.x版本移除对agentId的依赖 TencentBlueKing#1615
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Dec 14, 2022
1 parent 64cff95 commit bb207e3
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,6 @@ public HostDTO clone() {
return clone;
}

/**
* 获取最终的agentId,若agentId不存在,则使用cloudIp作为agentId
*
* @return 最终的agentId
*/
@JsonIgnore
public String getFinalAgentId() {
if (StringUtils.isNotBlank(agentId)) {
return agentId;
} else {
return toCloudIp();
}
}

/**
* 获取主机的唯一KEY,用于去重等操作
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public abstract class AbstractGseTaskStartCommand extends AbstractGseTaskCommand
this.requestId = requestId;
this.stepInstanceService = stepInstanceService;

this.agentIdHostMap = stepInstanceService.computeStepHosts(stepInstance,
host -> host.getAgentId() != null ? host.getAgentId() : host.toCloudIp());
this.agentIdHostMap = stepInstanceService.computeStepHosts(stepInstance, HostDTO::toCloudIp);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.tencent.bk.job.manage.common.consts.task.TaskStepTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -340,12 +339,7 @@ protected AgentTaskDTO buildGseAgentTask(long stepInstanceId,
agentTask.setStatus(status);
agentTask.setFileTaskMode(FileTaskModeEnum.DOWNLOAD);
agentTask.setHostId(host.getHostId());
if (StringUtils.isEmpty(host.getAgentId())) {
// 兼容老的Agent,没有AgentId,需要使用{bk_cloud_id:ip}的格式作为agentId传给GSE
agentTask.setAgentId(host.toCloudIp());
} else {
agentTask.setAgentId(host.getAgentId());
}
agentTask.setAgentId(host.toCloudIp());
return agentTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void fillHostInfo(HostDTO hostDTO, ServiceHostDTO serviceHostDTO) {
hostDTO.setHostId(serviceHostDTO.getHostId());
hostDTO.setBkCloudId(serviceHostDTO.getCloudAreaId());
hostDTO.setIp(serviceHostDTO.getIp());
hostDTO.setAgentId(serviceHostDTO.getFinalAgentId());
hostDTO.setAgentId(serviceHostDTO.getCloudIp());
}

private void handleFileSourceTaskResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ protected AbstractResultHandleTask(TaskInstanceService taskInstanceService,
});
this.notStartedTargetAgentIds.addAll(targetAgentIds);

this.agentIdHostMap = stepInstanceService.computeStepHosts(stepInstance,
host -> host.getAgentId() != null ? host.getAgentId() : host.toCloudIp());
this.agentIdHostMap = stepInstanceService.computeStepHosts(stepInstance, HostDTO::toCloudIp);

// 如果是执行方案,需要初始化全局变量
if (taskInstance.isPlanInstance()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private HostDTO getAgentBindHost() {
String agentBindCloudIp = Consts.DEFAULT_CLOUD_ID + ":" + agentBindIp;
ServiceHostDTO host = hostService.getHost(HostDTO.fromCloudIp(agentBindCloudIp));
agentHost = HostDTO.fromHostIdAndCloudIp(host.getHostId(), agentBindCloudIp);
agentHost.setAgentId(agentHost.getFinalAgentId());
agentHost.setAgentId(agentHost.toCloudIp());
return agentHost;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,11 @@ private void fillHostDetail(HostDTO host, Map<String, HostDTO> hostMap) {
host.setBkCloudId(hostDetail.getBkCloudId());
host.setIp(hostDetail.getIp());
// 兼容没有agent_id的主机,按照与GSE的约定,按照{云区域ID:ip}的方式构造agent_id
host.setAgentId(StringUtils.isEmpty(hostDetail.getAgentId()) ? host.toCloudIp() : hostDetail.getAgentId());
host.setAgentId(host.toCloudIp());
} else {
HostDTO hostDetail = hostMap.get("hostIp:" + host.toCloudIp());
// 兼容没有agent_id的主机,按照与GSE的约定,按照{云区域ID:ip}的方式构造agent_id
host.setAgentId(StringUtils.isEmpty(hostDetail.getAgentId()) ? host.toCloudIp() : hostDetail.getAgentId());
host.setAgentId(host.toCloudIp());
host.setHostId(hostDetail.getHostId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

/**
* 主机
Expand All @@ -49,11 +48,6 @@ public class ServiceHostDTO {
*/
private Long hostId;

/**
* AgentID
*/
private String agentId;

/**
* 云区域ID
*/
Expand All @@ -79,22 +73,13 @@ public String getCloudIp() {
return cloudAreaId + ":" + ip;
}

@JsonIgnore
public String getFinalAgentId() {
if (StringUtils.isNotBlank(agentId)) {
return agentId;
}
return getCloudIp();
}

public static ServiceHostDTO fromApplicationHostDTO(ApplicationHostDTO host) {
return ServiceHostDTO.builder()
.bizId(host.getBizId())
.appId(host.getAppId())
.hostId(host.getHostId())
.cloudAreaId(host.getCloudAreaId())
.ip(host.getIp())
.agentId(host.getAgentId())
.build();
}
}

0 comments on commit bb207e3

Please sign in to comment.