fix(接口测试): 修复k8s资源池没有可用的pod无提示问题
--bug=1020710 --user=赵勇 【接口测试】K8S资源池异常时接口测试执行失败未正常处理 https://www.tapd.cn/55049933/s/1313865
This commit is contained in:
parent
6204c6b8cd
commit
e0309cbe2d
|
@ -2,12 +2,14 @@ package io.metersphere.api.exec.engine;
|
||||||
|
|
||||||
import io.fabric8.kubernetes.api.model.Pod;
|
import io.fabric8.kubernetes.api.model.Pod;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
|
import io.metersphere.api.dto.MsgDTO;
|
||||||
import io.metersphere.base.domain.TestResource;
|
import io.metersphere.base.domain.TestResource;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.constants.ExtendedParameter;
|
import io.metersphere.commons.constants.ExtendedParameter;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.JSON;
|
import io.metersphere.commons.utils.JSON;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
|
import io.metersphere.commons.utils.WebSocketUtil;
|
||||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||||
import io.metersphere.utils.LoggerUtil;
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import io.metersphere.xpack.resourcepool.engine.provider.ClientCredential;
|
import io.metersphere.xpack.resourcepool.engine.provider.ClientCredential;
|
||||||
|
@ -21,6 +23,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public class KubernetesTestEngine extends AbstractEngine {
|
public class KubernetesTestEngine extends AbstractEngine {
|
||||||
private JmeterRunRequestDTO runRequest;
|
private JmeterRunRequestDTO runRequest;
|
||||||
|
private final String DEBUG_ERROR = "DEBUG_ERROR";
|
||||||
|
|
||||||
// 初始化API调用
|
// 初始化API调用
|
||||||
public KubernetesTestEngine(JmeterRunRequestDTO runRequest) {
|
public KubernetesTestEngine(JmeterRunRequestDTO runRequest) {
|
||||||
|
@ -77,6 +80,14 @@ public class KubernetesTestEngine extends AbstractEngine {
|
||||||
command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(path);
|
command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(path);
|
||||||
KubernetesApiExec.newExecWatch(client, clientCredential.getNamespace(), pod.getMetadata().getName(), command.toString());
|
KubernetesApiExec.newExecWatch(client, clientCredential.getNamespace(), pod.getMetadata().getName(), command.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
MsgDTO dto = new MsgDTO();
|
||||||
|
dto.setExecEnd(false);
|
||||||
|
dto.setContent(DEBUG_ERROR);
|
||||||
|
dto.setReportId("send." + runRequest.getReportId());
|
||||||
|
dto.setToReport(runRequest.getReportId());
|
||||||
|
LoggerUtil.debug("send. " + runRequest.getReportId());
|
||||||
|
WebSocketUtil.sendMessageSingle(dto);
|
||||||
|
WebSocketUtil.onClose(runRequest.getReportId());
|
||||||
LoggerUtil.error("当前报告:【" + runRequest.getReportId() + "】资源:【" + runRequest.getTestId() + "】CURL失败:", e);
|
LoggerUtil.error("当前报告:【" + runRequest.getReportId() + "】资源:【" + runRequest.getTestId() + "】CURL失败:", e);
|
||||||
MSException.throwException(e);
|
MSException.throwException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -503,6 +503,14 @@ export default {
|
||||||
this.runningEvaluation(e.data);
|
this.runningEvaluation(e.data);
|
||||||
this.sort(this.fullTreeNodes);
|
this.sort(this.fullTreeNodes);
|
||||||
}
|
}
|
||||||
|
if (e && e.data === 'DEBUG_ERROR') {
|
||||||
|
this.$error(this.$t('api_definition.debug_pool_warning'));
|
||||||
|
this.messageWebSocket.close();
|
||||||
|
this.cleanHeartBeat();
|
||||||
|
this.$EventBus.$emit('hide', this.scenarioId);
|
||||||
|
this.$emit('refresh', this.debugResult);
|
||||||
|
}
|
||||||
|
|
||||||
if (e.data && e.data.indexOf('MS_TEST_END') !== -1) {
|
if (e.data && e.data.indexOf('MS_TEST_END') !== -1) {
|
||||||
this.getReport();
|
this.getReport();
|
||||||
this.messageWebSocket.close();
|
this.messageWebSocket.close();
|
||||||
|
|
|
@ -1233,6 +1233,11 @@ export default {
|
||||||
if (e && e.data === 'CONN_SUCCEEDED') {
|
if (e && e.data === 'CONN_SUCCEEDED') {
|
||||||
this.run();
|
this.run();
|
||||||
}
|
}
|
||||||
|
if (e && e.data === 'DEBUG_ERROR') {
|
||||||
|
this.$error(this.$t('api_definition.debug_pool_warning'));
|
||||||
|
this.messageWebSocket.close();
|
||||||
|
this.errorRefresh();
|
||||||
|
}
|
||||||
if (e.data && e.data.startsWith('result_')) {
|
if (e.data && e.data.startsWith('result_')) {
|
||||||
let data = JSON.parse(e.data.substring(7));
|
let data = JSON.parse(e.data.substring(7));
|
||||||
this.reqTotal += 1;
|
this.reqTotal += 1;
|
||||||
|
|
|
@ -292,6 +292,13 @@ export default {
|
||||||
if (e && e.data === 'CONN_SUCCEEDED') {
|
if (e && e.data === 'CONN_SUCCEEDED') {
|
||||||
this.runDebug();
|
this.runDebug();
|
||||||
}
|
}
|
||||||
|
if (e && e.data === 'DEBUG_ERROR') {
|
||||||
|
this.$error(this.$t('api_definition.debug_pool_warning'));
|
||||||
|
this.loading = false;
|
||||||
|
this.node.expanded = true;
|
||||||
|
this.messageWebSocket.close();
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
if (e.data && e.data.startsWith('result_')) {
|
if (e.data && e.data.startsWith('result_')) {
|
||||||
let data = JSON.parse(e.data.substring(7));
|
let data = JSON.parse(e.data.substring(7));
|
||||||
this.debugCode(data);
|
this.debugCode(data);
|
||||||
|
|
|
@ -62,7 +62,11 @@ export default {
|
||||||
if (e && e.data === 'CONN_SUCCEEDED') {
|
if (e && e.data === 'CONN_SUCCEEDED') {
|
||||||
this.run();
|
this.run();
|
||||||
}
|
}
|
||||||
|
if (e && e.data === 'DEBUG_ERROR') {
|
||||||
|
this.$error(this.$t('api_definition.debug_pool_warning'));
|
||||||
|
this.websocket.close();
|
||||||
|
this.$emit('errorRefresh', '');
|
||||||
|
}
|
||||||
if (e.data && e.data.startsWith('result_')) {
|
if (e.data && e.data.startsWith('result_')) {
|
||||||
try {
|
try {
|
||||||
let data = e.data.substring(7);
|
let data = e.data.substring(7);
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
:isStop="isStop"
|
:isStop="isStop"
|
||||||
:run-data="runData"
|
:run-data="runData"
|
||||||
@runRefresh="runRefresh"
|
@runRefresh="runRefresh"
|
||||||
|
@errorRefresh="errorRefresh"
|
||||||
ref="runTest" />
|
ref="runTest" />
|
||||||
</el-card>
|
</el-card>
|
||||||
<div v-if="scenario">
|
<div v-if="scenario">
|
||||||
|
@ -188,11 +189,14 @@ export default {
|
||||||
this.reportId = getUUID().substring(0, 8);
|
this.reportId = getUUID().substring(0, 8);
|
||||||
},
|
},
|
||||||
runRefresh(data) {
|
runRefresh(data) {
|
||||||
this.responseData = data;
|
this.responseData = data || { type: 'DUBBO', responseResult: {}, subRequestResults: [] };
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.isStop = false;
|
this.isStop = false;
|
||||||
this.$refs.debugResult.reload();
|
this.$refs.debugResult.reload();
|
||||||
},
|
},
|
||||||
|
errorRefresh() {
|
||||||
|
this.runRefresh();
|
||||||
|
},
|
||||||
saveAsApi() {
|
saveAsApi() {
|
||||||
let obj = { request: this.request };
|
let obj = { request: this.request };
|
||||||
obj.request.id = getUUID();
|
obj.request.id = getUUID();
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
:isStop="isStop"
|
:isStop="isStop"
|
||||||
:run-data="runData"
|
:run-data="runData"
|
||||||
@runRefresh="runRefresh"
|
@runRefresh="runRefresh"
|
||||||
|
@errorRefresh="errorRefresh"
|
||||||
ref="runTest" />
|
ref="runTest" />
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
@ -240,13 +241,16 @@ export default {
|
||||||
this.$emit('refreshModule');
|
this.$emit('refreshModule');
|
||||||
},
|
},
|
||||||
runRefresh(data) {
|
runRefresh(data) {
|
||||||
this.responseData = data;
|
this.responseData = data || { type: 'HTTP', responseResult: {}, subRequestResults: [] };
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.isStop = false;
|
this.isStop = false;
|
||||||
if (this.$refs.debugResult) {
|
if (this.$refs.debugResult) {
|
||||||
this.$refs.debugResult.reload();
|
this.$refs.debugResult.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
errorRefresh() {
|
||||||
|
this.runRefresh();
|
||||||
|
},
|
||||||
saveAsApi() {
|
saveAsApi() {
|
||||||
this.$refs['debugForm'].validate((valid) => {
|
this.$refs['debugForm'].validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
:isStop="isStop"
|
:isStop="isStop"
|
||||||
:run-data="runData"
|
:run-data="runData"
|
||||||
@runRefresh="runRefresh"
|
@runRefresh="runRefresh"
|
||||||
|
@errorRefresh="errorRefresh"
|
||||||
ref="runTest" />
|
ref="runTest" />
|
||||||
</el-card>
|
</el-card>
|
||||||
<div v-if="scenario">
|
<div v-if="scenario">
|
||||||
|
@ -194,13 +195,16 @@ export default {
|
||||||
this.reportId = getUUID().substring(0, 8);
|
this.reportId = getUUID().substring(0, 8);
|
||||||
},
|
},
|
||||||
runRefresh(data) {
|
runRefresh(data) {
|
||||||
this.responseData = data;
|
this.responseData = data || { type: 'JDBC', responseResult: {}, subRequestResults: [] };
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.isStop = false;
|
this.isStop = false;
|
||||||
if (this.$refs.debugResult) {
|
if (this.$refs.debugResult) {
|
||||||
this.$refs.debugResult.reload();
|
this.$refs.debugResult.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
errorRefresh() {
|
||||||
|
this.runRefresh();
|
||||||
|
},
|
||||||
saveAsApi() {
|
saveAsApi() {
|
||||||
let obj = { request: this.request };
|
let obj = { request: this.request };
|
||||||
obj.request.id = getUUID();
|
obj.request.id = getUUID();
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
:isStop="isStop"
|
:isStop="isStop"
|
||||||
:run-data="runData"
|
:run-data="runData"
|
||||||
@runRefresh="runRefresh"
|
@runRefresh="runRefresh"
|
||||||
|
@errorRefresh="errorRefresh"
|
||||||
ref="runTest" />
|
ref="runTest" />
|
||||||
</el-card>
|
</el-card>
|
||||||
<div v-if="scenario">
|
<div v-if="scenario">
|
||||||
|
@ -193,13 +194,16 @@ export default {
|
||||||
this.reportId = getUUID().substring(0, 8);
|
this.reportId = getUUID().substring(0, 8);
|
||||||
},
|
},
|
||||||
runRefresh(data) {
|
runRefresh(data) {
|
||||||
this.responseData = data;
|
this.responseData = data || { type: 'TCP', responseResult: {}, subRequestResults: [] };
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.isStop = false;
|
this.isStop = false;
|
||||||
if (this.$refs.debugResult) {
|
if (this.$refs.debugResult) {
|
||||||
this.$refs.debugResult.reload();
|
this.$refs.debugResult.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
errorRefresh() {
|
||||||
|
this.runRefresh();
|
||||||
|
},
|
||||||
saveAsApi() {
|
saveAsApi() {
|
||||||
let obj = { request: this.request };
|
let obj = { request: this.request };
|
||||||
obj.request.id = getUUID();
|
obj.request.id = getUUID();
|
||||||
|
|
|
@ -7,6 +7,8 @@ const message = {
|
||||||
please_add_api_case: 'Please add api case',
|
please_add_api_case: 'Please add api case',
|
||||||
},
|
},
|
||||||
api_definition: {
|
api_definition: {
|
||||||
|
debug_pool_warning:
|
||||||
|
'Failed to call the resource pool, please check whether the configuration of the resource pool is normal',
|
||||||
document: {
|
document: {
|
||||||
name: 'name',
|
name: 'name',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
|
|
|
@ -7,6 +7,7 @@ const message = {
|
||||||
please_add_api_case: '请先添加接口用例',
|
please_add_api_case: '请先添加接口用例',
|
||||||
},
|
},
|
||||||
api_definition: {
|
api_definition: {
|
||||||
|
debug_pool_warning: '调用资源池执行失败,请检查资源池是否配置正常',
|
||||||
document: {
|
document: {
|
||||||
name: '名称',
|
name: '名称',
|
||||||
value: '值',
|
value: '值',
|
||||||
|
|
|
@ -7,6 +7,7 @@ const message = {
|
||||||
please_add_api_case: '请先添加接口用例',
|
please_add_api_case: '请先添加接口用例',
|
||||||
},
|
},
|
||||||
api_definition: {
|
api_definition: {
|
||||||
|
debug_pool_warning: '調用資源池執行失敗,請檢查資源池是否配置正常',
|
||||||
document: {
|
document: {
|
||||||
name: '名稱',
|
name: '名稱',
|
||||||
value: '值',
|
value: '值',
|
||||||
|
|
Loading…
Reference in New Issue