This commit is contained in:
chenjianxing 2020-03-25 13:03:16 +08:00
commit d31382ec2a
40 changed files with 683 additions and 565 deletions

View File

@ -19,6 +19,8 @@ public class LoadTest implements Serializable {
private String status;
private String testResourcePoolId;
private static final long serialVersionUID = 1L;
public String getId() {
@ -84,4 +86,12 @@ public class LoadTest implements Serializable {
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getTestResourcePoolId() {
return testResourcePoolId;
}
public void setTestResourcePoolId(String testResourcePoolId) {
this.testResourcePoolId = testResourcePoolId == null ? null : testResourcePoolId.trim();
}
}

View File

@ -643,6 +643,76 @@ public class LoadTestExample {
addCriterion("status not between", value1, value2, "status");
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 {

View File

@ -7,10 +7,6 @@ public class TestResource implements Serializable {
private String testResourcePoolId;
private String name;
private String description;
private String status;
private Long createTime;
@ -37,22 +33,6 @@ public class TestResource implements Serializable {
this.testResourcePoolId = testResourcePoolId == null ? null : testResourcePoolId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getStatus() {
return status;
}

View File

@ -244,146 +244,6 @@ public class TestResourceExample {
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("name is null");
return (Criteria) this;
}
public Criteria andNameIsNotNull() {
addCriterion("name is not null");
return (Criteria) this;
}
public Criteria andNameEqualTo(String value) {
addCriterion("name =", value, "name");
return (Criteria) this;
}
public Criteria andNameNotEqualTo(String value) {
addCriterion("name <>", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThan(String value) {
addCriterion("name >", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("name >=", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThan(String value) {
addCriterion("name <", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("name <=", value, "name");
return (Criteria) this;
}
public Criteria andNameLike(String value) {
addCriterion("name like", value, "name");
return (Criteria) this;
}
public Criteria andNameNotLike(String value) {
addCriterion("name not like", value, "name");
return (Criteria) this;
}
public Criteria andNameIn(List<String> values) {
addCriterion("name in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> values) {
addCriterion("name not in", values, "name");
return (Criteria) this;
}
public Criteria andNameBetween(String value1, String value2) {
addCriterion("name between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("name not between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andDescriptionIsNull() {
addCriterion("description is null");
return (Criteria) this;
}
public Criteria andDescriptionIsNotNull() {
addCriterion("description is not null");
return (Criteria) this;
}
public Criteria andDescriptionEqualTo(String value) {
addCriterion("description =", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotEqualTo(String value) {
addCriterion("description <>", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThan(String value) {
addCriterion("description >", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThanOrEqualTo(String value) {
addCriterion("description >=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThan(String value) {
addCriterion("description <", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThanOrEqualTo(String value) {
addCriterion("description <=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLike(String value) {
addCriterion("description like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotLike(String value) {
addCriterion("description not like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionIn(List<String> values) {
addCriterion("description in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotIn(List<String> values) {
addCriterion("description not in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionBetween(String value1, String value2) {
addCriterion("description between", value1, value2, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotBetween(String value1, String value2) {
addCriterion("description not between", value1, value2, "description");
return (Criteria) this;
}
public Criteria andStatusIsNull() {
addCriterion("status is null");
return (Criteria) this;

View File

@ -13,8 +13,6 @@ public class TestResourcePool implements Serializable {
private String status;
private String info;
private Long createTime;
private Long updateTime;
@ -61,14 +59,6 @@ public class TestResourcePool implements Serializable {
this.status = status == null ? null : status.trim();
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info == null ? null : info.trim();
}
public Long getCreateTime() {
return createTime;
}

View File

@ -454,76 +454,6 @@ public class TestResourcePoolExample {
return (Criteria) this;
}
public Criteria andInfoIsNull() {
addCriterion("info is null");
return (Criteria) this;
}
public Criteria andInfoIsNotNull() {
addCriterion("info is not null");
return (Criteria) this;
}
public Criteria andInfoEqualTo(String value) {
addCriterion("info =", value, "info");
return (Criteria) this;
}
public Criteria andInfoNotEqualTo(String value) {
addCriterion("info <>", value, "info");
return (Criteria) this;
}
public Criteria andInfoGreaterThan(String value) {
addCriterion("info >", value, "info");
return (Criteria) this;
}
public Criteria andInfoGreaterThanOrEqualTo(String value) {
addCriterion("info >=", value, "info");
return (Criteria) this;
}
public Criteria andInfoLessThan(String value) {
addCriterion("info <", value, "info");
return (Criteria) this;
}
public Criteria andInfoLessThanOrEqualTo(String value) {
addCriterion("info <=", value, "info");
return (Criteria) this;
}
public Criteria andInfoLike(String value) {
addCriterion("info like", value, "info");
return (Criteria) this;
}
public Criteria andInfoNotLike(String value) {
addCriterion("info not like", value, "info");
return (Criteria) this;
}
public Criteria andInfoIn(List<String> values) {
addCriterion("info in", values, "info");
return (Criteria) this;
}
public Criteria andInfoNotIn(List<String> values) {
addCriterion("info not in", values, "info");
return (Criteria) this;
}
public Criteria andInfoBetween(String value1, String value2) {
addCriterion("info between", value1, value2, "info");
return (Criteria) this;
}
public Criteria andInfoNotBetween(String value1, String value2) {
addCriterion("info not between", value1, value2, "info");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;

View File

@ -10,6 +10,7 @@
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestWithBLOBs">
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
@ -76,7 +77,7 @@
</sql>
<sql id="Base_Column_List">
id, project_id, name, description, scenario_definition, create_time, update_time,
status
status, test_resource_pool_id
</sql>
<sql id="Blob_Column_List">
load_configuration, advanced_configuration, schedule
@ -132,14 +133,14 @@
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
insert into load_test (id, project_id, name,
description, scenario_definition, create_time,
update_time, status, load_configuration,
advanced_configuration, schedule
)
update_time, status, test_resource_pool_id,
load_configuration, advanced_configuration,
schedule)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR},
#{advancedConfiguration,jdbcType=LONGVARCHAR}, #{schedule,jdbcType=LONGVARCHAR}
)
#{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR},
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR},
#{schedule,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
insert into load_test
@ -168,6 +169,9 @@
<if test="status != null">
status,
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id,
</if>
<if test="loadConfiguration != null">
load_configuration,
</if>
@ -203,6 +207,9 @@
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
<if test="testResourcePoolId != null">
#{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="loadConfiguration != null">
#{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -247,6 +254,9 @@
<if test="record.status != null">
status = #{record.status,jdbcType=VARCHAR},
</if>
<if test="record.testResourcePoolId != null">
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="record.loadConfiguration != null">
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -271,6 +281,7 @@
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
status = #{record.status,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
schedule = #{record.schedule,jdbcType=LONGVARCHAR}
@ -287,7 +298,8 @@
scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR},
create_time = #{record.createTime,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">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -316,6 +328,9 @@
<if test="status != null">
status = #{status,jdbcType=VARCHAR},
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="loadConfiguration != null">
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -337,6 +352,7 @@
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
status = #{status,jdbcType=VARCHAR},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
schedule = #{schedule,jdbcType=LONGVARCHAR}
@ -350,7 +366,8 @@
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
create_time = #{createTime,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}
</update>
</mapper>

View File

@ -4,8 +4,6 @@
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.TestResource">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
@ -72,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, test_resource_pool_id, name, description, status, create_time, update_time
id, test_resource_pool_id, status, create_time, update_time
</sql>
<sql id="Blob_Column_List">
configuration
@ -126,12 +124,12 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestResource">
insert into test_resource (id, test_resource_pool_id, name,
description, status, create_time,
update_time, configuration)
values (#{id,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{configuration,jdbcType=LONGVARCHAR})
insert into test_resource (id, test_resource_pool_id, status,
create_time, update_time, configuration
)
values (#{id,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{configuration,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestResource">
insert into test_resource
@ -142,12 +140,6 @@
<if test="testResourcePoolId != null">
test_resource_pool_id,
</if>
<if test="name != null">
name,
</if>
<if test="description != null">
description,
</if>
<if test="status != null">
status,
</if>
@ -168,12 +160,6 @@
<if test="testResourcePoolId != null">
#{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
@ -203,12 +189,6 @@
<if test="record.testResourcePoolId != null">
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
name = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=VARCHAR},
</if>
<if test="record.status != null">
status = #{record.status,jdbcType=VARCHAR},
</if>
@ -230,8 +210,6 @@
update test_resource
set id = #{record.id,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR},
status = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
@ -244,8 +222,6 @@
update test_resource
set id = #{record.id,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR},
status = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
@ -259,12 +235,6 @@
<if test="testResourcePoolId != null">
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=VARCHAR},
</if>
@ -283,8 +253,6 @@
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.TestResource">
update test_resource
set test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
@ -294,8 +262,6 @@
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.TestResource">
update test_resource
set test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}

View File

@ -7,7 +7,6 @@
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="info" jdbcType="VARCHAR" property="info" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap>
@ -70,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, name, type, description, status, info, create_time, update_time
id, name, type, description, status, create_time, update_time
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.TestResourcePoolExample" resultMap="BaseResultMap">
select
@ -104,11 +103,11 @@
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestResourcePool">
insert into test_resource_pool (id, name, type,
description, status, info,
create_time, update_time)
description, status, create_time,
update_time)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT})
#{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestResourcePool">
insert into test_resource_pool
@ -128,9 +127,6 @@
<if test="status != null">
status,
</if>
<if test="info != null">
info,
</if>
<if test="createTime != null">
create_time,
</if>
@ -154,9 +150,6 @@
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
<if test="info != null">
#{info,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
@ -189,9 +182,6 @@
<if test="record.status != null">
status = #{record.status,jdbcType=VARCHAR},
</if>
<if test="record.info != null">
info = #{record.info,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
@ -210,7 +200,6 @@
type = #{record.type,jdbcType=VARCHAR},
description = #{record.description,jdbcType=VARCHAR},
status = #{record.status,jdbcType=VARCHAR},
info = #{record.info,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
<if test="_parameter != null">
@ -232,9 +221,6 @@
<if test="status != null">
status = #{status,jdbcType=VARCHAR},
</if>
<if test="info != null">
info = #{info,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
@ -250,7 +236,6 @@
type = #{type,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=VARCHAR},
info = #{info,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}

View File

@ -0,0 +1,13 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtTestReourcePoolMapper {
List<TestResourcePoolDTO> listResourcePools(@Param("request") QueryResourcePoolRequest request);
// List<TestResource> listResourcesByPoolId(@Param("poolId") String poolId);
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper">
<resultMap id="TestReourcePoolResultMap" type="io.metersphere.dto.TestResourcePoolDTO">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
<collection property="resources" column="id" ofType="io.metersphere.base.domain.TestResource"
select="io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper.listResourcesByPoolId">
</collection>
</resultMap>
<select id="listResourcePools" resultMap="TestReourcePoolResultMap">
SELECT * FROM test_resource_pool
<where>
<if test="request.name != null">
and test_resource_pool.name like CONCAT('%', #{request.name},'%')
</if>
</where>
</select>
<select id="listResourcesByPoolId" resultType="io.metersphere.base.domain.TestResource">
SELECT * FROM test_resource WHERE test_resource_pool_id = #{id}
</select>
</mapper>

View File

@ -0,0 +1,15 @@
package io.metersphere.commons.constants;
/**
* @author dongbin
*/
public enum ResourceStatusEnum {
/**
* 无效
*/
INVALID,
/**
* 有效
*/
VALID
}

View File

@ -8,6 +8,7 @@ import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.ReportRequest;
import io.metersphere.dto.ReportDTO;
import io.metersphere.report.base.RequestStatistics;
import io.metersphere.service.ReportService;
import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.Logical;
@ -52,5 +53,10 @@ public class ReportController {
return reportService.getReportTestAndProInfo(reportId);
}
@GetMapping("/content/{reportId}")
public List<RequestStatistics> getReportContent(@PathVariable String reportId) {
return reportService.getReport(reportId);
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import io.metersphere.service.TestResourcePoolService;
import org.springframework.web.bind.annotation.*;
@ -20,8 +21,8 @@ public class TestResourcePoolController {
private TestResourcePoolService testResourcePoolService;
@PostMapping("/add")
public TestResourcePool addTestResourcePool(@RequestBody TestResourcePool testResourcePool) {
return testResourcePoolService.addTestResourcePool(testResourcePool);
public TestResourcePoolDTO addTestResourcePool(@RequestBody TestResourcePoolDTO testResourcePoolDTO) {
return testResourcePoolService.addTestResourcePool(testResourcePoolDTO);
}
@GetMapping("/delete/{testResourcePoolId}")
@ -30,18 +31,18 @@ public class TestResourcePoolController {
}
@PostMapping("/update")
public void updateTestResourcePool(@RequestBody TestResourcePool testResourcePool) {
testResourcePoolService.updateTestResourcePool(testResourcePool);
public void updateTestResourcePool(@RequestBody TestResourcePoolDTO testResourcePoolDTO) {
testResourcePoolService.updateTestResourcePool(testResourcePoolDTO);
}
@PostMapping("list/{goPage}/{pageSize}")
public Pager<List<TestResourcePool>> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) {
public Pager<List<TestResourcePoolDTO>> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testResourcePoolService.listResourcePools(request));
}
@GetMapping("list/all")
public List<TestResourcePool> listResourcePools() {
public List<TestResourcePoolDTO> listResourcePools() {
PageHelper.startPage(1, 10000, true);
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
return testResourcePoolService.listResourcePools(request);

View File

@ -24,6 +24,8 @@ public class TestPlanRequest {
private String schedule;
private String testResourcePoolId;
private static final long serialVersionUID = 1L;
@ -115,4 +117,11 @@ public class TestPlanRequest {
this.schedule = schedule == null ? null : schedule.trim();
}
public String getTestResourcePoolId() {
return testResourcePoolId;
}
public void setTestResourcePoolId(String testResourcePoolId) {
this.testResourcePoolId = testResourcePoolId;
}
}

View File

@ -1,41 +0,0 @@
package io.metersphere.dto;
public class KubernetesDTO {
private String masterUrl;
private String token;
private Integer maxConcurrency;
private Boolean validate;
public String getMasterUrl() {
return masterUrl;
}
public void setMasterUrl(String masterUrl) {
this.masterUrl = masterUrl;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public Integer getMaxConcurrency() {
return maxConcurrency;
}
public void setMaxConcurrency(Integer maxConcurrency) {
this.maxConcurrency = maxConcurrency;
}
public Boolean getValidate() {
return validate;
}
public void setValidate(Boolean validate) {
this.validate = validate;
}
}

View File

@ -4,7 +4,6 @@ public class NodeDTO {
private String ip;
private Integer port;
private Integer maxConcurrency;
private Boolean validate;
public String getIp() {
return ip;
@ -29,12 +28,4 @@ public class NodeDTO {
public void setMaxConcurrency(Integer maxConcurrency) {
this.maxConcurrency = maxConcurrency;
}
public Boolean getValidate() {
return validate;
}
public void setValidate(Boolean validate) {
this.validate = validate;
}
}

View File

@ -0,0 +1,19 @@
package io.metersphere.dto;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool;
import java.util.List;
public class TestResourcePoolDTO extends TestResourcePool {
private List<TestResource> resources;
public List<TestResource> getResources() {
return resources;
}
public void setResources(List<TestResource> resources) {
this.resources = resources;
}
}

View File

@ -0,0 +1,85 @@
package io.metersphere.engine;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool;
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.service.LoadTestService;
import io.metersphere.service.TestResourcePoolService;
import io.metersphere.service.TestResourceService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
public abstract class AbstractEngine implements Engine {
protected LoadTestWithBLOBs loadTest;
protected LoadTestService loadTestService;
protected Integer threadNum;
protected List<TestResource> resourceList;
private TestResourcePoolService testResourcePoolService;
private TestResourceService testResourceService;
public AbstractEngine() {
testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
testResourceService = CommonBeanFactory.getBean(TestResourceService.class);
}
@Override
public boolean init(LoadTestWithBLOBs loadTest) {
if (loadTest == null) {
MSException.throwException("LoadTest is null.");
}
this.loadTest = loadTest;
this.loadTestService = CommonBeanFactory.getBean(LoadTestService.class);
threadNum = getThreadNum(loadTest);
String resourcePoolId = loadTest.getTestResourcePoolId();
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");
}
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())) {
MSException.throwException("Invalid Resource Pool type.");
}
this.resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());
if (CollectionUtils.isEmpty(this.resourceList)) {
MSException.throwException("Test Resource is empty");
}
return true;
}
protected Integer getRunningThreadNum() {
List<LoadTestWithBLOBs> loadTests = loadTestService.selectByTestResourcePoolId(loadTest.getTestResourcePoolId());
// 使用当前资源池正在运行的测试占用的并发数
return loadTests.stream()
.filter(t -> TestStatus.Running.name().equals(t.getStatus()))
.map(this::getThreadNum)
.reduce(Integer::sum)
.orElse(0);
}
private Integer getThreadNum(LoadTestWithBLOBs 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;
}
}

View File

@ -1,7 +1,9 @@
package io.metersphere.engine;
import io.metersphere.base.domain.LoadTestWithBLOBs;
public interface Engine {
boolean init(EngineContext context);
boolean init(LoadTestWithBLOBs loadTest);
void start();

View File

@ -9,6 +9,8 @@ public class EngineContext {
private String namespace;
private String fileType;
private String content;
private String resourcePoolId;
private Long threadNum;
private Map<String, Object> properties = new HashMap<>();
private Map<String, String> testData = new HashMap<>();
@ -67,4 +69,20 @@ public class EngineContext {
public void setTestData(Map<String, String> testData) {
this.testData = testData;
}
public String getResourcePoolId() {
return resourcePoolId;
}
public void setResourcePoolId(String resourcePoolId) {
this.resourcePoolId = resourcePoolId;
}
public Long getThreadNum() {
return threadNum;
}
public void setThreadNum(Long threadNum) {
this.threadNum = threadNum;
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.constants.FileType;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.exception.MSException;
import io.metersphere.engine.docker.DockerTestEngine;
@ -24,6 +25,7 @@ import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class EngineFactory {
@ -31,17 +33,7 @@ public class EngineFactory {
private static TestResourcePoolService testResourcePoolService;
public static Engine createEngine(LoadTestWithBLOBs loadTest) {
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;
}
}
}
String resourcePoolId = loadTest.getTestResourcePoolId();
if (StringUtils.isBlank(resourcePoolId)) {
MSException.throwException("Resource Pool ID is empty.");
}
@ -62,8 +54,18 @@ public class EngineFactory {
return null;
}
public static EngineContext createContext(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, List<FileMetadata> csvFiles) throws Exception {
final FileContent fileContent = fileService.getFileContent(fileMetadata.getId());
public static EngineContext createContext(LoadTestWithBLOBs loadTest, long threadNum) throws Exception {
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());
}
FileMetadata 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());
});
List<FileMetadata> csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList());
final FileContent fileContent = fileService.getFileContent(jmxFile.getId());
if (fileContent == null) {
MSException.throwException(Translator.get("run_load_test_file_content_not_found") + loadTest.getId());
}
@ -71,7 +73,9 @@ public class EngineFactory {
engineContext.setTestId(loadTest.getId());
engineContext.setTestName(loadTest.getName());
engineContext.setNamespace(loadTest.getProjectId());
engineContext.setFileType(fileMetadata.getType());
engineContext.setFileType(jmxFile.getType());
engineContext.setThreadNum(threadNum);
engineContext.setResourcePoolId(loadTest.getTestResourcePoolId());
if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) {
final JSONArray jsonArray = JSONObject.parseArray(loadTest.getLoadConfiguration());
@ -88,8 +92,10 @@ public class EngineFactory {
MSException.throwException("File type unknown");
}
String content = engineSourceParser.parse(engineContext, new ByteArrayInputStream(fileContent.getFile()));
engineContext.setContent(content);
try (ByteArrayInputStream source = new ByteArrayInputStream(fileContent.getFile())) {
String content = engineSourceParser.parse(engineContext, source);
engineContext.setContent(content);
}
if (CollectionUtils.isNotEmpty(csvFiles)) {
Map<String, String> data = new HashMap<>();

View File

@ -1,32 +1,67 @@
package io.metersphere.engine.docker;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.controller.request.TestRequest;
import io.metersphere.engine.Engine;
import io.metersphere.dto.NodeDTO;
import io.metersphere.engine.AbstractEngine;
import io.metersphere.engine.EngineContext;
import io.metersphere.engine.EngineFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class DockerTestEngine implements Engine {
private EngineContext context;
public class DockerTestEngine extends AbstractEngine {
private RestTemplate restTemplate;
RestTemplate restTemplate;
@Override
public boolean init(EngineContext context) {
public boolean init(LoadTestWithBLOBs loadTest) {
super.init(loadTest);
this.restTemplate = CommonBeanFactory.getBean(RestTemplate.class);
// todo 初始化操作
this.context = context;
return true;
}
@Override
public void start() {
Integer runningSumThreadNum = getRunningThreadNum();
Integer totalThreadNum = resourceList.stream()
.filter(r -> ResourceStatusEnum.VALID.name().equals(r.getStatus()))
.map(r -> JSON.parseObject(r.getConfiguration(), NodeDTO.class).getMaxConcurrency())
.reduce(Integer::sum)
.orElse(0);
if (threadNum > totalThreadNum - runningSumThreadNum) {
MSException.throwException("Insufficient resources");
}
List<Integer> resourceRatio = resourceList.stream()
.filter(r -> ResourceStatusEnum.VALID.name().equals(r.getStatus()))
.map(r -> JSON.parseObject(r.getConfiguration(), NodeDTO.class).getMaxConcurrency())
.collect(Collectors.toList());
resourceRatio.forEach(ratio -> {
double realThreadNum = ((double) ratio / totalThreadNum) * threadNum;
runTest(Math.round(realThreadNum));
});
}
private void runTest(long realThreadNum) {
// todo 运行测试
// RestTemplate restTemplate = new RestTemplate();
EngineContext context = null;
try {
context = EngineFactory.createContext(loadTest, realThreadNum);
} catch (Exception e) {
e.printStackTrace();
}
String testId = context.getTestId();
String content = context.getContent();
@ -42,7 +77,7 @@ public class DockerTestEngine implements Engine {
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")) {
if (StringUtils.equals((String) h.get("State"), "running")) {
MSException.throwException("the test is running!");
}
}
@ -55,7 +90,7 @@ public class DockerTestEngine implements Engine {
// TODO 停止运行测试
// RestTemplate restTemplate = new RestTemplate();
String testId = context.getTestId();
String testId = loadTest.getId();
String uri = "http://localhost:8082/jmeter/container/stop/" + testId;
restTemplate.postForObject(uri, "", String.class);

View File

@ -4,41 +4,52 @@ 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.commons.utils.CommonBeanFactory;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.engine.Engine;
import io.metersphere.engine.AbstractEngine;
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.JmeterSpec;
import io.metersphere.engine.kubernetes.provider.ClientCredential;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.collections.MapUtils;
import java.util.HashMap;
public class KubernetesTestEngine implements Engine {
private EngineContext context;
private TestResourcePoolService testResourcePoolService;
public class KubernetesTestEngine extends AbstractEngine {
@Override
public boolean init(EngineContext context) {
// todo 初始化操作
this.context = context;
this.testResourcePoolService = CommonBeanFactory.getBean(TestResourcePoolService.class);
public boolean init(LoadTestWithBLOBs loadTest) {
super.init(loadTest);
return true;
}
@Override
public void start() {
if (context == null) {
LogUtil.warn("Please initial the engine.");
return;
}
// todo 运行测试
ClientCredential credential = new ClientCredential();
credential.setMasterUrl("https://172.16.10.93:6443");
Integer sumThreadNum = getRunningThreadNum();
// resourceList size 1
resourceList.forEach(r -> {
String configuration = r.getConfiguration();
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
// 最大并发数
Integer maxConcurrency = clientCredential.getMaxConcurrency();
// 当前测试需要的并发数大于剩余的并发数报错
if (threadNum > maxConcurrency - sumThreadNum) {
MSException.throwException("Insufficient resources");
}
try {
EngineContext context = EngineFactory.createContext(loadTest, threadNum);
runTest(context, clientCredential, 1);
} catch (Exception e) {
LogUtil.error(e);
}
});
}
private void runTest(EngineContext context, ClientCredential credential, int replicas) {
KubernetesProvider kubernetesProvider = new KubernetesProvider(JSON.toJSONString(credential));
// create namespace
kubernetesProvider.confirmNamespace(context.getNamespace());
@ -61,6 +72,7 @@ public class KubernetesTestEngine implements Engine {
}
}
// create jmeter
// todo image
try {
Jmeter jmeter = new Jmeter();
jmeter.setMetadata(new ObjectMeta() {{
@ -68,7 +80,7 @@ public class KubernetesTestEngine implements Engine {
setName(context.getTestId());
}});
jmeter.setSpec(new JmeterSpec() {{
setReplicas(1);
setReplicas(replicas);
setImage("registry.fit2cloud.com/metersphere/jmeter-master:0.0.2");
}});
LogUtil.info("Load test started. " + context.getTestId());

View File

@ -4,6 +4,7 @@ public class ClientCredential {
private String masterUrl;
private String token;
private Integer maxConcurrency;
public String getMasterUrl() {
return masterUrl;
@ -20,4 +21,12 @@ public class ClientCredential {
public void setToken(String token) {
this.token = token;
}
public Integer getMaxConcurrency() {
return maxConcurrency;
}
public void setMaxConcurrency(Integer maxConcurrency) {
this.maxConcurrency = maxConcurrency;
}
}

View File

@ -233,11 +233,10 @@ public class JmeterDocumentParser implements DocumentParser {
collectionProp.appendChild(createKafkaProp(document, "kafka.batch.size", kafkaProperties.getBatchSize()));
collectionProp.appendChild(createKafkaProp(document, "kafka.client.id", kafkaProperties.getClientId()));
collectionProp.appendChild(createKafkaProp(document, "kafka.connections.max.idle.ms", kafkaProperties.getConnectionsMaxIdleMs()));
// 添加关联关系 test.id test.name test.startTime test.size
// 添加关联关系 test.id test.name test.startTime
collectionProp.appendChild(createKafkaProp(document, "test.id", context.getTestId()));
collectionProp.appendChild(createKafkaProp(document, "test.name", context.getTestName()));
collectionProp.appendChild(createKafkaProp(document, "test.startTime", "" + System.currentTimeMillis()));
collectionProp.appendChild(createKafkaProp(document, "test.size", "1"));
elementProp.appendChild(collectionProp);
// set elementProp
@ -314,7 +313,7 @@ public class JmeterDocumentParser implements DocumentParser {
threadGroup.appendChild(createStringProp(document, "LogFilename", ""));
threadGroup.appendChild(createStringProp(document, "Iterations", "1"));
// todo 单位是S 要修改 成M
threadGroup.appendChild(createStringProp(document, "Unit", "S"));
threadGroup.appendChild(createStringProp(document, "Unit", "M"));
}
private void processCheckoutTimer(Element element) {
@ -387,6 +386,11 @@ public class JmeterDocumentParser implements DocumentParser {
if (nodeNameEquals(ele, STRING_PROP)) {
parseStringProp(ele);
}
// 设置具体的线程数
if (nodeNameEquals(ele, STRING_PROP) && "TargetLevel".equals(ele.getAttribute("name"))) {
ele.getFirstChild().setNodeValue(context.getThreadNum().toString());
}
}
}
}

View File

@ -9,12 +9,13 @@ import io.metersphere.report.base.RequestStatistics;
import java.io.Reader;
import java.io.StringReader;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
public class JtlResolver {
private List<Metric> resolver(String jtlString) {
private static List<Metric> resolver(String jtlString) {
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
ms.setType(Metric.class);
try (Reader reader = new StringReader(jtlString)) {
@ -32,7 +33,7 @@ public class JtlResolver {
return null;
}
private List<RequestStatistics> getOneRpsResult(Map<String, List<Metric>> map){
private static List<RequestStatistics> getOneRpsResult(Map<String, List<Metric>> map){
List<RequestStatistics> requestStatisticsList = new ArrayList<>();
Iterator<Map.Entry<String, List<Metric>>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
@ -45,7 +46,7 @@ public class JtlResolver {
int sumElapsed=0;
Integer failSize = 0;
Integer totalBytes = 0;
List<Integer> elapsedList = new ArrayList<Integer>();
List<Integer> elapsedList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
try {
@ -83,8 +84,10 @@ public class JtlResolver {
RequestStatistics requestStatistics = new RequestStatistics();
requestStatistics.setRequestLabel(label);
requestStatistics.setSamples(index+"");
requestStatistics.setAverage(sumElapsed/index+"");
requestStatistics.setSamples(index);
DecimalFormat df = new DecimalFormat("0.00");
String s = df.format((float)sumElapsed/index);
requestStatistics.setAverage(s+"");
/**
* TP90的计算
* 1把一段时间内全部的请求的响应时间从小到大排序获得序列A
@ -104,7 +107,7 @@ public class JtlResolver {
return requestStatisticsList;
}
public List<RequestStatistics> getRequestStatistics(String jtlString) {
public static List<RequestStatistics> getRequestStatistics(String jtlString) {
List<Metric> totalLines = resolver(jtlString);
Map<String, List<Metric>> map = totalLines.stream().collect(Collectors.groupingBy(Metric::getLabel));
return getOneRpsResult(map);

View File

@ -6,7 +6,7 @@ public class RequestStatistics {
private String requestLabel;
/**压测请求数*/
private String samples;
private Integer samples;
/**平均响应时间*/
private String average;
@ -43,11 +43,11 @@ public class RequestStatistics {
this.requestLabel = requestLabel;
}
public String getSamples() {
public Integer getSamples() {
return samples;
}
public void setSamples(String samples) {
public void setSamples(Integer samples) {
this.samples = samples;
}

View File

@ -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;
@ -88,6 +87,7 @@ public class LoadTestService {
loadTest.setUpdateTime(System.currentTimeMillis());
loadTest.setScenarioDefinition("todo");
loadTest.setDescription("todo");
loadTest.setTestResourcePoolId(request.getTestResourcePoolId());
loadTest.setLoadConfiguration(request.getLoadConfiguration());
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
loadTestMapper.insert(loadTest);
@ -154,6 +154,7 @@ public class LoadTestService {
loadTest.setDescription("todo");
loadTest.setLoadConfiguration(request.getLoadConfiguration());
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
loadTest.setTestResourcePoolId(request.getTestResourcePoolId());
loadTestMapper.updateByPrimaryKeySelective(loadTest);
}
@ -166,27 +167,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 runtest ID%sfile type%s", request.getId(), fileMetadata.getType()));
MSException.throwException(String.format("Test cannot be runtest ID%s", request.getId()));
}
boolean init = true;
try {
init = engine.init(EngineFactory.createContext(loadTest, fileMetadata, csvFiles));
init = engine.init(loadTest);
} catch (Exception e) {
MSException.throwException(e);
}
@ -226,4 +216,10 @@ public class LoadTestService {
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
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);
}
}

View File

@ -6,6 +6,8 @@ import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.controller.request.ReportRequest;
import io.metersphere.dto.ReportDTO;
import io.metersphere.report.JtlResolver;
import io.metersphere.report.base.RequestStatistics;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -42,7 +44,10 @@ public class ReportService {
return extLoadTestReportMapper.getReportTestAndProInfo(reportId);
}
public LoadTestReport getReport(String id) {
return loadTestReportMapper.selectByPrimaryKey(id);
public List<RequestStatistics> getReport(String id) {
LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent();
List<RequestStatistics> requestStatistics = JtlResolver.getRequestStatistics(content);
return requestStatistics;
}
}

View File

@ -1,15 +1,17 @@
package io.metersphere.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourceExample;
import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.domain.TestResourcePoolExample;
import io.metersphere.base.mapper.TestResourceMapper;
import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.KubernetesDTO;
import io.metersphere.dto.NodeDTO;
import io.metersphere.engine.kubernetes.provider.ClientCredential;
import io.metersphere.dto.TestResourcePoolDTO;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -30,40 +32,41 @@ import java.util.UUID;
@Transactional(rollbackFor = Exception.class)
public class TestResourcePoolService {
private final static String nodeControllerUrl = "%s:%s/status";
private final static String nodeControllerUrl = "http://%s:%s/status";
@Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private TestResourceMapper testResourceMapper;
@Resource
private ExtTestReourcePoolMapper extTestReourcePoolMapper;
public TestResourcePool addTestResourcePool(TestResourcePool testResourcePool) {
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) {
testResourcePool.setId(UUID.randomUUID().toString());
testResourcePool.setCreateTime(System.currentTimeMillis());
testResourcePool.setUpdateTime(System.currentTimeMillis());
testResourcePool.setStatus("1");
testResourcePool.setStatus(ResourceStatusEnum.VALID.name());
validateTestResourcePool(testResourcePool);
testResourcePoolMapper.insertSelective(testResourcePool);
return testResourcePool;
}
public void deleteTestResourcePool(String testResourcePoolId) {
deleteTestResource(testResourcePoolId);
testResourcePoolMapper.deleteByPrimaryKey(testResourcePoolId);
}
public void updateTestResourcePool(TestResourcePool testResourcePool) {
public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) {
testResourcePool.setUpdateTime(System.currentTimeMillis());
validateTestResourcePool(testResourcePool);
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
}
public List<TestResourcePool> listResourcePools(QueryResourcePoolRequest request) {
TestResourcePoolExample example = new TestResourcePoolExample();
if (!StringUtils.isEmpty(request.getName())) {
example.createCriteria().andNameLike("%" + request.getName() + "%");
}
return testResourcePoolMapper.selectByExample(example);
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
return extTestReourcePoolMapper.listResourcePools(request);
}
private void validateTestResourcePool(TestResourcePool testResourcePool) {
private void validateTestResourcePool(TestResourcePoolDTO testResourcePool) {
if (StringUtils.equalsIgnoreCase(testResourcePool.getType(), ResourcePoolTypeEnum.K8S.name())) {
validateK8s(testResourcePool);
return;
@ -71,47 +74,69 @@ public class TestResourcePoolService {
validateNodes(testResourcePool);
}
private void validateNodes(TestResourcePool testResourcePool) {
List<NodeDTO> nodes = JSON.parseArray(testResourcePool.getInfo(), NodeDTO.class);
if (CollectionUtils.isEmpty(nodes)) {
private void validateNodes(TestResourcePoolDTO testResourcePool) {
if (CollectionUtils.isEmpty(testResourcePool.getResources())) {
throw new RuntimeException("没有节点信息");
}
for (NodeDTO node : nodes) {
boolean isValidate = validateNode(node);
deleteTestResource(testResourcePool.getId());
for (TestResource resource : testResourcePool.getResources()) {
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
boolean isValidate = validateNode(nodeDTO);
if (!isValidate) {
testResourcePool.setStatus("0");
testResourcePool.setStatus(ResourceStatusEnum.INVALID.name());
resource.setStatus(ResourceStatusEnum.INVALID.name());
} else {
resource.setStatus(ResourceStatusEnum.VALID.name());
}
node.setValidate(isValidate);
resource.setTestResourcePoolId(testResourcePool.getId());
updateTestResource(resource);
}
testResourcePool.setInfo(JSON.toJSONString(nodes));
}
private boolean validateNode(NodeDTO dto) {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> entity = restTemplate.getForEntity(String.format(nodeControllerUrl, dto.getIp(), dto.getPort()), String.class);
return entity.getStatusCode().value() == HttpStatus.SC_OK;
private boolean validateNode(NodeDTO node) {
try {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> entity = restTemplate.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), String.class);
return entity.getStatusCode().value() == HttpStatus.SC_OK;
} catch (Exception e) {
return false;
}
}
private void validateK8s(TestResourcePool testResourcePool) {
List<KubernetesDTO> dtos = JSON.parseArray(testResourcePool.getInfo(), KubernetesDTO.class);
private void validateK8s(TestResourcePoolDTO testResourcePool) {
if (CollectionUtils.isEmpty(dtos) || dtos.size() != 1) {
if (CollectionUtils.isEmpty(testResourcePool.getResources()) || testResourcePool.getResources().size() != 1) {
throw new RuntimeException("只能添加一个 K8s");
}
ClientCredential clientCredential = new ClientCredential();
BeanUtils.copyBean(clientCredential, dtos.get(0));
TestResource testResource = testResourcePool.getResources().get(0);
testResource.setTestResourcePoolId(testResourcePool.getId());
try {
KubernetesProvider provider = new KubernetesProvider(JSON.toJSONString(clientCredential));
KubernetesProvider provider = new KubernetesProvider(testResource.getConfiguration());
provider.validateCredential();
dtos.get(0).setValidate(true);
testResource.setStatus(ResourceStatusEnum.VALID.name());
} catch (Exception e) {
dtos.get(0).setValidate(false);
testResourcePool.setStatus("0");
testResource.setStatus(ResourceStatusEnum.INVALID.name());
testResourcePool.setStatus(ResourceStatusEnum.INVALID.name());
}
testResourcePool.setInfo(JSON.toJSONString(dtos));
deleteTestResource(testResourcePool.getId());
updateTestResource(testResource);
}
private void updateTestResource(TestResource testResource) {
testResource.setUpdateTime(System.currentTimeMillis());
testResource.setCreateTime(System.currentTimeMillis());
testResource.setId(UUID.randomUUID().toString());
testResourceMapper.insertSelective(testResource);
}
private void deleteTestResource(String testResourcePoolId) {
TestResourceExample testResourceExample = new TestResourceExample();
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
testResourceMapper.deleteByExample(testResourceExample);
}
public TestResourcePool getResourcePool(String resourcePoolId) {

View File

@ -41,4 +41,10 @@ public class TestResourceService {
testResource.setUpdateTime(System.currentTimeMillis());
testResourceMapper.updateByPrimaryKeySelective(testResource);
}
public List<TestResource> getResourcesByPoolId(String resourcePoolId) {
TestResourceExample example = new TestResourceExample();
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
return testResourceMapper.selectByExampleWithBLOBs(example);
}
}

View File

@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS `load_test` (
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',
`status` varchar(64) DEFAULT NULL COMMENT 'Test Status Running, Completed, Error, etc.',
`test_resource_pool_id` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
@ -112,8 +113,6 @@ CREATE TABLE IF NOT EXISTS `system_parameter` (
CREATE TABLE IF NOT EXISTS `test_resource` (
`id` varchar(50) NOT NULL COMMENT 'Test resource ID',
`test_resource_pool_id` varchar(50) NOT NULL COMMENT 'Test resource pool ID this test resource belongs to',
`name` varchar(64) NOT NULL COMMENT 'Test resource name',
`description` varchar(255) DEFAULT NULL COMMENT 'Test resource description',
`configuration` longtext COMMENT 'Test resource configuration',
`status` varchar(64) NOT NULL COMMENT 'Test resource status',
@ -128,6 +127,7 @@ CREATE TABLE IF NOT EXISTS `test_resource` (
CREATE TABLE IF NOT EXISTS `test_resource_pool` (
`id` varchar(50) NOT NULL COMMENT 'Test resource pool ID',
`name` varchar(64) NOT NULL COMMENT 'Test resource pool name',
`type` varchar(30) NOT NULL COMMENT 'Test resource pool type',
`description` varchar(255) DEFAULT NULL COMMENT 'Test resource pool description',
`status` varchar(64) NOT NULL COMMENT 'Test resource pool status',
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',

View File

@ -199,6 +199,7 @@ public class JtlTest {
"1584602504095,65,https://rddev2.fit2cloud.com/auth/realms/cmp/login-actions/authenticate?session_code=YWUneSay4qlQuHRZsD4kPaZDIIR50KJLaNpW7uhsD-Q&execution=c7620733-54ab-46b2-802b-66764e42682b&client_id=cmp-client&tab_id=S8xOQPgCmhQ,400,Bad Request,Thread Group 1-7,text,false,,4469,1745,3,3,https://rddev2.fit2cloud.com/auth/realms/cmp/login-actions/authenticate,65,0,4\n" +
"1584602504200,12,https://rddev2.fit2cloud.com/dashboard/web-public/project/html/notification-menus.html?_t=1577351137654,200,OK,Thread Group 1-3,text,true,,1570,582,2,2,https://rddev2.fit2cloud.com/dashboard/web-public/project/html/notification-menus.html?_t=1577351137654,12,0,0\n";
List<Metric> metrics = beanBuilderExample(jtlString);
// 根据label分组label作为map的key
Map<String, List<Metric>> map = metrics.stream().collect(Collectors.groupingBy(Metric::getLabel));
getOneRpsResult(map);
}
@ -215,7 +216,8 @@ public class JtlTest {
int sumElapsed=0;
Integer failSize = 0;
Integer totalBytes = 0;
List<Integer> elapsedList = new ArrayList<Integer>();
// 响应时间的列表排序之后 用于计算90%line95%line99line
List<Integer> elapsedList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
try {
@ -253,8 +255,8 @@ public class JtlTest {
RequestStatistics sceneResult = new RequestStatistics();
sceneResult.setRequestLabel(label);
sceneResult.setSamples(index+"");
sceneResult.setAverage(sumElapsed/index+"");
sceneResult.setSamples(index);
// sceneResult.setAverage(sumElapsed/index);
sceneResult.setTp90(elapsedList.get(tp90)+"");
sceneResult.setTp95(elapsedList.get(tp95)+"");
sceneResult.setTp99(elapsedList.get(tp99)+"");

View File

@ -0,0 +1,25 @@
package io.metersphere.service;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestResourcePoolServiceTest {
@Resource
private TestResourcePoolService testResourcePoolService;
@Test
public void listResourcePools() {
List<TestResourcePoolDTO> list = testResourcePoolService.listResourcePools(new QueryResourcePoolRequest());
System.out.println(list.size());
}
}

View File

@ -160,6 +160,7 @@
this.testPlan.updatedFileList = this.$refs.basicConfig.updatedFileList();
//
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());

View File

@ -104,13 +104,12 @@
const STEPS = "Steps";
const DURATION = "duration";
const RPS_LIMIT = "rpsLimit";
const RESOURCE_POOL = "resourcePoolId";
export default {
name: "PerformancePressureConfig",
props: ['testPlan'],
data() {
return {
testPlan: {},
threadNumber: 10,
duration: 10,
rampUpTime: 10,
@ -128,7 +127,7 @@
} else {
this.calculateChart();
}
this.resourcePool = this.testPlan.testResourcePoolId;
this.getResourcePools();
},
watch: {
@ -142,6 +141,9 @@
} else {
this.calculateChart();
}
},
testPlan(n) {
this.resourcePool = n.testResourcePoolId;
}
},
methods: {
@ -174,9 +176,6 @@
case RPS_LIMIT:
this.rpsLimit = d.value;
break;
case RESOURCE_POOL:
this.resourcePool = d.value;
break;
default:
break;
}
@ -299,7 +298,6 @@
{key: STEPS, value: this.step},
{key: DURATION, value: this.duration},
{key: RPS_LIMIT, value: this.rpsLimit},
{key: RESOURCE_POOL, value: this.resourcePool},
];
}
}

View File

@ -38,7 +38,7 @@
<ms-report-test-overview />
</el-tab-pane>
<el-tab-pane :label="$t('report.test_request_statistics')">
<ms-report-request-statistics />
<ms-report-request-statistics :id="reportId"/>
</el-tab-pane>
<el-tab-pane :label="$t('report.test_error_log')">
<ms-report-error-log />

View File

@ -2,78 +2,73 @@
<div>
<el-table
:data="tableData"
stripe
border
style="width: 100%"
:default-sort = "{prop: 'elementLabel'}"
show-summary
:default-sort = "{prop: 'samples', order: 'descending'}"
>
<el-table-column
prop="elementLabel"
label="Element Label"
fixed
width="150"
sortable>
<el-table-column label="Requests" fixed width="450" align="center">
<el-table-column
prop="requestLabel"
label="Label"
width="450"/>
</el-table-column>
<el-table-column
prop="samples"
label="Samples"
width="150"
sortable>
<el-table-column label="Executions" align="center">
<el-table-column
prop="samples"
label="Samples"
sortable
width="110"
/>
<el-table-column
prop="errors"
label="Error%"
align="center"
fixed="right"/>
</el-table-column>
<el-table-column
prop="avgResponseTime"
label="Avg Response Time(ms)"
width="220"
sortable>
<el-table-column label="Response Times(ms)" align="center">
<el-table-column
prop="average"
label="Average"
/>
<el-table-column
prop="min"
label="Min"
/>
<el-table-column
prop="max"
label="Max"
/>
<el-table-column
prop="tp90"
label="90% line"
/>
<el-table-column
prop="tp95"
label="95% line"
/>
<el-table-column
prop="tp99"
label="99% line"
/>
</el-table-column>
<!-- <el-table-column-->
<!-- prop="avgHits"-->
<!-- label="Avg Hits/s"-->
<!-- width="150"-->
<!-- />-->
<el-table-column
prop="avgHits"
label="Avg Hits/s"
width="150"
sortable>
</el-table-column>
<el-table-column
prop="90line"
label="90% line(ms)"
width="150"
sortable>
</el-table-column>
<el-table-column
prop="95line"
label="95% line(ms)"
width="150"
sortable>
</el-table-column>
<el-table-column
prop="99line"
label="99% line(ms)"
width="150"
sortable>
</el-table-column>
<el-table-column
prop="minResponseTime"
label="Min Response Time(ms)"
width="220"
sortable>
</el-table-column>
<el-table-column
prop="maxResponseTime"
label="Max Response Time(ms)"
width="220"
sortable>
</el-table-column>
<el-table-column
prop="avgBandwidth"
prop="kbPerSec"
label="Avg Bandwidth(KBytes/s)"
width="220"
sortable>
</el-table-column>
<el-table-column
prop="errorPercentage"
label="Error Percentage"
width="180"
fixed="right"
sortable>
</el-table-column>
align="center"
width="200"
/>
</el-table>
</div>
</template>
@ -83,11 +78,29 @@
name: "RequestStatistics",
data() {
return {
tableData: [{},{},{},{},{}]
tableData: [{},{},{},{},{}],
}
},
methods: {
initTableData() {
this.$get("/report/content/" + this.id, res => {
this.tableData = res.data;
})
}
},
created() {
this.initTableData()
},
props: ['id'],
watch: {
'$route'(to) {
let reportId = to.path.split('/')[4];
if(reportId){
this.$get("/report/content/" + reportId, res => {
this.tableData = res.data;
})
}
}
}
}
</script>

View File

@ -27,8 +27,8 @@
<el-switch v-model="scope.row.status"
active-color="#13ce66"
inactive-color="#ff4949"
active-value="1"
inactive-value="0"
active-value="VALID"
inactive-value="INVALID"
@change="changeSwitch(scope.row)"
/>
</template>
@ -69,7 +69,7 @@
</div>
</el-card>
<el-dialog v-loading="testLoading" title="创建资源池" :visible.sync="createVisible" width="70%" @closed="closeFunc"
<el-dialog title="创建资源池" :visible.sync="createVisible" width="70%" @closed="closeFunc"
:destroy-on-close="true">
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule"
ref="createTestResourcePoolForm">
@ -144,7 +144,7 @@
</span>
</el-dialog>
<el-dialog v-loading="testLoading" title="修改资源池" :visible.sync="updateVisible" width="70%" :destroy-on-close="true"
<el-dialog title="修改资源池" :visible.sync="updateVisible" width="70%" :destroy-on-close="true"
@close="closeFunc">
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule"
ref="updateTestResourcePoolForm">
@ -244,7 +244,7 @@
rule: {
name: [
{required: true, message: '请输入资源池名称', trigger: 'blur'},
{min: 2, max: 10, message: this.$t('commons.input_limit', [2, 10]), trigger: 'blur'},
{min: 2, max: 64, message: this.$t('commons.input_limit', [2, 64]), trigger: 'blur'},
{
required: true,
pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
@ -334,11 +334,18 @@
this.createVisible = true;
},
edit(row) {
window.console.log(row);
// this.loading = true;
this.updateVisible = true;
this.form = JSON.parse(JSON.stringify(row));
this.infoList = JSON.parse(this.form.info);
this.convertResources();
},
convertResources() {
let resources = [];
if (this.form.resources) {
this.form.resources.forEach(function (resource) {
resources.push(JSON.parse(resource.configuration));
})
}
this.infoList = resources;
},
del(row) {
window.console.log(row);
@ -367,7 +374,7 @@
let vri = this.validateResourceInfo();
if (vri.validate) {
this.testLoading = true;
this.form.info = JSON.stringify(this.infoList);
this.convertSubmitResources();
this.$post("/testresourcepool/add", this.form)
.then(() => {
this.$message({
@ -392,13 +399,25 @@
}
})
},
convertSubmitResources() {
let resources = [];
let poolId = this.form.id;
this.infoList.forEach(function (info) {
let resource = {"configuration": JSON.stringify(info)};
if (poolId) {
resource.testResourcePoolId = poolId;
}
resources.push(resource);
});
this.form.resources = resources;
},
updateTestResourcePool(updateTestResourcePoolForm) {
this.$refs[updateTestResourcePoolForm].validate(valide => {
if (valide) {
this.testLoading = true;
let vri = this.validateResourceInfo();
if (vri.validate) {
this.form.info = JSON.stringify(this.infoList);
this.convertSubmitResources();
this.$post("/testresourcepool/update", this.form)
.then(() => {
this.$message({