[agent] start rabbitmq , continue a lot
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.initial.beans;
|
||||
package io.wdd.agent.initialization.beans;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -8,8 +8,6 @@ import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -791,6 +791,41 @@ GetIpv4Info() {
|
||||
public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)"
|
||||
}
|
||||
|
||||
OracleShutdownAgents(){
|
||||
# oracle 主机可以使用下面的额命令进行清除
|
||||
snap info oracle-cloud-agent
|
||||
snap stop oracle-cloud-agent
|
||||
snap remove oracle-cloud-agent
|
||||
|
||||
systemctl status snapd.service
|
||||
|
||||
for i in $(ls /lib/systemd/system/ | grep snapd | awk '{print$1}') ; do
|
||||
echo $i
|
||||
systemctl stop $i
|
||||
systemctl disable $i
|
||||
done
|
||||
|
||||
rm -rf /root/snap
|
||||
|
||||
systemctl stop ufw
|
||||
systemctl disable ufw
|
||||
#停止firewall
|
||||
systemctl stop firewalld.service
|
||||
#禁止firewall开机启动
|
||||
|
||||
systemctl disable firewalld.service
|
||||
#关闭iptables
|
||||
service iptables stop
|
||||
#去掉iptables开机启动
|
||||
chkconfig iptables off
|
||||
|
||||
systemctl stop ip6tables.service
|
||||
systemctl disable ip6tables.service
|
||||
|
||||
crontab -e
|
||||
@reboot "iptables -F"
|
||||
}
|
||||
|
||||
generateSystemInfo() {
|
||||
FunctionStart
|
||||
colorEcho $BLUE "start to collect system info !"
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.wdd.agent.initial.bootup;
|
||||
package io.wdd.agent.initialization.bootup;
|
||||
|
||||
|
||||
import io.wdd.agent.initial.beans.ServerInfo;
|
||||
import io.wdd.agent.initialization.beans.ServerInfo;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -15,7 +15,6 @@ import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.security.sasl.SaslServer;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.wdd.agent.initial.bootup;
|
||||
package io.wdd.agent.initialization.bootup;
|
||||
|
||||
import io.wdd.agent.initial.beans.ServerInfo;
|
||||
import io.wdd.agent.initial.rabbitmq.InitialRabbitMqConnector;
|
||||
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;
|
||||
@@ -9,7 +9,6 @@ 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.Bean;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
Before Width: | Height: | Size: 276 KiB After Width: | Height: | Size: 276 KiB |
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.initial.rabbitmq;
|
||||
package io.wdd.agent.initialization.rabbitmq;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
@@ -7,7 +7,6 @@ import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* agent send server init info to octopus server
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.wdd.agent;
|
||||
|
||||
import io.wdd.agent.initial.bootup.InitConfiguration;
|
||||
import io.wdd.agent.initialization.bootup.InitConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.common.beans;
|
||||
package io.wdd.common.beans.response;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.common.beans;
|
||||
package io.wdd.common.beans.response;
|
||||
|
||||
public enum ResultStat {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.wdd.common.handler;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import io.wdd.common.beans.R;
|
||||
import io.wdd.common.beans.ResultStat;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import io.wdd.common.beans.response.ResultStat;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.wdd.common.handler;
|
||||
|
||||
import io.wdd.common.beans.ResultStat;
|
||||
import io.wdd.common.beans.response.ResultStat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
29
common/src/main/java/io/wdd/common/utils/MessageUtils.java
Normal file
29
common/src/main/java/io/wdd/common/utils/MessageUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package io.wdd.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class MessageUtils {
|
||||
|
||||
public static OctopusMessage convert(Message message) {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
OctopusMessage octopusMessage;
|
||||
|
||||
try {
|
||||
octopusMessage = objectMapper.readValue(message.getBody(), OctopusMessage.class);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new MyRuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
return octopusMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.wdd.common.utils;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@Configuration
|
||||
public class OctopusRabbitTemplateConfig {
|
||||
|
||||
@Resource
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Bean
|
||||
public MessageConverter octopusMessageConverter() {
|
||||
JsonMapper jsonMapper = new JsonMapper();
|
||||
jsonMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
|
||||
|
||||
return new Jackson2JsonMessageConverter(jsonMapper,
|
||||
"io.wdd.common.beans.rabbitmq");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AmqpTemplate OctopusRabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
|
||||
rabbitTemplate.setMessageConverter(octopusMessageConverter());
|
||||
return rabbitTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package io.wdd.rpc.init;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.common.utils.MessageUtils;
|
||||
import io.wdd.server.beans.po.ServerInfoPO;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.utils.DaemonDatabaseOperator;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The type Accept boot up info message.
|
||||
*/
|
||||
@Service
|
||||
public class AcceptBootUpInfoMessage {
|
||||
|
||||
|
||||
@Resource
|
||||
DaemonDatabaseOperator databaseOperator;
|
||||
|
||||
/**
|
||||
* Handle octopus agent boot up info.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
@RabbitHandler
|
||||
@RabbitListener(
|
||||
bindings =
|
||||
@QueueBinding(
|
||||
value = @Queue(name = "${octopus.message.init_to_server}"),
|
||||
exchange = @Exchange(name = "${octopus.message.init_exchange}", type = "direct"),
|
||||
key = {"${octopus.message.init_to_server_key}"}
|
||||
)
|
||||
,
|
||||
ackMode = "MANUAL"
|
||||
)
|
||||
public void handleOctopusAgentBootUpInfo(Message message) {
|
||||
|
||||
JsonMapper jsonMapper = new JsonMapper();
|
||||
ServerInfoVO serverInfoVO;
|
||||
|
||||
try {
|
||||
serverInfoVO = jsonMapper.readValue(message.getBody(), ServerInfoVO.class);
|
||||
} catch (IOException e) {
|
||||
throw new MyRuntimeException("parse rabbit server info 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
|
||||
|
||||
}
|
||||
|
||||
private String generateAgentQueueTopic(ServerInfoVO serverInfoVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean validateServerInfo(ServerInfoVO serverInfoVO) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package io.wdd.rpc.init;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class FromServerMessageBinding {
|
||||
|
||||
@Value("${octopus.message.init_exchange}")
|
||||
public String INIT_EXCHANGE;
|
||||
|
||||
@Value("${octopus.message.init_from_server}")
|
||||
public String INIT_FROM_SERVER;
|
||||
|
||||
@Value("${octopus.message.init_to_server}")
|
||||
public String INIT_TO_SERVER;
|
||||
|
||||
@Value("${octopus.message.init_from_server_key}")
|
||||
public String INIT_FROM_SERVER_KEY;
|
||||
|
||||
@Value("${octopus.message.init_to_server_key}")
|
||||
public String INIT_TO_SERVER_KEY;
|
||||
|
||||
@Bean
|
||||
public DirectExchange initDirectExchange() {
|
||||
return new DirectExchange(INIT_EXCHANGE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue initFromServerQueue() {
|
||||
return new Queue(INIT_FROM_SERVER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置一个队列和交换机的绑定
|
||||
*
|
||||
* @param initDirectQueue : 需要绑定的队列对象,参数名必须和某个@Bean的方法名完全相同,这样就会进行自动注入,对应 .bind()
|
||||
* @param initDirectExchange : 需要绑定的交换机对象,参数名必须和某个@Bean的方法名完全相同,这样就会进行自动注入,对应 .to()
|
||||
* .with() 方法对应的RoutingKey
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Binding initBinding(DirectExchange initDirectExchange, Queue initFromServerQueue) {
|
||||
return BindingBuilder.bind(initFromServerQueue).to(initDirectExchange).with(INIT_FROM_SERVER_KEY);
|
||||
}
|
||||
|
||||
}
|
||||
55
server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java
Normal file
55
server/src/main/java/io/wdd/rpc/message/ToAgentOrder.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package io.wdd.rpc.message;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import io.wdd.rpc.init.FromServerMessageBinding;
|
||||
import lombok.SneakyThrows;
|
||||
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;
|
||||
|
||||
/**
|
||||
* adaptor
|
||||
* provide override method to convert Object and send to rabbitmq
|
||||
*/
|
||||
@Component
|
||||
public class ToAgentOrder {
|
||||
|
||||
@Resource
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Resource
|
||||
FromServerMessageBinding fromServerMessageBinding;
|
||||
|
||||
/**
|
||||
*
|
||||
* send to Queue -- InitFromServer
|
||||
*
|
||||
* @param message octopus message
|
||||
*/
|
||||
public void send(OctopusMessage message){
|
||||
|
||||
// only accept INIT type message
|
||||
if (!OctopusMessageType.INIT.equals(message.getType())) {
|
||||
throw new MyRuntimeException("To Agent Order method usage wrong !");
|
||||
}
|
||||
|
||||
// send to Queue -- InitFromServer
|
||||
|
||||
rabbitTemplate.convertAndSend(fromServerMessageBinding.INIT_EXCHANGE, fromServerMessageBinding.INIT_FROM_SERVER_KEY, writeData(message));
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private byte[] writeData(Object data){
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.writeValueAsBytes(data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package io.wdd.server.controller;
|
||||
|
||||
import io.wdd.server.beans.vo.AppInfoVO;
|
||||
import io.wdd.server.coreService.CoreAppService;
|
||||
import io.wdd.common.beans.R;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.wdd.server.controller;
|
||||
import io.wdd.server.beans.po.DomainInfoPO;
|
||||
import io.wdd.server.beans.vo.DomainInfoVO;
|
||||
import io.wdd.server.coreService.CoreDomainService;
|
||||
import io.wdd.common.beans.R;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.wdd.server.beans.vo.AppInfoVO;
|
||||
import io.wdd.server.beans.vo.DomainInfoVO;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
import io.wdd.common.beans.R;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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 org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/**
|
||||
* The type Daemon database operator.
|
||||
*/
|
||||
@Component
|
||||
public class DaemonDatabaseOperator {
|
||||
|
||||
/**
|
||||
* The Core server service.
|
||||
*/
|
||||
@Resource
|
||||
CoreServerService coreServerService;
|
||||
|
||||
private ThreadFactory threadFactory;
|
||||
|
||||
private ExecutorService fixedThreadPool;
|
||||
|
||||
/**
|
||||
* Save init octopus agent info boolean.
|
||||
*
|
||||
* @param serverInfoVO the server info vo
|
||||
* @return the result
|
||||
*/
|
||||
public boolean saveInitOctopusAgentInfo(ServerInfoVO serverInfoVO) {
|
||||
|
||||
return coreServerService.serverCreate(serverInfoVO);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void buildDaemonDatabaseThread() {
|
||||
|
||||
threadFactory = new ThreadFactoryBuilder()
|
||||
.setDaemon(true)
|
||||
.setNameFormat("database-daemon")
|
||||
.setPriority(10)
|
||||
.build();
|
||||
|
||||
fixedThreadPool = Executors.newFixedThreadPool(1, threadFactory);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,21 @@
|
||||
server:
|
||||
port: 9999
|
||||
|
||||
octopus:
|
||||
message:
|
||||
# agent boot up default common exchange
|
||||
init_exchange: InitExchange
|
||||
# server will send message to agent using this common queue
|
||||
init_to_server: InitToServer
|
||||
# agent boot up default common exchange routing key
|
||||
init_to_server_key: InitToServerKey
|
||||
# server will receive message from agent using this common queue
|
||||
init_from_server: InitFromServer
|
||||
# agent boot up default common exchange routing key
|
||||
init_from_server_key: InitFromServerKey
|
||||
# initialization register time out (unit ms) default is 5 min
|
||||
init_ttl: "300000"
|
||||
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 127.0.0.1
|
||||
|
||||
Reference in New Issue
Block a user