[ server ] [ executor ] - redis stream listener container all procedure
This commit is contained in:
@@ -81,7 +81,7 @@ public class CommandExecutor {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// cache log lines
|
// cache log lines
|
||||||
logToArrayListCache.cacheLog(streamKey, process.getInputStream());
|
logToArrayListCache.cacheLog(streamKey, process);
|
||||||
|
|
||||||
// start to send the result log
|
// start to send the result log
|
||||||
streamSender.startToWaitLog(streamKey);
|
streamSender.startToWaitLog(streamKey);
|
||||||
|
|||||||
@@ -27,6 +27,21 @@ public class LogToArrayListCache {
|
|||||||
new ArrayList<>(256)
|
new ArrayList<>(256)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public void cacheLog(String streamKey, Process process) {
|
||||||
|
|
||||||
|
ArrayList<String> commandCachedLog = this.getExecutionCmdCachedLogArrayList(streamKey);
|
||||||
|
|
||||||
|
String format = String.format("execution command are => [ %s ]", process.info().commandLine().get());
|
||||||
|
// add the command
|
||||||
|
commandCachedLog.add(format);
|
||||||
|
commandCachedLog.add("--------------- command result are as below --------------------");
|
||||||
|
commandCachedLog.add("");
|
||||||
|
|
||||||
|
// cache the real command logs
|
||||||
|
cacheLog(streamKey, process.getInputStream());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void cacheLog(String streamKey, InputStream commandLogStream) {
|
public void cacheLog(String streamKey, InputStream commandLogStream) {
|
||||||
|
|
||||||
ArrayList<String> commandCachedLog = this.getExecutionCmdCachedLogArrayList(streamKey);
|
ArrayList<String> commandCachedLog = this.getExecutionCmdCachedLogArrayList(streamKey);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.wdd.rpc.execute.result;
|
package io.wdd.rpc.execute.result;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
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 com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -12,6 +14,7 @@ import org.springframework.data.redis.stream.StreamListener;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -48,24 +51,34 @@ public class CommandResultReader implements StreamListener<String, MapRecord<Str
|
|||||||
public void onMessage(MapRecord<String, String, String> message) {
|
public void onMessage(MapRecord<String, String, String> message) {
|
||||||
|
|
||||||
String streamKey = message.getStream();
|
String streamKey = message.getStream();
|
||||||
|
|
||||||
RecordId messageId = message.getId();
|
RecordId messageId = message.getId();
|
||||||
|
|
||||||
String key = (String) message.getValue().keySet().toArray()[0];
|
String key = (String) message.getValue().keySet().toArray()[0];
|
||||||
|
String value = message.getValue().get(key);
|
||||||
|
|
||||||
String value = (String) message.getValue().values().toArray()[0];
|
|
||||||
|
|
||||||
|
log.info("Octopus Agent [ {} ] execution of [ {} ] Time is [ {} ] stream recordId is [{}]", streamKey, key, key, messageId);
|
||||||
|
|
||||||
|
// print to console
|
||||||
|
printPrettyDeserializedCommandResult(value);
|
||||||
|
|
||||||
|
// log to somewhere
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printPrettyDeserializedCommandResult(String valueString){
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
System.out.println("streamKey = " + streamKey);
|
String tmp = objectMapper.readValue(valueString, new TypeReference<String>() {
|
||||||
System.out.println("messageId = " + messageId);
|
});
|
||||||
System.out.println("key = " + key);
|
|
||||||
System.out.println("value = " + value);
|
|
||||||
|
|
||||||
ArrayList<String>commandResultList = objectMapper.readValue(value, ArrayList.class);
|
List<String> stringList = objectMapper.readValue(tmp, new TypeReference<List<String>>() {
|
||||||
commandResultList.stream().forEach(
|
});
|
||||||
|
|
||||||
|
stringList.stream().forEach(
|
||||||
System.out::println
|
System.out::println
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -73,9 +86,6 @@ public class CommandResultReader implements StreamListener<String, MapRecord<Str
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log.info("intend to be handled already !");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import io.wdd.common.beans.executor.ExecutionMessage;
|
import io.wdd.common.beans.executor.ExecutionMessage;
|
||||||
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;
|
||||||
|
import io.wdd.rpc.execute.result.CreateStreamReader;
|
||||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
@@ -29,6 +30,9 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
|||||||
@Resource
|
@Resource
|
||||||
RedisTemplate redisTemplate;
|
RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
CreateStreamReader createStreamReader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String SendCommandToAgent(String topicName, String command) {
|
public String SendCommandToAgent(String topicName, String command) {
|
||||||
return this.SendCommandToAgent(topicName, List.of(command));
|
return this.SendCommandToAgent(topicName, List.of(command));
|
||||||
@@ -58,11 +62,13 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String resultKey = executionMessage.getResultKey();
|
String resultKey = executionMessage.getResultKey();
|
||||||
|
|
||||||
// set up the stream read group
|
// set up the stream read group
|
||||||
String group = redisTemplate.opsForStream().createGroup(resultKey, resultKey);
|
String group = redisTemplate.opsForStream().createGroup(resultKey, resultKey);
|
||||||
System.out.println("group = " + group);
|
|
||||||
log.debug("set consumer group for the stream key with => [ {} ]", resultKey);
|
log.debug("set consumer group for the stream key with => [ {} ]", resultKey);
|
||||||
|
|
||||||
|
// change the redis stream listener container
|
||||||
|
createStreamReader.registerStreamReader(resultKey);
|
||||||
|
|
||||||
// send the message
|
// send the message
|
||||||
messageSender.send(octopusMessage);
|
messageSender.send(octopusMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user