节点信息 存进 test_resource 表

This commit is contained in:
W23123 2020-03-24 16:04:43 +08:00
parent 172688f3e1
commit 0329313845
15 changed files with 194 additions and 358 deletions

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

@ -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

@ -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,12 +31,12 @@ 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));
}

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

@ -1,15 +1,15 @@
package io.metersphere.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.domain.TestResourcePoolExample;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourceExample;
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.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,12 +30,16 @@ 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());
@ -46,24 +50,21 @@ public class TestResourcePoolService {
}
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,46 +72,67 @@ 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");
resource.setStatus("0");
}
node.setValidate(isValidate);
resource.setStatus("1");
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("1");
} catch (Exception e) {
dtos.get(0).setValidate(false);
testResource.setStatus("0");
testResourcePool.setStatus("0");
}
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);
}
}

View File

@ -49,7 +49,7 @@
<!-- <table tableName="user_role"/>-->
<!-- <table tableName="workspace"/>-->
<table tableName="test_resource_pool"/>
<!-- <table tableName="test_resource"/>-->
<table tableName="test_resource"/>
<!-- <table tableName="system_parameter"/>-->
<!-- <table tableName="role"/>-->
<!-- <table tableName="project"/>-->

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

@ -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.·-]+$/,
@ -338,7 +338,16 @@
// 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 +376,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 +401,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({