[ Server ] accomplish alive status precedure

This commit is contained in:
zeaslity
2023-06-20 10:02:49 +08:00
parent 92a2a16aea
commit a96d3e51ac
33 changed files with 497 additions and 170 deletions

View File

@@ -0,0 +1,9 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root~Default Group",
"filePath": "~.fastRequest~collections~Root~Default Group~",
"groupId": "1",
"id": "1",
"name": "Default Group",
"type": 1
}

View File

@@ -0,0 +1,9 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root",
"filePath": "~.fastRequest~collections~Root~",
"groupId": "-1",
"id": "0",
"name": "Root",
"type": 1
}

View File

@@ -0,0 +1,8 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root~server~ExecutionController",
"filePath": "~.fastRequest~collections~Root~server~ExecutionController~",
"id": "20230222093108443",
"name": "ExecutionController",
"type": 3
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~ExecutionController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~ExecutionController~patchCommandToAgentAll.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.ExecutionController.patchCommandToAgentAll",
"name": "[命令]- 发送命令至所有的主机",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.ExecutionController",
"jsonDocument": "",
"method": "patchCommandToAgentAll",
"methodDescription": "[命令]- 发送命令至所有的主机",
"methodType": "POST",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/executor/command/all",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/executor/command/all",
"urlEncodedKeyValueListJson": "[{\"comment\":\"命令行\",\"customFlag\":2,\"enabled\":true,\"key\":\"commandList\",\"type\":\"String\",\"value\":\"apt-get,update\"},{\"comment\":\"\",\"customFlag\":2,\"enabled\":true,\"key\":\"type\",\"type\":\"String\",\"value\":\"\"}]",
"urlEncodedKeyValueListText": "commandList=apt-get,update\n&type=",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.ExecutionController.patchCommandToAgentAll",
"type": 2
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~SchedulerController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~SchedulerController~createScriptScheduler.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.SchedulerController.createScriptScheduler",
"name": "新增一个定时脚本任务",
"paramGroup": {
"bodyKeyValueListJson": "{\n \"schedulerUuid\": \"\",\n \"name\": \"测试任务\",\n \"cronExpress\": \"30 */30 * * * ? *\",\n \"description\": \"这是注释内容\",\n \"scriptContent\": \"echo yes \\napt-get update \\necho no \\napt-get install nginx -y\",\n \"targetMachine\": \"Chengdu-amd64-98-98066f\",\n \"lastExecutionId\": null,\n \"lastExecutionResultKey\": \"\",\n \"lastExecutionStatus\": null ,\n \"createTime\": \"\",\n \"updateTime\": \"\",\n \"nextScheduleTime\": \"\",\n \"lastScheduleTime\": \"\"\n}",
"className": "io.wdd.rpc.controller.SchedulerController",
"jsonDocument": "{\n \"schedulerUuid\": \"No comment,Value =schedulerUuid_9dr3w\",\n \"name\": \"No comment,Value =name_ucmeh\",\n \"cronExpress\": \"No comment,Value =cronExpress_qbwqm\",\n \"description\": \"No comment,Value =description_drj0c\",\n \"scriptContent\": \"脚本任务的内容\",\n \"targetMachine\": \"执行目标机器agent_topic_name列表使用, 分隔\",\n \"lastExecutionId\": \"与 execution_log表的主键对应,方便查询执行日志\",\n \"lastExecutionResultKey\": \"与 execution_log表的 result_key 对应,方便查询执行日志\",\n \"lastExecutionStatus\": \"任务上次执行状态\",\n \"createTime\": \"定时脚本任务创建时间\",\n \"updateTime\": \"上次更新时间\",\n \"nextScheduleTime\": \"任务下次计划执行时间\",\n \"lastScheduleTime\": \"任务上次计划执行时间\"\n}",
"method": "createScriptScheduler",
"methodDescription": "新增一个定时脚本任务",
"methodType": "POST",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/scheduler/script/create",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/scheduler/script/create",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.SchedulerController.createScriptScheduler",
"type": 2
}

View File

@@ -0,0 +1,8 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root~server~SchedulerController",
"filePath": "~.fastRequest~collections~Root~server~SchedulerController~",
"id": "20230116173428298",
"name": "SchedulerController",
"type": 3
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~SchedulerController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~SchedulerController~queryAllQuartzJob.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.SchedulerController.queryAllQuartzJob",
"name": "查询所有job",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.SchedulerController",
"jsonDocument": "",
"method": "queryAllQuartzJob",
"methodDescription": "查询所有job",
"methodType": "GET",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/scheduler/queryAllJob",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/scheduler/queryAllJob",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.SchedulerController.queryAllQuartzJob",
"type": 2
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~SchedulerController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~SchedulerController~queryAllTriggers.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.SchedulerController.queryAllTriggers",
"name": "查询所有的触发器Trigger",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.SchedulerController",
"jsonDocument": "",
"method": "queryAllTriggers",
"methodDescription": "查询所有的触发器Trigger",
"methodType": "GET",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/scheduler/allTriggers",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/scheduler/allTriggers",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.SchedulerController.queryAllTriggers",
"type": 2
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~SchedulerController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~SchedulerController~queryRunQuartzJob.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.SchedulerController.queryRunQuartzJob",
"name": "查询所有运行job",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.SchedulerController",
"jsonDocument": "",
"method": "queryRunQuartzJob",
"methodDescription": "查询所有运行job",
"methodType": "POST",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/scheduler/queryRunJob",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/scheduler/queryRunJob",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.SchedulerController.queryRunQuartzJob",
"type": 2
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~StatusController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~StatusController~GetHealthyStatusAgentList.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.StatusController.GetHealthyStatusAgentList",
"name": "[ 状态-Agent ] Map",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.StatusController",
"jsonDocument": "",
"method": "GetHealthyStatusAgentList",
"methodDescription": "[ 状态-Agent ] Map",
"methodType": "GET",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/status/status/agent",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/status/status/agent",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.StatusController.GetHealthyStatusAgentList",
"type": 2
}

View File

@@ -0,0 +1,37 @@
{
"activeGroup": "Default",
"apiParamGroup": {},
"childList": [],
"description": "",
"directory": "~.fastRequest~collections~Root~server~StatusController",
"domain": "http://localhost:9999",
"enableEnv": "local",
"enableProject": "ProjectOctopus",
"filePath": "~.fastRequest~collections~Root~server~StatusController~ManualUpdateAgentStatus.rapi",
"headerList": [],
"id": "api_io.wdd.rpc.controller.StatusController.ManualUpdateAgentStatus",
"name": "手动更新Agent的状态",
"paramGroup": {
"bodyKeyValueListJson": "",
"className": "io.wdd.rpc.controller.StatusController",
"jsonDocument": "",
"method": "ManualUpdateAgentStatus",
"methodDescription": "手动更新Agent的状态",
"methodType": "POST",
"multipartKeyValueListJson": "[]",
"originUrl": "/octopus/server/status/agent/status/update",
"pathParamsKeyValueListJson": "[]",
"postScript": "",
"postType": "json",
"preScript": "",
"returnDocument": "{\n\t\"code\":\"No comment,Type =Number\",\n\t\"msg\":\"No comment,Type =String\",\n\t\"data\":{}\n}",
"tempId": "",
"url": "/octopus/server/status/agent/status/update",
"urlEncodedKeyValueListJson": "[]",
"urlEncodedKeyValueListText": "",
"urlParamsKeyValueListJson": "[]",
"urlParamsKeyValueListText": ""
},
"tempId": "id_io.wdd.rpc.controller.StatusController.ManualUpdateAgentStatus",
"type": 2
}

View File

@@ -0,0 +1,8 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root~server~StatusController",
"filePath": "~.fastRequest~collections~Root~server~StatusController~",
"id": "20230222092955736",
"name": "StatusController",
"type": 3
}

View File

@@ -0,0 +1,8 @@
{
"description": "",
"directory": "~.fastRequest~collections~Root~server",
"filePath": "~.fastRequest~collections~Root~server~",
"id": "20221230113234995",
"name": "server",
"type": 4
}

View File

@@ -0,0 +1,37 @@
{
"dataList": [
{
"hostGroup": [
{
"env": "local",
"url": "localhost:9090"
}
],
"name": "OctpusGO"
}
],
"envList": [
"local"
],
"headerList": [],
"postScript": "",
"preScript": "",
"projectList": [
"OctpusGO"
],
"syncModel": {
"branch": "master",
"domain": "https://github.com",
"enabled": false,
"namingPolicy": "byDoc",
"owner": "",
"repo": "",
"repoUrl": "",
"syncAfterRun": false,
"token": "",
"type": "github"
},
"urlEncodedKeyValueList": [],
"urlParamsKeyValueList": [],
"urlSuffix": ""
}

View File

@@ -1,32 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="RunServerToRemote" type="docker-deploy" factoryName="dockerfile"
server-name="Oracle-Seoul-0">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="remote-idea"/>
<option name="containerName" value="octopus-server-idea"/>
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9999"/>
<option name="hostPort" value="9999"/>
</DockerPortBindingImpl>
</list>
</option>
<option name="sourceFilePath" value="server/Dockerfile-shanghai-remote-idea"/>
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/octopus-server"/>
<option name="hostPath" value="/octopus-server"/>
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="SkipTest-Package"
run_configuration_type="MavenRunConfiguration"/>
</method>
</configuration>
</component>

View File

@@ -1,16 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Server-dev" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" activateToolWindowBeforeRun="false">
<option name="DEBUG_MODE" value="true"/>
<option name="HIDE_BANNER" value="true" />
<module name="server" />
<selectedOptions>
<option name="spring.boot.profiles" visible="false" />
</selectedOptions>
<option name="SPRING_BOOT_MAIN_CLASS" value="io.wdd.ServerApplication" />
<option name="VM_PARAMETERS"
value="-Ddebug=true -Dlogging.level.io.wdd.server=debug -Dfile.encoding=utf-8 -Dspring.profiles.active=dev -Dspring.cloud.nacos.config.group=dev -Dspring.cloud.nacos.config.extension-configs[0].dataId=common-dev.yaml -Dspring.cloud.nacos.config.extension-configs[0].group=dev"/>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -1,31 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SkipTest-Package" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings"/>
<option name="myRunnerSettings"/>
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set/>
</option>
<option name="goals">
<list>
<option value="clean"/>
<option value="-DskipTests=true"/>
<option value="package"/>
</list>
</option>
<option name="pomFileName"/>
<option name="profilesMap">
<map>
<entry key="pom.xml" value="true"/>
</map>
</option>
<option name="resolveToWorkspace" value="false"/>
<option name="workingDirPath" value="$PROJECT_DIR$"/>
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2"/>
</configuration>
</component>

View File

@@ -25,7 +25,7 @@ func NewLogger() (*Logger, error) {
LevelKey: "level",
TimeKey: "time",
//CallerKey: "caller",
EncodeLevel: zapcore.CapitalColorLevelEncoder,
EncodeLevel: zapcore.CapitalLevelEncoder,
EncodeTime: zapcore.RFC3339TimeEncoder,
//EncodeCaller: zapcore.FullCallerEncoder,
},

View File

@@ -55,7 +55,7 @@ spring:
port: 20672
username: boge
password: boge8tingH
virtual-host: /
virtual-host: /wdd
listener:
simple:
retry:

View File

@@ -30,7 +30,6 @@ func BuildOMsgRuntimeConnectorQueue(agentTopicName string) {
// 建立 业务消息 返回队列
// 统一为 OctopusToServer
octopusToServerQueueName := agentConfig.GetString("octopus.message.octopus_to_server")
octopusToServerProp := &ConnectProperty{

View File

@@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"strings"
"time"
)
var P = g.G.P
@@ -33,11 +32,11 @@ type OctopusMsgBuilder interface {
type OctopusMessage struct {
UUID string `json:"uuid"`
InitTime time.Time `json:"init_time" format:"2023-03-21 16:38:30"`
InitTime string `json:"init_time" format:"2023-03-21 16:38:30"`
Type string `json:"type"`
Content interface{} `json:"content"`
Result interface{} `json:"result"`
ACTime time.Time `json:"ac_time" format:"2023-03-21 16:38:30"`
ACTime string `json:"ac_time" format:"2023-03-21 16:38:30"`
}
func (om *OctopusMessage) Handle() {
@@ -52,7 +51,7 @@ func (om *OctopusMessage) Send(rabbitQueue *RabbitQueue, msg []byte) {
func (om *OctopusMessage) Build(omType string, content interface{}) *OctopusMessage {
// 当前时间
curTimeString := utils.CurTimeString()
curTimeString := utils.ParseDateTimeTime()
// must write to string format, otherwise it's very hard to deserialize
bytes, err := json.Marshal(content)
@@ -62,11 +61,11 @@ func (om *OctopusMessage) Build(omType string, content interface{}) *OctopusMess
return &OctopusMessage{
UUID: curTimeString,
InitTime: time.Now(),
InitTime: curTimeString,
Type: omType,
Content: string(bytes),
Result: nil,
ACTime: time.Time{},
ACTime: curTimeString,
}
}
@@ -134,7 +133,7 @@ func statusOMHandler(octopusMessage *OctopusMessage) {
}
var statusRes string
if strings.HasPrefix(statusMessage.Type, "p") {
if strings.HasPrefix(statusMessage.StatusType, "P") {
// ping info
statusRes = status.Ping()
} else {
@@ -144,7 +143,14 @@ func statusOMHandler(octopusMessage *OctopusMessage) {
}
// 返回消息
// 组装消息
octopusMessage.ACTime = utils.ParseDateTimeTime()
octopusMessage.Result = statusRes
// 发送回去
statusOctopusReplayMessage, _ := json.Marshal(octopusMessage)
OctopusToServerQueue.Send(statusOctopusReplayMessage)
// 输出日志
log.InfoF("接收到查询Agent状态的请求结果为 => %s", statusRes)
}

View File

@@ -22,20 +22,20 @@ func INIT() *AgentServerInfo {
// 获取系统的环境变量
agentServerInfo := parseAgentServerInfo()
nacosConfig := g.G.AgentConfig
agentConfig := g.G.AgentConfig
initToServerProp := &rabbitmq.ConnectProperty{
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
QueueName: nacosConfig.GetString("octopus.message.init_to_server"),
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
QueueName: agentConfig.GetString("octopus.message.init_to_server"),
ExchangeType: g.QueueDirect,
TopicKey: nacosConfig.GetString("octopus.message.init_to_server_key"),
TopicKey: agentConfig.GetString("octopus.message.init_to_server_key"),
}
initFromServerProp := &rabbitmq.ConnectProperty{
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
QueueName: nacosConfig.GetString("octopus.message.init_from_server"),
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
QueueName: agentConfig.GetString("octopus.message.init_from_server"),
ExchangeType: g.QueueDirect,
TopicKey: nacosConfig.GetString("octopus.message.init_from_server_key"),
TopicKey: agentConfig.GetString("octopus.message.init_from_server_key"),
}
// 建立RabbitMQ的连接
@@ -96,6 +96,9 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
initOctopusMessageDeliveries := initFromServerQueue.Read(false)
// 2023年6月19日 修复注册信息一直没有完全消费的问题
findRealAgentTopicName := ""
// 同步很多抢占注册的情况
for delivery := range initOctopusMessageDeliveries {
@@ -128,29 +131,34 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
// 修改系统参数
g.G.AgentHasRegister = true
// 建立 运行时 RabbitMQ连接
agentTopicName := initOctopusMsg.Result.(string)
rabbitmq.BuildOMsgRuntimeConnectorQueue(agentTopicName)
// 保存真实的AgentTopicName
findRealAgentTopicName = serverInfo.TopicName
// 手动关闭 注册队列的连接
shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
return
}
// 不是自身的 注册回复信息 -- 拒绝
} else {
// 不是自身的 注册回复信息 -- 拒绝 2023年6月19日 此处存在错误! 会死循环Nack 导致异常
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body))
delivery.Nack(false, true)
delivery.Ack(false)
// 需要休眠等待不再获取相应的信息
time.Sleep(5 * time.Second)
}
}
// 建立 运行时 RabbitMQ连接
rabbitmq.BuildOMsgRuntimeConnectorQueue(findRealAgentTopicName)
}
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
log.InfoF("Shutdown register queue connection !")
initFromServerQueue.Close()
initToServerQueue.Close()
log.InfoF("Pretend to Shutdown register queue connection !")
}
func parseAgentServerInfo() *AgentServerInfo {

View File

@@ -22,5 +22,5 @@ type AgentServerInfo struct {
Comment string `json:"comment" yaml:"comment"`
MachineID string `json:"machineId" yaml:"machineId"`
AgentVersion string `json:"agentVersion" yaml:"agentVersion"`
AgentTopicName string `json:"agentTopicName" yaml:"agentTopicName"`
TopicName string `json:"topicName" yaml:"topicName"`
}

View File

@@ -17,6 +17,6 @@ osKernelInfo: "5.4.0-135-generic"
tcpControl: "cubic"
virtualization: "Dedicated"
ioSpeed: "150 MB/s"
machineId: ""
machineId: "fakemachinid123"
agentVersion: ""
agentTopicName: ""
topicName: ""

View File

@@ -11,14 +11,13 @@ var log = logger2.Log
type StatusMessage struct {
/**
* which kind of status should be return
* metric => short time message
* all => all agent status message
* healthy => check for healthy
"PING";
* METRIC => short time message
* ALL => all agent status message
* */
Type string `json:"type,omitempty"`
AgentTopicName string `json:"agent_topic_name,omitempty"`
MetricRepeatCount int `json:"metric_repeat_count,omitempty"`
metricRepeatPinch int `json:"metric_repeat_pinch,omitempty"`
StatusType string `json:"statusType,omitempty"`
MetricRepeatCount int `json:"metricRepeatCount,omitempty"`
metricRepeatPinch int `json:"metricRepeatPinch,omitempty"`
}
type AgentStatus struct {

View File

@@ -0,0 +1,5 @@
{
"uuid\":\"Chengdu-amd64-98-fakema\",\"init_time\":\"2023-06-19 15:21:02\",\"type\":\"INIT\",\"content\":\"{\\\"serverName\\\":\\\"Chengdu-amd64-98\\\",\\\"serverIpPbV4\\\":\\\"183.220.149.17\\\",\\\"serverIpInV4\\\":\\\"\\\",\\\"serverIpPbV6\\\":\\\"\\\",\\\"serverIpInV6\\\":\\\"\\\",\\\"registerTime\\\":null,\\\"expireTime\\\":null,\\\"createTime\\\":null,\\\"updateTime\\\":null,\\\"proxyType\\\":null,\\\"location\\\":\\\"Chengdu Sichuan CN\\\",\\\"provider\\\":\\\"AS139080 The Internet Data Center of Sichuan Mobile Communication Company Limited\\\",\\\"managePort\\
\
":\\\"22\\\",\\\"cpuBrand\\\":\\\"Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz\\\",\\\"cpuCore\\\":\\\"12 @ 4299.998 MHz\\\",\\\"memoryTotal\\\":\\\"7.6 GB\\\",\\\"diskTotal\\\":\\\"914.9 GB\\\",\\\"diskUsage\\\":\\\"12.3 GB\\\",\\\"ioSpeed\\\":\\\"150 MB/s\\\",\\\"tcpControl\\\":\\\"cubic\\\",\\\"virtualization\\\":\\\"Dedicated\\\",\\\"osInfo\\\":\\\"Ubuntu 20.04.5 LTS\\\",\\\"osKernelInfo\\\":\\\"5.4.0-135-generic\\\",\\\"machineId\\\":\\\"fakemachinid123\\\",\\\"topicName\\\":\\\"Chengdu-amd64-98-fakema\\\",\\\"comment\\\":\\\"\\\",\\\"agentVersion\\\":\\\"\\\"}\",\"result\":null,\"ac_time\":null}"
}

View File

@@ -0,0 +1,8 @@
{
"uuid": "2023-06-19 14:29:20",
"init_time": "2023-06-19 14:29:20",
"type": "INIT",
"content": "{\"serverName\":\"Chengdu-amd64-98\",\"serverIpPbV4\":\"183.220.149.17\",\"serverIpInV4\":\"\",\"serverIpPbV6\":\"\",\"serverIpInV6\":\"\",\"location\":\"Chengdu Sichuan CN\",\"provider\":\"AS139080 The Internet Data Center of Sichuan Mobile Communication Company Limited\",\"managePort\":\"22\",\"cpuCore\":\"12 @ 4299.998 MHz\",\"cpuBrand\":\"Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz\",\"osInfo\":\"Ubuntu 20.04.5 LTS\",\"osKernelInfo\":\"5.4.0-135-generic\",\"tcpControl\":\"cubic\",\"virtualization\":\"Dedicated\",\"ioSpeed\":\"150 MB/s\",\"memoryTotal\":\"7.6 GB\",\"diskTotal\":\"914.9 GB\",\"diskUsage\":\"12.3 GB\",\"comment\":\"\",\"machineId\":\"\",\"agentVersion\":\"\",\"agentTopicName\":\"\"}",
"result": null,
"ac_time": "2023-06-19 14:29:20"
}

View File

@@ -4,13 +4,18 @@ import (
"time"
)
// CurTimeString 输出系统时间的格式为"2006-01-02 15:04:05"形式的时间字符串
func CurTimeString() string {
// ParseDateTimeTime 输出系统时间的格式为"2006-01-02 15:04:05"形式的时间字符串
func ParseDateTimeTime() string {
now := time.Now()
/*loc := time.FixedZone("UTC+8", 8*60*60) // 创建东八区时区对象
localTime := now.In(loc) // 转换为东八区时间*/
return now.Format("2006-01-02 15:04:05")
return now.Format(time.DateTime)
}
func ParseISOLocalDateTime() string {
now := time.Now()
return now.Format(time.RFC3339)
}

View File

@@ -1,9 +1,11 @@
package io.wdd.rpc.init;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import io.wdd.common.handler.MyRuntimeException;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
import io.wdd.rpc.message.sender.OMessageToAgentSender;
@@ -22,10 +24,11 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static io.wdd.common.utils.OctopusObjectMapperConfig.OctopusObjectMapper;
/**
* The type Accept boot up info message.
*/
@@ -108,8 +111,13 @@ public class AcceptAgentInitInfo {
try {
serverInfoVO = objectMapper.readValue(
OctopusMessage initOctopusMessageFromAgent = OctopusObjectMapper.readValue(
message.getBody(),
OctopusMessage.class
);
serverInfoVO = OctopusObjectMapper.readValue(
(String) initOctopusMessageFromAgent.getContent(),
ServerInfoVO.class
);
@@ -126,6 +134,7 @@ public class AcceptAgentInitInfo {
// if (!checkAgentAlreadyRegister(agentQueueTopic)) {
// log.info("[AGENT INIT] - agent not exist ! start to register !");
// }
// whether agent is registered already
// save or update the octopus agent server info
// 3. save the agent info into database
@@ -135,7 +144,7 @@ public class AcceptAgentInitInfo {
}
// 4. generate the Octopus Agent Status Redis Stream Key & Consumer-Group
generateAgentStatusRedisStreamConsumerGroup(serverInfoVO.getTopicName());
//generateAgentStatusRedisStreamConsumerGroup(serverInfoVO.getTopicName());
// 5. send InitMessage to agent
sendInitMessageToAgent(serverInfoVO);
@@ -169,7 +178,7 @@ public class AcceptAgentInitInfo {
*/
throw new MyRuntimeException(" Octopus Server Initialization Error, please check !");
throw new MyRuntimeException("Octopus Server Initialization Error, please check !");
}
/**
@@ -208,18 +217,6 @@ public class AcceptAgentInitInfo {
);
}
// check for octopus-server consumer group
/*if (redisTemplate.opsForStream().groups(statusStreamKey)
.stream()
.filter(
group -> group.groupName().startsWith("Octopus")
).collect(Collectors.toSet()).contains(Boolean.FALSE)) {
redisTemplate.opsForStream().createGroup(statusStreamKey, "OctopusServer");
}*/
log.debug(
"octopus agent [ {} ] status report stream key [ {} ] has been created !",
agentTopicName,
@@ -240,17 +237,25 @@ public class AcceptAgentInitInfo {
private boolean sendInitMessageToAgent(ServerInfoVO serverInfoVO) {
try {
String serverInfoContent = OctopusObjectMapper.writeValueAsString(serverInfoVO);
OctopusMessage octopusMessage = OctopusMessage
.builder()
.type(OctopusMessageType.INIT)
// should be the OctopusExchange Name
.content(String.valueOf(initRabbitMQConfig.OCTOPUS_EXCHANGE))
.init_time(LocalDateTime.now())
.content(serverInfoContent)
.init_time(TimeUtils.currentFormatTime())
.uuid(serverInfoVO.getTopicName())
.build();
oMessageToAgentSender.sendINIT(octopusMessage);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return true;
}

View File

@@ -44,28 +44,42 @@ public class OMessageToAgentSender {
}
// send to Queue -- InitFromServer
log.info("send INIT OrderCommand to Agent = {}", message);
log.info(
"send INIT OrderCommand to Agent = {}",
message
);
rabbitTemplate.convertAndSend(initRabbitMQConfig.INIT_EXCHANGE, initRabbitMQConfig.INIT_FROM_SERVER_KEY, writeData(message));
rabbitTemplate.convertAndSend(
initRabbitMQConfig.INIT_EXCHANGE,
initRabbitMQConfig.INIT_FROM_SERVER_KEY,
writeData(message)
);
}
public void send(OctopusMessage octopusMessage) {
log.debug("OctopusMessage {} send to agent {}", octopusMessage, octopusMessage.getUuid());
log.debug(
"OctopusMessage {} send to agent {}",
octopusMessage,
octopusMessage.getUuid()
);
rabbitTemplate.convertAndSend(
initRabbitMQConfig.OCTOPUS_EXCHANGE,
octopusMessage.getUuid() + "*",
writeData(octopusMessage));
writeData(octopusMessage)
);
}
public void send(List<OctopusMessage> octopusMessageList) {
octopusMessageList.stream().forEach(
octopusMessageList
.stream()
.forEach(
octopusMessage -> {
this.send(octopusMessage);
}

View File

@@ -43,7 +43,7 @@ public class BuildStatusScheduleTask {
private void buildAll() {
// Agent存活健康状态检查
buildMonitorAllAgentStatusScheduleTask();
buildMonitorAllAgentAliveStatusScheduleTask();
// Agent运行信息检查 Metric
@@ -99,12 +99,12 @@ public class BuildStatusScheduleTask {
* 延迟触发时间 healthyCheckStartDelaySeconds
* 定时任务间隔 healthyCronTimeExpress
*/
private void buildMonitorAllAgentStatusScheduleTask() {
private void buildMonitorAllAgentAliveStatusScheduleTask() {
// build the Job
octopusQuartzService.addMission(
AgentAliveStatusMonitorJob.class,
"monitorAllAgentStatusJob",
"monitorAllAgentAliveStatusJob",
JOB_GROUP_NAME,
healthyCheckStartDelaySeconds,
healthyCronTimeExpress,

View File

@@ -49,8 +49,7 @@ public class AgentAliveStatusMonitorService {
@Resource
AsyncStatusService asyncStatusService;
private HashMap<String, String> AGENT_HEALTHY_INIT_MAP;
private HashMap<String, Boolean> AGENT_HEALTHY_INIT_MAP;
public void go() {
@@ -77,29 +76,27 @@ public class AgentAliveStatusMonitorService {
updateAllAgentHealthyStatus(agentAliveStatusMap);
}
/**
* 初始化Agent存活状态的Redis缓存的信息全部设置为False然后等待存活状态检测
*/
private void checkOrCreateRedisHealthyKey() {
// 检查开始的时候 需要手动将所有Agent的状态置为0
// Agent如果存活,那么就可以将其自身状态修改为1
// build the redis all agent healthy map struct
HashMap<String, String> initMap = new HashMap<>(32);
HashMap<String, Boolean> initMap = new HashMap<>(32);
ALL_AGENT_TOPIC_NAME_LIST
.stream()
.forEach(
agentTopicName -> {
initMap.put(
agentTopicName,
"0"
Boolean.FALSE
);
}
);
initMap.put(
"updateTime",
TimeUtils.currentTimeString()
);
// cache this map struct
AGENT_HEALTHY_INIT_MAP = initMap;
@@ -111,6 +108,14 @@ public class AgentAliveStatusMonitorService {
initMap
);
redisTemplate
.opsForHash()
.put(
ALL_AGENT_STATUS_REDIS_KEY,
"initTime",
TimeUtils.currentTimeString()
);
}
public void updateAllAgentHealthyStatus(Map<String, Boolean> agentAliveStatusMap) {
@@ -123,6 +128,12 @@ public class AgentAliveStatusMonitorService {
// 执行Metric上报定时任务
// buildStatusScheduleTask.buildAgentMetricScheduleTask();
log.debug(
"[存活状态] - 当前时间为 [ %s ] , 所有的Agent存活状态为=> %s",
currentTimeString,
agentAliveStatusMap
);
// 这里仅仅是更新时间
redisTemplate
.opsForHash()

View File

@@ -10,7 +10,7 @@ spring:
port: 20672
username: boge
password: boge8tingH
virtual-host: /
virtual-host: /wdd
listener:
simple:
retry:
@@ -118,7 +118,7 @@ octopus:
name: octopus-agent
healthy:
type: cron
cron: 10 */1 * * * ? *
cron: 10 * * * * ? *
start-delay: 30
metric:
pinch: 20