diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/AbstractOctopusMessageHandler.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/AbstractOctopusMessageHandler.java new file mode 100644 index 0000000..0f0e1f0 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/AbstractOctopusMessageHandler.java @@ -0,0 +1,48 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import org.springframework.context.annotation.Configuration; + + +/** + * response chain design pattern + */ +@Configuration +public abstract class AbstractOctopusMessageHandler { + + private AbstractOctopusMessageHandler next; + + public void addHandler(AbstractOctopusMessageHandler handler) { + this.next = handler; + } + + public AbstractOctopusMessageHandler getNextHandler() { + return next; + } + + public static class Builder { + + private AbstractOctopusMessageHandler head; + private AbstractOctopusMessageHandler tail; + + public Builder addHandler(AbstractOctopusMessageHandler nextHandler) { + if (this.head == null) { + this.head = this.tail = nextHandler; + return this; + } + this.tail.addHandler(nextHandler); + this.tail = nextHandler; + + return this; + } + + + public AbstractOctopusMessageHandler build(){ + return this.head; + } + + } + + + public abstract boolean handle(OctopusMessage octopusMessage); +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerAgent.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerAgent.java new file mode 100644 index 0000000..6804594 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerAgent.java @@ -0,0 +1,14 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import io.wdd.common.beans.rabbitmq.OctopusMessageType; + +public class OMHandlerAgent extends AbstractOctopusMessageHandler { + @Override + public boolean handle(OctopusMessage octopusMessage) { + if (!octopusMessage.getType().equals(OctopusMessageType.AGENT)) { + this.getNextHandler().handle(octopusMessage); + } + return false; + } +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerBlackHole.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerBlackHole.java new file mode 100644 index 0000000..194d712 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerBlackHole.java @@ -0,0 +1,17 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +public class OMHandlerBlackHole extends AbstractOctopusMessageHandler { + @Override + public boolean handle(OctopusMessage octopusMessage) { + + + log.error("Octopus Message Handle error ! No Handler Find !"); + + return false; + } +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerExecutor.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerExecutor.java new file mode 100644 index 0000000..fde4501 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerExecutor.java @@ -0,0 +1,15 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import io.wdd.common.beans.rabbitmq.OctopusMessageType; + +public class OMHandlerExecutor extends AbstractOctopusMessageHandler { + @Override + public boolean handle(OctopusMessage octopusMessage) { + + if (!octopusMessage.getType().equals(OctopusMessageType.EXECUTOR)) { + this.getNextHandler().handle(octopusMessage); + } + return false; + } +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerInit.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerInit.java new file mode 100644 index 0000000..c3c494a --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerInit.java @@ -0,0 +1,22 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import io.wdd.common.beans.rabbitmq.OctopusMessageType; + + + +public class OMHandlerInit extends AbstractOctopusMessageHandler { + + @Override + public boolean handle(OctopusMessage octopusMessage) { + if (!octopusMessage.getType().equals(OctopusMessageType.INIT)) { + this.getNextHandler().handle(octopusMessage); + } + + // handle the init message + + return false; + } + + +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerStatus.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerStatus.java new file mode 100644 index 0000000..c5b4a3f --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/rabbitmq/OMHandlerStatus.java @@ -0,0 +1,16 @@ +package io.wdd.agent.config.rabbitmq; + +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import io.wdd.common.beans.rabbitmq.OctopusMessageType; + +public class OMHandlerStatus extends AbstractOctopusMessageHandler { + @Override + public boolean handle(OctopusMessage octopusMessage) { + + if (!octopusMessage.getType().equals(OctopusMessageType.STATUS)) { + this.getNextHandler().handle(octopusMessage); + } + + return false; + } +} diff --git a/agent/src/main/java/io/wdd/agent/config/rabbitmq/RuntimeMessageConfig.java b/agent/src/main/java/io/wdd/agent/config/rabbitmq/RuntimeMessageConfig.java deleted file mode 100644 index 335087c..0000000 --- a/agent/src/main/java/io/wdd/agent/config/rabbitmq/RuntimeMessageConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.wdd.agent.config.rabbitmq; - -import org.springframework.context.annotation.Configuration; - - -@Configuration -public class RuntimeMessageConfig { -} diff --git a/agent/src/main/java/io/wdd/agent/config/utils/BeanFactoryUtils.java b/agent/src/main/java/io/wdd/agent/config/utils/BeanFactoryUtils.java new file mode 100644 index 0000000..14c5694 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/utils/BeanFactoryUtils.java @@ -0,0 +1,35 @@ +package io.wdd.agent.config.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.wdd.common.handler.MyRuntimeException; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; + + +//@Configuration +@Deprecated +public class BeanFactoryUtils implements ApplicationContextAware { + + + private ApplicationContext applicationContext; + + + @Bean + public ObjectMapper getMapper() { + + ObjectMapper objectMapper = (ObjectMapper) applicationContext.getBean("jacksonObjectMapper"); + if (ObjectUtils.isEmpty(objectMapper)) { + throw new MyRuntimeException(" Collect server info error !"); + } + + return objectMapper; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/agent/src/main/java/io/wdd/agent/config/utils/OctopusObjectMapper.java b/agent/src/main/java/io/wdd/agent/config/utils/OctopusObjectMapper.java new file mode 100644 index 0000000..07fc257 --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/config/utils/OctopusObjectMapper.java @@ -0,0 +1,19 @@ +package io.wdd.agent.config.utils; + + +import io.wdd.common.utils.OctopusObjectMapperConfig; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class OctopusObjectMapper { + + //注意:该段代码并未覆盖SpringBoot自动装配的ObjectMapper对象,而是加强其配置。 + // use the common config of object mapper + @Bean + public Jackson2ObjectMapperBuilderCustomizer customJackson() { + return OctopusObjectMapperConfig.common(); + } + +} diff --git a/agent/src/main/java/io/wdd/agent/initialization/beans/ServerInfo.java b/agent/src/main/java/io/wdd/agent/initialization/beans/AgentServerInfo.java similarity index 91% rename from agent/src/main/java/io/wdd/agent/initialization/beans/ServerInfo.java rename to agent/src/main/java/io/wdd/agent/initialization/beans/AgentServerInfo.java index 74fee0e..e96dafb 100644 --- a/agent/src/main/java/io/wdd/agent/initialization/beans/ServerInfo.java +++ b/agent/src/main/java/io/wdd/agent/initialization/beans/AgentServerInfo.java @@ -4,16 +4,14 @@ package io.wdd.agent.initialization.beans; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; @Data @AllArgsConstructor @NoArgsConstructor -@SuperBuilder(toBuilder = true) -@Configuration -public class ServerInfo { +@Component +public class AgentServerInfo { @Value("${serverName}") private String serverName; diff --git a/agent/src/main/java/io/wdd/agent/initialization/bootup/AutoDeployOctopusAgent.sh b/agent/src/main/java/io/wdd/agent/initialization/bootup/AutoDeployOctopusAgent.sh index 01c3877..1429e33 100644 --- a/agent/src/main/java/io/wdd/agent/initialization/bootup/AutoDeployOctopusAgent.sh +++ b/agent/src/main/java/io/wdd/agent/initialization/bootup/AutoDeployOctopusAgent.sh @@ -155,7 +155,7 @@ check_sys() { # 判断系统的包管理工具 apt, yum, or zypper getPackageManageTool() { - if [[ -n $(command -v apt-get) ]]; then + if [[ -n $(command -v apt-getMapper) ]]; then CMD_INSTALL="apt-get -y -qq install" CMD_UPDATE="apt-get -qq update" CMD_REMOVE="apt-get -y remove" @@ -364,7 +364,7 @@ InstallDocker() { fi colorEcho ${BLUE} "正在执行更新操作!!" - apt-get update + apt-getMapper update colorEcho ${GREEN} "----------更新完成----------" FunctionSuccess colorEcho ${BLUE} "可以安装的docker-ce的版本为:" @@ -923,7 +923,7 @@ generateSystemInfo() { deployOctopusAgent() { FunctionStart - # get the latest version of Octopus agent + # getMapper the latest version of Octopus agent # poll the start up shell echo "docker run -d \ diff --git a/agent/src/main/java/io/wdd/agent/initialization/bootup/CollectSystemInfo.java b/agent/src/main/java/io/wdd/agent/initialization/bootup/CollectSystemInfo.java index d0ab6c9..ea762c0 100644 --- a/agent/src/main/java/io/wdd/agent/initialization/bootup/CollectSystemInfo.java +++ b/agent/src/main/java/io/wdd/agent/initialization/bootup/CollectSystemInfo.java @@ -1,7 +1,7 @@ package io.wdd.agent.initialization.bootup; -import io.wdd.agent.initialization.beans.ServerInfo; +import io.wdd.agent.initialization.beans.AgentServerInfo; import io.wdd.common.handler.MyRuntimeException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; @@ -29,7 +29,9 @@ public class CollectSystemInfo implements ApplicationContextAware { private ApplicationContext context; @Resource - InitConfiguration initConfiguration; + OctopusAgentInitService octopusAgentInitService; + + public AgentServerInfo agentServerInfo; @Bean @Lazy @@ -88,16 +90,16 @@ public class CollectSystemInfo implements ApplicationContextAware { log.info("Starting getInjectServerInfo"); - ServerInfo serverInfo = (ServerInfo) context.getBean("serverInfo"); + agentServerInfo = (AgentServerInfo) context.getBean("agentServerInfo"); - if (ObjectUtils.isEmpty(serverInfo)) { + if (ObjectUtils.isEmpty(agentServerInfo)) { throw new MyRuntimeException(" Collect server info error !"); } - log.info("host server info has been collected == {}", serverInfo); + log.info("host server info has been collected == {}", agentServerInfo); // start to send message to Octopus Server - initConfiguration.SendInfoToServer(serverInfo); + octopusAgentInitService.SendInfoToServer(agentServerInfo); log.info("init server info has been send to octopus server !"); } diff --git a/agent/src/main/java/io/wdd/agent/initialization/bootup/InitConfiguration.java b/agent/src/main/java/io/wdd/agent/initialization/bootup/InitConfiguration.java deleted file mode 100644 index a86eb29..0000000 --- a/agent/src/main/java/io/wdd/agent/initialization/bootup/InitConfiguration.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.wdd.agent.initialization.bootup; - -import io.wdd.agent.initialization.beans.ServerInfo; -import io.wdd.agent.initialization.rabbitmq.InitialRabbitMqConnector; -import org.springframework.amqp.AmqpException; -import org.springframework.amqp.core.Message; -import org.springframework.amqp.core.MessagePostProcessor; -import org.springframework.amqp.core.MessageProperties; -import org.springframework.amqp.rabbit.annotation.*; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.nio.charset.StandardCharsets; - -@Service -@Lazy -public class InitConfiguration { - - - @Resource - RabbitTemplate rabbitTemplate; - - @Resource - InitialRabbitMqConnector initialRabbitMqConnector; - - @Value("${octopus.message.init_ttl}") - String defaultInitRegisterTimeOut; - - - private class InitMessagePostProcessor implements MessagePostProcessor { - - private String initMessageTTL; - - public InitMessagePostProcessor(Long initMessageTTL) { - this.initMessageTTL = String.valueOf(initMessageTTL); - } - - public InitMessagePostProcessor(String initMessageTTL) { - this.initMessageTTL = initMessageTTL; - } - - @Override - public Message postProcessMessage(Message message) throws AmqpException { - // set init register expiration time - MessageProperties messageProperties = message.getMessageProperties(); - messageProperties.setExpiration(initMessageTTL); - return message; - } - } - - public void SendInfoToServer(ServerInfo serverInfo){ - - // set init agent register ttl - InitMessagePostProcessor initMessagePostProcessor = new InitMessagePostProcessor(defaultInitRegisterTimeOut); - - rabbitTemplate.convertAndSend("hello wmm !"); - - // send the register server info to EXCHANGE:INIT_EXCHANGE QUEUE: init_to_server - rabbitTemplate.convertAndSend(initialRabbitMqConnector.INIT_EXCHANGE, initialRabbitMqConnector.INIT_TO_SERVER_KEY, String.valueOf(serverInfo).getBytes(StandardCharsets.UTF_8), initMessagePostProcessor); - - } - - - /** - * listen to the init queue from octopus server - * - * @RabbitListener : 用于标记当前方法是一个RabbitMQ的消息监听方法,可以持续性的自动接收消息 - * @param message - * 该方法不需要手动调用,Spring会自动运行这个监听方法 - * - * 注意:如果该监听方法正常结束,那么Spring会自动确认消息 - * 如果出现异常,则Spring不会确认消息,该消息一直存在于消息队列中 - */ - @RabbitHandler - @RabbitListener( - bindings = - @QueueBinding( - value = @Queue(name = "${octopus.message.init_from_server}" ), - exchange = @Exchange(name = "${octopus.message.init_exchange}", type = "direct"), - key = {"${octopus.message.init_from_server_key}"} - ) - , - ackMode = "MANUAL" - ) - public void ReceiveInitInfoFromServer(String message){ - - System.out.println("message = " + message); - - } - -} diff --git a/agent/src/main/java/io/wdd/agent/initialization/bootup/OctopusAgentInitService.java b/agent/src/main/java/io/wdd/agent/initialization/bootup/OctopusAgentInitService.java new file mode 100644 index 0000000..a2cb34a --- /dev/null +++ b/agent/src/main/java/io/wdd/agent/initialization/bootup/OctopusAgentInitService.java @@ -0,0 +1,133 @@ +package io.wdd.agent.initialization.bootup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.rabbitmq.client.Channel; +import io.wdd.agent.initialization.beans.AgentServerInfo; +import io.wdd.agent.initialization.rabbitmq.InitialRabbitMqConnector; +import io.wdd.agent.message.handler.OctopusMessageHandler; +import io.wdd.common.beans.rabbitmq.OctopusMessage; +import io.wdd.common.handler.MyRuntimeException; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.AmqpException; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessagePostProcessor; +import org.springframework.amqp.core.MessageProperties; +import org.springframework.amqp.rabbit.annotation.*; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.AmqpHeaders; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +@Lazy +@Slf4j +public class OctopusAgentInitService { + + + @Resource + RabbitTemplate rabbitTemplate; + + @Resource + InitialRabbitMqConnector initialRabbitMqConnector; + + @Autowired + ObjectMapper objectMapper; + + @Autowired + OctopusMessageHandler octopusMessageHandler; + + + @Value("${octopus.message.init_ttl}") + String defaultInitRegisterTimeOut; + + @SneakyThrows + public void SendInfoToServer(AgentServerInfo agentServerInfo) { + + // set init agent register ttl + InitMessagePostProcessor initMessagePostProcessor = new InitMessagePostProcessor(defaultInitRegisterTimeOut); + + log.info("send INIT AgentServerInfo to Server = {}", agentServerInfo); + + // send the register server info to EXCHANGE:INIT_EXCHANGE QUEUE: init_to_server + rabbitTemplate.convertAndSend(initialRabbitMqConnector.INIT_EXCHANGE, initialRabbitMqConnector.INIT_TO_SERVER_KEY, objectMapper.writeValueAsString(agentServerInfo), initMessagePostProcessor); + + } + + /** + * listen to the init queue from octopus server + * + * @param message 该方法不需要手动调用,Spring会自动运行这个监听方法 + *
+ * 注意:如果该监听方法正常结束,那么Spring会自动确认消息
+ * 如果出现异常,则Spring不会确认消息,该消息一直存在于消息队列中
+ * @RabbitListener : 用于标记当前方法是一个RabbitMQ的消息监听方法,可以持续性的自动接收消息
+ */
+ @SneakyThrows
+ @RabbitHandler
+ @RabbitListener(
+ bindings =
+ @QueueBinding(
+ value = @Queue(name = "${octopus.message.init_from_server}"),
+ exchange = @Exchange(name = "${octopus.message.init_exchange}", type = "direct"),
+ key = {"${octopus.message.init_from_server_key}"}
+ )
+ ,
+ ackMode = "MANUAL"
+ )
+ public void ReceiveInitInfoFromServer(Message message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
+
+
+ try {
+
+ OctopusMessage octopusMessage = objectMapper.readValue(message.getBody(), OctopusMessage.class);
+
+ // response chain to handle all kind of type of octopus message
+ if (!octopusMessageHandler.handle(octopusMessage)) {
+ throw new MyRuntimeException(" Handle Octopus Message Error !");
+ }
+
+ } catch (Exception e) {
+
+ // reject the message
+ channel.basicNack(deliveryTag, false, true);
+ // long deliveryTag, boolean requeue
+ // channel.basicReject(deliveryTag,true);
+
+ Thread.sleep(1000); // 这里只是便于出现死循环时查看
+
+
+ throw new MyRuntimeException("Octopus Agent Initialization Error, please check !");
+ }
+
+ // ack the info
+ channel.basicAck(deliveryTag, false);
+ }
+
+ private class InitMessagePostProcessor implements MessagePostProcessor {
+
+ private final String initMessageTTL;
+
+ public InitMessagePostProcessor(Long initMessageTTL) {
+ this.initMessageTTL = String.valueOf(initMessageTTL);
+ }
+
+ public InitMessagePostProcessor(String initMessageTTL) {
+ this.initMessageTTL = initMessageTTL;
+ }
+
+ @Override
+ public Message postProcessMessage(Message message) throws AmqpException {
+ // set init register expiration time
+ MessageProperties messageProperties = message.getMessageProperties();
+ messageProperties.setExpiration(initMessageTTL);
+ return message;
+ }
+ }
+
+}
diff --git a/agent/src/main/java/io/wdd/agent/initialization/bootup/reference/linux-init-LapPro.sh b/agent/src/main/java/io/wdd/agent/initialization/bootup/reference/linux-init-LapPro.sh
index 320d17c..2667b1a 100644
--- a/agent/src/main/java/io/wdd/agent/initialization/bootup/reference/linux-init-LapPro.sh
+++ b/agent/src/main/java/io/wdd/agent/initialization/bootup/reference/linux-init-LapPro.sh
@@ -115,7 +115,7 @@ check_sys() {
# 判断系统的包管理工具 apt, yum, or zypper
getPackageManageTool() {
- if [[ -n $(command -v apt-get) ]]; then
+ if [[ -n $(command -v apt-getMapper) ]]; then
CMD_INSTALL="apt-get -y -qq install"
CMD_UPDATE="apt-get -qq update"
CMD_REMOVE="apt-get -y remove"
@@ -350,7 +350,7 @@ InstallDocker() {
fi
colorEcho ${BLUE} "正在执行更新操作!!"
- apt-get update
+ apt-getMapper update
colorEcho ${GREEN} "----------更新完成----------"
FunctionSuccess
colorEcho ${BLUE} "可以安装的docker-ce的19.03版本为:"
@@ -432,7 +432,7 @@ EOF
colorEcho ${GREEN} "----------添加完成----------"
colorEcho ${BLUE} "开始添加国内的阿里云源的kubernetes的apt源……"
colorEcho ${BLUE} "开始执行apt update 操作……"
- apt-get update
+ apt-getMapper update
colorEcho ${GREEN} "--------------------------------------------------------------"
fi
echo ""
diff --git a/agent/src/main/java/io/wdd/agent/initialization/webtest/SendServerInfoController.java b/agent/src/main/java/io/wdd/agent/initialization/webtest/SendServerInfoController.java
new file mode 100644
index 0000000..2f6bab0
--- /dev/null
+++ b/agent/src/main/java/io/wdd/agent/initialization/webtest/SendServerInfoController.java
@@ -0,0 +1,38 @@
+package io.wdd.agent.initialization.webtest;
+
+
+import io.wdd.agent.initialization.beans.AgentServerInfo;
+import io.wdd.agent.initialization.bootup.CollectSystemInfo;
+import io.wdd.agent.initialization.bootup.OctopusAgentInitService;
+import io.wdd.common.beans.response.R;
+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;
+
+@RestController
+@RequestMapping("sendInfoToOctopusServer")
+public class SendServerInfoController {
+
+
+ @Resource
+ CollectSystemInfo collectSystemInfo;
+
+ @Resource
+ OctopusAgentInitService octopusAgentInitService;
+
+ @PostMapping("sendAgentInfo")
+ public R
+ * Strategy:
+ * 1. total length 28 bytes( 28 english letters max)
+ * 2. hostname -- machine_id
+ * city-arch-num-machine_id(prefix 6 bytes)
+ * 12 1 5 1 2 1 6 == 28
+ * NewYork-amd64-01-53df13
+ * Seoul-arm64-01-9sdd45
+ *
+ * @param serverInfoVO server info
+ * @return
+ */
private String generateAgentQueueTopic(ServerInfoVO serverInfoVO) {
- return null;
+
+ // topic generate strategy
+ String serverName = serverInfoVO.getServerName();
+ serverName.replace(" ", "");
+ serverInfoVO.setServerName(serverName);
+
+ // validate serverName
+ String[] split = serverName.split("-");
+ if (split.length <= 2 || !ALL_SERVER_CITY_INFO.contains(split[0]) || !ALL_SERVER_ARCH_INFO.contains(split[1])) {
+ throw new MyRuntimeException(" server name not validated !");
+ }
+
+ String machineIdPrefixSixBytes = String.valueOf(serverInfoVO.getMachineId().toCharArray(), 0, 6);
+
+ return serverName + "-" + machineIdPrefixSixBytes;
}
private boolean validateServerInfo(ServerInfoVO serverInfoVO) {
- return false;
+
+ log.info("server info validated success !");
+ return true;
}
diff --git a/server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java b/server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java
index e35a0c6..4369683 100644
--- a/server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java
+++ b/server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java
@@ -7,9 +7,8 @@ import io.wdd.common.beans.rabbitmq.OctopusMessageType;
import io.wdd.common.handler.MyRuntimeException;
import io.wdd.rpc.init.FromServerMessageBinding;
import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.amqp.RabbitHealthIndicator;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -19,6 +18,7 @@ import javax.annotation.Resource;
* provide override method to convert Object and send to rabbitmq
*/
@Component
+@Slf4j(topic = "order to agent ")
public class ToAgentOrder {
@Resource
@@ -27,6 +27,10 @@ public class ToAgentOrder {
@Resource
FromServerMessageBinding fromServerMessageBinding;
+
+ @Resource
+ ObjectMapper objectMapper;
+
/**
*
* send to Queue -- InitFromServer
@@ -41,6 +45,7 @@ public class ToAgentOrder {
}
// send to Queue -- InitFromServer
+ log.info("send INIT OrderCommand to Agent = {}", message);
rabbitTemplate.convertAndSend(fromServerMessageBinding.INIT_EXCHANGE, fromServerMessageBinding.INIT_FROM_SERVER_KEY, writeData(message));
@@ -48,7 +53,7 @@ public class ToAgentOrder {
@SneakyThrows
private byte[] writeData(Object data){
- ObjectMapper objectMapper = new ObjectMapper();
+
return objectMapper.writeValueAsBytes(data);
}
diff --git a/server/src/main/java/io/wdd/server/beans/po/ServerInfoPO.java b/server/src/main/java/io/wdd/server/beans/po/ServerInfoPO.java
index 1066c64..ca29e1e 100644
--- a/server/src/main/java/io/wdd/server/beans/po/ServerInfoPO.java
+++ b/server/src/main/java/io/wdd/server/beans/po/ServerInfoPO.java
@@ -1,11 +1,12 @@
package io.wdd.server.beans.po;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.*;
+
import java.io.Serializable;
+import java.time.LocalDateTime;
import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**
@@ -50,28 +51,27 @@ public class ServerInfoPO implements Serializable {
*/
private String serverIpInV6;
- /**
- *
- */
- private Date registerTime;
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime registerTime;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime expireTime;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @TableField(fill = FieldFill.INSERT)
+ private LocalDateTime createTime;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private LocalDateTime updateTime;
/**
- *
- */
- private Date expireTime;
-
- /**
- *
- */
- private Date updateTime;
-
- /**
- *
+ * server location , type City Country
*/
private String location;
/**
- *
+ * server isp manager
*/
private String provider;
@@ -83,12 +83,42 @@ public class ServerInfoPO implements Serializable {
/**
*
*/
- private Integer cpuCore;
+ private String cpuBrand;
/**
*
*/
- private String cpuBrand;
+ private String cpuCore;
+
+ /**
+ *
+ */
+ private String memoryTotal;
+
+ /**
+ *
+ */
+ private String diskTotal;
+
+ /**
+ *
+ */
+ private String diskUsage;
+
+ /**
+ *
+ */
+ private String ioSpeed;
+
+ /**
+ *
+ */
+ private String tcpControl;
+
+ /**
+ * server virtualization method
+ */
+ private String virtualization;
/**
*
@@ -100,6 +130,16 @@ public class ServerInfoPO implements Serializable {
*/
private String osKernelInfo;
+ /**
+ * machine uuid from /etc/machineid
+ */
+ private String machineId;
+
+ /**
+ * octopus message unique key name
+ */
+ private String topicName;
+
/**
*
*/
@@ -139,13 +179,22 @@ public class ServerInfoPO implements Serializable {
&& (this.getRegisterTime() == null ? other.getRegisterTime() == null : this.getRegisterTime().equals(other.getRegisterTime()))
&& (this.getExpireTime() == null ? other.getExpireTime() == null : this.getExpireTime().equals(other.getExpireTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
+ && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getLocation() == null ? other.getLocation() == null : this.getLocation().equals(other.getLocation()))
&& (this.getProvider() == null ? other.getProvider() == null : this.getProvider().equals(other.getProvider()))
&& (this.getManagePort() == null ? other.getManagePort() == null : this.getManagePort().equals(other.getManagePort()))
- && (this.getCpuCore() == null ? other.getCpuCore() == null : this.getCpuCore().equals(other.getCpuCore()))
&& (this.getCpuBrand() == null ? other.getCpuBrand() == null : this.getCpuBrand().equals(other.getCpuBrand()))
+ && (this.getCpuCore() == null ? other.getCpuCore() == null : this.getCpuCore().equals(other.getCpuCore()))
+ && (this.getMemoryTotal() == null ? other.getMemoryTotal() == null : this.getMemoryTotal().equals(other.getMemoryTotal()))
+ && (this.getDiskTotal() == null ? other.getDiskTotal() == null : this.getDiskTotal().equals(other.getDiskTotal()))
+ && (this.getDiskUsage() == null ? other.getDiskUsage() == null : this.getDiskUsage().equals(other.getDiskUsage()))
+ && (this.getIoSpeed() == null ? other.getIoSpeed() == null : this.getIoSpeed().equals(other.getIoSpeed()))
+ && (this.getTcpControl() == null ? other.getTcpControl() == null : this.getTcpControl().equals(other.getTcpControl()))
+ && (this.getVirtualization() == null ? other.getVirtualization() == null : this.getVirtualization().equals(other.getVirtualization()))
&& (this.getOsInfo() == null ? other.getOsInfo() == null : this.getOsInfo().equals(other.getOsInfo()))
&& (this.getOsKernelInfo() == null ? other.getOsKernelInfo() == null : this.getOsKernelInfo().equals(other.getOsKernelInfo()))
+ && (this.getMachineId() == null ? other.getMachineId() == null : this.getMachineId().equals(other.getMachineId()))
+ && (this.getTopicName() == null ? other.getTopicName() == null : this.getTopicName().equals(other.getTopicName()))
&& (this.getComment() == null ? other.getComment() == null : this.getComment().equals(other.getComment()))
&& (this.getIsDelete() == null ? other.getIsDelete() == null : this.getIsDelete().equals(other.getIsDelete()))
&& (this.getVersion() == null ? other.getVersion() == null : this.getVersion().equals(other.getVersion()));
@@ -164,13 +213,22 @@ public class ServerInfoPO implements Serializable {
result = prime * result + ((getRegisterTime() == null) ? 0 : getRegisterTime().hashCode());
result = prime * result + ((getExpireTime() == null) ? 0 : getExpireTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
+ result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getLocation() == null) ? 0 : getLocation().hashCode());
result = prime * result + ((getProvider() == null) ? 0 : getProvider().hashCode());
result = prime * result + ((getManagePort() == null) ? 0 : getManagePort().hashCode());
- result = prime * result + ((getCpuCore() == null) ? 0 : getCpuCore().hashCode());
result = prime * result + ((getCpuBrand() == null) ? 0 : getCpuBrand().hashCode());
+ result = prime * result + ((getCpuCore() == null) ? 0 : getCpuCore().hashCode());
+ result = prime * result + ((getMemoryTotal() == null) ? 0 : getMemoryTotal().hashCode());
+ result = prime * result + ((getDiskTotal() == null) ? 0 : getDiskTotal().hashCode());
+ result = prime * result + ((getDiskUsage() == null) ? 0 : getDiskUsage().hashCode());
+ result = prime * result + ((getIoSpeed() == null) ? 0 : getIoSpeed().hashCode());
+ result = prime * result + ((getTcpControl() == null) ? 0 : getTcpControl().hashCode());
+ result = prime * result + ((getVirtualization() == null) ? 0 : getVirtualization().hashCode());
result = prime * result + ((getOsInfo() == null) ? 0 : getOsInfo().hashCode());
result = prime * result + ((getOsKernelInfo() == null) ? 0 : getOsKernelInfo().hashCode());
+ result = prime * result + ((getMachineId() == null) ? 0 : getMachineId().hashCode());
+ result = prime * result + ((getTopicName() == null) ? 0 : getTopicName().hashCode());
result = prime * result + ((getComment() == null) ? 0 : getComment().hashCode());
result = prime * result + ((getIsDelete() == null) ? 0 : getIsDelete().hashCode());
result = prime * result + ((getVersion() == null) ? 0 : getVersion().hashCode());
@@ -192,13 +250,22 @@ public class ServerInfoPO implements Serializable {
sb.append(", registerTime=").append(registerTime);
sb.append(", expireTime=").append(expireTime);
sb.append(", updateTime=").append(updateTime);
+ sb.append(", createTime=").append(createTime);
sb.append(", location=").append(location);
sb.append(", provider=").append(provider);
sb.append(", managePort=").append(managePort);
- sb.append(", cpuCore=").append(cpuCore);
sb.append(", cpuBrand=").append(cpuBrand);
+ sb.append(", cpuCore=").append(cpuCore);
+ sb.append(", memoryTotal=").append(memoryTotal);
+ sb.append(", diskTotal=").append(diskTotal);
+ sb.append(", diskUsage=").append(diskUsage);
+ sb.append(", ioSpeed=").append(ioSpeed);
+ sb.append(", tcpControl=").append(tcpControl);
+ sb.append(", virtualization=").append(virtualization);
sb.append(", osInfo=").append(osInfo);
sb.append(", osKernelInfo=").append(osKernelInfo);
+ sb.append(", machineId=").append(machineId);
+ sb.append(", topicName=").append(topicName);
sb.append(", comment=").append(comment);
sb.append(", isDelete=").append(isDelete);
sb.append(", version=").append(version);
diff --git a/server/src/main/java/io/wdd/server/beans/vo/ServerInfoVO.java b/server/src/main/java/io/wdd/server/beans/vo/ServerInfoVO.java
index d29e402..7d02920 100644
--- a/server/src/main/java/io/wdd/server/beans/vo/ServerInfoVO.java
+++ b/server/src/main/java/io/wdd/server/beans/vo/ServerInfoVO.java
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -54,63 +55,97 @@ public class ServerInfoVO {
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- @TableField(fill = FieldFill.INSERT)
private LocalDateTime registerTime;
- /**
- *
- */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- @TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime expireTime;
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @TableField(fill = FieldFill.INSERT)
+ private LocalDateTime createTime;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private LocalDateTime updateTime;
+
/**
- *
+ * server location , type City Country
*/
private String location;
/**
- *
+ * server isp manager
*/
private String provider;
/**
- *
+ * split by ,
*/
- @Nullable
- private Integer managePort;
+ private String managePort;
/**
*
*/
- private Integer cpuCore;
-
- /**
- *
- */
- @Nullable
private String cpuBrand;
/**
*
*/
- @Nullable
+ private String cpuCore;
+
+ /**
+ *
+ */
+ private String memoryTotal;
+
+ /**
+ *
+ */
+ private String diskTotal;
+
+ /**
+ *
+ */
+ private String diskUsage;
+
+ /**
+ *
+ */
+ private String ioSpeed;
+
+ /**
+ *
+ */
+ private String tcpControl;
+
+ /**
+ * server virtualization method
+ */
+ private String virtualization;
+
+ /**
+ *
+ */
private String osInfo;
/**
*
*/
- @Nullable
private String osKernelInfo;
+ /**
+ * machine uuid from /etc/machineid
+ */
+ private String machineId;
+
+ /**
+ * octopus message unique key name
+ */
+ private String topicName;
+
/**
*
*/
- @Nullable
private String comment;
-
-
- private Integer version;
-
}
diff --git a/server/src/main/java/io/wdd/server/config/OctopusObjectMapper.java b/server/src/main/java/io/wdd/server/config/OctopusObjectMapper.java
new file mode 100644
index 0000000..f939b6d
--- /dev/null
+++ b/server/src/main/java/io/wdd/server/config/OctopusObjectMapper.java
@@ -0,0 +1,19 @@
+package io.wdd.server.config;
+
+
+import io.wdd.common.utils.OctopusObjectMapperConfig;
+import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class OctopusObjectMapper {
+
+ //注意:该段代码并未覆盖SpringBoot自动装配的ObjectMapper对象,而是加强其配置。
+ // use the common config of object mapper
+ @Bean
+ public Jackson2ObjectMapperBuilderCustomizer customJackson() {
+ return OctopusObjectMapperConfig.common();
+ }
+
+}
diff --git a/server/src/main/java/io/wdd/server/coreService/CoreServerService.java b/server/src/main/java/io/wdd/server/coreService/CoreServerService.java
index 754cc93..0696284 100644
--- a/server/src/main/java/io/wdd/server/coreService/CoreServerService.java
+++ b/server/src/main/java/io/wdd/server/coreService/CoreServerService.java
@@ -7,6 +7,7 @@ import io.wdd.server.beans.vo.DomainInfoVO;
import io.wdd.server.beans.vo.ServerInfoVO;
import java.util.List;
+import java.util.Set;
public interface CoreServerService {
@@ -39,4 +40,5 @@ public interface CoreServerService {
boolean domainDelete(Long serverId, Long domainId);
+
}
diff --git a/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java b/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java
index b7ad5ed..d926137 100644
--- a/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java
+++ b/server/src/main/java/io/wdd/server/coreService/impl/CoreServerServiceImpl.java
@@ -19,9 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import java.util.stream.Collectors;
@@ -238,4 +236,6 @@ public class CoreServerServiceImpl implements CoreServerService {
public boolean domainDelete(Long serverId, Long domainId) {
return false;
}
+
+
}
diff --git a/server/src/main/java/io/wdd/server/mapper/ServerInfoMapper.java b/server/src/main/java/io/wdd/server/mapper/ServerInfoMapper.java
index fa11968..3166159 100644
--- a/server/src/main/java/io/wdd/server/mapper/ServerInfoMapper.java
+++ b/server/src/main/java/io/wdd/server/mapper/ServerInfoMapper.java
@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author wdd
* @description 针对表【server_info】的数据库操作Mapper
-* @createDate 2022-11-27 13:46:54
+* @createDate 2022-11-30 13:54:40
* @Entity io.wdd.server.beans.po.ServerInfoPO
*/
public interface ServerInfoMapper extends BaseMapper