fix(测试跟踪): 开源用户copy测试计划提示UI服务异常

--bug=1019261 --user=陈建星 [测试跟踪]开源版-复制测试计划失败,提示UI服务异常 https://www.tapd.cn/55049933/s/1286005
This commit is contained in:
chenjianxing 2022-11-02 10:58:47 +08:00 committed by zhangdahai112
parent 98fce03ef7
commit 5113b46ab0
3 changed files with 53 additions and 30 deletions

View File

@ -0,0 +1,17 @@
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;
}
}

View File

@ -29,6 +29,7 @@ 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;
@ -295,7 +296,7 @@ public class TestPlanReportService {
}
try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
// todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
@ -362,33 +363,23 @@ public class TestPlanReportService {
if (saveRequest.isCountResources()) {
String planId = saveRequest.getPlanId();
try {
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId));
testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId));
}
} catch (Exception e) {
LogUtil.error(e);
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId));
testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId));
}
try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
}
} catch (Exception e) {
LogUtil.error(e);
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
}
try {
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId()));
}
} catch (Exception e) {
LogUtil.error(e);
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId()));
}
} else {
testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting());
testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting());

View File

@ -48,6 +48,7 @@ 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;
@ -363,7 +364,7 @@ public class TestPlanService {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId);
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId);
}
@ -1004,7 +1005,6 @@ public class TestPlanService {
return null;
}
@Transactional(rollbackFor = Exception.class)
public TestPlan copy(String planId) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId);
if (testPlan == null) {
@ -1047,7 +1047,6 @@ public class TestPlanService {
}
}
@Transactional(rollbackFor = Exception.class)
public void copyPlanCase(String sourcePlanId, String targetPlanId) {
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId);
@ -1076,10 +1075,26 @@ public class TestPlanService {
}
sqlSession.flushStatements();
planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId);
planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId);
planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
try {
planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId);
} catch (Exception e) {
LogUtil.error(e);
}
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId);
planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);