[ server ] [ execution ]- optimize some controller - 2
This commit is contained in:
@@ -22,8 +22,8 @@ import static io.wdd.rpc.status.AgentRuntimeMetricStatus.ALL_HEALTHY_AGENT_TOPIC
|
||||
|
||||
/**
|
||||
* 更新频率被类 BuildStatusScheduleTask.class控制
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* 获取所有注册的Agent
|
||||
* <p>
|
||||
* 发送状态检查信息, agent需要update相应的HashMap的值
|
||||
@@ -38,26 +38,24 @@ import static io.wdd.rpc.status.AgentRuntimeMetricStatus.ALL_HEALTHY_AGENT_TOPIC
|
||||
@Slf4j
|
||||
public class MonitorAllAgentStatus {
|
||||
|
||||
private static final int MAX_WAIT_AGENT_REPORT_STATUS_TIME = 5;
|
||||
/**
|
||||
* 存储 状态对应Agent列表的Map
|
||||
* 存储 状态对应Agent列表的Map
|
||||
* Agent的状态描述为 AgentHealthyStatusEnum
|
||||
* HEALTHY -> ["agentTopicName-1", "agentTopicName-2"]
|
||||
* FAILED -> ["agentTopicName-1", "agentTopicName-2"]
|
||||
*/
|
||||
public static final Map<String, List<String>> HEALTHY_STATUS_AGENT_LIST_MAP = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 存储所有Agent状态的Map
|
||||
*
|
||||
* <p>
|
||||
* 内容为 agentTopicName-健康状态
|
||||
*/
|
||||
public static final Map<String, String> ALL_AGENT_HEALTHY_STATUS_MAP = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 存储所有的AgentTopicName的缓存
|
||||
* 存储所有的AgentTopicName的缓存
|
||||
*/
|
||||
public static final Set<String> ALL_AGENT_TOPIC_NAME_LIST = new HashSet<>();
|
||||
public static final Set<String> ALL_AGENT_TOPIC_NAME_SET = new HashSet<>();
|
||||
private static final int MAX_WAIT_AGENT_REPORT_STATUS_TIME = 5;
|
||||
@Resource
|
||||
RedisTemplate redisTemplate;
|
||||
@Resource
|
||||
@@ -66,6 +64,7 @@ public class MonitorAllAgentStatus {
|
||||
CoreServerService coreServerService;
|
||||
@Resource
|
||||
BuildStatusScheduleTask buildStatusScheduleTask;
|
||||
private List<String> ALL_AGENT_TOPIC_NAME_LIST;
|
||||
private HashMap<String, String> AGENT_HEALTHY_INIT_MAP;
|
||||
|
||||
public void go() {
|
||||
@@ -75,14 +74,19 @@ public class MonitorAllAgentStatus {
|
||||
// 1. 获取所有注册的Agent
|
||||
// todo need to cache this
|
||||
List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll();
|
||||
Assert.notEmpty(allAgentInfo,
|
||||
"not agent registered ! skip the agent healthy status check !");
|
||||
Assert.notEmpty(
|
||||
allAgentInfo,
|
||||
"not agent registered ! skip the agent healthy status check !"
|
||||
);
|
||||
|
||||
Set<String> collect = allAgentInfo.stream()
|
||||
.map(ServerInfoVO::getTopicName)
|
||||
.collect(Collectors.toSet());
|
||||
ALL_AGENT_TOPIC_NAME_LIST.clear();
|
||||
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
|
||||
ALL_AGENT_TOPIC_NAME_LIST = allAgentInfo
|
||||
.stream()
|
||||
.map(ServerInfoVO::getTopicName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2023-01-16
|
||||
ALL_AGENT_TOPIC_NAME_SET.clear();
|
||||
ALL_AGENT_TOPIC_NAME_SET.addAll(ALL_AGENT_TOPIC_NAME_LIST);
|
||||
|
||||
// 1.1 检查 Agent状态保存数据结构是否正常
|
||||
checkOrCreateRedisHealthyKey();
|
||||
@@ -110,28 +114,38 @@ public class MonitorAllAgentStatus {
|
||||
|
||||
// build the redis all agent healthy map struct
|
||||
HashMap<String, String> initMap = new HashMap<>(32);
|
||||
ALL_AGENT_TOPICNAME_LIST.stream()
|
||||
.forEach(
|
||||
agentTopicName -> {
|
||||
initMap.put(agentTopicName,
|
||||
"0");
|
||||
}
|
||||
);
|
||||
initMap.put("updateTime",
|
||||
TimeUtils.currentTimeString());
|
||||
ALL_AGENT_TOPIC_NAME_LIST
|
||||
.stream()
|
||||
.forEach(
|
||||
agentTopicName -> {
|
||||
initMap.put(
|
||||
agentTopicName,
|
||||
"0"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
initMap.put(
|
||||
"updateTime",
|
||||
TimeUtils.currentTimeString()
|
||||
);
|
||||
|
||||
// cache this map struct
|
||||
AGENT_HEALTHY_INIT_MAP = initMap;
|
||||
|
||||
redisTemplate.opsForHash()
|
||||
.putAll(ALL_AGENT_STATUS_REDIS_KEY,
|
||||
initMap);
|
||||
// create the healthy redis structure
|
||||
redisTemplate
|
||||
.opsForHash()
|
||||
.putAll(
|
||||
ALL_AGENT_STATUS_REDIS_KEY,
|
||||
initMap
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildAndSendAgentHealthMessage() {
|
||||
|
||||
List<OctopusStatusMessage> collect = ALL_AGENT_TOPICNAME_LIST
|
||||
List<OctopusStatusMessage> collect = ALL_AGENT_TOPIC_NAME_LIST
|
||||
.stream()
|
||||
.map(
|
||||
agentTopicName -> OctopusStatusMessage
|
||||
@@ -146,26 +160,29 @@ public class MonitorAllAgentStatus {
|
||||
}
|
||||
|
||||
private void updateAllAgentHealthyStatus() {
|
||||
|
||||
List statusList = redisTemplate
|
||||
.opsForHash()
|
||||
.multiGet(
|
||||
ALL_AGENT_STATUS_REDIS_KEY,
|
||||
ALL_AGENT_TOPICNAME_LIST);
|
||||
|
||||
ALL_AGENT_TOPIC_NAME_LIST
|
||||
);
|
||||
|
||||
// current log to console is ok
|
||||
// agent-topic-name : STATUS(healthy, failed, unknown)
|
||||
HashMap<String, String> agentStatusMap = new HashMap<>(32);
|
||||
for (int i = 0; i < ALL_AGENT_TOPICNAME_LIST.size(); i++) {
|
||||
for (int i = 0; i < ALL_AGENT_TOPIC_NAME_LIST.size(); i++) {
|
||||
agentStatusMap.put(
|
||||
ALL_AGENT_TOPICNAME_LIST.get(i),
|
||||
ALL_AGENT_TOPIC_NAME_LIST.get(i),
|
||||
uniformHealthyStatus(String.valueOf(statusList.get(i)))
|
||||
);
|
||||
}
|
||||
String currentTimeString = TimeUtils.currentTimeString();
|
||||
log.info("[ AGENT HEALTHY CHECK ] time is {} , result are => {}",
|
||||
currentTimeString,
|
||||
agentStatusMap);
|
||||
log.info(
|
||||
"[ AGENT HEALTHY CHECK ] time is {} , result are => {}",
|
||||
currentTimeString,
|
||||
agentStatusMap
|
||||
);
|
||||
|
||||
// 2023-01-16
|
||||
ALL_AGENT_HEALTHY_STATUS_MAP.clear();
|
||||
@@ -204,9 +221,10 @@ public class MonitorAllAgentStatus {
|
||||
// Trigger调用Agent Metric 任务
|
||||
ArrayList<String> allHealthyAgentTopicNames = new ArrayList<>(32);
|
||||
for (int i = 0; i < statusList.size(); i++) {
|
||||
if (statusList.get(i)
|
||||
.equals("1")) {
|
||||
allHealthyAgentTopicNames.add(ALL_AGENT_TOPICNAME_LIST.get(i));
|
||||
if (statusList
|
||||
.get(i)
|
||||
.equals("1")) {
|
||||
allHealthyAgentTopicNames.add(ALL_AGENT_TOPIC_NAME_LIST.get(i));
|
||||
}
|
||||
}
|
||||
ALL_HEALTHY_AGENT_TOPIC_NAMES = allHealthyAgentTopicNames;
|
||||
@@ -214,12 +232,18 @@ public class MonitorAllAgentStatus {
|
||||
buildStatusScheduleTask.buildAgentMetricScheduleTask();
|
||||
|
||||
// update time
|
||||
AGENT_HEALTHY_INIT_MAP.put("updateTime",
|
||||
currentTimeString);
|
||||
AGENT_HEALTHY_INIT_MAP.put(
|
||||
"updateTime",
|
||||
currentTimeString
|
||||
);
|
||||
|
||||
// init the healthy map
|
||||
redisTemplate.opsForHash()
|
||||
.putAll(ALL_AGENT_STATUS_REDIS_KEY,
|
||||
AGENT_HEALTHY_INIT_MAP);
|
||||
redisTemplate
|
||||
.opsForHash()
|
||||
.putAll(
|
||||
ALL_AGENT_STATUS_REDIS_KEY,
|
||||
AGENT_HEALTHY_INIT_MAP
|
||||
);
|
||||
}
|
||||
|
||||
private String uniformHealthyStatus(String agentStatus) {
|
||||
|
||||
Reference in New Issue
Block a user