This commit is contained in:
Captain.B 2020-03-23 18:58:14 +08:00
parent e699eaf04d
commit fdb6d69050
12 changed files with 48 additions and 135 deletions

View File

@ -9,8 +9,6 @@ public class FileMetadata implements Serializable {
private String type; private String type;
private String engine;
private Long createTime; private Long createTime;
private Long updateTime; private Long updateTime;
@ -43,14 +41,6 @@ public class FileMetadata implements Serializable {
this.type = type == null ? null : type.trim(); this.type = type == null ? null : type.trim();
} }
public String getEngine() {
return engine;
}
public void setEngine(String engine) {
this.engine = engine == null ? null : engine.trim();
}
public Long getCreateTime() { public Long getCreateTime() {
return createTime; return createTime;
} }

View File

@ -314,76 +314,6 @@ public class FileMetadataExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andEngineIsNull() {
addCriterion("engine is null");
return (Criteria) this;
}
public Criteria andEngineIsNotNull() {
addCriterion("engine is not null");
return (Criteria) this;
}
public Criteria andEngineEqualTo(String value) {
addCriterion("engine =", value, "engine");
return (Criteria) this;
}
public Criteria andEngineNotEqualTo(String value) {
addCriterion("engine <>", value, "engine");
return (Criteria) this;
}
public Criteria andEngineGreaterThan(String value) {
addCriterion("engine >", value, "engine");
return (Criteria) this;
}
public Criteria andEngineGreaterThanOrEqualTo(String value) {
addCriterion("engine >=", value, "engine");
return (Criteria) this;
}
public Criteria andEngineLessThan(String value) {
addCriterion("engine <", value, "engine");
return (Criteria) this;
}
public Criteria andEngineLessThanOrEqualTo(String value) {
addCriterion("engine <=", value, "engine");
return (Criteria) this;
}
public Criteria andEngineLike(String value) {
addCriterion("engine like", value, "engine");
return (Criteria) this;
}
public Criteria andEngineNotLike(String value) {
addCriterion("engine not like", value, "engine");
return (Criteria) this;
}
public Criteria andEngineIn(List<String> values) {
addCriterion("engine in", values, "engine");
return (Criteria) this;
}
public Criteria andEngineNotIn(List<String> values) {
addCriterion("engine not in", values, "engine");
return (Criteria) this;
}
public Criteria andEngineBetween(String value1, String value2) {
addCriterion("engine between", value1, value2, "engine");
return (Criteria) this;
}
public Criteria andEngineNotBetween(String value1, String value2) {
addCriterion("engine not between", value1, value2, "engine");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() { public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null"); addCriterion("create_time is null");
return (Criteria) this; return (Criteria) this;

View File

@ -5,7 +5,6 @@
<id column="id" jdbcType="VARCHAR" property="id" /> <id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="type" jdbcType="VARCHAR" property="type" /> <result column="type" jdbcType="VARCHAR" property="type" />
<result column="engine" jdbcType="VARCHAR" property="engine" />
<result column="create_time" jdbcType="BIGINT" property="createTime" /> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" /> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="size" jdbcType="BIGINT" property="size" /> <result column="size" jdbcType="BIGINT" property="size" />
@ -69,7 +68,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, name, type, engine, create_time, update_time, size id, name, type, create_time, update_time, size
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.FileMetadataExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.base.domain.FileMetadataExample" resultMap="BaseResultMap">
select select
@ -103,11 +102,11 @@
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.base.domain.FileMetadata"> <insert id="insert" parameterType="io.metersphere.base.domain.FileMetadata">
insert into file_metadata (id, name, type, insert into file_metadata (id, name, type,
engine, create_time, update_time, create_time, update_time, size
size) )
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{engine,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{size,jdbcType=BIGINT}
#{size,jdbcType=BIGINT}) )
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.FileMetadata"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.FileMetadata">
insert into file_metadata insert into file_metadata
@ -121,9 +120,6 @@
<if test="type != null"> <if test="type != null">
type, type,
</if> </if>
<if test="engine != null">
engine,
</if>
<if test="createTime != null"> <if test="createTime != null">
create_time, create_time,
</if> </if>
@ -144,9 +140,6 @@
<if test="type != null"> <if test="type != null">
#{type,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
</if> </if>
<if test="engine != null">
#{engine,jdbcType=VARCHAR},
</if>
<if test="createTime != null"> <if test="createTime != null">
#{createTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
</if> </if>
@ -176,9 +169,6 @@
<if test="record.type != null"> <if test="record.type != null">
type = #{record.type,jdbcType=VARCHAR}, type = #{record.type,jdbcType=VARCHAR},
</if> </if>
<if test="record.engine != null">
engine = #{record.engine,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null"> <if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
</if> </if>
@ -198,7 +188,6 @@
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR}, name = #{record.name,jdbcType=VARCHAR},
type = #{record.type,jdbcType=VARCHAR}, type = #{record.type,jdbcType=VARCHAR},
engine = #{record.engine,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
size = #{record.size,jdbcType=BIGINT} size = #{record.size,jdbcType=BIGINT}
@ -215,9 +204,6 @@
<if test="type != null"> <if test="type != null">
type = #{type,jdbcType=VARCHAR}, type = #{type,jdbcType=VARCHAR},
</if> </if>
<if test="engine != null">
engine = #{engine,jdbcType=VARCHAR},
</if>
<if test="createTime != null"> <if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
</if> </if>
@ -234,7 +220,6 @@
update file_metadata update file_metadata
set name = #{name,jdbcType=VARCHAR}, set name = #{name,jdbcType=VARCHAR},
type = #{type,jdbcType=VARCHAR}, type = #{type,jdbcType=VARCHAR},
engine = #{engine,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
size = #{size,jdbcType=BIGINT} size = #{size,jdbcType=BIGINT}

View File

@ -1,5 +0,0 @@
package io.metersphere.commons.constants;
public enum EngineType {
DOCKER, KUBERNETES
}

View File

@ -7,7 +7,6 @@ public class EngineContext {
private String testId; private String testId;
private String testName; private String testName;
private String namespace; private String namespace;
private String engineType;
private String fileType; private String fileType;
private String content; private String content;
private Map<String, Object> properties = new HashMap<>(); private Map<String, Object> properties = new HashMap<>();
@ -37,14 +36,6 @@ public class EngineContext {
this.namespace = namespace; this.namespace = namespace;
} }
public String getEngineType() {
return engineType;
}
public void setEngineType(String engineType) {
this.engineType = engineType;
}
public void addProperty(String key, Object value) { public void addProperty(String key, Object value) {
this.properties.put(key, value); this.properties.put(key, value);
} }

View File

@ -5,7 +5,8 @@ import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.FileContent; import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTestWithBLOBs; import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.commons.constants.EngineType; import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.engine.docker.DockerTestEngine; import io.metersphere.engine.docker.DockerTestEngine;
import io.metersphere.engine.kubernetes.KubernetesTestEngine; import io.metersphere.engine.kubernetes.KubernetesTestEngine;
@ -13,6 +14,7 @@ import io.metersphere.i18n.Translator;
import io.metersphere.parse.EngineSourceParser; import io.metersphere.parse.EngineSourceParser;
import io.metersphere.parse.EngineSourceParserFactory; import io.metersphere.parse.EngineSourceParserFactory;
import io.metersphere.service.FileService; import io.metersphere.service.FileService;
import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,14 +28,35 @@ import java.util.Map;
@Service @Service
public class EngineFactory { public class EngineFactory {
private static FileService fileService; private static FileService fileService;
private static TestResourcePoolService testResourcePoolService;
public static Engine createEngine(String engineType) { public static Engine createEngine(LoadTestWithBLOBs loadTest) {
final EngineType type = EngineType.valueOf(engineType); String resourcePoolId = null;
if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) {
final JSONArray jsonArray = JSONObject.parseArray(loadTest.getLoadConfiguration());
for (int i = 0; i < jsonArray.size(); i++) {
final JSONObject jsonObject = jsonArray.getJSONObject(i);
if (StringUtils.equals(jsonObject.getString("key"), "resourcePoolId")) {
resourcePoolId = jsonObject.getString("value");
break;
}
}
}
if (StringUtils.isBlank(resourcePoolId)) {
MSException.throwException("Resource Pool ID is empty.");
}
TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId);
if (resourcePool == null) {
MSException.throwException("Resource Pool is empty.");
}
final ResourcePoolTypeEnum type = ResourcePoolTypeEnum.valueOf(resourcePool.getType());
switch (type) { switch (type) {
case DOCKER: case NODE:
return new DockerTestEngine(); return new DockerTestEngine();
case KUBERNETES: case K8S:
return new KubernetesTestEngine(); return new KubernetesTestEngine();
} }
return null; return null;
@ -48,7 +71,6 @@ public class EngineFactory {
engineContext.setTestId(loadTest.getId()); engineContext.setTestId(loadTest.getId());
engineContext.setTestName(loadTest.getName()); engineContext.setTestName(loadTest.getName());
engineContext.setNamespace(loadTest.getProjectId()); engineContext.setNamespace(loadTest.getProjectId());
engineContext.setEngineType(fileMetadata.getEngine());
engineContext.setFileType(fileMetadata.getType()); engineContext.setFileType(fileMetadata.getType());
if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) { if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) {
@ -86,4 +108,9 @@ public class EngineFactory {
private void setFileService(FileService fileService) { private void setFileService(FileService fileService) {
EngineFactory.fileService = fileService; EngineFactory.fileService = fileService;
} }
@Resource
public void setTestResourcePoolService(TestResourcePoolService testResourcePoolService) {
EngineFactory.testResourcePoolService = testResourcePoolService;
}
} }

View File

@ -14,7 +14,6 @@ import io.metersphere.engine.kubernetes.provider.ClientCredential;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider; import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import io.metersphere.service.TestResourcePoolService; import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;

View File

@ -3,12 +3,9 @@ package io.metersphere.service;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtFunctionalTestMapper; import io.metersphere.base.mapper.ext.ExtFunctionalTestMapper;
import io.metersphere.commons.constants.EngineType;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.testplan.*; import io.metersphere.controller.request.testplan.*;
import io.metersphere.dto.FunctionalTestDTO; import io.metersphere.dto.FunctionalTestDTO;
import io.metersphere.engine.Engine;
import io.metersphere.engine.EngineFactory;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -94,8 +91,6 @@ public class FuctionalTestService {
fileMetadata.setCreateTime(System.currentTimeMillis()); fileMetadata.setCreateTime(System.currentTimeMillis());
fileMetadata.setUpdateTime(System.currentTimeMillis()); fileMetadata.setUpdateTime(System.currentTimeMillis());
fileMetadata.setType("jmx"); fileMetadata.setType("jmx");
// TODO engine 选择
fileMetadata.setEngine(EngineType.DOCKER.name());
fileMetadataMapper.insert(fileMetadata); fileMetadataMapper.insert(fileMetadata);
FileContent fileContent = new FileContent(); FileContent fileContent = new FileContent();

View File

@ -6,7 +6,6 @@ import io.metersphere.base.mapper.FileMetadataMapper;
import io.metersphere.base.mapper.LoadTestFileMapper; import io.metersphere.base.mapper.LoadTestFileMapper;
import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.commons.constants.EngineType;
import io.metersphere.commons.constants.FileType; import io.metersphere.commons.constants.FileType;
import io.metersphere.commons.constants.TestStatus; import io.metersphere.commons.constants.TestStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
@ -45,6 +44,8 @@ public class LoadTestService {
private LoadTestFileMapper loadTestFileMapper; private LoadTestFileMapper loadTestFileMapper;
@Resource @Resource
private FileService fileService; private FileService fileService;
@Resource
private TestResourcePoolService testResourcePoolService;
public List<LoadTestDTO> list(QueryTestPlanRequest request) { public List<LoadTestDTO> list(QueryTestPlanRequest request) {
return extLoadTestMapper.list(request); return extLoadTestMapper.list(request);
@ -102,8 +103,6 @@ public class LoadTestService {
fileMetadata.setUpdateTime(System.currentTimeMillis()); fileMetadata.setUpdateTime(System.currentTimeMillis());
FileType fileType = getFileType(fileMetadata.getName()); FileType fileType = getFileType(fileMetadata.getName());
fileMetadata.setType(fileType.name()); fileMetadata.setType(fileType.name());
// TODO engine 选择
fileMetadata.setEngine(EngineType.DOCKER.name());
fileMetadataMapper.insert(fileMetadata); fileMetadataMapper.insert(fileMetadata);
FileContent fileContent = new FileContent(); FileContent fileContent = new FileContent();
@ -179,9 +178,8 @@ public class LoadTestService {
List<FileMetadata> csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList()); List<FileMetadata> csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList());
LogUtil.info("Load test started " + loadTest.getName()); LogUtil.info("Load test started " + loadTest.getName());
// engine type (DOCKER|KUBERNETES) // engine type (NODE|K8S)
// todo set type final Engine engine = EngineFactory.createEngine(loadTest);
final Engine engine = EngineFactory.createEngine(fileMetadata.getEngine());
if (engine == null) { if (engine == null) {
MSException.throwException(String.format("Test cannot be runtest ID%sfile type%s", request.getId(), fileMetadata.getType())); MSException.throwException(String.format("Test cannot be runtest ID%sfile type%s", request.getId(), fileMetadata.getType()));
} }

View File

@ -113,4 +113,8 @@ public class TestResourcePoolService {
} }
testResourcePool.setInfo(JSON.toJSONString(dtos)); testResourcePool.setInfo(JSON.toJSONString(dtos));
} }
public TestResourcePool getResourcePool(String resourcePoolId) {
return testResourcePoolMapper.selectByPrimaryKey(resourcePoolId);
}
} }

View File

@ -11,7 +11,6 @@ CREATE TABLE IF NOT EXISTS `file_metadata` (
`id` varchar(64) NOT NULL COMMENT 'File ID', `id` varchar(64) NOT NULL COMMENT 'File ID',
`name` varchar(64) NOT NULL COMMENT 'File name', `name` varchar(64) NOT NULL COMMENT 'File name',
`type` varchar(64) DEFAULT NULL COMMENT 'File type', `type` varchar(64) DEFAULT NULL COMMENT 'File type',
`engine` varchar(64) DEFAULT 'DOCKER' COMMENT 'engine type',
`size` bigint(13) NOT NULL COMMENT 'File size', `size` bigint(13) NOT NULL COMMENT 'File size',
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp', `create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp', `update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',

View File

@ -48,7 +48,7 @@
<!-- <table tableName="user"/>--> <!-- <table tableName="user"/>-->
<!-- <table tableName="user_role"/>--> <!-- <table tableName="user_role"/>-->
<!-- <table tableName="workspace"/>--> <!-- <table tableName="workspace"/>-->
<table tableName="test_resource_pool"/> <!-- <table tableName="test_resource_pool"/>-->
<!-- <table tableName="test_resource"/>--> <!-- <table tableName="test_resource"/>-->
<!-- <table tableName="system_parameter"/>--> <!-- <table tableName="system_parameter"/>-->
<!-- <table tableName="role"/>--> <!-- <table tableName="role"/>-->
@ -57,7 +57,7 @@
<!-- <table tableName="load_test_report"/>--> <!-- <table tableName="load_test_report"/>-->
<!-- <table tableName="load_test"/>--> <!-- <table tableName="load_test"/>-->
<!-- <table tableName="file_content"/>--> <!-- <table tableName="file_content"/>-->
<!-- <table tableName="file_metadata"/>--> <table tableName="file_metadata"/>
<!-- <table tableName="load_test_file"/>--> <!-- <table tableName="load_test_file"/>-->
</context> </context>
</generatorConfiguration> </generatorConfiguration>