[server][status]- 新增手动更新状态的代码
This commit is contained in:
@@ -11,9 +11,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import static io.wdd.func.xray.beans.node.ProxyNodeSet.*;
|
import static io.wdd.func.xray.beans.node.ProxyNodeSet.*;
|
||||||
import static io.wdd.func.xray.beans.node.ProxyNodeSet.phoenix2;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/server/func/xray")
|
@RequestMapping("/server/func/xray")
|
||||||
@@ -27,7 +27,7 @@ public class XrayController {
|
|||||||
XrayConfigDistribute xrayConfigDistribute;
|
XrayConfigDistribute xrayConfigDistribute;
|
||||||
|
|
||||||
@GetMapping("/test")
|
@GetMapping("/test")
|
||||||
public void test(){
|
public void test() {
|
||||||
|
|
||||||
ArrayList<ArrayList<ProxyNode>> allNetworkPathList = new ArrayList<>();
|
ArrayList<ArrayList<ProxyNode>> allNetworkPathList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public class XrayController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ArrayList<ProxyNode> pathD = new ArrayList<>(
|
ArrayList<ProxyNode> pathD = new ArrayList<>(
|
||||||
Arrays.asList(
|
Collections.singletonList(
|
||||||
chengduAgent
|
chengduAgent
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_SET;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.ALL_AGENT_TOPIC_NAME_SET;
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||||
import static io.wdd.rpc.message.handler.AsyncWaitOMResult.REPLAY_CACHE_MAP;
|
import static io.wdd.rpc.message.handler.AsyncWaitOMResult.REPLAY_CACHE_MAP;
|
||||||
import static io.wdd.rpc.message.handler.OMessageHandlerServer.AGENT_LATEST_VERSION;
|
import static io.wdd.rpc.message.handler.OMessageHandlerServer.AGENT_LATEST_VERSION;
|
||||||
import static io.wdd.rpc.message.handler.OMessageHandlerServer.OCTOPUS_MESSAGE_FROM_AGENT;
|
import static io.wdd.rpc.message.handler.OMessageHandlerServer.OCTOPUS_MESSAGE_FROM_AGENT;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import javax.annotation.Resource;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER;
|
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER;
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_LIST;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.ALL_AGENT_TOPIC_NAME_LIST;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/octopus/server/executor")
|
@RequestMapping("/octopus/server/executor")
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package io.wdd.rpc.controller;
|
package io.wdd.rpc.controller;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.wdd.common.beans.response.R;
|
import io.wdd.common.beans.response.R;
|
||||||
|
import io.wdd.rpc.init.ServerCacheAgentStatus;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -14,7 +14,7 @@ import javax.annotation.Resource;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.*;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.*;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -22,17 +22,19 @@ import static io.wdd.rpc.init.ServerBootUpEnvironment.*;
|
|||||||
@RequestMapping("/octopus/server/status")
|
@RequestMapping("/octopus/server/status")
|
||||||
public class StatusController {
|
public class StatusController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ServerCacheAgentStatus serverCacheAgentStatus;
|
||||||
|
|
||||||
@ApiOperation("[ Agent-状态 ] Map")
|
@ApiOperation("[ Agent-状态 ] Map")
|
||||||
@GetMapping("/agent/status")
|
@GetMapping("/agent/status")
|
||||||
public R<Map> GetAllAgentHealthyStatus() {
|
public R<Map<String, String>> GetAllAgentHealthyStatus() {
|
||||||
|
|
||||||
return R.ok(ALL_AGENT_STATUS_MAP);
|
return R.ok(ALL_AGENT_STATUS_MAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("[ 状态-Agent ] Map")
|
@ApiOperation("[ 状态-Agent ] Map")
|
||||||
@GetMapping("/status/agent")
|
@GetMapping("/status/agent")
|
||||||
public R<Map> GetHealthyStatusAgentList() {
|
public R<Map<String, List<String>>> GetHealthyStatusAgentList() {
|
||||||
|
|
||||||
return R.ok(STATUS_AGENT_LIST_MAP);
|
return R.ok(STATUS_AGENT_LIST_MAP);
|
||||||
}
|
}
|
||||||
@@ -51,8 +53,10 @@ public class StatusController {
|
|||||||
|
|
||||||
|
|
||||||
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
|
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
|
||||||
data.replace("[","");
|
data.replace("[",
|
||||||
data.replace("]","");
|
"");
|
||||||
|
data.replace("]",
|
||||||
|
"");
|
||||||
return R.ok(
|
return R.ok(
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
@@ -67,5 +71,15 @@ public class StatusController {
|
|||||||
return R.ok(ALL_HEALTHY_AGENT_TOPIC_NAME_LIST);
|
return R.ok(ALL_HEALTHY_AGENT_TOPIC_NAME_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("手动更新Agent的状态")
|
||||||
|
@PostMapping("/agent/status/update")
|
||||||
|
public R<Map<String, List<String>>> ManualUpdateAgentStatus() {
|
||||||
|
|
||||||
|
// 手动调用更新
|
||||||
|
serverCacheAgentStatus.updateAgentStatusMapCache();
|
||||||
|
|
||||||
|
return R.ok(STATUS_AGENT_LIST_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import io.wdd.common.beans.executor.ExecutionMessage;
|
import io.wdd.common.beans.executor.ExecutionMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
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.config.ExecutionLog;
|
||||||
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -19,7 +18,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_AGENT_TOPIC_NAME_SET;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.ALL_AGENT_TOPIC_NAME_SET;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ 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.ALL_AGENT_STATUS_REDIS_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server启动的时候,需要初始化一系列的信息
|
* Server启动或者运行的时候,需要初 缓存一系列的信息
|
||||||
* <p>
|
* <p>
|
||||||
* 所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET
|
* 所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET
|
||||||
* <p>
|
* <p>
|
||||||
@@ -26,7 +26,7 @@ import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_R
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ServerBootUpEnvironment {
|
public class ServerCacheAgentStatus {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储所有的AgentTopicName的缓存
|
* 存储所有的AgentTopicName的缓存
|
||||||
@@ -58,6 +58,11 @@ public class ServerBootUpEnvironment {
|
|||||||
*/
|
*/
|
||||||
public static final List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST = new ArrayList<>();
|
public static final List<String> ALL_HEALTHY_AGENT_TOPIC_NAME_LIST = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录状态信息缓存的更新时间
|
||||||
|
*/
|
||||||
|
private static final String STATUS_UPDATE_TIME_KEY = "UPDATE_TIME";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
CoreServerService coreServerService;
|
CoreServerService coreServerService;
|
||||||
|
|
||||||
@@ -75,8 +80,12 @@ public class ServerBootUpEnvironment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据库中获取所有注册过的Agent名称
|
||||||
|
*/
|
||||||
public void updateAllAgentTopicNameCache() {
|
public void updateAllAgentTopicNameCache() {
|
||||||
|
|
||||||
|
//查询DB
|
||||||
List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll();
|
List<ServerInfoVO> allAgentInfo = coreServerService.serverGetAll();
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(allAgentInfo)) {
|
if (CollectionUtils.isEmpty(allAgentInfo)) {
|
||||||
@@ -100,18 +109,23 @@ public class ServerBootUpEnvironment {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 从redis中获取信息,更新Agent状态信息的全局缓存
|
||||||
* 更新Agent状态信息的全局缓存
|
* ALL_AGENT_STATUS_MAP
|
||||||
*
|
* ALL_HEALTHY_AGENT_TOPIC_NAME_LIST
|
||||||
* 由定时任务或者初始化服务触发
|
* STATUS_AGENT_LIST_MAP
|
||||||
|
* <p>
|
||||||
|
* 由定时任务或者初始化服务触发
|
||||||
|
* 2023-02-21 前端接口,手动更新
|
||||||
*/
|
*/
|
||||||
public void updateAgentStatusMapCache() {
|
public void updateAgentStatusMapCache() {
|
||||||
|
|
||||||
|
// 检查,排除没有节点的情况
|
||||||
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
||||||
log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
|
log.warn("[Serer Boot Up] Octopus Serer First Boot Up ! No Agent Registered Ever!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从redis中获取所有节点的当前状态
|
||||||
List statusList = redisTemplate
|
List statusList = redisTemplate
|
||||||
.opsForHash()
|
.opsForHash()
|
||||||
.multiGet(
|
.multiGet(
|
||||||
@@ -125,6 +139,9 @@ public class ServerBootUpEnvironment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 增加更新时间 2023年2月21日
|
||||||
|
String timeString = TimeUtils.currentTimeString();
|
||||||
|
|
||||||
// 结构保存为agentStatusMap ==> agent-topic-name : STATUS(healthy, failed, unknown)
|
// 结构保存为agentStatusMap ==> agent-topic-name : STATUS(healthy, failed, unknown)
|
||||||
HashMap<String, String> agentStatusMap = new HashMap<>(32);
|
HashMap<String, String> agentStatusMap = new HashMap<>(32);
|
||||||
for (int i = 0; i < ALL_AGENT_TOPIC_NAME_LIST.size(); i++) {
|
for (int i = 0; i < ALL_AGENT_TOPIC_NAME_LIST.size(); i++) {
|
||||||
@@ -134,17 +151,15 @@ public class ServerBootUpEnvironment {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 由于太多了,所以关闭此处log输出
|
|
||||||
/* String currentTimeString = TimeUtils.currentTimeString();
|
|
||||||
log.debug(
|
|
||||||
"[ AGENT HEALTHY CHECK ] time is {} , result are => {}",
|
|
||||||
currentTimeString,
|
|
||||||
agentStatusMap
|
|
||||||
);*/
|
|
||||||
|
|
||||||
// 2023-01-16
|
// 2023-01-16
|
||||||
ALL_AGENT_STATUS_MAP.clear();
|
ALL_AGENT_STATUS_MAP.clear();
|
||||||
ALL_AGENT_STATUS_MAP.putAll(agentStatusMap);
|
ALL_AGENT_STATUS_MAP.putAll(agentStatusMap);
|
||||||
|
ALL_AGENT_STATUS_MAP.put(
|
||||||
|
STATUS_UPDATE_TIME_KEY,
|
||||||
|
timeString
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// 2023-01-16
|
// 2023-01-16
|
||||||
// 更新 状态-Agent容器 内容为
|
// 更新 状态-Agent容器 内容为
|
||||||
@@ -176,6 +191,12 @@ public class ServerBootUpEnvironment {
|
|||||||
// 2023-2-3 bug fix
|
// 2023-2-3 bug fix
|
||||||
STATUS_AGENT_LIST_MAP.clear();
|
STATUS_AGENT_LIST_MAP.clear();
|
||||||
STATUS_AGENT_LIST_MAP.putAll(statusAgentListMap);
|
STATUS_AGENT_LIST_MAP.putAll(statusAgentListMap);
|
||||||
|
// 2023年2月21日,更新时间
|
||||||
|
STATUS_AGENT_LIST_MAP.put(
|
||||||
|
STATUS_UPDATE_TIME_KEY,
|
||||||
|
Collections.singletonList(timeString)
|
||||||
|
);
|
||||||
|
|
||||||
log.debug("Agent存活状态 状态-Agent名称-Map 已经更新了");
|
log.debug("Agent存活状态 状态-Agent名称-Map 已经更新了");
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static io.wdd.common.beans.status.OctopusStatusMessage.METRIC_STATUS_MESSAGE_TYPE;
|
import static io.wdd.common.beans.status.OctopusStatusMessage.METRIC_STATUS_MESSAGE_TYPE;
|
||||||
import static io.wdd.rpc.init.ServerBootUpEnvironment.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
import static io.wdd.rpc.init.ServerCacheAgentStatus.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收集OctopusAgent的运行Metric信息
|
* 收集OctopusAgent的运行Metric信息
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.wdd.rpc.scheduler.service.status;
|
|||||||
|
|
||||||
import io.wdd.common.beans.status.OctopusStatusMessage;
|
import io.wdd.common.beans.status.OctopusStatusMessage;
|
||||||
import io.wdd.common.utils.TimeUtils;
|
import io.wdd.common.utils.TimeUtils;
|
||||||
import io.wdd.rpc.init.ServerBootUpEnvironment;
|
import io.wdd.rpc.init.ServerCacheAgentStatus;
|
||||||
import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask;
|
import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
@@ -18,7 +18,7 @@ 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.ALL_AGENT_STATUS_REDIS_KEY;
|
||||||
import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
|
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.ServerCacheAgentStatus.ALL_AGENT_TOPIC_NAME_LIST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新频率被类 BuildStatusScheduleTask.class控制
|
* 更新频率被类 BuildStatusScheduleTask.class控制
|
||||||
@@ -46,7 +46,7 @@ public class MonitorAllAgentStatus {
|
|||||||
CollectAgentStatus collectAgentStatus;
|
CollectAgentStatus collectAgentStatus;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ServerBootUpEnvironment serverBootUpEnvironment;
|
ServerCacheAgentStatus serverCacheAgentStatus;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BuildStatusScheduleTask buildStatusScheduleTask;
|
BuildStatusScheduleTask buildStatusScheduleTask;
|
||||||
@@ -57,7 +57,7 @@ public class MonitorAllAgentStatus {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. 获取所有注册的Agent 手动更新
|
// 1. 获取所有注册的Agent 手动更新
|
||||||
serverBootUpEnvironment.updateAllAgentTopicNameCache();
|
serverCacheAgentStatus.updateAllAgentTopicNameCache();
|
||||||
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
||||||
log.warn("[Scheduler] No Agent Registered ! End Up Status Monitor !");
|
log.warn("[Scheduler] No Agent Registered ! End Up Status Monitor !");
|
||||||
return;
|
return;
|
||||||
@@ -139,7 +139,7 @@ public class MonitorAllAgentStatus {
|
|||||||
String currentTimeString = TimeUtils.currentTimeString();
|
String currentTimeString = TimeUtils.currentTimeString();
|
||||||
|
|
||||||
// 更新所有的缓存状态
|
// 更新所有的缓存状态
|
||||||
serverBootUpEnvironment.updateAgentStatusMapCache();
|
serverCacheAgentStatus.updateAgentStatusMapCache();
|
||||||
|
|
||||||
// 执行Metric上报定时任务
|
// 执行Metric上报定时任务
|
||||||
buildStatusScheduleTask.buildAgentMetricScheduleTask();
|
buildStatusScheduleTask.buildAgentMetricScheduleTask();
|
||||||
|
|||||||
Reference in New Issue
Block a user