DockerTestEngine

This commit is contained in:
shiziyuan9527 2020-03-18 14:53:31 +08:00
parent e2af4ef462
commit 330f9def83
3 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,32 @@
package io.metersphere.controller.request;
public class TestRequest {
int size;
String fileString;
String testId;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getFileString() {
return fileString;
}
public void setFileString(String fileString) {
this.fileString = fileString;
}
public String getTestId() {
return testId;
}
public void setTestId(String testId) {
this.testId = testId;
}
}

View File

@ -1,7 +1,14 @@
package io.metersphere.engine.docker; package io.metersphere.engine.docker;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.TestRequest;
import io.metersphere.engine.Engine; import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineContext; import io.metersphere.engine.EngineContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
public class DockerTestEngine implements Engine { public class DockerTestEngine implements Engine {
private EngineContext context; private EngineContext context;
@ -15,11 +22,38 @@ public class DockerTestEngine implements Engine {
@Override @Override
public void start() { public void start() {
RestTemplate restTemplate = new RestTemplate();
String testId = context.getTestId();
String content = context.getContent();
String uri = "http://localhost:8082/jmeter/container/start";
TestRequest testRequest = new TestRequest();
testRequest.setSize(1);
testRequest.setTestId(testId);
testRequest.setFileString(content);
String taskStatusUri = "http://localhost:8082/jmeter/task/status/" + testId;
List containerList = restTemplate.getForObject(taskStatusUri, List.class);
for (int i = 0; i < containerList.size(); i++) {
HashMap h = (HashMap) containerList.get(i);
if (StringUtils.equals((String)h.get("State"), "running")) {
MSException.throwException("the test is running!");
}
}
restTemplate.postForObject(uri, testRequest, String.class);
} }
@Override @Override
public void stop() { public void stop() {
RestTemplate restTemplate = new RestTemplate();
String testId = context.getTestId();
String uri = "http://localhost:8082/jmeter/container/stop" + testId;
restTemplate.getForObject(uri, String.class);
} }
} }

View File

@ -97,7 +97,7 @@ public class LoadTestService {
fileMetadata.setSize(file.getSize()); fileMetadata.setSize(file.getSize());
fileMetadata.setCreateTime(System.currentTimeMillis()); fileMetadata.setCreateTime(System.currentTimeMillis());
fileMetadata.setUpdateTime(System.currentTimeMillis()); fileMetadata.setUpdateTime(System.currentTimeMillis());
fileMetadata.setType("jmx"); fileMetadata.setType("JMX");
// TODO engine 选择 // TODO engine 选择
fileMetadata.setEngine(EngineType.DOCKER.name()); fileMetadata.setEngine(EngineType.DOCKER.name());
fileMetadataMapper.insert(fileMetadata); fileMetadataMapper.insert(fileMetadata);