From 25082b9ea121bccf1aa98044acecdf6a13912e00 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Tue, 7 Oct 2025 00:28:49 +0800 Subject: [PATCH] =?UTF-8?q?:hammer:=20=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8C=96.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose-testing.yaml | 6 +- docker-compose.yaml | 8 +- .../constant/AutoConfigureOrderConst.java | 4 +- orion-visor-dependencies/pom.xml | 5 + .../listener/PushMessageEventListener.java | 5 +- .../pom.xml | 27 ++++ .../OrionExecutorAutoConfiguration.java | 70 +++++++++++ .../configuration/config/ExecutorConfig.java | 102 +++++++++++++++ .../config/ExecutorsConfig.java} | 38 ++---- .../core/context/ExecutorContext.java | 119 ++++++++++++++++++ .../executor/core/utils/ExecutorUtils.java | 84 +++++++++++++ ...itional-spring-configuration-metadata.json | 77 ++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../OrionAsyncAutoConfiguration.java | 96 -------------- .../OrionSchedulerAutoConfiguration.java | 9 +- ...itional-spring-configuration-metadata.json | 35 ------ ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../OrionWebAutoConfiguration.java | 2 + orion-visor-framework/pom.xml | 3 +- orion-visor-launch/pom.xml | 6 +- .../src/main/resources/application-dev.yaml | 81 ++++++++++++ .../src/main/resources/application-prod.yaml | 80 +++++++++++- .../src/main/resources/application.yaml | 12 +- .../orion-visor-module-asset-service/pom.xml | 6 +- .../module/asset/define/AssetThreadPools.java | 16 +-- .../orion-visor-module-exec-service/pom.xml | 6 +- .../module/exec/define/ExecThreadPools.java | 60 ++------- .../pom.xml | 6 +- .../pom.xml | 4 + .../terminal/define/TerminalThreadPools.java | 36 ++---- .../compoments/metrics-chart-tab.vue | 2 +- 31 files changed, 720 insertions(+), 287 deletions(-) create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/pom.xml create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/OrionExecutorAutoConfiguration.java create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorConfig.java rename orion-visor-framework/{orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/config/AsyncExecutorConfig.java => orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorsConfig.java} (59%) create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/context/ExecutorContext.java create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/utils/ExecutorUtils.java create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionAsyncAutoConfiguration.java delete mode 100644 orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/additional-spring-configuration-metadata.json diff --git a/docker-compose-testing.yaml b/docker-compose-testing.yaml index 1d189c97..a6a5c363 100644 --- a/docker-compose-testing.yaml +++ b/docker-compose-testing.yaml @@ -19,6 +19,10 @@ services: DEMO_MODE: false volumes: - /data/orion-visor-space/docker-volumes/service/root-orion:/root/orion + ulimits: + nofile: + soft: 65536 + hard: 65536 healthcheck: test: [ "CMD", "curl", "http://127.0.0.1:9200/orion-visor/api/server/bootstrap/health" ] interval: 15s @@ -87,4 +91,4 @@ services: networks: orion-visor-net: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/docker-compose.yaml b/docker-compose.yaml index 73371019..2bb604da 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,6 +1,6 @@ version: '3.3' -# latest = 2.5.2 +# latest = 2.5.1 # 支持以下源 # lijiahangmax/* @@ -27,10 +27,6 @@ services: privileged: true ports: - "9200:9200" - ulimits: - nofile: - soft: 65536 - hard: 65536 environment: SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-prod} MYSQL_HOST: ${MYSQL_HOST:-mysql} @@ -178,4 +174,4 @@ services: networks: orion-visor-net: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/orion-visor-common/src/main/java/org/dromara/visor/common/constant/AutoConfigureOrderConst.java b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/AutoConfigureOrderConst.java index c11c7a29..4fdfdc85 100644 --- a/orion-visor-common/src/main/java/org/dromara/visor/common/constant/AutoConfigureOrderConst.java +++ b/orion-visor-common/src/main/java/org/dromara/visor/common/constant/AutoConfigureOrderConst.java @@ -33,6 +33,8 @@ package org.dromara.visor.common.constant; */ public interface AutoConfigureOrderConst { + int FRAMEWORK_EXECUTOR = Integer.MIN_VALUE + 1000; + int FRAMEWORK_WEB = Integer.MIN_VALUE + 1100; int FRAMEWORK_SECURITY = Integer.MIN_VALUE + 1200; @@ -65,8 +67,6 @@ public interface AutoConfigureOrderConst { int FRAMEWORK_JOB_QUARTZ = Integer.MIN_VALUE + 2610; - int FRAMEWORK_JOB_ASYNC = Integer.MIN_VALUE + 2620; - int FRAMEWORK_BIZ_PUSH = Integer.MIN_VALUE + 2700; int FRAMEWORK_BIZ_OPERATOR_LOG = Integer.MIN_VALUE + 7000; diff --git a/orion-visor-dependencies/pom.xml b/orion-visor-dependencies/pom.xml index 22e38a91..32771f7d 100644 --- a/orion-visor-dependencies/pom.xml +++ b/orion-visor-dependencies/pom.xml @@ -106,6 +106,11 @@ orion-visor-spring-boot-starter-job ${revision} + + org.dromara.visor + orion-visor-spring-boot-starter-executor + ${revision} + org.dromara.visor orion-visor-spring-boot-starter-websocket diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-biz-push/src/main/java/org/dromara/visor/framework/biz/push/core/listener/PushMessageEventListener.java b/orion-visor-framework/orion-visor-spring-boot-starter-biz-push/src/main/java/org/dromara/visor/framework/biz/push/core/listener/PushMessageEventListener.java index 6df72da8..da16acde 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-biz-push/src/main/java/org/dromara/visor/framework/biz/push/core/listener/PushMessageEventListener.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-biz-push/src/main/java/org/dromara/visor/framework/biz/push/core/listener/PushMessageEventListener.java @@ -48,8 +48,7 @@ public class PushMessageEventListener implements ApplicationListener) pushServiceMap.get(message.getChannel()); } -} \ No newline at end of file +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/pom.xml b/orion-visor-framework/orion-visor-spring-boot-starter-executor/pom.xml new file mode 100644 index 00000000..c6761bf4 --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/pom.xml @@ -0,0 +1,27 @@ + + + + org.dromara.visor + orion-visor-framework + ${revision} + + + 4.0.0 + orion-visor-spring-boot-starter-executor + ${project.artifactId} + jar + + 项目线程池配置包 + https://github.com/dromara/orion-visor + + + + + org.dromara.visor + orion-visor-common + + + + diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/OrionExecutorAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/OrionExecutorAutoConfiguration.java new file mode 100644 index 00000000..2df895b9 --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/OrionExecutorAutoConfiguration.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023 - present Dromara, All rights reserved. + * + * https://visor.dromara.org + * https://visor.dromara.org.cn + * https://visor.orionsec.cn + * + * Members: + * Jiahang Li - ljh1553488six@139.com - author + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dromara.visor.framework.executor.configuration; + +import org.dromara.visor.common.constant.AutoConfigureOrderConst; +import org.dromara.visor.framework.executor.configuration.config.ExecutorsConfig; +import org.dromara.visor.framework.executor.core.context.ExecutorContext; +import org.dromara.visor.framework.executor.core.utils.ExecutorUtils; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.Map; + +/** + * 项目线程池配置 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/9/16 14:34 + */ +@EnableAsync +@AutoConfiguration +@EnableConfigurationProperties({ExecutorsConfig.class}) +@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_EXECUTOR) +public class OrionExecutorAutoConfiguration { + + /** + * 创建线程池上下文 + * + * @param executorsConfig executorsConfig + * @param beanFactory beanFactory + * @return 线程池上下文 + */ + @Bean + public ExecutorContext executorContext(ExecutorsConfig executorsConfig, + ConfigurableBeanFactory beanFactory) { + // 创建上下文 + ExecutorContext context = new ExecutorContext(executorsConfig, beanFactory); + Map executorMap = context.init(); + // 获取线程池列表 + ExecutorUtils.setExecutors(executorMap); + return context; + } + +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorConfig.java b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorConfig.java new file mode 100644 index 00000000..2d65c14c --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorConfig.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 - present Dromara, All rights reserved. + * + * https://visor.dromara.org + * https://visor.dromara.org.cn + * https://visor.orionsec.cn + * + * Members: + * Jiahang Li - ljh1553488six@139.com - author + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dromara.visor.framework.executor.configuration.config; + +import cn.orionsec.kit.lang.define.thread.RejectPolicy; +import cn.orionsec.kit.lang.utils.Systems; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +/** + * 线程池配置 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/9/16 10:51 + */ +@Data +@Builder +@AllArgsConstructor +public class ExecutorConfig { + + /** + * 是否启用 + */ + private boolean enabled; + + /** + * 是否使用 MDC + */ + private boolean mdc; + + /** + * 核心线程数 + */ + private int corePoolSize; + + /** + * 最大线程数 + */ + private int maxPoolSize; + + /** + * 队列容量 + */ + private int queueCapacity; + + /** + * 空闲线程存活时间 + */ + private int keepAliveSeconds; + + /** + * 是否允许核心线程超时 + */ + private boolean allowCoreTimeout; + + /** + * 是否使用同步队列 + */ + private boolean synchronousQueue; + + /** + * 线程名称前缀 + */ + private String threadNamePrefix; + + /** + * 拒绝策略 + */ + private RejectPolicy rejectPolicy; + + public ExecutorConfig() { + this.enabled = true; + this.corePoolSize = Systems.PROCESS_NUM; + this.maxPoolSize = Systems.PROCESS_NUM; + this.queueCapacity = 100; + this.keepAliveSeconds = 300; + this.rejectPolicy = RejectPolicy.CALLER_RUNS; + } + +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/config/AsyncExecutorConfig.java b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorsConfig.java similarity index 59% rename from orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/config/AsyncExecutorConfig.java rename to orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorsConfig.java index 4ea9f91c..db454c48 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/config/AsyncExecutorConfig.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/configuration/config/ExecutorsConfig.java @@ -20,47 +20,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.dromara.visor.framework.job.configuration.config; +package org.dromara.visor.framework.executor.configuration.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; +import java.util.Map; + /** - * 线程池配置类 + * 线程池配置 * * @author Jiahang Li * @version 1.0.0 - * @since 2023/7/10 15:49 + * @since 2025/9/16 16:21 */ @Data -@ConfigurationProperties(prefix = "orion.async.executor") -public class AsyncExecutorConfig { +@ConfigurationProperties(prefix = "app") +public class ExecutorsConfig { /** - * 核心线程数量 + * 线程池配置 */ - private int corePoolSize; - - /** - * 最大线程数量 - */ - private int maxPoolSize; - - /** - * 队列容量 - */ - private int queueCapacity; - - /** - * 活跃时间 - */ - private int keepAliveSeconds; - - public AsyncExecutorConfig() { - this.corePoolSize = 8; - this.maxPoolSize = 16; - this.queueCapacity = 200; - this.keepAliveSeconds = 300; - } + private Map executors; } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/context/ExecutorContext.java b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/context/ExecutorContext.java new file mode 100644 index 00000000..43ee3df3 --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/context/ExecutorContext.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023 - present Dromara, All rights reserved. + * + * https://visor.dromara.org + * https://visor.dromara.org.cn + * https://visor.orionsec.cn + * + * Members: + * Jiahang Li - ljh1553488six@139.com - author + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dromara.visor.framework.executor.core.context; + +import cn.orionsec.kit.lang.define.thread.RejectPolicy; +import cn.orionsec.kit.lang.utils.Strings; +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.dromara.visor.common.thread.ThreadPoolMdcTaskExecutor; +import org.dromara.visor.framework.executor.configuration.config.ExecutorConfig; +import org.dromara.visor.framework.executor.configuration.config.ExecutorsConfig; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.HashMap; +import java.util.Map; + +/** + * 执行器上下文 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/9/16 16:28 + */ +@Slf4j +public class ExecutorContext { + + private final ExecutorsConfig executorsConfig; + + private final ConfigurableBeanFactory beanFactory; + + public ExecutorContext(ExecutorsConfig executorsConfig, ConfigurableBeanFactory beanFactory) { + this.executorsConfig = executorsConfig; + this.beanFactory = beanFactory; + } + + /** + * 初始化 + * + * @return executorMap + */ + public Map init() { + log.info("--------- Executors init start --------- "); + Map executorMap = new HashMap<>(); + executorsConfig.getExecutors().forEach((beanName, config) -> { + String executorName = Strings.leftPad(beanName, 30); + // 是否启用 + if (!config.isEnabled()) { + log.info("Executor [{}] is disabled.", executorName); + return; + } + // 创建线程池 + ThreadPoolTaskExecutor executor = this.createTaskExecutor(config); + // 注册到容器中 + beanFactory.registerSingleton(beanName, executor); + executorMap.put(beanName, executor); + log.info("Executor [{}] init success. {}", executorName, JSON.toJSONString(config)); + }); + log.info("--------- Executors init end --------- "); + return executorMap; + } + + /** + * 创建线程池 + * + * @param config config + */ + private ThreadPoolTaskExecutor createTaskExecutor(ExecutorConfig config) { + // 创建线程池 + ThreadPoolTaskExecutor executor; + if (config.isMdc()) { + executor = new ThreadPoolMdcTaskExecutor(); + } else { + executor = new ThreadPoolTaskExecutor(); + } + // 同步队列 + if (config.isSynchronousQueue()) { + config.setCorePoolSize(0); + config.setMaxPoolSize(Integer.MAX_VALUE); + config.setQueueCapacity(0); + config.setRejectPolicy(RejectPolicy.ABORT); + } + // 设置参数 + executor.setCorePoolSize(config.getCorePoolSize()); + executor.setMaxPoolSize(config.getMaxPoolSize()); + executor.setQueueCapacity(config.getQueueCapacity()); + executor.setThreadNamePrefix(config.getThreadNamePrefix()); + executor.setKeepAliveSeconds(config.getKeepAliveSeconds()); + executor.setAllowCoreThreadTimeOut(config.isAllowCoreTimeout()); + executor.setRejectedExecutionHandler(config.getRejectPolicy().getHandler()); + // 设置等待所有任务执行结束再关闭线程池 + executor.setWaitForTasksToCompleteOnShutdown(true); + executor.setAwaitTerminationSeconds(60); + // 初始化 + executor.initialize(); + return executor; + } + +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/utils/ExecutorUtils.java b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/utils/ExecutorUtils.java new file mode 100644 index 00000000..5666b3cf --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/java/org/dromara/visor/framework/executor/core/utils/ExecutorUtils.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 - present Dromara, All rights reserved. + * + * https://visor.dromara.org + * https://visor.dromara.org.cn + * https://visor.orionsec.cn + * + * Members: + * Jiahang Li - ljh1553488six@139.com - author + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dromara.visor.framework.executor.core.utils; + +import cn.orionsec.kit.lang.able.Executable; +import cn.orionsec.kit.lang.utils.Exceptions; +import cn.orionsec.kit.lang.utils.collect.Maps; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.Map; + +/** + * 线程池工具类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/9/16 16:34 + */ +public class ExecutorUtils { + + private static Map executorMap; + + private ExecutorUtils() { + } + + /** + * 获取线程池 + * + * @param name name + * @return executor + */ + public static ThreadPoolTaskExecutor getExecutor(String name) { + return executorMap.get(name); + } + + /** + * 执行 + * + * @param name name + * @param runnable runnable + */ + public static void execute(String name, Runnable runnable) { + getExecutor(name).execute(runnable); + } + + /** + * 执行 + * + * @param name name + * @param executable executable + */ + public static void execute(String name, Executable executable) { + getExecutor(name).execute(executable::exec); + } + + public static void setExecutors(Map executorMap) { + if (ExecutorUtils.executorMap != null) { + // unmodified + throw Exceptions.state(); + } + ExecutorUtils.executorMap = Maps.unmodified(executorMap); + } + +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..25f0906c --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,77 @@ +{ + "groups": [ + { + "name": "orion.executors.*", + "type": "org.dromara.visor.framework.executor.configuration.config.ExecutorConfig", + "sourceType": "org.dromara.visor.framework.executor.configuration.config.ExecutorConfig", + "description": "线程池配置项." + } + ], + "properties": [ + { + "name": "orion.executors", + "type": "java.util.Map", + "description": "线程池配置.", + "defaultValue": "{}" + }, + { + "name": "orion.executors.*.enabled", + "type": "java.lang.Boolean", + "description": "是否启用.", + "defaultValue": false + }, + { + "name": "orion.executors.*.corePoolSize", + "type": "java.lang.Integer", + "description": "核心线程数.", + "defaultValue": "CPU_NUM" + }, + { + "name": "orion.executors.*.maxPoolSize", + "type": "java.lang.Integer", + "description": "最大线程数.", + "defaultValue": "CPU_NUM" + }, + { + "name": "orion.executors.*.queueCapacity", + "type": "java.lang.Integer", + "description": "任务队列容量.", + "defaultValue": 100 + }, + { + "name": "orion.executors.*.keepAliveSeconds", + "type": "java.lang.Integer", + "description": "空闲线程存活时间.", + "defaultValue": 60 + }, + { + "name": "orion.executors.*.allowCoreTimeout", + "type": "java.lang.Boolean", + "description": "是否允许核心线程超时回收.", + "defaultValue": false + }, + { + "name": "orion.executors.*.synchronousQueue", + "type": "java.lang.Boolean", + "description": "是否启用同步队列模式.", + "defaultValue": false + }, + { + "name": "orion.executors.*.mdc", + "type": "java.lang.Boolean", + "description": "是否启用 MDC 上下文传递.", + "defaultValue": false + }, + { + "name": "orion.executors.*.threadNamePrefix", + "type": "java.lang.String", + "description": "线程名称前缀." + }, + { + "name": "orion.executors.*.rejectPolicy", + "type": "cn.orionsec.kit.lang.define.thread.RejectPolicy", + "description": "拒绝策略.", + "defaultValue": "CALLER_RUNS" + } + ] +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..9ef44eb1 --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-executor/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.dromara.visor.framework.executor.configuration.OrionExecutorAutoConfiguration diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionAsyncAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionAsyncAutoConfiguration.java deleted file mode 100644 index 7544e5b8..00000000 --- a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionAsyncAutoConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2023 - present Dromara, All rights reserved. - * - * https://visor.dromara.org - * https://visor.dromara.org.cn - * https://visor.orionsec.cn - * - * Members: - * Jiahang Li - ljh1553488six@139.com - author - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.visor.framework.job.configuration; - -import org.dromara.visor.common.constant.AutoConfigureOrderConst; -import org.dromara.visor.common.constant.Const; -import org.dromara.visor.common.thread.ThreadPoolMdcTaskExecutor; -import org.dromara.visor.framework.job.configuration.config.AsyncExecutorConfig; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureOrder; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.core.task.TaskExecutor; -import org.springframework.scheduling.annotation.EnableAsync; - -import java.util.concurrent.ThreadPoolExecutor; - -/** - * async 异步任务 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/6/20 10:34 - */ -@EnableAsync -@AutoConfiguration -@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_JOB_ASYNC) -@EnableConfigurationProperties(AsyncExecutorConfig.class) -public class OrionAsyncAutoConfiguration { - - /** - * {@code @Async("asyncExecutor")} - * - * @return 支持 MDC 的异步线程池 - */ - @Bean(name = "asyncExecutor") - public TaskExecutor asyncExecutor(AsyncExecutorConfig config) { - ThreadPoolMdcTaskExecutor executor = new ThreadPoolMdcTaskExecutor(); - executor.setCorePoolSize(config.getCorePoolSize()); - executor.setMaxPoolSize(config.getMaxPoolSize()); - executor.setQueueCapacity(config.getQueueCapacity()); - executor.setKeepAliveSeconds(config.getKeepAliveSeconds()); - executor.setAllowCoreThreadTimeOut(true); - executor.setThreadNamePrefix("async-task-"); - // 设置等待所有任务执行结束再关闭线程池 - executor.setWaitForTasksToCompleteOnShutdown(true); - // 以确保应用最后能够被关闭 - executor.setAwaitTerminationSeconds(60); - // 调用者调用拒绝策略 - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); - executor.initialize(); - return executor; - } - - /** - * {@code @Async("metricsExecutor")} - * - * @return 指标线程池 - */ - @Bean(name = "metricsExecutor") - public TaskExecutor metricsExecutor() { - ThreadPoolMdcTaskExecutor executor = new ThreadPoolMdcTaskExecutor(); - executor.setCorePoolSize(4); - executor.setMaxPoolSize(8); - executor.setQueueCapacity(1000); - executor.setKeepAliveSeconds(Const.MS_S_60); - executor.setAllowCoreThreadTimeOut(true); - executor.setThreadNamePrefix("metrics-task-"); - executor.setWaitForTasksToCompleteOnShutdown(true); - executor.setAwaitTerminationSeconds(60); - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); - executor.initialize(); - return executor; - } - -} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionSchedulerAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionSchedulerAutoConfiguration.java index c6c78804..81b14a16 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionSchedulerAutoConfiguration.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/java/org/dromara/visor/framework/job/configuration/OrionSchedulerAutoConfiguration.java @@ -25,6 +25,8 @@ package org.dromara.visor.framework.job.configuration; import org.dromara.visor.common.constant.AutoConfigureOrderConst; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.task.TaskSchedulingProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; @@ -40,17 +42,18 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @EnableScheduling @AutoConfiguration @AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_JOB) +@EnableConfigurationProperties(TaskSchedulingProperties.class) public class OrionSchedulerAutoConfiguration { /** * @return 任务调度器 */ @Bean - public TaskScheduler taskScheduler() { + public TaskScheduler taskScheduler(TaskSchedulingProperties properties) { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); - scheduler.setPoolSize(4); scheduler.setRemoveOnCancelPolicy(true); - scheduler.setThreadNamePrefix("scheduling-task-"); + scheduler.setPoolSize(properties.getPool().getSize()); + scheduler.setThreadNamePrefix(properties.getThreadNamePrefix()); return scheduler; } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 80da6cb2..00000000 --- a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "groups": [ - { - "name": "orion.async.executor", - "type": "org.dromara.visor.framework.job.configuration.config.AsyncExecutorConfig", - "sourceType": "org.dromara.visor.framework.job.configuration.config.AsyncExecutorConfig" - } - ], - "properties": [ - { - "name": "orion.async.executor.core-pool-size", - "type": "java.lang.Integer", - "description": "核心线程数量.", - "defaultValue": "8" - }, - { - "name": "orion.async.executor.max-pool-size", - "type": "java.lang.Integer", - "description": "最大线程数量.", - "defaultValue": "16" - }, - { - "name": "orion.async.executor.queue-capacity", - "type": "java.lang.Integer", - "description": "队列容量.", - "defaultValue": "200" - }, - { - "name": "orion.async.executor.keep-alive-seconds", - "type": "java.lang.Integer", - "description": "活跃时间.", - "defaultValue": "300" - } - ] -} \ No newline at end of file diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 73005eb9..5b215b2a 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/orion-visor-framework/orion-visor-spring-boot-starter-job/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,3 +1,2 @@ org.dromara.visor.framework.job.configuration.OrionSchedulerAutoConfiguration org.dromara.visor.framework.job.configuration.OrionQuartzAutoConfiguration -org.dromara.visor.framework.job.configuration.OrionAsyncAutoConfiguration \ No newline at end of file diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/configuration/OrionWebAutoConfiguration.java b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/configuration/OrionWebAutoConfiguration.java index 18fb70d8..6e89fe0e 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/configuration/OrionWebAutoConfiguration.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-web/src/main/java/org/dromara/visor/framework/web/configuration/OrionWebAutoConfiguration.java @@ -42,6 +42,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.DependsOn; import org.springframework.http.MediaType; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; @@ -67,6 +68,7 @@ import java.util.List; * @version 1.0.0 * @since 2023/6/16 16:26 */ +@DependsOn({"executorContext"}) @AutoConfiguration @AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_WEB) @EnableConfigurationProperties(ExposeApiConfig.class) diff --git a/orion-visor-framework/pom.xml b/orion-visor-framework/pom.xml index 5b9f3849..eb543e33 100644 --- a/orion-visor-framework/pom.xml +++ b/orion-visor-framework/pom.xml @@ -24,6 +24,7 @@ orion-visor-spring-boot-starter-cipher orion-visor-spring-boot-starter-config orion-visor-spring-boot-starter-job + orion-visor-spring-boot-starter-executor orion-visor-spring-boot-starter-websocket orion-visor-spring-boot-starter-redis orion-visor-spring-boot-starter-desensitize @@ -37,4 +38,4 @@ orion-visor-spring-boot-starter-biz-operator-log - \ No newline at end of file + diff --git a/orion-visor-launch/pom.xml b/orion-visor-launch/pom.xml index 06d81696..85b012fb 100644 --- a/orion-visor-launch/pom.xml +++ b/orion-visor-launch/pom.xml @@ -102,6 +102,10 @@ org.dromara.visor orion-visor-spring-boot-starter-job + + org.dromara.visor + orion-visor-spring-boot-starter-executor + org.dromara.visor orion-visor-spring-boot-starter-websocket @@ -199,4 +203,4 @@ - \ No newline at end of file + diff --git a/orion-visor-launch/src/main/resources/application-dev.yaml b/orion-visor-launch/src/main/resources/application-dev.yaml index a448b939..bfad7464 100644 --- a/orion-visor-launch/src/main/resources/application-dev.yaml +++ b/orion-visor-launch/src/main/resources/application-dev.yaml @@ -49,3 +49,84 @@ mybatis-plus: configuration: # 日志打印 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +app: + executors: + # 默认异步线程池 + asyncExecutor: + mdc: true + core-pool-size: 2 + max-pool-size: 4 + queue-capacity: 30 + allow-core-timeout: false + thread-name-prefix: async-executor- + # 指标存储异步线程池 + metricsExecutor: + mdc: true + core-pool-size: 2 + max-pool-size: 2 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: metrics-task- + # 推送异步线程池 + pushExecutor: + mdc: true + core-pool-size: 1 + max-pool-size: 1 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: message-push- + # 探针安装线程池 + agentInstallExecutor: + core-pool-size: 2 + max-pool-size: 2 + queue-capacity: 200 + allow-core-timeout: true + thread-name-prefix: agent-install- + # 终端标准输出线程池 + terminalStdoutExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: terminal-stdout- + # 终端操作线程池 + terminalOperatorExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: terminal-operator- + # 终端异步保存线程池 + terminalAsyncSaverExecutor: + core-pool-size: 1 + max-pool-size: 1 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: terminal-watcher- + # 批量执行超时检查线程池 + execTimeoutCheckExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: timeout-check- + # 批量执行任务线程池 + execTaskExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-task- + # 批量执行主机命令线程池 + execHostCommandExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-host- + # 批量执行日志查看线程池 + execLogViewExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-log- + # 批量上传任务线程池 + uploadTaskExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: upload-task- + # 批量上传主机线程池 + uploadHostExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: upload-host- diff --git a/orion-visor-launch/src/main/resources/application-prod.yaml b/orion-visor-launch/src/main/resources/application-prod.yaml index e9c8619e..ffd195e1 100644 --- a/orion-visor-launch/src/main/resources/application-prod.yaml +++ b/orion-visor-launch/src/main/resources/application-prod.yaml @@ -84,9 +84,81 @@ orion: aes: # 加密密钥 secret-key: ${SECRET_KEY:uQeacXV8b3isvKLK} - async: - executor: + +app: + executors: + # 默认异步线程池 + asyncExecutor: + mdc: true core-pool-size: 8 max-pool-size: 16 - queue-capacity: 200 - keep-alive-seconds: 300 + queue-capacity: 100 + allow-core-timeout: false + thread-name-prefix: async-executor- + # 指标存储异步线程池 + metricsExecutor: + mdc: true + core-pool-size: 4 + max-pool-size: 4 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: metrics-task- + # 推送异步线程池 + pushExecutor: + mdc: true + core-pool-size: 4 + max-pool-size: 4 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: message-push- + # 探针安装线程池 + agentInstallExecutor: + allow-core-timeout: true + thread-name-prefix: agent-install- + # 终端标准输出线程池 + terminalStdoutExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: terminal-stdout- + # 终端操作线程池 + terminalOperatorExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: terminal-operator- + # 终端异步保存线程池 + terminalAsyncSaverExecutor: + core-pool-size: 1 + max-pool-size: 1 + queue-capacity: 1000 + allow-core-timeout: true + thread-name-prefix: terminal-watcher- + # 批量执行超时检查线程池 + execTimeoutCheckExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: timeout-check- + # 批量执行任务线程池 + execTaskExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-task- + # 批量执行主机命令线程池 + execHostCommandExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-host- + # 批量执行日志查看线程池 + execLogViewExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: exec-log- + # 批量上传任务线程池 + uploadTaskExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: upload-task- + # 批量上传主机线程池 + uploadHostExecutor: + synchronous-queue: true + allow-core-timeout: true + thread-name-prefix: upload-host- diff --git a/orion-visor-launch/src/main/resources/application.yaml b/orion-visor-launch/src/main/resources/application.yaml index c04432cc..1a151e5b 100644 --- a/orion-visor-launch/src/main/resources/application.yaml +++ b/orion-visor-launch/src/main/resources/application.yaml @@ -22,6 +22,11 @@ spring: async: # 异步请求时间 30min request-timeout: 1800000 + task: + scheduling: + thread-name-prefix: scheduling-task- + pool: + size: 4 datasource: druid: driver-class-name: com.mysql.cj.jdbc.Driver @@ -255,13 +260,6 @@ orion: secret-key: I66AndrKWrwXjtBL use-generator-key: true generator-key-length: 128 - async: - # 线程池配置 - executor: - core-pool-size: 2 - max-pool-size: 4 - queue-capacity: 30 - keep-alive-seconds: 180 operator-log: error-message-length: 255 user-agent-length: 128 diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/pom.xml b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/pom.xml index dea24084..657bfb13 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/pom.xml +++ b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/pom.xml @@ -88,6 +88,10 @@ org.dromara.visor orion-visor-spring-boot-starter-job + + org.dromara.visor + orion-visor-spring-boot-starter-executor + org.dromara.visor orion-visor-spring-boot-starter-test @@ -102,4 +106,4 @@ - \ No newline at end of file + diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/AssetThreadPools.java b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/AssetThreadPools.java index b38fe855..5dd72dc1 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/AssetThreadPools.java +++ b/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/AssetThreadPools.java @@ -22,12 +22,9 @@ */ package org.dromara.visor.module.asset.define; -import cn.orionsec.kit.lang.define.thread.ExecutorBuilder; -import cn.orionsec.kit.lang.utils.Systems; -import org.dromara.visor.common.constant.Const; +import org.dromara.visor.framework.executor.core.utils.ExecutorUtils; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.Executor; /** * 执行线程池 @@ -41,13 +38,6 @@ public interface AssetThreadPools { /** * 批量执行主机命令线程池 */ - ThreadPoolExecutor AGENT_INSTALL = ExecutorBuilder.create() - .namedThreadFactory("agent-install-") - .corePoolSize(Systems.PROCESS_NUM) - .maxPoolSize(Systems.PROCESS_NUM) - .keepAliveTime(Const.MS_S_60) - .workQueue(new LinkedBlockingQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor AGENT_INSTALL = ExecutorUtils.getExecutor("agentInstallExecutor"); } diff --git a/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/pom.xml b/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/pom.xml index c8ad58ff..616a9f98 100644 --- a/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/pom.xml +++ b/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/pom.xml @@ -87,10 +87,14 @@ org.dromara.visor orion-visor-spring-boot-starter-job + + org.dromara.visor + orion-visor-spring-boot-starter-executor + org.dromara.visor orion-visor-spring-boot-starter-test - \ No newline at end of file + diff --git a/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/src/main/java/org/dromara/visor/module/exec/define/ExecThreadPools.java b/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/src/main/java/org/dromara/visor/module/exec/define/ExecThreadPools.java index 81e78ae2..5c1b9cdc 100644 --- a/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/src/main/java/org/dromara/visor/module/exec/define/ExecThreadPools.java +++ b/orion-visor-modules/orion-visor-module-exec/orion-visor-module-exec-service/src/main/java/org/dromara/visor/module/exec/define/ExecThreadPools.java @@ -22,11 +22,9 @@ */ package org.dromara.visor.module.exec.define; -import cn.orionsec.kit.lang.define.thread.ExecutorBuilder; -import org.dromara.visor.common.constant.Const; +import org.dromara.visor.framework.executor.core.utils.ExecutorUtils; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.Executor; /** * 执行线程池 @@ -40,73 +38,31 @@ public interface ExecThreadPools { /** * 超时检查线程池 */ - ThreadPoolExecutor TIMEOUT_CHECK = ExecutorBuilder.create() - .namedThreadFactory("timeout-check-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor TIMEOUT_CHECK = ExecutorUtils.getExecutor("execTimeoutCheckExecutor"); /** * 批量执行任务线程池 */ - ThreadPoolExecutor EXEC_TASK = ExecutorBuilder.create() - .namedThreadFactory("exec-task-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor EXEC_TASK = ExecutorUtils.getExecutor("execTaskExecutor"); /** * 批量执行主机命令线程池 */ - ThreadPoolExecutor EXEC_HOST = ExecutorBuilder.create() - .namedThreadFactory("exec-host-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor EXEC_HOST = ExecutorUtils.getExecutor("execHostCommandExecutor"); /** * 批量执行日志查看线程池 */ - ThreadPoolExecutor EXEC_LOG = ExecutorBuilder.create() - .namedThreadFactory("exec-log-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor EXEC_LOG = ExecutorUtils.getExecutor("execLogViewExecutor"); /** * 批量上传任务线程池 */ - ThreadPoolExecutor UPLOAD_TASK = ExecutorBuilder.create() - .namedThreadFactory("upload-task-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor UPLOAD_TASK = ExecutorUtils.getExecutor("uploadTaskExecutor"); /** * 批量上传主机线程池 */ - ThreadPoolExecutor UPLOAD_HOST = ExecutorBuilder.create() - .namedThreadFactory("upload-host-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor UPLOAD_HOST = ExecutorUtils.getExecutor("uploadHostExecutor"); } diff --git a/orion-visor-modules/orion-visor-module-monitor/orion-visor-module-monitor-service/pom.xml b/orion-visor-modules/orion-visor-module-monitor/orion-visor-module-monitor-service/pom.xml index 6a67c475..65d76d12 100644 --- a/orion-visor-modules/orion-visor-module-monitor/orion-visor-module-monitor-service/pom.xml +++ b/orion-visor-modules/orion-visor-module-monitor/orion-visor-module-monitor-service/pom.xml @@ -83,6 +83,10 @@ org.dromara.visor orion-visor-spring-boot-starter-job + + org.dromara.visor + orion-visor-spring-boot-starter-executor + org.dromara.visor orion-visor-spring-boot-starter-test @@ -111,4 +115,4 @@ - \ No newline at end of file + diff --git a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/pom.xml b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/pom.xml index 83ae569b..f7b7ec1a 100644 --- a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/pom.xml +++ b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/pom.xml @@ -83,6 +83,10 @@ org.dromara.visor orion-visor-spring-boot-starter-job + + org.dromara.visor + orion-visor-spring-boot-starter-executor + org.dromara.visor orion-visor-spring-boot-starter-test diff --git a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/define/TerminalThreadPools.java b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/define/TerminalThreadPools.java index 637c4f60..c515abc9 100644 --- a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/define/TerminalThreadPools.java +++ b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/define/TerminalThreadPools.java @@ -22,12 +22,9 @@ */ package org.dromara.visor.module.terminal.define; -import cn.orionsec.kit.lang.define.thread.ExecutorBuilder; -import org.dromara.visor.common.constant.Const; +import org.dromara.visor.framework.executor.core.utils.ExecutorUtils; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.Executor; /** * 终端线程池 @@ -39,37 +36,18 @@ import java.util.concurrent.ThreadPoolExecutor; public interface TerminalThreadPools { /** - * terminal 标准输出线程池 + * 终端标准输出线程池 */ - ThreadPoolExecutor TERMINAL_STDOUT = ExecutorBuilder.create() - .namedThreadFactory("terminal-stdout-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor TERMINAL_STDOUT = ExecutorUtils.getExecutor("terminalStdoutExecutor"); /** - * terminal 操作线程池 + * 终端操作线程池 */ - ThreadPoolExecutor TERMINAL_OPERATOR = ExecutorBuilder.create() - .namedThreadFactory("terminal-operator-") - .corePoolSize(1) - .maxPoolSize(Integer.MAX_VALUE) - .keepAliveTime(Const.MS_S_60) - .workQueue(new SynchronousQueue<>()) - .allowCoreThreadTimeout(true) - .build(); + Executor TERMINAL_OPERATOR = ExecutorUtils.getExecutor("terminalOperatorExecutor"); /** * 终端异步保存线程池 */ - ThreadPoolExecutor TERMINAL_ASYNC_SAVER = ExecutorBuilder.create() - .namedThreadFactory("terminal-async-saver-") - .corePoolSize(1) - .maxPoolSize(1) - .workQueue(new LinkedBlockingQueue<>()) - .build(); + Executor TERMINAL_ASYNC_SAVER = ExecutorUtils.getExecutor("terminalAsyncSaverExecutor"); } diff --git a/orion-visor-ui/src/views/monitor/monitor-detail/compoments/metrics-chart-tab.vue b/orion-visor-ui/src/views/monitor/monitor-detail/compoments/metrics-chart-tab.vue index cfe480f1..7e755f8c 100644 --- a/orion-visor-ui/src/views/monitor/monitor-detail/compoments/metrics-chart-tab.vue +++ b/orion-visor-ui/src/views/monitor/monitor-detail/compoments/metrics-chart-tab.vue @@ -40,7 +40,7 @@ md: props.chartCompose ? 2 : 1, lg: props.chartCompose ? 2 : 1, xl: props.chartCompose ? 3 : 1, - xxl: props.chartCompose ? 3 : 1, + xxl: props.chartCompose ? 4 : 1, }; });