[ server ] [ agent ]- 收集Agent的版本信息
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package io.wdd.rpc.agent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface OctopusAgentService {
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有Agent的版本信息,附带最新的版本信息
|
||||
* 超时时间为 5s
|
||||
* @return key - AgentTopicName value - version Info
|
||||
*/
|
||||
Map<String, String> getAllAgentVersion();
|
||||
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.wdd.rpc.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import io.wdd.rpc.agent.OctopusAgentService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/octopus/server/agent")
|
||||
@Api("处理Agent核心内容的Controller")
|
||||
public class AgentController {
|
||||
|
||||
@Resource
|
||||
OctopusAgentService octopusAgentService;
|
||||
|
||||
@GetMapping("/version")
|
||||
@ApiOperation("获取所有OctopusAgent的版本")
|
||||
public R<Map<String, String>> getAllAgentVersion(){
|
||||
|
||||
return R.ok(octopusAgentService.getAllAgentVersion());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.rpc.execute.config.ExecutionLog;
|
||||
import io.wdd.rpc.execute.result.BuildStreamReader;
|
||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -27,7 +27,7 @@ import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_SET;
|
||||
public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
|
||||
@Resource
|
||||
ToAgentMessageSender toAgentMessageSender;
|
||||
OMessageToAgentSender oMessageToAgentSender;
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
@@ -110,7 +110,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
);
|
||||
|
||||
// send the message
|
||||
toAgentMessageSender.send(octopusMessage);
|
||||
oMessageToAgentSender.send(octopusMessage);
|
||||
|
||||
// set up the stream read group
|
||||
String group = redisTemplate
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.beans.status.AgentStatus;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.utils.DaemonDatabaseOperator;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -27,7 +27,6 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Accept boot up info message.
|
||||
@@ -63,7 +62,7 @@ public class AcceptAgentInitInfo {
|
||||
* The To agent order.
|
||||
*/
|
||||
@Resource
|
||||
ToAgentMessageSender toAgentMessageSender;
|
||||
OMessageToAgentSender oMessageToAgentSender;
|
||||
|
||||
|
||||
/**
|
||||
@@ -208,7 +207,7 @@ public class AcceptAgentInitInfo {
|
||||
.uuid(serverInfoVO.getTopicName())
|
||||
.build();
|
||||
|
||||
toAgentMessageSender.sendINIT(octopusMessage);
|
||||
oMessageToAgentSender.sendINIT(octopusMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
*/
|
||||
@Component
|
||||
@Slf4j(topic = "Send Message To Octopus Agent ")
|
||||
public class ToAgentMessageSender {
|
||||
public class OMessageToAgentSender {
|
||||
|
||||
@Resource
|
||||
RabbitTemplate rabbitTemplate;
|
||||
@@ -6,7 +6,7 @@ import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.beans.status.OctopusStatusMessage;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -22,7 +22,7 @@ import java.util.stream.Collectors;
|
||||
public class CollectAgentStatus {
|
||||
|
||||
@Resource
|
||||
ToAgentMessageSender toAgentMessageSender;
|
||||
OMessageToAgentSender oMessageToAgentSender;
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
@@ -45,7 +45,7 @@ public class CollectAgentStatus {
|
||||
).collect(Collectors.toList());
|
||||
|
||||
// batch send all messages to RabbitMQ
|
||||
toAgentMessageSender.send(octopusMessageList);
|
||||
oMessageToAgentSender.send(octopusMessageList);
|
||||
|
||||
// todo how to get result ?
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.wdd.server.config;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class ServerCommonPool {
|
||||
|
||||
public static ExecutorService pool;
|
||||
|
||||
|
||||
static {
|
||||
|
||||
ThreadFactory threadFactory = new ThreadFactoryBuilder()
|
||||
.setPriority(5)
|
||||
.setNameFormat("server-pool-%d")
|
||||
.setDaemon(true)
|
||||
.build();
|
||||
|
||||
pool = new ThreadPoolExecutor(
|
||||
10,
|
||||
30,
|
||||
500L,
|
||||
TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>(10,true),
|
||||
threadFactory,
|
||||
new ThreadPoolExecutor.AbortPolicy()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user