From 2abc0bd91257fb0ec6765fafe145e6f74413c28b Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 14 Sep 2020 16:08:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A4=84=E7=90=86=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AE=B9=E5=99=A8=E7=9A=84=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/docker/DockerTestEngine.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java index 1ab74dd46d..ade042112a 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java @@ -6,7 +6,7 @@ import io.metersphere.base.domain.TestResource; import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.LogUtil; +import io.metersphere.controller.ResultHolder; import io.metersphere.dto.NodeDTO; import io.metersphere.i18n.Translator; import io.metersphere.performance.engine.AbstractEngine; @@ -87,12 +87,14 @@ public class DockerTestEngine extends AbstractEngine { testRequest.setTestData(context.getTestData()); testRequest.setEnv(context.getEnv()); - try { - restTemplate.postForObject(uri, testRequest, String.class); - } catch (Exception e) { - LogUtil.error(e); + + ResultHolder result = restTemplate.postForObject(uri, testRequest, ResultHolder.class); + if (result == null) { MSException.throwException(Translator.get("start_engine_fail")); } + if (!result.isSuccess()) { + MSException.throwException(result.getMessage()); + } } @Override @@ -105,12 +107,13 @@ public class DockerTestEngine extends AbstractEngine { Integer port = node.getPort(); String uri = String.format(BASE_URL + "/jmeter/container/stop/" + testId, ip, port); - try { - restTemplateWithTimeOut.getForObject(uri, String.class); - } catch (Exception e) { - LogUtil.error("stop load test fail... " + testId, e); + ResultHolder result = restTemplateWithTimeOut.getForObject(uri, ResultHolder.class); + if (result == null) { MSException.throwException(Translator.get("container_delete_fail")); } + if (!result.isSuccess()) { + MSException.throwException(result.getMessage()); + } }); } }