[ server ] [ agent ]- 收集Agent的版本信息

This commit is contained in:
zeaslity
2023-02-07 16:26:22 +08:00
parent f4e636a368
commit 602e3c3034
20 changed files with 334 additions and 84 deletions

View File

@@ -0,0 +1,102 @@
package io.wdd.rpc.agent;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wdd.common.beans.agent.AgentOperationMessage;
import io.wdd.common.beans.agent.AgentOperationType;
import io.wdd.common.beans.rabbitmq.OctopusMessage;
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.message.sender.OMessageToAgentSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST;
@Service
@Slf4j
public class OctopusAgentServiceImpl implements OctopusAgentService{
@Resource
OMessageToAgentSender oMessageToAgentSender;
@Resource
ObjectMapper objectMapper;
@Override
public Map<String, String> getAllAgentVersion() {
HashMap<String, String> result = new HashMap<>();
// 查询获取到最新的Agent版本信息
result.put("LATEST_VERSION","2023-02-06-09-23-00");
// 获取Agent的版本信息 -- 超时时间
// 发送OctopusMessage-Agent
// 从OctopusToServer中收集到所有Agent的版本信息
// 组装信息至集合中
buildAndSendToAllAgent(AgentOperationType.VERSION);
waitCollectAllAgentVersionInfo(result);
return result;
}
private void waitCollectAllAgentVersionInfo(HashMap<String, String> result) {
}
private void buildAndSendToAllAgent(AgentOperationType operationType) {
List<OctopusMessage> octopusMessageList = ALL_AGENT_TOPIC_NAME_LIST
.stream()
.map(
agentTopicName ->
ConstructAgentOperationMessage(
agentTopicName,
operationType
)
)
.collect(Collectors.toList());
// 发送相应的消息
oMessageToAgentSender.send(octopusMessageList);
}
/**
* 专门构造 Agent 类型的 OctopusMessage
* 通常只能在此类中使用
*
* @param agentTopicName
* @param operationType
* @return
*/
private OctopusMessage ConstructAgentOperationMessage(String agentTopicName, AgentOperationType operationType) {
AgentOperationMessage operationMessage = AgentOperationMessage
.builder()
.opType(operationType)
.build();
String ops;
try {
ops = objectMapper.writeValueAsString(operationMessage);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return OctopusMessage
.builder()
.type(OctopusMessageType.AGENT)
.uuid(agentTopicName)
.init_time(TimeUtils.currentTime())
.content(ops)
.build();
}
}