关于并发数
This commit is contained in:
parent
9d10c1e037
commit
db211cb76b
|
@ -19,6 +19,8 @@ public class LoadTest implements Serializable {
|
||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
private String testResourcePoolId;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -84,4 +86,12 @@ public class LoadTest implements Serializable {
|
||||||
public void setStatus(String status) {
|
public void setStatus(String status) {
|
||||||
this.status = status == null ? null : status.trim();
|
this.status = status == null ? null : status.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTestResourcePoolId() {
|
||||||
|
return testResourcePoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestResourcePoolId(String testResourcePoolId) {
|
||||||
|
this.testResourcePoolId = testResourcePoolId == null ? null : testResourcePoolId.trim();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -643,6 +643,76 @@ public class LoadTestExample {
|
||||||
addCriterion("status not between", value1, value2, "status");
|
addCriterion("status not between", value1, value2, "status");
|
||||||
return (Criteria) this;
|
return (Criteria) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdIsNull() {
|
||||||
|
addCriterion("test_resource_pool_id is null");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdIsNotNull() {
|
||||||
|
addCriterion("test_resource_pool_id is not null");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdEqualTo(String value) {
|
||||||
|
addCriterion("test_resource_pool_id =", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdNotEqualTo(String value) {
|
||||||
|
addCriterion("test_resource_pool_id <>", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdGreaterThan(String value) {
|
||||||
|
addCriterion("test_resource_pool_id >", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdGreaterThanOrEqualTo(String value) {
|
||||||
|
addCriterion("test_resource_pool_id >=", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdLessThan(String value) {
|
||||||
|
addCriterion("test_resource_pool_id <", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdLessThanOrEqualTo(String value) {
|
||||||
|
addCriterion("test_resource_pool_id <=", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdLike(String value) {
|
||||||
|
addCriterion("test_resource_pool_id like", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdNotLike(String value) {
|
||||||
|
addCriterion("test_resource_pool_id not like", value, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdIn(List<String> values) {
|
||||||
|
addCriterion("test_resource_pool_id in", values, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdNotIn(List<String> values) {
|
||||||
|
addCriterion("test_resource_pool_id not in", values, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdBetween(String value1, String value2) {
|
||||||
|
addCriterion("test_resource_pool_id between", value1, value2, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Criteria andTestResourcePoolIdNotBetween(String value1, String value2) {
|
||||||
|
addCriterion("test_resource_pool_id not between", value1, value2, "testResourcePoolId");
|
||||||
|
return (Criteria) this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Criteria extends GeneratedCriteria {
|
public static class Criteria extends GeneratedCriteria {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<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="status" jdbcType="VARCHAR" property="status" />
|
<result column="status" jdbcType="VARCHAR" property="status" />
|
||||||
|
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestWithBLOBs">
|
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestWithBLOBs">
|
||||||
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
|
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
</sql>
|
</sql>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, project_id, name, description, scenario_definition, create_time, update_time,
|
id, project_id, name, description, scenario_definition, create_time, update_time,
|
||||||
status
|
status, test_resource_pool_id
|
||||||
</sql>
|
</sql>
|
||||||
<sql id="Blob_Column_List">
|
<sql id="Blob_Column_List">
|
||||||
load_configuration, advanced_configuration, schedule
|
load_configuration, advanced_configuration, schedule
|
||||||
|
@ -132,14 +133,14 @@
|
||||||
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
||||||
insert into load_test (id, project_id, name,
|
insert into load_test (id, project_id, name,
|
||||||
description, scenario_definition, create_time,
|
description, scenario_definition, create_time,
|
||||||
update_time, status, load_configuration,
|
update_time, status, test_resource_pool_id,
|
||||||
advanced_configuration, schedule
|
load_configuration, advanced_configuration,
|
||||||
)
|
schedule)
|
||||||
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
|
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
|
||||||
#{description,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
|
#{description,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
|
||||||
#{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR},
|
#{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR},
|
||||||
#{advancedConfiguration,jdbcType=LONGVARCHAR}, #{schedule,jdbcType=LONGVARCHAR}
|
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR},
|
||||||
)
|
#{schedule,jdbcType=LONGVARCHAR})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
||||||
insert into load_test
|
insert into load_test
|
||||||
|
@ -168,6 +169,9 @@
|
||||||
<if test="status != null">
|
<if test="status != null">
|
||||||
status,
|
status,
|
||||||
</if>
|
</if>
|
||||||
|
<if test="testResourcePoolId != null">
|
||||||
|
test_resource_pool_id,
|
||||||
|
</if>
|
||||||
<if test="loadConfiguration != null">
|
<if test="loadConfiguration != null">
|
||||||
load_configuration,
|
load_configuration,
|
||||||
</if>
|
</if>
|
||||||
|
@ -203,6 +207,9 @@
|
||||||
<if test="status != null">
|
<if test="status != null">
|
||||||
#{status,jdbcType=VARCHAR},
|
#{status,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="testResourcePoolId != null">
|
||||||
|
#{testResourcePoolId,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
<if test="loadConfiguration != null">
|
<if test="loadConfiguration != null">
|
||||||
#{loadConfiguration,jdbcType=LONGVARCHAR},
|
#{loadConfiguration,jdbcType=LONGVARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
@ -247,6 +254,9 @@
|
||||||
<if test="record.status != null">
|
<if test="record.status != null">
|
||||||
status = #{record.status,jdbcType=VARCHAR},
|
status = #{record.status,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="record.testResourcePoolId != null">
|
||||||
|
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
<if test="record.loadConfiguration != null">
|
<if test="record.loadConfiguration != null">
|
||||||
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
|
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
@ -271,6 +281,7 @@
|
||||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||||
update_time = #{record.updateTime,jdbcType=BIGINT},
|
update_time = #{record.updateTime,jdbcType=BIGINT},
|
||||||
status = #{record.status,jdbcType=VARCHAR},
|
status = #{record.status,jdbcType=VARCHAR},
|
||||||
|
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
|
||||||
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
|
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
|
||||||
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
|
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
|
||||||
schedule = #{record.schedule,jdbcType=LONGVARCHAR}
|
schedule = #{record.schedule,jdbcType=LONGVARCHAR}
|
||||||
|
@ -287,7 +298,8 @@
|
||||||
scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR},
|
scenario_definition = #{record.scenarioDefinition,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},
|
||||||
status = #{record.status,jdbcType=VARCHAR}
|
status = #{record.status,jdbcType=VARCHAR},
|
||||||
|
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}
|
||||||
<if test="_parameter != null">
|
<if test="_parameter != null">
|
||||||
<include refid="Update_By_Example_Where_Clause" />
|
<include refid="Update_By_Example_Where_Clause" />
|
||||||
</if>
|
</if>
|
||||||
|
@ -316,6 +328,9 @@
|
||||||
<if test="status != null">
|
<if test="status != null">
|
||||||
status = #{status,jdbcType=VARCHAR},
|
status = #{status,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="testResourcePoolId != null">
|
||||||
|
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
<if test="loadConfiguration != null">
|
<if test="loadConfiguration != null">
|
||||||
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
|
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
|
||||||
</if>
|
</if>
|
||||||
|
@ -337,6 +352,7 @@
|
||||||
create_time = #{createTime,jdbcType=BIGINT},
|
create_time = #{createTime,jdbcType=BIGINT},
|
||||||
update_time = #{updateTime,jdbcType=BIGINT},
|
update_time = #{updateTime,jdbcType=BIGINT},
|
||||||
status = #{status,jdbcType=VARCHAR},
|
status = #{status,jdbcType=VARCHAR},
|
||||||
|
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
|
||||||
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
|
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
|
||||||
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
|
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
|
||||||
schedule = #{schedule,jdbcType=LONGVARCHAR}
|
schedule = #{schedule,jdbcType=LONGVARCHAR}
|
||||||
|
@ -350,7 +366,8 @@
|
||||||
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
|
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
|
||||||
create_time = #{createTime,jdbcType=BIGINT},
|
create_time = #{createTime,jdbcType=BIGINT},
|
||||||
update_time = #{updateTime,jdbcType=BIGINT},
|
update_time = #{updateTime,jdbcType=BIGINT},
|
||||||
status = #{status,jdbcType=VARCHAR}
|
status = #{status,jdbcType=VARCHAR},
|
||||||
|
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}
|
||||||
where id = #{id,jdbcType=VARCHAR}
|
where id = #{id,jdbcType=VARCHAR}
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
|
@ -1,7 +1,12 @@
|
||||||
package io.metersphere.engine;
|
package io.metersphere.engine;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.FileMetadata;
|
||||||
|
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface Engine {
|
public interface Engine {
|
||||||
boolean init(EngineContext context);
|
boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EngineFactory {
|
public class EngineFactory {
|
||||||
|
private static final String RESOURCE_POOL_ID = "resourcePoolId";
|
||||||
private static FileService fileService;
|
private static FileService fileService;
|
||||||
private static TestResourcePoolService testResourcePoolService;
|
private static TestResourcePoolService testResourcePoolService;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class EngineFactory {
|
||||||
final JSONArray jsonArray = JSONObject.parseArray(loadTest.getLoadConfiguration());
|
final JSONArray jsonArray = JSONObject.parseArray(loadTest.getLoadConfiguration());
|
||||||
for (int i = 0; i < jsonArray.size(); i++) {
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
final JSONObject jsonObject = jsonArray.getJSONObject(i);
|
final JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||||
if (StringUtils.equals(jsonObject.getString("key"), "resourcePoolId")) {
|
if (StringUtils.equals(jsonObject.getString("key"), RESOURCE_POOL_ID)) {
|
||||||
resourcePoolId = jsonObject.getString("value");
|
resourcePoolId = jsonObject.getString("value");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ public class EngineFactory {
|
||||||
for (int i = 0; i < jsonArray.size(); i++) {
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
final JSONObject jsonObject = jsonArray.getJSONObject(i);
|
final JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||||
engineContext.addProperty(jsonObject.getString("key"), jsonObject.get("value"));
|
engineContext.addProperty(jsonObject.getString("key"), jsonObject.get("value"));
|
||||||
if (StringUtils.equals(jsonObject.getString("key"), "resourcePoolId")) {
|
if (StringUtils.equals(jsonObject.getString("key"), RESOURCE_POOL_ID)) {
|
||||||
engineContext.setResourcePoolId(jsonObject.getString("value"));
|
engineContext.setResourcePoolId(jsonObject.getString("value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,8 +92,10 @@ public class EngineFactory {
|
||||||
MSException.throwException("File type unknown");
|
MSException.throwException("File type unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = engineSourceParser.parse(engineContext, new ByteArrayInputStream(fileContent.getFile()));
|
try (ByteArrayInputStream source = new ByteArrayInputStream(fileContent.getFile())) {
|
||||||
|
String content = engineSourceParser.parse(engineContext, source);
|
||||||
engineContext.setContent(content);
|
engineContext.setContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(csvFiles)) {
|
if (CollectionUtils.isNotEmpty(csvFiles)) {
|
||||||
Map<String, String> data = new HashMap<>();
|
Map<String, String> data = new HashMap<>();
|
||||||
|
|
|
@ -1,69 +1,121 @@
|
||||||
package io.metersphere.engine.kubernetes;
|
package io.metersphere.engine.kubernetes;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.fabric8.kubernetes.api.model.ConfigMap;
|
import io.fabric8.kubernetes.api.model.ConfigMap;
|
||||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
|
import io.metersphere.base.domain.FileMetadata;
|
||||||
|
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||||
import io.metersphere.base.domain.TestResource;
|
import io.metersphere.base.domain.TestResource;
|
||||||
import io.metersphere.base.domain.TestResourcePool;
|
import io.metersphere.base.domain.TestResourcePool;
|
||||||
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
||||||
|
import io.metersphere.commons.constants.TestStatus;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.engine.Engine;
|
import io.metersphere.engine.Engine;
|
||||||
import io.metersphere.engine.EngineContext;
|
import io.metersphere.engine.EngineContext;
|
||||||
|
import io.metersphere.engine.EngineFactory;
|
||||||
import io.metersphere.engine.kubernetes.crds.jmeter.Jmeter;
|
import io.metersphere.engine.kubernetes.crds.jmeter.Jmeter;
|
||||||
import io.metersphere.engine.kubernetes.crds.jmeter.JmeterSpec;
|
import io.metersphere.engine.kubernetes.crds.jmeter.JmeterSpec;
|
||||||
import io.metersphere.engine.kubernetes.provider.ClientCredential;
|
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.LoadTestService;
|
||||||
import io.metersphere.service.TestResourcePoolService;
|
import io.metersphere.service.TestResourcePoolService;
|
||||||
import io.metersphere.service.TestResourceService;
|
import io.metersphere.service.TestResourceService;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class KubernetesTestEngine implements Engine {
|
public class KubernetesTestEngine implements Engine {
|
||||||
private EngineContext context;
|
private FileMetadata jmxFile;
|
||||||
private TestResourcePoolService testResourcePoolService;
|
private List<FileMetadata> csvFiles;
|
||||||
private TestResourceService testResourceService;
|
private LoadTestWithBLOBs loadTest;
|
||||||
|
private LoadTestService loadTestService;
|
||||||
|
private Integer threadNum;
|
||||||
|
|
||||||
|
private String resourcePoolId;
|
||||||
|
private List<TestResource> resourceList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(EngineContext context) {
|
public boolean init(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles) {
|
||||||
this.context = context;
|
this.loadTest = loadTest;
|
||||||
this.testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
|
this.jmxFile = fileMetadata;
|
||||||
this.testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
|
this.csvFiles = csvFiles;
|
||||||
return true;
|
TestResourcePoolService testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
|
||||||
}
|
TestResourceService testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
|
||||||
|
this.loadTestService = CommonBeanFactory.getBean(LoadTestService.class);
|
||||||
|
|
||||||
|
String loadConfiguration = loadTest.getLoadConfiguration();
|
||||||
@Override
|
JSONArray jsonArray = JSON.parseArray(loadConfiguration);
|
||||||
public void start() {
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
if (context == null) {
|
JSONObject o = jsonArray.getJSONObject(i);
|
||||||
LogUtil.warn("Please initial the engine.");
|
if (StringUtils.equals("resourcePoolId", o.getString("key"))) {
|
||||||
return;
|
resourcePoolId = o.getString("value");
|
||||||
}
|
}
|
||||||
TestResourcePool resourcePool = testResourcePoolService.getResourcePool(context.getResourcePoolId());
|
if (StringUtils.equals(o.getString("key"), "TargetLevel")) {
|
||||||
|
threadNum = o.getInteger("value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(resourcePoolId)) {
|
||||||
|
MSException.throwException("Resource Pool ID is empty");
|
||||||
|
}
|
||||||
|
TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId);
|
||||||
if (resourcePool == null) {
|
if (resourcePool == null) {
|
||||||
MSException.throwException("Resource Pool is empty");
|
MSException.throwException("Resource Pool is empty");
|
||||||
}
|
}
|
||||||
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())) {
|
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())) {
|
||||||
MSException.throwException("Invalid Resource Pool type.");
|
MSException.throwException("Invalid Resource Pool type.");
|
||||||
}
|
}
|
||||||
List<TestResource> resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());
|
this.resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());
|
||||||
if (CollectionUtils.isEmpty(resourceList)) {
|
if (CollectionUtils.isEmpty(this.resourceList)) {
|
||||||
MSException.throwException("Test Resource is empty");
|
MSException.throwException("Test Resource is empty");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
// resourceList size 1
|
// resourceList size 1
|
||||||
|
List<LoadTestWithBLOBs> loadTests = loadTestService.selectByTestResourcePoolId(resourcePoolId);
|
||||||
|
// 使用当前资源池正在运行的测试占用的并发数
|
||||||
|
Integer sumThreadNum = loadTests.stream().filter(t -> TestStatus.Running.name().equals(t.getStatus())).map(t -> {
|
||||||
|
Integer s = 0;
|
||||||
|
String loadConfiguration = t.getLoadConfiguration();
|
||||||
|
JSONArray jsonArray = JSON.parseArray(loadConfiguration);
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
JSONObject o = jsonArray.getJSONObject(i);
|
||||||
|
if (StringUtils.equals(o.getString("key"), "TargetLevel")) {
|
||||||
|
s = o.getInteger("value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}).reduce(Integer::sum).orElse(0);
|
||||||
resourceList.forEach(r -> {
|
resourceList.forEach(r -> {
|
||||||
String configuration = r.getConfiguration();
|
String configuration = r.getConfiguration();
|
||||||
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
|
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
|
||||||
runTest(clientCredential);
|
// 最大并发数
|
||||||
|
Integer maxConcurrency = clientCredential.getMaxConcurrency();
|
||||||
|
// 当前测试需要的并发数大于剩余的并发数报错
|
||||||
|
if (threadNum > maxConcurrency - sumThreadNum) {
|
||||||
|
MSException.throwException("资源不足");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
EngineContext context = EngineFactory.createContext(loadTest, jmxFile, csvFiles);
|
||||||
|
runTest(context, clientCredential, 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(ClientCredential credential) {
|
private void runTest(EngineContext context, ClientCredential credential, int replicas) {
|
||||||
KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential));
|
KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential));
|
||||||
// create namespace
|
// create namespace
|
||||||
kubernetesProvider.confirmNamespace(context.getNamespace());
|
kubernetesProvider.confirmNamespace(context.getNamespace());
|
||||||
|
@ -94,7 +146,7 @@ public class KubernetesTestEngine implements Engine {
|
||||||
setName(context.getTestId());
|
setName(context.getTestId());
|
||||||
}});
|
}});
|
||||||
jmeter.setSpec(new JmeterSpec() {{
|
jmeter.setSpec(new JmeterSpec() {{
|
||||||
setReplicas(1);
|
setReplicas(replicas);
|
||||||
setImage("registry.fit2cloud.com/metersphere/jmeter-master:0.0.2");
|
setImage("registry.fit2cloud.com/metersphere/jmeter-master:0.0.2");
|
||||||
}});
|
}});
|
||||||
LogUtil.info("Load test started. " + context.getTestId());
|
LogUtil.info("Load test started. " + context.getTestId());
|
||||||
|
|
|
@ -313,7 +313,7 @@ public class JmeterDocumentParser implements DocumentParser {
|
||||||
threadGroup.appendChild(createStringProp(document, "LogFilename", ""));
|
threadGroup.appendChild(createStringProp(document, "LogFilename", ""));
|
||||||
threadGroup.appendChild(createStringProp(document, "Iterations", "1"));
|
threadGroup.appendChild(createStringProp(document, "Iterations", "1"));
|
||||||
// todo 单位是S 要修改 成M
|
// todo 单位是S 要修改 成M
|
||||||
threadGroup.appendChild(createStringProp(document, "Unit", "S"));
|
threadGroup.appendChild(createStringProp(document, "Unit", "M"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCheckoutTimer(Element element) {
|
private void processCheckoutTimer(Element element) {
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class LoadTestService {
|
||||||
|
|
||||||
boolean init = true;
|
boolean init = true;
|
||||||
try {
|
try {
|
||||||
init = engine.init(EngineFactory.createContext(loadTest, fileMetadata, csvFiles));
|
init = engine.init(loadTest, fileMetadata, csvFiles);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MSException.throwException(e);
|
MSException.throwException(e);
|
||||||
}
|
}
|
||||||
|
@ -226,4 +226,10 @@ public class LoadTestService {
|
||||||
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
|
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
|
||||||
return Optional.ofNullable(loadTestWithBLOBs).orElse(new LoadTestWithBLOBs()).getLoadConfiguration();
|
return Optional.ofNullable(loadTestWithBLOBs).orElse(new LoadTestWithBLOBs()).getLoadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<LoadTestWithBLOBs> selectByTestResourcePoolId(String resourcePoolId) {
|
||||||
|
LoadTestExample example = new LoadTestExample();
|
||||||
|
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
|
||||||
|
return loadTestMapper.selectByExampleWithBLOBs(example);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS `load_test` (
|
||||||
`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',
|
||||||
`status` varchar(64) DEFAULT NULL COMMENT 'Test Status Running, Completed, Error, etc.',
|
`status` varchar(64) DEFAULT NULL COMMENT 'Test Status Running, Completed, Error, etc.',
|
||||||
|
`test_resource_pool_id` varchar(50) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
)
|
)
|
||||||
ENGINE = InnoDB
|
ENGINE = InnoDB
|
||||||
|
|
|
@ -56,9 +56,9 @@
|
||||||
<!-- <table tableName="project"/>-->
|
<!-- <table tableName="project"/>-->
|
||||||
<!-- <table tableName="organization"/>-->
|
<!-- <table tableName="organization"/>-->
|
||||||
<!-- <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>
|
|
@ -160,6 +160,7 @@
|
||||||
this.testPlan.updatedFileList = this.$refs.basicConfig.updatedFileList();
|
this.testPlan.updatedFileList = this.$refs.basicConfig.updatedFileList();
|
||||||
// 压力配置
|
// 压力配置
|
||||||
this.testPlan.loadConfiguration = JSON.stringify(this.$refs.pressureConfig.convertProperty());
|
this.testPlan.loadConfiguration = JSON.stringify(this.$refs.pressureConfig.convertProperty());
|
||||||
|
this.testPlan.testResourcePoolId = this.$refs.pressureConfig.resourcePool;
|
||||||
// 高级配置
|
// 高级配置
|
||||||
this.testPlan.advancedConfiguration = JSON.stringify(this.$refs.advancedConfig.configurations());
|
this.testPlan.advancedConfiguration = JSON.stringify(this.$refs.advancedConfig.configurations());
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,6 @@
|
||||||
const STEPS = "Steps";
|
const STEPS = "Steps";
|
||||||
const DURATION = "duration";
|
const DURATION = "duration";
|
||||||
const RPS_LIMIT = "rpsLimit";
|
const RPS_LIMIT = "rpsLimit";
|
||||||
const RESOURCE_POOL = "resourcePoolId";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "PerformancePressureConfig",
|
name: "PerformancePressureConfig",
|
||||||
|
@ -174,9 +173,6 @@
|
||||||
case RPS_LIMIT:
|
case RPS_LIMIT:
|
||||||
this.rpsLimit = d.value;
|
this.rpsLimit = d.value;
|
||||||
break;
|
break;
|
||||||
case RESOURCE_POOL:
|
|
||||||
this.resourcePool = d.value;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -299,7 +295,6 @@
|
||||||
{key: STEPS, value: this.step},
|
{key: STEPS, value: this.step},
|
||||||
{key: DURATION, value: this.duration},
|
{key: DURATION, value: this.duration},
|
||||||
{key: RPS_LIMIT, value: this.rpsLimit},
|
{key: RPS_LIMIT, value: this.rpsLimit},
|
||||||
{key: RESOURCE_POOL, value: this.resourcePool},
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue