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 6a5984dbab..9825fb61a9 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 @@ -23,6 +23,7 @@ import io.metersphere.service.BaseProjectApplicationService; import io.metersphere.service.RemakeReportService; import io.metersphere.service.SystemParameterService; import io.metersphere.utils.LoggerUtil; +import io.metersphere.xpack.api.service.ApiPoolDebugService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.ArrayUtils; @@ -58,11 +59,14 @@ public class JMeterService { private SystemParameterService systemParameterService; @Resource private BaseProjectApplicationService projectApplicationService; + @Resource + private RemakeReportService remakeReportService; + @Resource + private ExecThreadPoolExecutor execThreadPoolExecutor; @PostConstruct private void init() { String JMETER_HOME = getJmeterHome(); - String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties"; JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES); JMeterUtils.setJMeterHome(JMETER_HOME); @@ -150,8 +154,7 @@ public class JMeterService { final Engine engine = EngineFactory.createApiEngine(request); engine.start(); } catch (Exception e) { - RemakeReportService apiScenarioReportService = CommonBeanFactory.getBean(RemakeReportService.class); - apiScenarioReportService.testEnded(request, e.getMessage()); + remakeReportService.testEnded(request, e.getMessage()); LoggerUtil.error("调用K8S执行请求[ " + request.getTestId() + " ]失败:", request.getReportId(), e); } } else if ((MapUtils.isNotEmpty(request.getExtendedParameters()) @@ -166,34 +169,15 @@ public class JMeterService { private synchronized void nodeDebug(JmeterRunRequestDTO request) { try { - if (request.isDebug() && !StringUtils.equalsAny(request.getRunMode(), ApiRunMode.DEFINITION.name())) { - request.getExtendedParameters().put(ExtendedParameter.SAVE_RESULT, true); - } else if (!request.isDebug()) { - request.getExtendedParameters().put(ExtendedParameter.SAVE_RESULT, true); - } - List resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId()); - String uri = null; - int index = (int) (Math.random() * resources.size()); - String configuration = resources.get(index).getConfiguration(); - if (StringUtils.isNotEmpty(configuration)) { - NodeDTO node = com.alibaba.fastjson.JSON.parseObject(configuration, NodeDTO.class); - uri = String.format(BASE_URL + "/jmeter/debug", node.getIp(), node.getPort()); - } - if (StringUtils.isEmpty(uri)) { - LoggerUtil.info("未获取到资源池,请检查配置【系统设置-系统-测试资源池】", request.getReportId()); - MSException.throwException("调用资源池执行失败,请检查资源池是否配置正常"); - } - request.getExtendedParameters().put(ExtendedParameter.JMX, new MsTestPlan().getJmx(request.getHashTree())); - request.setHashTree(null); - LoggerUtil.info("开始发送请求【 " + request.getTestId() + " 】到 " + uri + " 节点执行", request.getReportId()); - ResponseEntity result = restTemplate.postForEntity(uri, request, String.class); - if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) { - LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 到" + uri + " 节点执行失败", request.getReportId()); - LoggerUtil.info(result); - MSException.throwException("调用资源池执行失败,请检查资源池是否配置正常"); + ApiPoolDebugService apiPoolDebugService = CommonBeanFactory.getBean(ApiPoolDebugService.class); + if (apiPoolDebugService != null) { + List resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId()); + request.getExtendedParameters().put(ExtendedParameter.JMX, new MsTestPlan().getJmx(request.getHashTree())); + request.setHashTree(null); + apiPoolDebugService.run(request, resources); } } catch (Exception e) { - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); + LoggerUtil.error(e); remakeReportService.remake(request); LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 执行失败,进行数据回滚:", request.getReportId(), e); MSException.throwException("调用资源池执行失败,请检查资源池是否配置正常"); @@ -212,7 +196,6 @@ public class JMeterService { } if (config == null) { LoggerUtil.info("未获取到资源池,请检查配置【系统设置-系统-测试资源池】", request.getReportId()); - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); remakeReportService.remake(request); return; } @@ -221,13 +204,11 @@ public class JMeterService { LoggerUtil.info("开始发送请求【 " + request.getTestId() + " 】到 " + config.getUrl() + " 节点执行", request.getReportId()); ResponseEntity result = restTemplate.postForEntity(config.getUrl(), request, String.class); if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) { - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); remakeReportService.remake(request); LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 到" + config.getUrl() + " 节点执行失败", request.getReportId()); LoggerUtil.info(result.getBody()); } } catch (Exception e) { - RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); remakeReportService.remake(request); LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 执行失败,进行数据回滚:", request.getReportId(), e); } @@ -240,7 +221,7 @@ public class JMeterService { } else if (request.getHashTree() != null) { //解析hashTree,是否含有文件库文件 HashTreeUtil.initRepositoryFiles(request); - CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).addTask(request); + execThreadPoolExecutor.addTask(request); } } @@ -275,7 +256,8 @@ public class JMeterService { public void verifyPool(String projectId, RunModeConfigDTO runConfig) { // 检查是否禁用了本地执行 - if (runConfig != null && StringUtils.isEmpty(runConfig.getResourcePoolId())) { + if (runConfig != null && StringUtils.isEmpty(runConfig.getResourcePoolId()) + && CommonBeanFactory.getBean(ApiPoolDebugService.class) != null) { BaseSystemConfigDTO configDTO = systemParameterService.getBaseInfo(); if (StringUtils.equals(configDTO.getRunMode(), POOL)) { ProjectConfig config = projectApplicationService.getProjectConfig(projectId); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java index eafe37a7f0..7ab62c2a56 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java @@ -1,9 +1,9 @@ package io.metersphere.api.jmeter; -import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.MsgDTO; import io.metersphere.commons.constants.KafkaTopicConstants; +import io.metersphere.commons.utils.JSONUtil; import io.metersphere.commons.utils.NamedThreadFactory; import io.metersphere.commons.utils.WebSocketUtil; import io.metersphere.service.ApiExecutionQueueService; @@ -74,7 +74,7 @@ public class MsKafkaListener { try { LoggerUtil.info("接收到执行结果:", record.key()); if (ObjectUtils.isNotEmpty(record.value()) && WebSocketUtil.has(record.key().toString())) { - MsgDTO dto = JSON.parseObject(record.value(), MsgDTO.class); + MsgDTO dto = JSONUtil.parseObject(record.value(), MsgDTO.class); WebSocketUtil.sendMessageSingle(dto); } } catch (Exception e) { diff --git a/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue b/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue index 7983a4bdf2..1961d2dcc7 100644 --- a/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue +++ b/api-test/frontend/src/business/automation/scenario/common/ApiRunMode.vue @@ -95,6 +95,7 @@ import {getCurrentProjectID} from "metersphere-frontend/src/utils/token"; import {getSystemBaseSetting} from "metersphere-frontend/src/api/system"; import EnvSelectPopover from "@/business/automation/scenario/EnvSelectPopover"; import {getApiCaseEnvironments} from "@/api/api-test-case"; +import {hasLicense} from "metersphere-frontend/src/utils/permission"; export default { name: "ApiRunMode", @@ -149,7 +150,9 @@ export default { this.runModeVisible = true; this.getResourcePools(); this.getWsProjects(); - this.query(); + if(hasLicense()) { + this.query(); + } this.showPopover(); this.runConfig.environmentType = ENV_TYPE.JSON; }, diff --git a/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue b/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue index b400758ca1..dc291ad25d 100644 --- a/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue +++ b/api-test/frontend/src/business/automation/schedule/ScheduleMaintain.vue @@ -109,6 +109,7 @@ import EnvPopover from "@/business/automation/scenario/EnvPopover"; import {getMaintainer, getOwnerProjects, getProjectConfig} from "@/api/project"; import {getTestResourcePools} from "@/api/test-resource-pool"; import {getSystemBaseSetting} from "metersphere-frontend/src/api/system"; +import {hasLicense} from "metersphere-frontend/src/utils/permission"; function defaultCustomValidate() { return {pass: true}; @@ -317,7 +318,9 @@ export default { this.activeName = 'first'; this.getResourcePools(); this.getWsProjects(); - this.query(); + if(hasLicense()) { + this.query(); + } this.runConfig.environmentType = ENV_TYPE.JSON; }, findSchedule() { diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/api/service/ApiPoolDebugService.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/api/service/ApiPoolDebugService.java new file mode 100644 index 0000000000..92d9c15a9e --- /dev/null +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/api/service/ApiPoolDebugService.java @@ -0,0 +1,10 @@ +package io.metersphere.xpack.api.service; + +import io.metersphere.base.domain.TestResource; +import io.metersphere.dto.JmeterRunRequestDTO; + +import java.util.List; + +public interface ApiPoolDebugService { + public void run(JmeterRunRequestDTO request, List resources); +} diff --git a/project-management/frontend/src/business/menu/appmanage/AppManage.vue b/project-management/frontend/src/business/menu/appmanage/AppManage.vue index 4241e11938..ff6e76f7dc 100644 --- a/project-management/frontend/src/business/menu/appmanage/AppManage.vue +++ b/project-management/frontend/src/business/menu/appmanage/AppManage.vue @@ -97,7 +97,7 @@ + :append-span="4" v-if="isPool && isXpack">