[ server ] [ executor ] start to accomplish the function -1
This commit is contained in:
@@ -9,7 +9,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -32,6 +34,10 @@ public class CommandExecutor {
|
||||
*/
|
||||
public void execute(ExecutionMessage executionMessage) {
|
||||
|
||||
|
||||
this.execute(executionMessage.getResultKey(), executionMessage.getCommandList());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TestCommandExecutorController {
|
||||
ExecutionMessage executionMessage = ExecutionMessage.builder()
|
||||
.resultKey(streamKey)
|
||||
.type(messageType)
|
||||
.contend(messageType)
|
||||
.command(messageType)
|
||||
.build();
|
||||
|
||||
System.out.println("executionMessage = " + executionMessage);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.wdd.agent;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SimpleTest {
|
||||
|
||||
@@ -5,6 +5,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@@ -13,7 +15,7 @@ public class ExecutionMessage {
|
||||
|
||||
private String type;
|
||||
|
||||
private String contend;
|
||||
private List<String> commandList;
|
||||
|
||||
private String resultKey;
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.wdd.rpc.execute.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface CoreExecutionService {
|
||||
|
||||
|
||||
void SendCommandToAgent(String topicName, String command);
|
||||
|
||||
void SendCommandToAgent(String topicName, List<String> commandList);
|
||||
|
||||
|
||||
void SendCommandToAgent(String topicName, String type, List<String> command);
|
||||
|
||||
void SendCommandToAgent(List<String> topicNameList, String type, String command);
|
||||
|
||||
void SendCommandToAgent(List<String> topicNameList, String type, List<String> command);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.wdd.rpc.execute.service;
|
||||
|
||||
import io.wdd.common.beans.executor.ExecutionMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
|
||||
@Resource
|
||||
ToAgentMessageSender messageSender;
|
||||
|
||||
|
||||
@Override
|
||||
public void SendCommandToAgent(String topicName, String command) {
|
||||
this.SendCommandToAgent(topicName, List.of(command));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendCommandToAgent(String topicName, List<String> commandList) {
|
||||
this.SendCommandToAgent(topicName,"manual-command", commandList);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendCommandToAgent(String topicName, String type, List<String> commandList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendCommandToAgent(List<String> topicNameList, String type, String command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SendCommandToAgent(List<String> topicNameList, String type, List<String> command) {
|
||||
|
||||
}
|
||||
|
||||
private OctopusMessage generateOctopusMessage(String topicName, String type, List<String> commandList){
|
||||
|
||||
|
||||
return OctopusMessage.builder()
|
||||
.type(OctopusMessageType.EXECUTOR)
|
||||
.init_time(LocalDateTime.now())
|
||||
.content(generateExecutionMessage(
|
||||
type,
|
||||
commandList,
|
||||
generateCommandResultKey(topicName)
|
||||
))
|
||||
.uuid(topicName)
|
||||
.build();
|
||||
}
|
||||
|
||||
private ExecutionMessage generateExecutionMessage(String type, List<String> commandList, String resultKey) {
|
||||
|
||||
return ExecutionMessage.builder()
|
||||
.type(type)
|
||||
.commandList(commandList)
|
||||
.resultKey(resultKey)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
private String generateCommandResultKey(String topicName) {
|
||||
|
||||
String TimeString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
|
||||
return topicName + TimeString;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ 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.rpc.message.sender.ToAgentOrder;
|
||||
import io.wdd.rpc.message.sender.ToAgentMessageSender;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.utils.DaemonDatabaseOperator;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -60,7 +60,7 @@ public class AcceptAgentInitInfo {
|
||||
* The To agent order.
|
||||
*/
|
||||
@Resource
|
||||
ToAgentOrder toAgentOrder;
|
||||
ToAgentMessageSender toAgentMessageSender;
|
||||
|
||||
|
||||
/**
|
||||
@@ -174,7 +174,7 @@ public class AcceptAgentInitInfo {
|
||||
.uuid(serverInfoVO.getTopicName())
|
||||
.build();
|
||||
|
||||
toAgentOrder.send(octopusMessage);
|
||||
toAgentMessageSender.sendINIT(octopusMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import javax.annotation.Resource;
|
||||
* provide override method to convert Object and send to rabbitmq
|
||||
*/
|
||||
@Component
|
||||
@Slf4j(topic = "To Octopus Server Message ")
|
||||
public class ToAgentOrder {
|
||||
@Slf4j(topic = "Send Message To Octopus Agent ")
|
||||
public class ToAgentMessageSender {
|
||||
|
||||
@Resource
|
||||
RabbitTemplate rabbitTemplate;
|
||||
@@ -27,7 +27,6 @@ public class ToAgentOrder {
|
||||
@Resource
|
||||
InitRabbitMQConfig initRabbitMQConfig;
|
||||
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class ToAgentOrder {
|
||||
*
|
||||
* @param message octopus message
|
||||
*/
|
||||
public void send(OctopusMessage message){
|
||||
public void sendINIT(OctopusMessage message){
|
||||
|
||||
// only accept INIT type message
|
||||
if (!OctopusMessageType.INIT.equals(message.getType())) {
|
||||
@@ -51,6 +50,12 @@ public class ToAgentOrder {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void send(OctopusMessage octopusMessage) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private byte[] writeData(Object data){
|
||||
|
||||
Reference in New Issue
Block a user