From 593b6882fa451417dc8302889387e86244003666 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 26 Mar 2020 17:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/docker/DockerTestEngine.java | 12 ++++--- .../docker/request/DockerLoginRequest.java | 31 +++++++++++++++++++ .../docker}/request/TestRequest.java | 4 +-- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/engine/docker/request/DockerLoginRequest.java rename backend/src/main/java/io/metersphere/{controller => engine/docker}/request/TestRequest.java (90%) diff --git a/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java index af7cb5b7f0..b08cb4676c 100644 --- a/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java @@ -6,11 +6,12 @@ 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.controller.request.TestRequest; import io.metersphere.dto.NodeDTO; import io.metersphere.engine.AbstractEngine; import io.metersphere.engine.EngineContext; import io.metersphere.engine.EngineFactory; +import io.metersphere.engine.docker.request.DockerLoginRequest; +import io.metersphere.engine.docker.request.TestRequest; import io.metersphere.engine.kubernetes.registry.RegistryService; import org.apache.commons.lang3.StringUtils; import org.springframework.web.client.RestTemplate; @@ -85,10 +86,12 @@ public class DockerTestEngine extends AbstractEngine { testRequest.setFileString(content); testRequest.setImage(registryService.getRegistry() + JMETER_IMAGE); testRequest.setTestData(context.getTestData()); - + testRequest.setRegistry(registryService.getRegistryUrl()); + testRequest.setPassword(registryService.getRegistryPassword()); + testRequest.setUsername(registryService.getRegistryUsername()); // todo 判断测试状态 String taskStatusUri = String.format(BASE_URL + "/jmeter/task/status/" + testId, nodeIp, port); - List containerList = restTemplate.getForObject(taskStatusUri, List.class); + List containerList = restTemplate.postForObject(taskStatusUri, testRequest, List.class); for (int i = 0; i < containerList.size(); i++) { HashMap h = (HashMap) containerList.get(i); if (StringUtils.equals((String) h.get("State"), "running")) { @@ -103,13 +106,14 @@ public class DockerTestEngine extends AbstractEngine { public void stop() { // TODO 停止运行测试 String testId = loadTest.getId(); + DockerLoginRequest request = new DockerLoginRequest(); this.resourceList.forEach(r -> { NodeDTO node = JSON.parseObject(r.getConfiguration(), NodeDTO.class); String ip = node.getIp(); Integer port = node.getPort(); String uri = String.format(BASE_URL + "/jmeter/container/stop/" + testId, ip, port); - restTemplate.postForObject(uri, "", String.class); + restTemplate.postForObject(uri, request, String.class); }); diff --git a/backend/src/main/java/io/metersphere/engine/docker/request/DockerLoginRequest.java b/backend/src/main/java/io/metersphere/engine/docker/request/DockerLoginRequest.java new file mode 100644 index 0000000000..db6ab045a8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/engine/docker/request/DockerLoginRequest.java @@ -0,0 +1,31 @@ +package io.metersphere.engine.docker.request; + +public class DockerLoginRequest { + private String username; + private String password; + private String registry; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRegistry() { + return registry; + } + + public void setRegistry(String registry) { + this.registry = registry; + } +} diff --git a/backend/src/main/java/io/metersphere/controller/request/TestRequest.java b/backend/src/main/java/io/metersphere/engine/docker/request/TestRequest.java similarity index 90% rename from backend/src/main/java/io/metersphere/controller/request/TestRequest.java rename to backend/src/main/java/io/metersphere/engine/docker/request/TestRequest.java index 22061bdaec..3f4131886b 100644 --- a/backend/src/main/java/io/metersphere/controller/request/TestRequest.java +++ b/backend/src/main/java/io/metersphere/engine/docker/request/TestRequest.java @@ -1,9 +1,9 @@ -package io.metersphere.controller.request; +package io.metersphere.engine.docker.request; import java.util.HashMap; import java.util.Map; -public class TestRequest { +public class TestRequest extends DockerLoginRequest { private int size; private String fileString;