[ server ] [ scheduler ]- script scheduler - 3

This commit is contained in:
zeaslity
2023-01-17 16:27:35 +08:00
parent 8ef3b271b1
commit e080d3f858
11 changed files with 280 additions and 94 deletions

View File

@@ -7,10 +7,12 @@ import io.wdd.agent.executor.FunctionExecutor;
import io.wdd.common.beans.executor.ExecutionMessage;
import io.wdd.common.beans.rabbitmq.OctopusMessage;
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import static io.wdd.agent.config.utils.NacosConfigurationCollector.ALL_FUNCTION_MAP;
@@ -26,7 +28,6 @@ public class OMHandlerExecutor extends AbstractOctopusMessageHandler {
@Resource
ObjectMapper objectMapper;
@Override
public boolean handle(OctopusMessage octopusMessage) {
@@ -36,6 +37,8 @@ public class OMHandlerExecutor extends AbstractOctopusMessageHandler {
return next.handle(octopusMessage);
}
boolean isScheduledScript = false;
try {
// 需要首先解析成 ExecutionMessage
@@ -45,13 +48,16 @@ public class OMHandlerExecutor extends AbstractOctopusMessageHandler {
}
);
// add in 2023-1-17
if (CollectionUtils.isNotEmpty(executionMessage.getScriptCommandList())) {
// 传递的是 页面定时任务脚本
isScheduledScript = true;
}
String executionType = executionMessage.getType();
if (ALL_FUNCTION_MAP.containsKey(executionType)) {
// execute the exist function
functionExecutor.execute(executionMessage);
functionExecutor.execute(executionMessage, isScheduledScript);
} else {
// handle command
commandExecutor.execute(executionMessage);

View File

@@ -37,7 +37,7 @@ public class CommandExecutor {
/**
* handle command from octopus server
*
* @param executionMessage get from EXECUTOR_HANDLERju
* @param executionMessage get from EXECUTOR_HANDLER
*/
public void execute(ExecutionMessage executionMessage) {
this.execute(

View File

@@ -27,34 +27,39 @@ public class FunctionExecutor {
@Resource
NacosConfigurationCollector nacosConfigurationCollector;
public void execute(ExecutionMessage executionMessage) {
String resultKey = executionMessage.getResultKey();
public void executeScriptScheduler(ExecutionMessage executionMessage) {
List<List<String>> commandList = ALL_FUNCTION_MAP.get(executionMessage.getType());
this.execute(resultKey, commandList);
/*Method execute = null;
try {
execute = Class.forName(functionShellScriptFileName).getMethod("execute", String.class);
ReflectionUtils.invokeMethod(execute, functionShellScriptFileName, resultKey);
} catch (NoSuchMethodException | ClassNotFoundException e) {
throw new MyRuntimeException(" Function Executor Reflection Error ! {} + {}", e.getCause(), e.getMessage());
}*/
executionMessage.getScriptCommandList();
}
private void execute(String streamKey, List<List<String>> commandList) {
public void execute(ExecutionMessage executionMessage, boolean isScheduledScript) {
// List<List<String>> commandList = functionReader.ReadFileToCommandList(functionFileName);
// 拿到 resultKey
String resultKey = executionMessage.getResultKey();
log.info("[ Function Executor ] all commands are ==> {}", commandList);
List<List<String>> completeCommandList;
if (isScheduledScript) {
// 检测到是 页面定时任务脚本
completeCommandList = executionMessage.getScriptCommandList();
} else {
// 从 ALL_FUNCTION_MAP本地容器中(Nacos配置中获取)获取到 功能脚本的内容
completeCommandList = ALL_FUNCTION_MAP.get(executionMessage.getType());
}
Iterator<List<String>> iterator = commandList.iterator();
this.execute(resultKey, completeCommandList);
}
private void execute(String streamKey, List<List<String>> completeCommandList) {
log.info("[ Function Executor ] all commands are ==> {}", completeCommandList);
Iterator<List<String>> iterator = completeCommandList.iterator();
while (iterator.hasNext()) {
int execute = commandExecutor.execute(streamKey, iterator.next());

View File

@@ -50,7 +50,7 @@ public class TestCommandExecutorController {
System.out.println("executionMessage = " + executionMessage);
functionExecutor.execute(executionMessage);
functionExecutor.execute(executionMessage, false);
return R.ok(streamKey);
}