[ server ] [ executor ] start to accomplish the function -1

This commit is contained in:
zeaslity
2022-12-14 15:15:20 +08:00
parent 2e97f9326d
commit d0bdca5ced
8 changed files with 128 additions and 10 deletions

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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){