mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-03 20:49:56 +08:00
DockerTestEngine
This commit is contained in:
parent
e2af4ef462
commit
330f9def83
@ -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;
|
||||
}
|
||||
}
|
@ -1,7 +1,14 @@
|
||||
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.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 {
|
||||
private EngineContext context;
|
||||
@ -15,11 +22,38 @@ public class DockerTestEngine implements Engine {
|
||||
|
||||
@Override
|
||||
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
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class LoadTestService {
|
||||
fileMetadata.setSize(file.getSize());
|
||||
fileMetadata.setCreateTime(System.currentTimeMillis());
|
||||
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||
fileMetadata.setType("jmx");
|
||||
fileMetadata.setType("JMX");
|
||||
// TODO engine 选择
|
||||
fileMetadata.setEngine(EngineType.DOCKER.name());
|
||||
fileMetadataMapper.insert(fileMetadata);
|
||||
|
Loading…
Reference in New Issue
Block a user