package io.wdd.rpc.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.wdd.common.response.R; import io.wdd.rpc.scheduler.service.status.AgentAliveStatusMonitorService; import io.wdd.rpc.status.service.AsyncStatusService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.Map; import static io.wdd.rpc.init.AgentStatusCacheService.*; @RestController @Api(value = "Agent运行状态Controller", tags = "Status") @RequestMapping("/octopus/server/status") public class StatusController { @Resource AsyncStatusService asyncStatusService; @Resource AgentAliveStatusMonitorService agentAliveStatusMonitorService; @ApiOperation("[ Agent-状态 ] Map") @GetMapping("/agent/status") public R> GetAllAgentHealthyStatus() { return R.ok(ALL_AGENT_STATUS_MAP); } @ApiOperation("[ 状态-Agent ] Map") @GetMapping("/status/agent") public R>> GetHealthyStatusAgentList() { return R.ok(STATUS_AGENT_LIST_MAP); } @ApiOperation("[ Agent ] - 所有的Agent主机") @PostMapping("/agent/all") public R> GetAllAgentTopicNameList() { return R.ok(ALL_AGENT_TOPIC_NAME_LIST); } @ApiOperation("[ Agent ] - 所有主机String") @PostMapping("/agent/all/string") public R GetAllAgentString() { String data = ALL_AGENT_TOPIC_NAME_LIST.toString(); data.replace("[", ""); data.replace("]", ""); return R.ok( data ); } @ApiOperation("[ Agent ] - 健康的Agent主机") @PostMapping("/agent/healthy") public R> GetAllHealthyAgent() { return R.ok(ALL_HEALTHY_AGENT_TOPIC_NAME_LIST); } @ApiOperation("手动更新Agent的状态") @PostMapping("/agent/status/update") public R>> ManualUpdateAgentStatus() { // 手动调用更新 Map agentAliveStatusMap = asyncStatusService.AsyncCollectAgentAliveStatus(ALL_AGENT_TOPIC_NAME_LIST, 5); agentAliveStatusMonitorService.updateAllAgentHealthyStatus(agentAliveStatusMap); return R.ok(STATUS_AGENT_LIST_MAP); } }