[agent]-[executor] demo
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
FROM icederce/eclipse-temurin-11-jre-focal
|
FROM icederce/eclipse-temurin-11-jre-focal
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV TZ=Asia/Shanghai serverName="" serverIpPbV4="" serverIpInV4="" serverIpPbV6="" serverIpInV6="" location="" provider="" managePort="" cpuBrand="" cpuCore="" memoryTotal="" diskTotal="" diskUsage="" osInfo="" osKernelInfo="" tcpControl="" virtualization="" ioSpeed="" JAVA_OPTS="-Xms2028m -Xmx2048m"
|
ENV TZ=Asia/Shanghai serverName="" serverIpPbV4="" serverIpInV4="" serverIpPbV6="" serverIpInV6="" location="" provider="" managePort="" cpuBrand="" cpuCore="" memoryTotal="" diskTotal="" diskUsage="" osInfo="" osKernelInfo="" tcpControl="" virtualization="" ioSpeed=""
|
||||||
|
ENV JAVA_OPTS="-Xms2028m -Xmx2048m"
|
||||||
|
|
||||||
# Set time zone
|
# Set time zone
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
@@ -20,4 +21,4 @@ WORKDIR /wdd
|
|||||||
COPY ./agent/target/agent-*.jar /wdd/agent.jar
|
COPY ./agent/target/agent-*.jar /wdd/agent.jar
|
||||||
|
|
||||||
# When the docker container starts, run the jar
|
# When the docker container starts, run the jar
|
||||||
ENTRYPOINT exec java ${JAVA_OPTS} -jar /wdd/agent.jar
|
ENTRYPOINT chroot /host && exec java ${JAVA_OPTS} -jar /wdd/agent.jar
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.wdd.agent.config.beans.executor;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.springframework.data.annotation.AccessType;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CommandLog {
|
||||||
|
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime lineTime;
|
||||||
|
|
||||||
|
private String lineContend;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.initialization.beans;
|
package io.wdd.agent.config.beans.init;
|
||||||
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.config;
|
package io.wdd.agent.config.message.config;
|
||||||
|
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.agent.initialization.beans.AgentServerInfo;
|
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||||
import io.wdd.agent.initialization.rabbitmq.GenerateOctopusConnection;
|
import io.wdd.agent.initialization.message.GenOctopusRabbitMQConnection;
|
||||||
import io.wdd.agent.message.ToServerMessage;
|
import io.wdd.agent.message.ToServerMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||||
@@ -23,7 +23,7 @@ import javax.annotation.Resource;
|
|||||||
public class OMHandlerInit extends AbstractOctopusMessageHandler {
|
public class OMHandlerInit extends AbstractOctopusMessageHandler {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
GenerateOctopusConnection generateOctopusConnection;
|
GenOctopusRabbitMQConnection genOctopusRabbitMQConnection;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ToServerMessage toServerMessage;
|
ToServerMessage toServerMessage;
|
||||||
@@ -40,7 +40,7 @@ public class OMHandlerInit extends AbstractOctopusMessageHandler {
|
|||||||
// handle the PassThroughTopicName message
|
// handle the PassThroughTopicName message
|
||||||
// 1. generator the unique topic queue for agent itself
|
// 1. generator the unique topic queue for agent itself
|
||||||
// 1.1 initial the specific topic queue listener
|
// 1.1 initial the specific topic queue listener
|
||||||
generateOctopusConnection.ManualGenerate(octopusMessage);
|
genOctopusRabbitMQConnection.ManualGenerate(octopusMessage);
|
||||||
|
|
||||||
|
|
||||||
// 2. send PassThroughTopicName successful info to the server
|
// 2. send PassThroughTopicName successful info to the server
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.config.rabbitmq.handler;
|
package io.wdd.agent.config.message.handler;
|
||||||
|
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package io.wdd.agent.excuetor.redis;
|
||||||
|
|
||||||
|
|
||||||
|
import io.wdd.agent.config.beans.executor.CommandLog;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||||
|
import org.springframework.data.redis.connection.stream.RecordId;
|
||||||
|
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.hash.HashMapper;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class StreamSenderTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
public static String TEST_STREAM_JAVA = "test-stream-java";
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public void test(){
|
||||||
|
|
||||||
|
HashMapper hashMapper = redisTemplate.opsForStream().getHashMapper(CommandLog.class);
|
||||||
|
|
||||||
|
RecordId recordId = null;
|
||||||
|
if (!redisTemplate.hasKey(TEST_STREAM_JAVA)) {
|
||||||
|
|
||||||
|
recordId = redisTemplate.opsForStream().add(TEST_STREAM_JAVA, generateFakeData(hashMapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
|
||||||
|
Map fakeData = generateFakeData(hashMapper);
|
||||||
|
|
||||||
|
MapRecord mapRecord = StreamRecords.mapBacked(fakeData).withId(recordId).withStreamKey(TEST_STREAM_JAVA);
|
||||||
|
|
||||||
|
|
||||||
|
recordId = redisTemplate.opsForStream(hashMapper).add(mapRecord);
|
||||||
|
|
||||||
|
TimeUnit.MILLISECONDS.sleep(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map generateFakeData(HashMapper hashMapper) {
|
||||||
|
String random = RandomStringUtils.random(16);
|
||||||
|
CommandLog commandLog = new CommandLog(LocalDateTime.now(), random);
|
||||||
|
Map map = hashMapper.toHash(commandLog);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
docker run -d \
|
docker run -d \
|
||||||
-e ServerName: "${ServerName}" \
|
-e ServerName: "${ServerName}" \
|
||||||
-e serverIpPbV4: "$serverIpPbV4" \
|
-e serverIpPbV4: "$serverIspPbV4" \
|
||||||
-e serverIpInV4: "$serverIpInV4" \
|
-e serverIpInV4: "$serverIpInV4" \
|
||||||
-e serverIpPbV6: "$serverIpPbV6" \
|
-e serverIpPbV6: "$serverIpPbV6" \
|
||||||
-e serverIpInV6: "$serverIpInV6" \
|
-e serverIpInV6: "$serverIpInV6" \
|
||||||
@@ -20,4 +19,9 @@ docker run -d \
|
|||||||
-e tcpControl: "$tcpControl" \
|
-e tcpControl: "$tcpControl" \
|
||||||
-e virtualization: "$virtualization" \
|
-e virtualization: "$virtualization" \
|
||||||
-e ioSpeed: "$ioSpeed" \
|
-e ioSpeed: "$ioSpeed" \
|
||||||
|
--privileged \
|
||||||
|
--net=host \
|
||||||
|
--pid=host \
|
||||||
|
--ipc=host \
|
||||||
|
--volume /:/host \
|
||||||
icederce/wdd-octopus-agent:latest
|
icederce/wdd-octopus-agent:latest
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.wdd.agent.initialization.bootup;
|
package io.wdd.agent.initialization.bootup;
|
||||||
|
|
||||||
|
|
||||||
import io.wdd.agent.initialization.beans.AgentServerInfo;
|
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||||
import io.wdd.common.handler.MyRuntimeException;
|
import io.wdd.common.handler.MyRuntimeException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.wdd.agent.initialization.bootup;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import io.wdd.agent.initialization.beans.AgentServerInfo;
|
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||||
import io.wdd.agent.message.ToServerMessage;
|
import io.wdd.agent.message.ToServerMessage;
|
||||||
import io.wdd.agent.message.handler.OctopusMessageHandler;
|
import io.wdd.agent.message.handler.OctopusMessageHandler;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.initialization.rabbitmq;
|
package io.wdd.agent.initialization.message;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -30,7 +30,7 @@ import java.util.List;
|
|||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GenerateOctopusConnection {
|
public class GenOctopusRabbitMQConnection {
|
||||||
|
|
||||||
private final List<MessageListenerContainer> messageListenerContainerList = new ArrayList<>();
|
private final List<MessageListenerContainer> messageListenerContainerList = new ArrayList<>();
|
||||||
private final SimpleRabbitListenerContainerFactory containerFactory;
|
private final SimpleRabbitListenerContainerFactory containerFactory;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package io.wdd.agent.initialization.rabbitmq;
|
package io.wdd.agent.initialization.message;
|
||||||
|
|
||||||
import org.springframework.amqp.core.Binding;
|
import org.springframework.amqp.core.Binding;
|
||||||
import org.springframework.amqp.core.BindingBuilder;
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.wdd.agent.initialization.webtest;
|
package io.wdd.agent.initialization.webtest;
|
||||||
|
|
||||||
|
|
||||||
import io.wdd.agent.initialization.beans.AgentServerInfo;
|
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||||
import io.wdd.agent.initialization.bootup.CollectSystemInfo;
|
import io.wdd.agent.initialization.bootup.CollectSystemInfo;
|
||||||
import io.wdd.agent.initialization.bootup.OctopusAgentInitService;
|
import io.wdd.agent.initialization.bootup.OctopusAgentInitService;
|
||||||
import io.wdd.common.beans.response.R;
|
import io.wdd.common.beans.response.R;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package io.wdd.agent.message;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.wdd.agent.initialization.beans.AgentServerInfo;
|
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||||
import io.wdd.agent.initialization.rabbitmq.InitRabbitMQConnector;
|
import io.wdd.agent.initialization.message.InitRabbitMQConnector;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import io.wdd.common.handler.MyRuntimeException;
|
import io.wdd.common.handler.MyRuntimeException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package io.wdd.agent.message.handler;
|
package io.wdd.agent.message.handler;
|
||||||
|
|
||||||
|
|
||||||
import io.wdd.agent.config.rabbitmq.handler.*;
|
import io.wdd.agent.config.message.handler.*;
|
||||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,20 @@ spring:
|
|||||||
username: boge
|
username: boge
|
||||||
password: boge14@Level5
|
password: boge14@Level5
|
||||||
virtual-host: /wddserver
|
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:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 36379
|
||||||
|
database: 0
|
||||||
|
password: boge14@Level5
|
||||||
|
|
||||||
octopus:
|
octopus:
|
||||||
message:
|
message:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.wdd.agent;
|
package io.wdd.agent;
|
||||||
|
|
||||||
|
import io.wdd.agent.excuetor.redis.StreamSenderTest;
|
||||||
import io.wdd.agent.initialization.bootup.OctopusAgentInitService;
|
import io.wdd.agent.initialization.bootup.OctopusAgentInitService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@@ -10,10 +11,12 @@ import javax.annotation.Resource;
|
|||||||
public class InitRabbitMQTest {
|
public class InitRabbitMQTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
OctopusAgentInitService octopusAgentInitService;
|
StreamSenderTest streamSenderTest;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInitSendInfo(){
|
void testInitSendInfo(){
|
||||||
|
|
||||||
|
|
||||||
|
streamSenderTest.test();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -73,6 +73,12 @@
|
|||||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- redis dependency -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
|||||||
@@ -66,10 +66,6 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>-->
|
</dependency>-->
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user