refactor(接口测试): 默认分配local资源池
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
c59e381d36
commit
ea0e5b5553
|
@ -11,7 +11,9 @@ import io.metersphere.commons.utils.JSON;
|
|||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.RunModeConfigDTO;
|
||||
import io.metersphere.service.ApiPoolDebugService;
|
||||
import io.metersphere.service.scenario.ApiScenarioService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.*;
|
||||
|
||||
|
@ -34,6 +36,8 @@ public class ApiScenarioTestJob extends MsScheduleJob {
|
|||
|
||||
private ApiScenarioService apiAutomationService;
|
||||
|
||||
private ApiPoolDebugService apiPoolDebugService;
|
||||
|
||||
public ApiScenarioTestJob() {
|
||||
apiAutomationService = CommonBeanFactory.getBean(ApiScenarioService.class);
|
||||
}
|
||||
|
@ -79,7 +83,14 @@ public class ApiScenarioTestJob extends MsScheduleJob {
|
|||
runModeConfigDTO.setMode(RunModeConstants.PARALLEL.toString());
|
||||
request.setConfig(runModeConfigDTO);
|
||||
}
|
||||
|
||||
// 兼容历史定时任务默认给一个资源池
|
||||
if (StringUtils.isBlank(request.getConfig().getResourcePoolId())) {
|
||||
try {
|
||||
apiPoolDebugService.verifyPool(projectID, request.getConfig());
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error(e);
|
||||
}
|
||||
}
|
||||
apiAutomationService.run(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.commons.utils.JSON;
|
|||
import io.metersphere.dto.*;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -70,9 +71,12 @@ 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());
|
||||
boolean contains = poolList.stream().map(TestResourcePoolDTO::getId)
|
||||
.collect(Collectors.toList()).contains(config.getResourcePoolId());
|
||||
|
||||
if (StringUtils.isEmpty(config.getResourcePoolId()) || !contains) {
|
||||
if ((StringUtils.isEmpty(config.getResourcePoolId())
|
||||
&& BooleanUtils.isTrue(config.getPoolEnable()))
|
||||
|| !contains) {
|
||||
String id = systemParameterService.filterQuota(poolList, projectId);
|
||||
if (StringUtils.isBlank(id)) {
|
||||
MSException.throwException("请在【项目设置-应用管理-接口测试】中选择资源池");
|
||||
|
|
|
@ -314,13 +314,26 @@ public class SystemParameterService {
|
|||
poolList = list.stream().filter(pool -> pools.contains(pool.getId())).collect(Collectors.toList());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(poolList)) {
|
||||
return poolList.get(0).getId();
|
||||
return getPreLocalPoolId(poolList);
|
||||
} else if (CollectionUtils.isNotEmpty(list)) {
|
||||
return list.get(0).getId();
|
||||
return getPreLocalPoolId(list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String getPreLocalPoolId(List<TestResourcePoolDTO> poolList) {
|
||||
if (CollectionUtils.isEmpty(poolList)) {
|
||||
return null;
|
||||
}
|
||||
List<TestResourcePoolDTO> poolDTOS = poolList.stream().filter(pool ->
|
||||
StringUtils.equals(pool.getName(), "LOCAL")).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(poolDTOS)) {
|
||||
return poolDTOS.get(0).getId();
|
||||
} else {
|
||||
return poolList.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
public void batchSaveApp(List<String> projectIds, List<TestResourcePoolDTO> poolList, ProjectApplicationMapper batchMapper) {
|
||||
if (CollectionUtils.isNotEmpty(projectIds)) {
|
||||
List<String> appProjectIds = baseProjectApplicationService.getProjectIds(projectIds);
|
||||
|
|
Loading…
Reference in New Issue