diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java deleted file mode 100644 index fe2f897209..0000000000 --- a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/utils/XpackUtil.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.metersphere.xpack.utils; - -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.xpack.license.service.LicenseService; - -public class XpackUtil { - - public static final String LICENSE_STATUS = "valid"; - - public static boolean validateLicense() { - LicenseService licenseService = CommonBeanFactory.getBean(LicenseService.class); - if (licenseService != null) { - return licenseService.validate().getStatus().equals(LICENSE_STATUS); - } - return false; - } -} diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index e5dd458276..5f4f64e300 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -1,7 +1,6 @@ package io.metersphere.plan.service; -import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; @@ -29,7 +28,6 @@ import io.metersphere.service.BaseUserService; import io.metersphere.service.ServiceUtils; import io.metersphere.utils.DiscoveryUtil; import io.metersphere.xpack.track.dto.IssuesDao; -import io.metersphere.xpack.utils.XpackUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -296,7 +294,7 @@ public class TestPlanReportService { } try { - if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { // todo 远程调用失败处理逻辑 Map uiScenarioIdMap = new LinkedHashMap<>(); List testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId); @@ -371,7 +369,7 @@ public class TestPlanReportService { } - if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId)); } @@ -615,7 +613,7 @@ public class TestPlanReportService { private void initTestPlanReportBaseCount(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) { if (testPlanReport != null && reportContent != null) { TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildPlanReport(testPlanReport, reportContent); - reportContent.setApiBaseCount(JSONObject.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO())); + reportContent.setApiBaseCount(JSON.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO())); } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 2bfdd85db5..a0a7e406e0 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -1,7 +1,5 @@ package io.metersphere.plan.service; - -import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; @@ -37,7 +35,6 @@ import io.metersphere.plan.request.ui.RunUiScenarioRequest; import io.metersphere.plan.service.remote.api.PlanApiAutomationService; import io.metersphere.plan.service.remote.api.PlanTestPlanApiCaseService; import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService; -import io.metersphere.plan.service.remote.gateway.GatewayService; import io.metersphere.plan.service.remote.performance.PerfExecService; import io.metersphere.plan.service.remote.performance.PlanTestPlanLoadCaseService; import io.metersphere.plan.service.remote.ui.PlanTestPlanUiScenarioCaseService; @@ -48,7 +45,6 @@ import io.metersphere.service.*; import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.LoggerUtil; import io.metersphere.xpack.track.dto.IssuesDao; -import io.metersphere.xpack.utils.XpackUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -146,8 +142,6 @@ public class TestPlanService { private TestPlanExecutionQueueService testPlanExecutionQueueService; @Resource private KafkaTemplate kafkaTemplate; - @Resource - private GatewayService gatewayService; public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -364,7 +358,7 @@ public class TestPlanService { calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId); } - if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId); } @@ -1092,7 +1086,7 @@ public class TestPlanService { planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId); } - if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) { + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); } @@ -1103,7 +1097,7 @@ public class TestPlanService { } public String getShareReport() { - Object microServices = gatewayService.getMicroServices(); + Object microServices = DiscoveryUtil.getServices(); return replaceSharReport(microServices); } @@ -1301,7 +1295,7 @@ public class TestPlanService { returnDTO.setTestPlanSimpleReportDTO(report); if (apiBaseInfoChanged) { - testPlanReportContentWithBLOBs.setApiBaseCount(JSONObject.toJSONString(report)); + testPlanReportContentWithBLOBs.setApiBaseCount(JSON.toJSONString(report)); returnDTO.setApiBaseInfoChanged(true); } return returnDTO; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java deleted file mode 100644 index 184e7a757f..0000000000 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/gateway/GatewayService.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.metersphere.plan.service.remote.gateway; - -import io.metersphere.commons.constants.MicroServiceName; -import io.metersphere.dto.ServiceDTO; -import io.metersphere.service.RemoteService; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class GatewayService extends RemoteService { - public GatewayService() { - super(MicroServiceName.GATEWAY); - } - - public List getMicroServices() { - return microService.getForDataArray(serviceName, "/services", ServiceDTO.class); - } -} diff --git a/test-track/backend/src/main/java/io/metersphere/utils/DiscoveryUtil.java b/test-track/backend/src/main/java/io/metersphere/utils/DiscoveryUtil.java index 3d9a32e3ca..81cf6590d9 100644 --- a/test-track/backend/src/main/java/io/metersphere/utils/DiscoveryUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/utils/DiscoveryUtil.java @@ -2,8 +2,9 @@ package io.metersphere.utils; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.dto.ServiceDTO; -import io.metersphere.plan.service.remote.gateway.GatewayService; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -14,10 +15,16 @@ public class DiscoveryUtil { } public static Set getServiceIdSet() { - GatewayService gatewayService = CommonBeanFactory.getBean(GatewayService.class); - return gatewayService.getMicroServices() + DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class); + return discoveryClient.getServices() .stream() - .map(ServiceDTO::getServiceId) .collect(Collectors.toSet()); } + + public static List getServices() { + DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class); + return discoveryClient.getServices().stream() + .map(service -> new ServiceDTO(service, discoveryClient.getInstances(service).get(0).getPort())) + .collect(Collectors.toList()); + } }