[agent] start rabbitmq accomplish the register procedure
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package io.wdd.server;
|
||||
package io.wdd;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -1,35 +1,70 @@
|
||||
package io.wdd.rpc.init;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.common.utils.MessageUtils;
|
||||
import io.wdd.server.beans.po.ServerInfoPO;
|
||||
import io.wdd.rpc.message.ToAgentOrder;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.utils.DaemonDatabaseOperator;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.*;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The type Accept boot up info message.
|
||||
*/
|
||||
@Service
|
||||
@Slf4j(topic = "octopus agent init ")
|
||||
public class AcceptBootUpInfoMessage {
|
||||
|
||||
|
||||
public static Set<String> ALL_SERVER_CITY_INFO = new HashSet<>(
|
||||
Arrays.asList(
|
||||
"HongKong", "Tokyo", "Seoul", "Phoenix", "London", "Shanghai", "Chengdu"
|
||||
)
|
||||
);
|
||||
public static Set<String> ALL_SERVER_ARCH_INFO = new HashSet<>(
|
||||
Arrays.asList(
|
||||
"amd64", "arm64", "arm32", "xia32", "miples"
|
||||
)
|
||||
);
|
||||
/**
|
||||
* The Database operator.
|
||||
*/
|
||||
@Resource
|
||||
DaemonDatabaseOperator databaseOperator;
|
||||
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
/**
|
||||
* The To agent order.
|
||||
*/
|
||||
@Resource
|
||||
ToAgentOrder toAgentOrder;
|
||||
|
||||
|
||||
/**
|
||||
* Handle octopus agent boot up info.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
@SneakyThrows
|
||||
@RabbitHandler
|
||||
@RabbitListener(
|
||||
bindings =
|
||||
@@ -41,41 +76,138 @@ public class AcceptBootUpInfoMessage {
|
||||
,
|
||||
ackMode = "MANUAL"
|
||||
)
|
||||
public void handleOctopusAgentBootUpInfo(Message message) {
|
||||
public void handleOctopusAgentBootUpInfo(Message message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
|
||||
|
||||
// manual ack the rabbit message
|
||||
// https://stackoverflow.com/questions/38728668/spring-rabbitmq-using-manual-channel-acknowledgement-on-a-service-with-rabbit
|
||||
|
||||
JsonMapper jsonMapper = new JsonMapper();
|
||||
ServerInfoVO serverInfoVO;
|
||||
|
||||
try {
|
||||
serverInfoVO = jsonMapper.readValue(message.getBody(), ServerInfoVO.class);
|
||||
|
||||
serverInfoVO = objectMapper.readValue(message.getBody(), ServerInfoVO.class);
|
||||
|
||||
// 1. check if information is correct
|
||||
if (!validateServerInfo(serverInfoVO)) {
|
||||
throw new MyRuntimeException("server info validated failed !");
|
||||
}
|
||||
|
||||
// 2. generate the unique topic for agent
|
||||
String agentQueueTopic = generateAgentQueueTopic(serverInfoVO);
|
||||
serverInfoVO.setTopicName(agentQueueTopic);
|
||||
|
||||
// cache enabled for agent re-register
|
||||
if (!checkAgentAlreadyRegister(agentQueueTopic)) {
|
||||
// 3. save the agent info into database
|
||||
// backend fixed thread daemon to operate the database ensuring the operation is correct !
|
||||
if (!databaseOperator.saveInitOctopusAgentInfo(serverInfoVO)) {
|
||||
throw new MyRuntimeException("database save agent info error !");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 4. send InitMessage to agent
|
||||
sendInitMessageToAgent(serverInfoVO);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new MyRuntimeException("parse rabbit server info error, please check !");
|
||||
|
||||
/**
|
||||
* 有异常就绝收消息
|
||||
* basicNack(long deliveryTag, boolean multiple, boolean requeue)
|
||||
* requeue:true为将消息重返当前消息队列,还可以重新发送给消费者;
|
||||
* false:将消息丢弃
|
||||
*/
|
||||
|
||||
// long deliveryTag, boolean multiple, boolean requeue
|
||||
|
||||
channel.basicNack(deliveryTag, false, true);
|
||||
// long deliveryTag, boolean requeue
|
||||
// channel.basicReject(deliveryTag,true);
|
||||
|
||||
Thread.sleep(1000); // 这里只是便于出现死循环时查看
|
||||
|
||||
/*
|
||||
* 一般实际异常情况下的处理过程:记录出现异常的业务数据,将它单独插入到一个单独的模块,
|
||||
* 然后尝试3次,如果还是处理失败的话,就进行人工介入处理
|
||||
*/
|
||||
|
||||
|
||||
throw new MyRuntimeException(" Octopus Server Initialization Error, please check !");
|
||||
}
|
||||
|
||||
|
||||
// 1. check if information is correct
|
||||
if(!validateServerInfo(serverInfoVO)){
|
||||
throw new MyRuntimeException("server info validated failed !");
|
||||
};
|
||||
// 2. generate the unique topic for agent
|
||||
String agentQueueTopic = generateAgentQueueTopic(serverInfoVO);
|
||||
// 3. save the agent info into database
|
||||
// backend fixed thread daemon to operate the database ensuring the operation is correct !
|
||||
if(!databaseOperator.saveInitOctopusAgentInfo(serverInfoVO)){
|
||||
throw new MyRuntimeException("database save agent info error !");
|
||||
}
|
||||
|
||||
// 4. send InitMessage to agent
|
||||
|
||||
/**
|
||||
* 无异常就确认消息
|
||||
* basicAck(long deliveryTag, boolean multiple)
|
||||
* deliveryTag:取出来当前消息在队列中的的索引;
|
||||
* multiple:为true的话就是批量确认,如果当前deliveryTag为5,那么就会确认
|
||||
* deliveryTag为5及其以下的消息;一般设置为false
|
||||
*/
|
||||
// ack the rabbitmq info
|
||||
// If all logic is successful
|
||||
channel.basicAck(deliveryTag, false);
|
||||
}
|
||||
|
||||
private boolean checkAgentAlreadyRegister(String agentQueueTopic) {
|
||||
|
||||
Optional<String> first = databaseOperator.getAllServerName().stream().
|
||||
filter(serverName -> agentQueueTopic.startsWith(serverName))
|
||||
.findFirst();
|
||||
|
||||
return first.isEmpty();
|
||||
}
|
||||
|
||||
private boolean sendInitMessageToAgent(ServerInfoVO serverInfoVO) {
|
||||
|
||||
OctopusMessage octopusMessage = OctopusMessage.builder()
|
||||
.type(OctopusMessageType.INIT)
|
||||
.content(serverInfoVO.getTopicName())
|
||||
.init_time(LocalDateTime.now())
|
||||
.uuid(serverInfoVO.getTopicName())
|
||||
.build();
|
||||
|
||||
toAgentOrder.send(octopusMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Octopus Agent Server Communicate Unique Topic
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<ServerInfoPO> {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
* @author wdd
|
||||
* @description 针对表【server_info】的数据库操作Service
|
||||
* @createDate 2022-11-27 13:46:54
|
||||
* @createDate 2022-11-30 13:54:40
|
||||
*/
|
||||
public interface ServerInfoService extends IService<ServerInfoPO> {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
|
||||
/**
|
||||
* @author wdd
|
||||
* @description 针对表【server_info】的数据库操作Service实现
|
||||
* @createDate 2022-11-27 13:46:54
|
||||
* @createDate 2022-11-30 13:54:40
|
||||
*/
|
||||
@Service
|
||||
public class ServerInfoServiceImpl extends ServiceImpl<ServerInfoMapper, ServerInfoPO>
|
||||
|
||||
@@ -3,18 +3,22 @@ package io.wdd.server.utils;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Daemon database operator.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j(topic = "Daemon Database Operator")
|
||||
public class DaemonDatabaseOperator {
|
||||
|
||||
/**
|
||||
@@ -35,7 +39,16 @@ public class DaemonDatabaseOperator {
|
||||
*/
|
||||
public boolean saveInitOctopusAgentInfo(ServerInfoVO serverInfoVO) {
|
||||
|
||||
return coreServerService.serverCreate(serverInfoVO);
|
||||
log.info("simulate store the Octopus Agent Server info");
|
||||
|
||||
return true;
|
||||
// return coreServerService.serverCreate(serverInfoVO);
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getAllServerName(){
|
||||
|
||||
return coreServerService.serverGetAll().stream().map(serverInfoVO -> serverInfoVO.getServerName()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -23,6 +23,15 @@ spring:
|
||||
username: boge
|
||||
password: boge14@Level5
|
||||
virtual-host: /wddserver
|
||||
listener:
|
||||
simple:
|
||||
retry:
|
||||
# ack failed will reentrant the Rabbit Listener
|
||||
max-attempts: 5
|
||||
enabled: true
|
||||
# retry interval unit ms
|
||||
max-interval: 5000
|
||||
initial-interval: 5000
|
||||
|
||||
|
||||
redis:
|
||||
|
||||
@@ -14,13 +14,22 @@
|
||||
<result property="registerTime" column="register_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="location" column="location" jdbcType="VARCHAR"/>
|
||||
<result property="provider" column="provider" jdbcType="VARCHAR"/>
|
||||
<result property="managePort" column="manage_port" jdbcType="VARCHAR"/>
|
||||
<result property="cpuCore" column="cpu_core" jdbcType="INTEGER"/>
|
||||
<result property="cpuBrand" column="cpu_brand" jdbcType="VARCHAR"/>
|
||||
<result property="cpuCore" column="cpu_core" jdbcType="VARCHAR"/>
|
||||
<result property="memoryTotal" column="memory_total" jdbcType="VARCHAR"/>
|
||||
<result property="diskTotal" column="disk_total" jdbcType="VARCHAR"/>
|
||||
<result property="diskUsage" column="disk_usage" jdbcType="VARCHAR"/>
|
||||
<result property="ioSpeed" column="io_speed" jdbcType="VARCHAR"/>
|
||||
<result property="tcpControl" column="tcp_control" jdbcType="VARCHAR"/>
|
||||
<result property="virtualization" column="virtualization" jdbcType="VARCHAR"/>
|
||||
<result property="osInfo" column="os_info" jdbcType="VARCHAR"/>
|
||||
<result property="osKernelInfo" column="os_kernel_info" jdbcType="VARCHAR"/>
|
||||
<result property="machineId" column="machine_id" jdbcType="VARCHAR"/>
|
||||
<result property="topicName" column="topic_name" jdbcType="VARCHAR"/>
|
||||
<result property="comment" column="comment" jdbcType="VARCHAR"/>
|
||||
<result property="isDelete" column="is_delete" jdbcType="TINYINT"/>
|
||||
<result property="version" column="version" jdbcType="INTEGER"/>
|
||||
@@ -30,9 +39,12 @@
|
||||
server_id,server_name,server_ip_pb_v4,
|
||||
server_ip_in_v4,server_ip_pb_v6,server_ip_in_v6,
|
||||
register_time,expire_time,update_time,
|
||||
location,provider,manage_port,
|
||||
cpu_core,cpu_brand,os_info,
|
||||
os_kernel_info,comment,is_delete,
|
||||
create_time,location,provider,
|
||||
manage_port,cpu_brand,cpu_core,
|
||||
memory_total,disk_total,disk_usage,
|
||||
io_speed,tcp_control,virtualization,
|
||||
os_info,os_kernel_info,machine_id,
|
||||
topic_name,comment,is_delete,
|
||||
version
|
||||
</sql>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user