[ server ] [ status ]- update some code - 2

This commit is contained in:
zeaslity
2023-02-03 14:58:10 +08:00
parent fd5f2607b9
commit 487e808c58
4 changed files with 35 additions and 23 deletions

View File

@@ -6,9 +6,9 @@ import io.wdd.common.utils.TimeUtils;
import io.wdd.server.beans.vo.ServerInfoVO;
import io.wdd.server.coreService.CoreServerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -56,7 +56,7 @@ public class ServerBootUpEnvironment {
/**
* 保存所有健康运行的Agent Topic Name
*/
public static List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
public static final List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST = new ArrayList<>();
@Resource
CoreServerService coreServerService;
@@ -68,21 +68,21 @@ public class ServerBootUpEnvironment {
public void GenerateAllCache() {
//所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET
updateAllAgentTopicNameSetCache();
updateAllAgentTopicNameCache();
// Agent状态信息的两个Map
updateAgentStatusMapCache();
}
public void updateAllAgentTopicNameSetCache() {
public void updateAllAgentTopicNameCache() {
List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll();
Assert.notEmpty(
allAgentInfo,
"not agent registered ! skip the agent healthy status check !"
);
if (CollectionUtils.isEmpty(allAgentInfo)) {
log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
return;
}
ALL_AGENT_TOPIC_NAME_LIST.clear();
ALL_AGENT_TOPIC_NAME_SET.clear();
@@ -101,13 +101,23 @@ public class ServerBootUpEnvironment {
public void updateAgentStatusMapCache() {
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
return;
}
List statusList = redisTemplate
.opsForHash()
.multiGet(
ALL_AGENT_STATUS_REDIS_KEY,
ALL_AGENT_TOPIC_NAME_LIST
);
// current log to console is ok
// 初始话 还没有状态的情况直接return
if (CollectionUtils.isEmpty(statusList)) {
log.warn("agent status from redis is empty !");
return;
}
// 结构保存为agentStatusMap ==> agent-topic-name : STATUS(healthy, failed, unknown)
HashMap<String, String> agentStatusMap = new HashMap<>(32);

View File

@@ -1,15 +1,14 @@
package io.wdd.rpc.scheduler.service.status;
import io.wdd.common.beans.status.AgentHealthyStatusEnum;
import io.wdd.common.beans.status.OctopusStatusMessage;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.init.ServerBootUpEnvironment;
import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.HashMap;
@@ -20,7 +19,6 @@ import java.util.stream.Collectors;
import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY;
import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST;
import static io.wdd.rpc.init.ServerBootUpEnvironment.STATUS_AGENT_LIST_MAP;
/**
* 更新频率被类 BuildStatusScheduleTask.class控制
@@ -59,6 +57,12 @@ public class MonitorAllAgentStatus {
try {
// 1. 获取所有注册的Agent 手动更新
serverBootUpEnvironment.updateAllAgentTopicNameCache();
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
log.warn("[Scheduler] No Agent Registered ! End Up Status Monitor !");
return;
}
// 1.1 检查 Agent状态保存数据结构是否正常
checkOrCreateRedisHealthyKey();
@@ -126,6 +130,7 @@ public class MonitorAllAgentStatus {
)
.collect(Collectors.toList());
// 发送信息
collectAgentStatus.statusMessageToAgent(collect);
}
@@ -139,17 +144,13 @@ public class MonitorAllAgentStatus {
// 执行Metric上报定时任务
buildStatusScheduleTask.buildAgentMetricScheduleTask();
// update time
AGENT_HEALTHY_INIT_MAP.put(
"updateTime",
currentTimeString
);
// 这里仅仅是更新时间
redisTemplate
.opsForHash()
.putAll(
.put(
ALL_AGENT_STATUS_REDIS_KEY,
AGENT_HEALTHY_INIT_MAP
"updateTime",
currentTimeString
);
}