启动测试
This commit is contained in:
parent
c4cfae5bae
commit
e1a1175cc9
|
@ -7,10 +7,13 @@ import io.metersphere.base.domain.FileMetadata;
|
|||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.base.domain.TestResourcePool;
|
||||
import io.metersphere.commons.constants.FileType;
|
||||
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
||||
import io.metersphere.commons.constants.TestStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.LoadTestService;
|
||||
import io.metersphere.service.TestResourcePoolService;
|
||||
import io.metersphere.service.TestResourceService;
|
||||
|
@ -18,6 +21,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractEngine implements Engine {
|
||||
protected FileMetadata jmxFile;
|
||||
|
@ -27,13 +31,35 @@ public abstract class AbstractEngine implements Engine {
|
|||
protected Integer threadNum;
|
||||
protected List<TestResource> resourceList;
|
||||
|
||||
private TestResourcePoolService testResourcePoolService;
|
||||
private TestResourceService testResourceService;
|
||||
private FileService fileService;
|
||||
|
||||
public AbstractEngine() {
|
||||
testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
|
||||
testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
|
||||
fileService = CommonBeanFactory.getBean(FileService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles) {
|
||||
public boolean init(LoadTestWithBLOBs loadTest) {
|
||||
if (loadTest == null) {
|
||||
MSException.throwException("LoadTest is null.");
|
||||
}
|
||||
this.loadTest = loadTest;
|
||||
this.jmxFile = fileMetadata;
|
||||
this.csvFiles = csvFiles;
|
||||
TestResourcePoolService testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
|
||||
TestResourceService testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
|
||||
|
||||
final List<FileMetadata> fileMetadataList = fileService.getFileMetadataByTestId(loadTest.getId());
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(fileMetadataList)) {
|
||||
MSException.throwException(Translator.get("run_load_test_file_not_found") + loadTest.getId());
|
||||
}
|
||||
jmxFile = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.JMX.name()))
|
||||
.findFirst().orElseGet(() -> {
|
||||
throw new RuntimeException(Translator.get("run_load_test_file_not_found") + loadTest.getId());
|
||||
});
|
||||
|
||||
csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList());
|
||||
|
||||
|
||||
this.loadTestService = CommonBeanFactory.getBean(LoadTestService.class);
|
||||
|
||||
threadNum = getThreadNum(loadTest);
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package io.metersphere.engine;
|
||||
|
||||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Engine {
|
||||
boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles);
|
||||
boolean init(LoadTestWithBLOBs loadTest);
|
||||
|
||||
void start();
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.engine.docker;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.commons.constants.ResourceStatusEnum;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
|
@ -24,8 +23,8 @@ public class DockerTestEngine extends AbstractEngine {
|
|||
|
||||
|
||||
@Override
|
||||
public boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles) {
|
||||
super.init(loadTest, fileMetadata, csvFiles);
|
||||
public boolean init(LoadTestWithBLOBs loadTest) {
|
||||
super.init(loadTest);
|
||||
this.restTemplate = CommonBeanFactory.getBean(RestTemplate.class);
|
||||
// todo 初始化操作
|
||||
return true;
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|||
import io.fabric8.kubernetes.api.model.ConfigMap;
|
||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -18,13 +17,12 @@ import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
|
|||
import org.apache.commons.collections.MapUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class KubernetesTestEngine extends AbstractEngine {
|
||||
|
||||
@Override
|
||||
public boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles) {
|
||||
super.init(loadTest, fileMetadata, csvFiles);
|
||||
public boolean init(LoadTestWithBLOBs loadTest) {
|
||||
super.init(loadTest);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import io.metersphere.engine.Engine;
|
|||
import io.metersphere.engine.EngineFactory;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -166,27 +165,16 @@ public class LoadTestService {
|
|||
MSException.throwException(Translator.get("run_load_test_not_found") + request.getId());
|
||||
}
|
||||
|
||||
final List<FileMetadata> fileMetadataList = fileService.getFileMetadataByTestId(request.getId());
|
||||
if (CollectionUtils.isEmpty(fileMetadataList)) {
|
||||
MSException.throwException(Translator.get("run_load_test_file_not_found") + request.getId());
|
||||
}
|
||||
FileMetadata fileMetadata = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.JMX.name()))
|
||||
.findFirst().orElseGet(() -> {
|
||||
throw new RuntimeException(Translator.get("run_load_test_file_not_found") + request.getId());
|
||||
});
|
||||
|
||||
List<FileMetadata> csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList());
|
||||
|
||||
LogUtil.info("Load test started " + loadTest.getName());
|
||||
// engine type (NODE|K8S)
|
||||
final Engine engine = EngineFactory.createEngine(loadTest);
|
||||
if (engine == null) {
|
||||
MSException.throwException(String.format("Test cannot be run,test ID:%s,file type:%s", request.getId(), fileMetadata.getType()));
|
||||
MSException.throwException(String.format("Test cannot be run,test ID:%s", request.getId()));
|
||||
}
|
||||
|
||||
boolean init = true;
|
||||
try {
|
||||
init = engine.init(loadTest, fileMetadata, csvFiles);
|
||||
init = engine.init(loadTest);
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue