From a8725ca9e532886b6123c851923dab4a8ab24ae7 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 6 Feb 2023 14:53:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=20=E8=B5=84=E6=BA=90=E6=B1=A0=E5=8A=A0=E8=BD=BD=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=9B=B4=E6=8E=A5=E4=BB=8EMinIO=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1011108 --user=王孝刚 资源池加载插件直接从MinIO获取 https://www.tapd.cn/55049933/s/1331634 --- .../metersphere/api/jmeter/JMeterService.java | 6 +++++ .../controller/ApiJMeterFileController.java | 7 ------ .../service/ApiJMeterFileService.java | 23 ------------------ .../io/metersphere/service/PluginService.java | 24 ++++++++++++++++++- .../metersphere/dto/JmeterRunRequestDTO.java | 3 +++ 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 6bfa5b6b47..9d897b9dfc 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -21,6 +21,7 @@ import io.metersphere.constants.BackendListenerConstants; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.dto.NodeDTO; +import io.metersphere.dto.PluginConfigDTO; import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.engine.Engine; import io.metersphere.jmeter.JMeterBase; @@ -153,6 +154,11 @@ public class JMeterService { private void runNode(JmeterRunRequestDTO request) { request.setKafkaConfig(KafkaConfig.getKafka()); + //获取MinIO配置和系统下的插件jar包 + PluginConfigDTO pluginConfigDTO = pluginService.getPluginConfig(); + if (pluginConfigDTO != null) { + request.setPluginConfigDTO(pluginConfigDTO); + } // 如果是K8S调用 if (request.getPool().isK8s()) { try { diff --git a/api-test/backend/src/main/java/io/metersphere/controller/ApiJMeterFileController.java b/api-test/backend/src/main/java/io/metersphere/controller/ApiJMeterFileController.java index 7fe2bd1b39..5e2fee0acb 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/ApiJMeterFileController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/ApiJMeterFileController.java @@ -2,7 +2,6 @@ package io.metersphere.controller; import io.metersphere.api.dto.BodyFileRequest; import io.metersphere.api.jmeter.JMeterThreadUtils; -import io.metersphere.dto.PluginConfigDTO; import io.metersphere.service.ApiJMeterFileService; import io.metersphere.utils.LoggerUtil; import jakarta.annotation.Resource; @@ -67,12 +66,6 @@ public class ApiJMeterFileController { .body(bytes); } - @GetMapping("download/plugin/jar/list") - public PluginConfigDTO downloadPlugLists() { - return apiJmeterFileService.downloadPluginJarList(); - } - - @PostMapping("download/files") public ResponseEntity downloadJmeterFiles(@RequestBody BodyFileRequest request) { byte[] bytes = apiJmeterFileService.zipFilesToByteArray(request); diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java index 2279d6a7bb..3e95f193fb 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java @@ -9,12 +9,9 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiExecutionQueueDetailMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; -import io.metersphere.commons.config.MinioConfig; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.*; import io.metersphere.dto.JmeterRunRequestDTO; -import io.metersphere.dto.PluginConfigDTO; -import io.metersphere.dto.PluginDTO; import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.metadata.service.FileMetadataService; import io.metersphere.request.BodyFile; @@ -184,26 +181,6 @@ public class ApiJMeterFileService { return listBytesToZip(files); } - public PluginConfigDTO downloadPluginJarList() { - PluginConfigDTO pluginConfigDTO = new PluginConfigDTO(); - List plugins = pluginService.list(); - if (CollectionUtils.isNotEmpty(plugins)) { - plugins = plugins.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> - new TreeSet<>(Comparator.comparing(Plugin::getPluginId))), ArrayList::new)); - List plugin = plugins.stream().map( - item -> { - PluginDTO pluginDTO = new PluginDTO(); - pluginDTO.setPluginId(item.getPluginId()); - pluginDTO.setSourcePath(item.getSourcePath()); - return pluginDTO; - } - ).collect(Collectors.toList()); - pluginConfigDTO.setPluginDTOS(plugin); - } - pluginConfigDTO.setConfig(MinioConfig.getMinio()); - return pluginConfigDTO; - } - private Map getJar(String projectId) { Map jarFiles = new LinkedHashMap<>(); FileMetadataService jarConfigService = CommonBeanFactory.getBean(FileMetadataService.class); diff --git a/api-test/backend/src/main/java/io/metersphere/service/PluginService.java b/api-test/backend/src/main/java/io/metersphere/service/PluginService.java index e2e793cfe1..3ba1952b09 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/PluginService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/PluginService.java @@ -6,20 +6,22 @@ import io.metersphere.base.domain.Plugin; import io.metersphere.base.domain.PluginExample; import io.metersphere.base.domain.PluginWithBLOBs; import io.metersphere.base.mapper.PluginMapper; +import io.metersphere.commons.config.MinioConfig; import io.metersphere.commons.constants.PluginScenario; import io.metersphere.commons.constants.StorageConstants; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.dto.PluginConfigDTO; import io.metersphere.metadata.service.FileManagerService; import io.metersphere.metadata.vo.FileRequest; +import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; import java.io.File; import java.lang.reflect.Method; import java.net.URL; @@ -183,4 +185,24 @@ public class PluginService { List plugins = pluginMapper.selectByExample(example); return plugins; } + + public PluginConfigDTO getPluginConfig() { + PluginConfigDTO pluginConfigDTO = new PluginConfigDTO(); + List plugins = this.list(); + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(plugins)) { + plugins = plugins.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> + new TreeSet<>(Comparator.comparing(Plugin::getPluginId))), ArrayList::new)); + List plugin = plugins.stream().map( + item -> { + io.metersphere.dto.PluginDTO pluginDTO = new io.metersphere.dto.PluginDTO(); + pluginDTO.setPluginId(item.getPluginId()); + pluginDTO.setSourcePath(item.getSourcePath()); + return pluginDTO; + } + ).collect(Collectors.toList()); + pluginConfigDTO.setPluginDTOS(plugin); + } + pluginConfigDTO.setConfig(MinioConfig.getMinio()); + return pluginConfigDTO; + } } diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java index e594a13d7d..d122aaedcb 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java @@ -90,6 +90,9 @@ public class JmeterRunRequestDTO { // 失败重试次数 private long retryNum; + //MinIO配置和系统插件信息 + private PluginConfigDTO pluginConfigDTO; + public JmeterRunRequestDTO() { }