[ agent ] [ status ] - accomplish agent status - 4
This commit is contained in:
@@ -39,14 +39,6 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Operating System and Hardware Information library for Java -->
|
||||
<dependency>
|
||||
<groupId>com.github.oshi</groupId>
|
||||
<artifactId>oshi-core-java11</artifactId>
|
||||
<version>6.4.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -4,8 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||
import io.wdd.agent.config.utils.TimeUtils;
|
||||
import io.wdd.agent.status.hardware.CpuInfo;
|
||||
import io.wdd.agent.status.hardware.MemoryInfo;
|
||||
import io.wdd.common.beans.status.CpuInfo;
|
||||
import io.wdd.common.beans.status.DiskInfo;
|
||||
import io.wdd.common.beans.status.MemoryInfo;
|
||||
import io.wdd.common.beans.status.NetworkInfo;
|
||||
import io.wdd.common.beans.status.AgentStatus;
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||
import org.springframework.data.redis.connection.stream.StringRecord;
|
||||
@@ -13,6 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.HWDiskStore;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
@@ -20,6 +25,7 @@ import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -61,13 +67,19 @@ public class AgentStatusCollector {
|
||||
agentStatus.setCpuInfo(new CpuInfo(hardware.getProcessor(), 1000));
|
||||
|
||||
/* Memory */
|
||||
agentStatus.setMemoryInfo(new MemoryInfo().build(hardware.getMemory()));
|
||||
agentStatus.setMemoryInfo(
|
||||
MemoryInfo.build(hardware.getMemory())
|
||||
);
|
||||
|
||||
/* Storage */
|
||||
agentStatus.setDiskStoreInfo(hardware.getDiskStores());
|
||||
agentStatus.setDiskStoreInfo(
|
||||
DiskInfo.mapFromDiskStore(hardware.getDiskStores())
|
||||
);
|
||||
|
||||
/* Network */
|
||||
agentStatus.setNetworkInfo(hardware.getNetworkIFs(false));
|
||||
agentStatus.setNetworkInfo(
|
||||
NetworkInfo.mapFromNetworkIFS(hardware.getNetworkIFs(false))
|
||||
);
|
||||
|
||||
/* operating system info */
|
||||
agentStatus.setOsInfo(os);
|
||||
@@ -78,10 +90,21 @@ public class AgentStatusCollector {
|
||||
return agentStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* when server first time boot up
|
||||
* the server info are not collected completely
|
||||
* this will be executed to update or complete the octopus agent server info
|
||||
*/
|
||||
@Scheduled(initialDelay = 180000)
|
||||
public void updateAgentServerInfo(){
|
||||
|
||||
// agent boot up 60s then start to report its status
|
||||
|
||||
|
||||
}
|
||||
|
||||
// agent boot up 120s then start to report its status
|
||||
// at the fix rate of 15s
|
||||
@Scheduled(initialDelay = 60000, fixedRate = 5000)
|
||||
@Scheduled(initialDelay = 60000, fixedRate = 15000)
|
||||
public void sendAgentStatusToRedis() {
|
||||
|
||||
try {
|
||||
@@ -101,5 +124,4 @@ public class AgentStatusCollector {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.wdd.agent.status.hardware;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.NetworkIF;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class NetworkInfo {
|
||||
|
||||
|
||||
public static List<NetworkInfo> mapFromNetworkIFS(List<NetworkIF> networkIFList){
|
||||
|
||||
return networkIFList.stream().map(
|
||||
networkIF -> NetworkInfo.builder()
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,18 @@
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Operating System and Hardware Information library for Java -->
|
||||
<dependency>
|
||||
<groupId>com.github.oshi</groupId>
|
||||
<artifactId>oshi-core-java11</artifactId>
|
||||
<version>6.4.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<!-- <build>-->
|
||||
<!-- <plugins>-->
|
||||
<!-- <plugin>-->
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package io.wdd.agent.status;
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
|
||||
import io.wdd.agent.status.hardware.CpuInfo;
|
||||
import io.wdd.agent.status.hardware.MemoryInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.HWDiskStore;
|
||||
import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import java.util.List;
|
||||
@@ -30,9 +26,9 @@ public class AgentStatus {
|
||||
|
||||
MemoryInfo memoryInfo;
|
||||
|
||||
List<HWDiskStore> diskStoreInfo;
|
||||
List<DiskInfo> diskStoreInfo;
|
||||
|
||||
List<NetworkIF> networkInfo;
|
||||
List<NetworkInfo> networkInfo;
|
||||
|
||||
OperatingSystem osInfo;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.status.hardware;
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.status.hardware;
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -0,0 +1,71 @@
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.HWDiskStore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class DiskInfo {
|
||||
|
||||
String name;
|
||||
|
||||
String model;
|
||||
|
||||
String serial;
|
||||
|
||||
String size;
|
||||
|
||||
|
||||
private List<PartitionInfo> partitionInfoList;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
private static class PartitionInfo{
|
||||
|
||||
String path;
|
||||
|
||||
String type;
|
||||
|
||||
String size;
|
||||
|
||||
String mountPoint;
|
||||
|
||||
}
|
||||
|
||||
public static List<DiskInfo> mapFromDiskStore(List<HWDiskStore> hwDiskStoreList){
|
||||
|
||||
return hwDiskStoreList.stream().map(
|
||||
hwDiskStore -> DiskInfo.builder()
|
||||
.name(hwDiskStore.getName())
|
||||
.model(hwDiskStore.getModel())
|
||||
.serial(hwDiskStore.getSerial())
|
||||
.size(FormatUtils.formatData(hwDiskStore.getSize()))
|
||||
.partitionInfoList(
|
||||
// partition should also be got from stream
|
||||
hwDiskStore.getPartitions().stream().map(partition -> DiskInfo.PartitionInfo.builder()
|
||||
.path(partition.getIdentification())
|
||||
.size(FormatUtils.formatData(partition.getSize()))
|
||||
.type(partition.getType())
|
||||
.mountPoint(partition.getMountPoint())
|
||||
.build()
|
||||
).collect(Collectors.toList())
|
||||
)
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.wdd.agent.status.hardware;
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
import io.wdd.agent.status.hardware.config.FormatUtils;
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -30,7 +30,7 @@ public class MemoryInfo {
|
||||
|
||||
String swapUsage;
|
||||
|
||||
public MemoryInfo build(GlobalMemory memory) {
|
||||
public static MemoryInfo build(GlobalMemory memory) {
|
||||
|
||||
VirtualMemory virtualMemory = memory.getVirtualMemory();
|
||||
return MemoryInfo.builder()
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.NetworkIF;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class NetworkInfo {
|
||||
|
||||
private String name;
|
||||
private String displayName;
|
||||
|
||||
private String macAddr;
|
||||
|
||||
private String mtu;
|
||||
|
||||
private String[] ipv4Addr;
|
||||
private String[] ipv6Addr;
|
||||
|
||||
private String trafficRecv;
|
||||
|
||||
private String trafficSend;
|
||||
|
||||
public static List<NetworkInfo> mapFromNetworkIFS(List<NetworkIF> networkIFList) {
|
||||
|
||||
return networkIFList.stream().map(networkIF -> NetworkInfo.builder().name(networkIF.getName()).displayName(networkIF.getDisplayName()).mtu(String.valueOf(networkIF.getMTU())).macAddr(networkIF.getMacaddr()).ipv4Addr(generateIPDICRFromNetworkIFList(networkIF, 4)).ipv6Addr(generateIPDICRFromNetworkIFList(networkIF, 6)).trafficSend(FormatUtils.formatData(networkIF.getBytesSent())).trafficRecv(FormatUtils.formatData(networkIF.getBytesRecv())).build()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static String[] generateIPDICRFromNetworkIFList(NetworkIF networkIF, int Ipv4OrIpv6) {
|
||||
|
||||
String[] iPAddr;
|
||||
Short[] subnetMasks;
|
||||
|
||||
if (Ipv4OrIpv6 == 4) {
|
||||
iPAddr = networkIF.getIPv4addr();
|
||||
subnetMasks = networkIF.getSubnetMasks();
|
||||
} else {
|
||||
iPAddr = networkIF.getIPv6addr();
|
||||
subnetMasks = networkIF.getPrefixLengths();
|
||||
}
|
||||
|
||||
String[] result = new String[iPAddr.length];
|
||||
for (int index = 0; index < iPAddr.length; index++) {
|
||||
result[index] = iPAddr[index] + "/" + subnetMasks[index];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.status.hardware.config;
|
||||
package io.wdd.common.utils;
|
||||
|
||||
import org.springframework.util.unit.DataSize;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.wdd.agent.status.hardware.config;
|
||||
package io.wdd.common.utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
22
pom.xml
22
pom.xml
@@ -35,10 +35,10 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
|
||||
<!-- spring cloud -->
|
||||
<dependency>
|
||||
@@ -67,10 +67,10 @@
|
||||
<version>${alibaba-cloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -126,15 +126,15 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
</dependencies>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<!--<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.shell</groupId>
|
||||
@@ -157,7 +157,7 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</dependencyManagement>-->
|
||||
|
||||
<!--<build>
|
||||
<plugins>
|
||||
|
||||
@@ -8,10 +8,9 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.REDIS_STREAM_LISTENER_CONTAINER;
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER;
|
||||
|
||||
|
||||
@Component
|
||||
@@ -25,7 +24,7 @@ public class CreateStreamReader implements ApplicationContextAware {
|
||||
private RedisStreamReaderConfig redisStreamReaderConfig;
|
||||
|
||||
|
||||
private HashMap<String, StreamMessageListenerContainer> REDIS_STREAM_LISTENER_CONTAINER_CACHE = new HashMap<>(16);
|
||||
private final HashMap<String, StreamMessageListenerContainer> REDIS_STREAM_LISTENER_CONTAINER_CACHE = new HashMap<>(16);
|
||||
|
||||
|
||||
@Override
|
||||
@@ -33,7 +32,7 @@ public class CreateStreamReader implements ApplicationContextAware {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public void registerStreamReader(String streamKey) {
|
||||
public void registerStreamReader(String redisStreamListenerContainerBeanName, String streamKey) {
|
||||
|
||||
// prepare the environment
|
||||
prepareEnv();
|
||||
@@ -51,11 +50,11 @@ public class CreateStreamReader implements ApplicationContextAware {
|
||||
modifyStreamReader(streamKey);
|
||||
|
||||
// re-create the REDIS_STREAM_LISTENER_CONTAINER
|
||||
createStreamReader(streamKey);
|
||||
createStreamReader(redisStreamListenerContainerBeanName, streamKey);
|
||||
|
||||
}
|
||||
|
||||
private void prepareEnv(){
|
||||
private void prepareEnv() {
|
||||
|
||||
getBeanFactory();
|
||||
|
||||
@@ -68,16 +67,16 @@ public class CreateStreamReader implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
|
||||
private void getBeanFactory(){
|
||||
private void getBeanFactory() {
|
||||
this.beanFactory = applicationContext.getAutowireCapableBeanFactory();
|
||||
}
|
||||
|
||||
private void createStreamReader(String streamKey) {
|
||||
private void createStreamReader(String redisStreamListenerContainerBeanName, String streamKey) {
|
||||
|
||||
log.debug("start to create the redis stream listener container");
|
||||
// create the lazy bean
|
||||
|
||||
StreamMessageListenerContainer streamMessageListenerContainer = applicationContext.getBean(REDIS_STREAM_LISTENER_CONTAINER, StreamMessageListenerContainer.class);
|
||||
StreamMessageListenerContainer streamMessageListenerContainer = applicationContext.getBean(redisStreamListenerContainerBeanName, StreamMessageListenerContainer.class);
|
||||
|
||||
REDIS_STREAM_LISTENER_CONTAINER_CACHE.put(streamKey, streamMessageListenerContainer);
|
||||
|
||||
@@ -102,7 +101,6 @@ public class CreateStreamReader implements ApplicationContextAware {
|
||||
|
||||
private void destroyStreamReader(String streamKey) {
|
||||
|
||||
log.debug("start to destroy {}", REDIS_STREAM_LISTENER_CONTAINER);
|
||||
|
||||
String oldStreamKey = redisStreamReaderConfig.getStreamKey();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.wdd.rpc.execute.result;
|
||||
|
||||
|
||||
import io.wdd.rpc.status.AgentStatusStreamReader;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -22,7 +23,9 @@ public class RedisStreamReaderConfig {
|
||||
@Resource
|
||||
private RedisConnectionFactory redisConnectionFactory;
|
||||
|
||||
public static final String REDIS_STREAM_LISTENER_CONTAINER = "redisStreamListenerContainer";
|
||||
public static final String COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER = "commandResultRedisStreamListenerContainer";
|
||||
|
||||
public static final String AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER = "agentStatusRedisStreamListenerContainer";
|
||||
|
||||
private String streamKey = "cccc";
|
||||
|
||||
@@ -34,10 +37,10 @@ public class RedisStreamReaderConfig {
|
||||
return streamKey;
|
||||
}
|
||||
|
||||
@Bean(value = REDIS_STREAM_LISTENER_CONTAINER)
|
||||
@Bean(value = COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER)
|
||||
@Scope("prototype")
|
||||
@Lazy
|
||||
public StreamMessageListenerContainer<String, MapRecord<String, String, String>> redisStreamListenerContainer(){
|
||||
public StreamMessageListenerContainer<String, MapRecord<String, String, String>> commandResultRedisStreamListenerContainer(){
|
||||
|
||||
StreamMessageListenerContainer.StreamMessageListenerContainerOptions<String, MapRecord<String, String, String>> options = StreamMessageListenerContainer.StreamMessageListenerContainerOptions
|
||||
.builder()
|
||||
@@ -60,6 +63,31 @@ public class RedisStreamReaderConfig {
|
||||
return listenerContainer;
|
||||
}
|
||||
|
||||
@Bean(value = AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER)
|
||||
@Scope("prototype")
|
||||
@Lazy
|
||||
public StreamMessageListenerContainer<String, MapRecord<String, String, String>> agentStatusRedisStreamListenerContainer(){
|
||||
|
||||
StreamMessageListenerContainer.StreamMessageListenerContainerOptions<String, MapRecord<String, String, String>> options = StreamMessageListenerContainer.StreamMessageListenerContainerOptions
|
||||
.builder()
|
||||
.pollTimeout(Duration.ofSeconds(2))
|
||||
.build();
|
||||
|
||||
StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer = StreamMessageListenerContainer.create(redisConnectionFactory, options);
|
||||
|
||||
listenerContainer.receive(
|
||||
|
||||
StreamOffset.create(streamKey, ReadOffset.lastConsumed()),
|
||||
|
||||
new AgentStatusStreamReader(
|
||||
"OctopusServer",
|
||||
"OctopusServer",
|
||||
"OctopusServer")
|
||||
|
||||
);
|
||||
|
||||
return listenerContainer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
@@ -68,7 +70,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
log.debug("set consumer group for the stream key with => [ {} ]", resultKey);
|
||||
|
||||
// change the redis stream listener container
|
||||
createStreamReader.registerStreamReader(resultKey);
|
||||
createStreamReader.registerStreamReader(COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER, resultKey);
|
||||
|
||||
// send the message
|
||||
messageSender.send(octopusMessage);
|
||||
|
||||
@@ -13,6 +13,9 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER;
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("octopus/server/executor")
|
||||
public class ExecutionController {
|
||||
@@ -47,7 +50,17 @@ public class ExecutionController {
|
||||
@RequestParam(value = "streamKey") String streamKey
|
||||
) {
|
||||
|
||||
createStreamReader.registerStreamReader(streamKey);
|
||||
createStreamReader.registerStreamReader(COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER ,streamKey);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/agentStatusStream")
|
||||
public void getAgentStatus(
|
||||
@RequestParam(value = "streamKey") String streamKey
|
||||
) {
|
||||
|
||||
createStreamReader.registerStreamReader(AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER ,streamKey);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.status.AgentStatus;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.stream.StreamListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Slf4j
|
||||
public class AgentStatusStreamReader implements StreamListener<String, MapRecord<String,String, String >> {
|
||||
|
||||
// https://medium.com/nerd-for-tech/event-driven-architecture-with-redis-streams-using-spring-boot-a81a1c9a4cde
|
||||
|
||||
//https://segmentfault.com/a/1190000040946712
|
||||
|
||||
//https://docs.spring.io/spring-data/redis/docs/2.5.5/reference/html/#redis.streams.receive.containers
|
||||
|
||||
/**
|
||||
* 消费者类型:独立消费、消费组消费
|
||||
*/
|
||||
private String consumerType;
|
||||
/**
|
||||
* 消费组
|
||||
*/
|
||||
private String group;
|
||||
/**
|
||||
* 消费组中的某个消费者
|
||||
*/
|
||||
private String consumerName;
|
||||
|
||||
|
||||
public AgentStatusStreamReader(String consumerType, String group, String consumerName) {
|
||||
this.consumerType = consumerType;
|
||||
this.group = group;
|
||||
this.consumerName = consumerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(MapRecord<String, String, String> message) {
|
||||
|
||||
String streamKey = message.getStream();
|
||||
RecordId messageId = message.getId();
|
||||
String key = (String) message.getValue().keySet().toArray()[0];
|
||||
String value = message.getValue().get(key);
|
||||
|
||||
|
||||
log.info("Octopus Agent [ {} ] status of [ {} ] Time is [ {} ] stream recordId is [{}]", streamKey, key, key, messageId);
|
||||
|
||||
// print to console
|
||||
printPrettyAgentStatus(value);
|
||||
|
||||
}
|
||||
|
||||
private void printPrettyAgentStatus(String valueString){
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
|
||||
try {
|
||||
|
||||
String tmp = objectMapper.readValue(valueString, new TypeReference<String>() {
|
||||
});
|
||||
|
||||
AgentStatus agentStatus = objectMapper.readValue(tmp, new TypeReference<AgentStatus>() {
|
||||
});
|
||||
|
||||
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(agentStatus));
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import io.wdd.server.coreService.CoreServerService;
|
||||
import io.wdd.server.service.*;
|
||||
import io.wdd.server.utils.EntityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -85,8 +87,22 @@ public class CoreServerServiceImpl implements CoreServerService {
|
||||
@Override
|
||||
public boolean serverCreateOrUpdate(ServerInfoVO serverInfoVO) {
|
||||
|
||||
ServerInfoPO serverInfoPO = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
|
||||
return serverInfoService.saveOrUpdate(serverInfoPO);
|
||||
ServerInfoPO po = new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
|
||||
.eq(ServerInfoPO::getServerName, serverInfoVO.getServerName()).one();
|
||||
|
||||
if (ObjectUtils.isNotEmpty(po)) {
|
||||
try {
|
||||
org.apache.commons.beanutils.BeanUtils.copyProperties(po, serverInfoVO);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
po = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
|
||||
}
|
||||
|
||||
return serverInfoService.saveOrUpdate(po);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user