refactor(接口定义): 资源池加载插件直接从MinIO获取

--story=1011108 --user=王孝刚 资源池加载插件直接从MinIO获取
https://www.tapd.cn/55049933/s/1331634
This commit is contained in:
wxg0103 2023-02-06 14:53:36 +08:00 committed by fit2-zhao
parent 208906eafe
commit a8725ca9e5
5 changed files with 32 additions and 31 deletions

View File

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

View File

@ -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<byte[]> downloadJmeterFiles(@RequestBody BodyFileRequest request) {
byte[] bytes = apiJmeterFileService.zipFilesToByteArray(request);

View File

@ -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<Plugin> plugins = pluginService.list();
if (CollectionUtils.isNotEmpty(plugins)) {
plugins = plugins.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(Plugin::getPluginId))), ArrayList::new));
List<PluginDTO> 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<String, byte[]> getJar(String projectId) {
Map<String, byte[]> jarFiles = new LinkedHashMap<>();
FileMetadataService jarConfigService = CommonBeanFactory.getBean(FileMetadataService.class);

View File

@ -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<Plugin> plugins = pluginMapper.selectByExample(example);
return plugins;
}
public PluginConfigDTO getPluginConfig() {
PluginConfigDTO pluginConfigDTO = new PluginConfigDTO();
List<Plugin> 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<io.metersphere.dto.PluginDTO> 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;
}
}

View File

@ -90,6 +90,9 @@ public class JmeterRunRequestDTO {
// 失败重试次数
private long retryNum;
//MinIO配置和系统插件信息
private PluginConfigDTO pluginConfigDTO;
public JmeterRunRequestDTO() {
}