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.service.ServiceUtils;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.xpack.utils.XpackUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -295,7 +296,7 @@ public class TestPlanReportService {
} }
try { try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
// todo 远程调用失败处理逻辑 // todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>(); Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId); List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
@ -362,33 +363,23 @@ public class TestPlanReportService {
if (saveRequest.isCountResources()) { if (saveRequest.isCountResources()) {
String planId = saveRequest.getPlanId(); String planId = saveRequest.getPlanId();
try {
if (serviceIdSet.contains(MicroServiceName.API_TEST)) { if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId)); testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId));
testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId)); testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId));
} }
} catch (Exception e) {
LogUtil.error(e);
}
try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId)); testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
} }
} catch (Exception e) {
LogUtil.error(e);
}
try {
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId())); testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId()));
} }
} catch (Exception e) {
LogUtil.error(e);
}
} else { } else {
testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting()); testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting());
testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting()); testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting());

View File

@ -48,6 +48,7 @@ import io.metersphere.service.*;
import io.metersphere.utils.DiscoveryUtil; import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.utils.LoggerUtil; import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.xpack.utils.XpackUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -363,7 +364,7 @@ public class TestPlanService {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId); 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); calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId);
} }
@ -1004,7 +1005,6 @@ public class TestPlanService {
return null; return null;
} }
@Transactional(rollbackFor = Exception.class)
public TestPlan copy(String planId) { public TestPlan copy(String planId) {
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId); TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId);
if (testPlan == null) { if (testPlan == null) {
@ -1047,7 +1047,6 @@ public class TestPlanService {
} }
} }
@Transactional(rollbackFor = Exception.class)
public void copyPlanCase(String sourcePlanId, String targetPlanId) { public void copyPlanCase(String sourcePlanId, String targetPlanId) {
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId); testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId);
@ -1076,10 +1075,26 @@ public class TestPlanService {
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
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); planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId);
planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); planTestPlanScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId); planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId); planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (sqlSession != null && sqlSessionFactory != null) { if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);