refactor(接口测试): 资源池执行前校验当前站点
--bug=1039322 --user=陈建星 【接口测试】系统-资源池-错误的当前站点url-使用该资源池执行接口,一直在加载中状态 https://www.tapd.cn/55049933/s/1501013
This commit is contained in:
parent
008817403b
commit
3051af68e0
|
@ -0,0 +1,28 @@
|
||||||
|
package io.metersphere.sdk.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jianxing
|
||||||
|
*/
|
||||||
|
public enum TaskRunnerResultCode implements IResultCode {
|
||||||
|
|
||||||
|
MS_URL_NOT_AVAILABLE(200001, "ms_url_not_available");
|
||||||
|
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
TaskRunnerResultCode(int code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return getTranslationMessage(this.message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -528,3 +528,4 @@ relate_source_type_not_blank=关联资源类型不能为空
|
||||||
api_import_schedule=接口定义-定时导入任务
|
api_import_schedule=接口定义-定时导入任务
|
||||||
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
project.description.length_range=项目描述长度必须在{min}和{max}之间
|
||||||
api_test_environment_datasource_connect_failed=数据源连接失败
|
api_test_environment_datasource_connect_failed=数据源连接失败
|
||||||
|
ms_url_not_available=资源池无法访问当前站点
|
|
@ -566,3 +566,4 @@ api_test_environment_datasource_connect_failed=Data source connection failed
|
||||||
|
|
||||||
permission.api_definition.delete_and_recover=Delete/Recover
|
permission.api_definition.delete_and_recover=Delete/Recover
|
||||||
permission.service_integration.reset=Reset
|
permission.service_integration.reset=Reset
|
||||||
|
ms_url_not_available=The resource pool cannot access the current site
|
||||||
|
|
|
@ -563,3 +563,4 @@ api_test_environment_datasource_connect_failed=数据源连接失败
|
||||||
|
|
||||||
permission.api_definition.delete_and_recover=删除/恢复
|
permission.api_definition.delete_and_recover=删除/恢复
|
||||||
permission.service_integration.reset=重置
|
permission.service_integration.reset=重置
|
||||||
|
ms_url_not_available=资源池无法访问当前站点
|
|
@ -563,3 +563,4 @@ project.description.length_range=項目描述長度必須在{min}和{max}之間
|
||||||
|
|
||||||
permission.api_definition.delete_and_recover=刪除/恢復
|
permission.api_definition.delete_and_recover=刪除/恢復
|
||||||
permission.service_integration.reset=重置
|
permission.service_integration.reset=重置
|
||||||
|
ms_url_not_available=資源池無法訪問當前站點
|
|
@ -27,11 +27,13 @@ import io.metersphere.sdk.dto.api.task.ApiExecuteFileInfo;
|
||||||
import io.metersphere.sdk.dto.api.task.ApiRunModeConfigDTO;
|
import io.metersphere.sdk.dto.api.task.ApiRunModeConfigDTO;
|
||||||
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
|
import io.metersphere.sdk.exception.TaskRunnerResultCode;
|
||||||
import io.metersphere.sdk.file.FileCenter;
|
import io.metersphere.sdk.file.FileCenter;
|
||||||
import io.metersphere.sdk.file.FileRepository;
|
import io.metersphere.sdk.file.FileRepository;
|
||||||
import io.metersphere.sdk.file.FileRequest;
|
import io.metersphere.sdk.file.FileRequest;
|
||||||
import io.metersphere.sdk.util.*;
|
import io.metersphere.sdk.util.*;
|
||||||
import io.metersphere.system.config.MinioProperties;
|
import io.metersphere.system.config.MinioProperties;
|
||||||
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.domain.TestResourcePool;
|
import io.metersphere.system.domain.TestResourcePool;
|
||||||
import io.metersphere.system.dto.pool.TestResourceNodeDTO;
|
import io.metersphere.system.dto.pool.TestResourceNodeDTO;
|
||||||
import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO;
|
import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO;
|
||||||
|
@ -50,6 +52,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.client.HttpServerErrorException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -164,17 +167,29 @@ public class ApiExecuteService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return doExecute(taskRequest);
|
return doExecute(taskRequest);
|
||||||
|
} catch (HttpServerErrorException e) {
|
||||||
|
handleDoExecuteException(scriptRedisKey, e);
|
||||||
|
int errorCode = e.getResponseBodyAs(ResultHolder.class).getCode();
|
||||||
|
for (TaskRunnerResultCode taskRunnerResultCode : TaskRunnerResultCode.values()) {
|
||||||
|
// 匹配资源池的错误代码,抛出相应异常
|
||||||
|
if (taskRunnerResultCode.getCode() == errorCode) {
|
||||||
|
throw new MSException(taskRunnerResultCode, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
||||||
} catch (MSException e) {
|
} catch (MSException e) {
|
||||||
LogUtils.error(e);
|
handleDoExecuteException(scriptRedisKey, e);
|
||||||
// 调用失败清理脚本
|
|
||||||
stringRedisTemplate.delete(scriptRedisKey);
|
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
handleDoExecuteException(scriptRedisKey, e);
|
||||||
|
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDoExecuteException(String scriptRedisKey, Exception e) {
|
||||||
LogUtils.error(e);
|
LogUtils.error(e);
|
||||||
// 调用失败清理脚本
|
// 调用失败清理脚本
|
||||||
stringRedisTemplate.delete(scriptRedisKey);
|
stringRedisTemplate.delete(scriptRedisKey);
|
||||||
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GlobalParams getGlobalParam(String projectId) {
|
private GlobalParams getGlobalParam(String projectId) {
|
||||||
|
|
Loading…
Reference in New Issue