[ Service ] [ Executor ] 重构Executor部分
This commit is contained in:
@@ -3,6 +3,7 @@ package io.wdd.rpc.execute;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import io.wdd.rpc.message.OctopusMessage;
|
||||
import io.wdd.rpc.message.OctopusMessageType;
|
||||
import io.wdd.rpc.message.handler.OMessageReplayContent;
|
||||
import io.wdd.rpc.message.sender.OMessageToAgentSender;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -11,9 +12,10 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.wdd.rpc.message.handler.sync.OMessageHandler.StopWaitingResult;
|
||||
import static io.wdd.rpc.message.handler.sync.OMessageHandler.WaitFromAgent;
|
||||
import static io.wdd.rpc.message.handler.OMessageHandler.*;
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_AGENT_TOPIC_NAME_SET;
|
||||
|
||||
@Service
|
||||
@@ -53,41 +55,53 @@ public class ExecutionServiceImpl implements ExecutionService {
|
||||
// send the message
|
||||
oMessageToAgentSender.send(octopusMessage);
|
||||
|
||||
System.out.println("originOctopusMessage = " + octopusMessage.hashCode());
|
||||
log.debug(
|
||||
"发送的 matchKey为 {}, 内容为 {}",
|
||||
GenerateOMessageMatchKey(
|
||||
octopusMessage.getOctopusMessageType(),
|
||||
octopusMessage.getInit_time()
|
||||
),
|
||||
octopusMessage
|
||||
);
|
||||
|
||||
// 需要返回结果
|
||||
if (!durationTask) {
|
||||
// 等待结果
|
||||
WaitFromAgent(octopusMessage);
|
||||
|
||||
synchronized (octopusMessage) {
|
||||
|
||||
try {
|
||||
octopusMessage.wait(10000);
|
||||
|
||||
|
||||
log.debug("等待结束!");
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
// 转换结果
|
||||
commandResultLog = (ArrayList<String>) octopusMessage.getResult();
|
||||
|
||||
// debug
|
||||
log.debug(
|
||||
"执行命令 {} 的结果为 {} 内容为 {}",
|
||||
executionMessage.getSingleLineCommand() == null ? executionMessage.getMultiLineCommand() : executionMessage.getSingleLineCommand(),
|
||||
octopusMessage.getResultCode(),
|
||||
octopusMessage.getResult()
|
||||
OMessageReplayContent replayContent = WaitFromAgent(
|
||||
octopusMessage,
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
CountDownLatch replayLatch = replayContent.getCountDownLatch();
|
||||
boolean waitOK = false;
|
||||
|
||||
// 释放等待队列
|
||||
StopWaitingResult(octopusMessage);
|
||||
try {
|
||||
waitOK = replayLatch.await(
|
||||
10,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
||||
// 释放等待队列
|
||||
StopWaitingResult(octopusMessage);
|
||||
|
||||
// 转换结果
|
||||
commandResultLog = (ArrayList<String>) octopusMessage.getResult();
|
||||
|
||||
// debug
|
||||
log.debug(
|
||||
"执行命令 {} {} 在规定时间内结束, 结果为 {} 返回内容为 {}",
|
||||
executionMessage.getSingleLineCommand() == null ? executionMessage.getMultiLineCommand() : executionMessage.getSingleLineCommand(),
|
||||
waitOK ? "已经" : "未",
|
||||
octopusMessage.getResultCode(),
|
||||
octopusMessage.getResult()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return commandResultLog;
|
||||
}
|
||||
@@ -98,7 +112,7 @@ public class ExecutionServiceImpl implements ExecutionService {
|
||||
return OctopusMessage
|
||||
.builder()
|
||||
.octopusMessageType(OctopusMessageType.EXECUTOR)
|
||||
.init_time(TimeUtils.currentTime())
|
||||
.init_time(TimeUtils.currentFormatTime())
|
||||
.uuid(agentTopicName)
|
||||
.content(
|
||||
executionMessage
|
||||
|
||||
Reference in New Issue
Block a user