refactor(接口定义): 优化选择资源池执行
This commit is contained in:
parent
800e586268
commit
e11fecdc30
|
@ -5,8 +5,10 @@ import io.metersphere.commons.constants.ApiRunMode;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.dto.*;
|
||||
import io.metersphere.quota.service.BaseQuotaService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -14,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -28,6 +31,8 @@ public class ApiPoolDebugService {
|
|||
private SystemParameterService systemParameterService;
|
||||
@Resource
|
||||
private BaseProjectApplicationService baseProjectApplicationService;
|
||||
@Resource
|
||||
private BaseQuotaService baseQuotaService;
|
||||
|
||||
public void run(JmeterRunRequestDTO request, List<TestResource> resources) throws MSException {
|
||||
try {
|
||||
|
@ -71,17 +76,29 @@ public class ApiPoolDebugService {
|
|||
LoggerUtil.info("校验项目为:【" + projectId + "】", runConfig.getReportId());
|
||||
ProjectConfig config = baseProjectApplicationService.getProjectConfig(projectId);
|
||||
List<TestResourcePoolDTO> poolList = systemParameterService.getTestResourcePool();
|
||||
boolean contains = poolList.stream().map(TestResourcePoolDTO::getId)
|
||||
.collect(Collectors.toList()).contains(config.getResourcePoolId());
|
||||
|
||||
if (StringUtils.isEmpty(config.getResourcePoolId()) || !contains || BooleanUtils.isFalse(config.getPoolEnable())) {
|
||||
String id = systemParameterService.filterQuota(poolList, projectId);
|
||||
if (StringUtils.isBlank(id)) {
|
||||
MSException.throwException("请在【项目设置-应用管理-接口测试】中选择资源池");
|
||||
Set<String> poolSets = baseQuotaService.getQuotaResourcePools(projectId);
|
||||
if (CollectionUtils.isNotEmpty(poolSets)) {
|
||||
poolList = poolList.stream().filter(pool -> poolSets.contains(pool.getId())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(poolList)) {
|
||||
MSException.throwException("请在【项目设置-应用管理-接口测试】中选择资源池");
|
||||
}
|
||||
|
||||
boolean contains = poolList.stream().map(TestResourcePoolDTO::getId)
|
||||
.collect(Collectors.toList()).contains(config.getResourcePoolId()) && BooleanUtils.isTrue(config.getPoolEnable());
|
||||
|
||||
if (!contains) {
|
||||
List<TestResourcePoolDTO> pools = poolList.stream().filter(pool ->
|
||||
StringUtils.equals(pool.getName(), "LOCAL")).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(pools)) {
|
||||
config.setResourcePoolId(pools.get(0).getId());
|
||||
} else {
|
||||
config.setResourcePoolId(id);
|
||||
config.setResourcePoolId(poolList.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
||||
runConfig = runConfig == null ? new RunModeConfigDTO() : runConfig;
|
||||
runConfig.setResourcePoolId(config.getResourcePoolId());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import io.metersphere.base.mapper.SystemHeaderMapper;
|
|||
import io.metersphere.base.mapper.SystemParameterMapper;
|
||||
import io.metersphere.base.mapper.UserHeaderMapper;
|
||||
import io.metersphere.base.mapper.ext.BaseSystemParameterMapper;
|
||||
import io.metersphere.commons.constants.MicroServiceName;
|
||||
import io.metersphere.commons.constants.ParamConstants;
|
||||
import io.metersphere.commons.constants.ProjectApplicationType;
|
||||
import io.metersphere.commons.constants.ResourceStatusEnum;
|
||||
|
@ -398,19 +397,6 @@ public class SystemParameterService {
|
|||
SystemParameterExample example = new SystemParameterExample();
|
||||
|
||||
parameters.forEach(param -> {
|
||||
if (param.getParamKey().equals("base.concurrency")) {
|
||||
if (StringUtils.isNotEmpty(param.getParamValue())) {
|
||||
try {
|
||||
int poolSize = Integer.parseInt(param.getParamValue());
|
||||
if (poolSize > 10000) {
|
||||
MSException.throwException("并发数设置太大,请重新设置");
|
||||
}
|
||||
microService.getForData(MicroServiceName.API_TEST, "/exec/thread/pool/set-core-size/" + poolSize);
|
||||
} catch (Exception e) {
|
||||
MSException.throwException("并发数设置不规范,请重新设置");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 去掉路径最后的 /
|
||||
param.setParamValue(StringUtils.removeEnd(param.getParamValue(), "/"));
|
||||
if (StringUtils.equals(param.getParamKey(), "base.url")) {
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
|
||||
<!-- 创建、编辑、复制环境时的对话框 -->
|
||||
<el-dialog :visible.sync="dialogVisible" :close-on-click-modal="false" width="66%" top="50px"
|
||||
:fullscreen="isFullScreen">
|
||||
:fullscreen="isFullScreen" destroy-on-close>
|
||||
<template #title>
|
||||
<ms-dialog-header :title="dialogTitle" :hide-button="true"
|
||||
@cancel="dialogVisible = false"
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
<el-input v-model="formInline.url" :placeholder="$t('system_config.base.url_tip')"/>
|
||||
<i>({{ $t('commons.examples') }}:https://rdmetersphere.fit2cloud.com)</i>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('report.max_users')" prop="concurrency">
|
||||
<el-input v-model="formInline.concurrency" :placeholder="$t('report.max_users')"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('system_config.prometheus.host')" prop="prometheusHost">
|
||||
<el-input v-model="formInline.prometheusHost" :placeholder="$t('system_config.prometheus.host_tip')"/>
|
||||
<i>({{ $t('commons.examples') }}:http://ms-prometheus:9090)</i>
|
||||
|
|
Loading…
Reference in New Issue