diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResource.java b/backend/src/main/java/io/metersphere/base/domain/TestResource.java index 1dcfe373e3..b20b15820e 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResource.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResource.java @@ -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; } diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResourceExample.java b/backend/src/main/java/io/metersphere/base/domain/TestResourceExample.java index 23c3133b84..163a35a952 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResourceExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResourceExample.java @@ -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 values) { - addCriterion("name in", values, "name"); - return (Criteria) this; - } - - public Criteria andNameNotIn(List 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 values) { - addCriterion("description in", values, "description"); - return (Criteria) this; - } - - public Criteria andDescriptionNotIn(List 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; diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java b/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java index 887cb33d4a..c2eb38d5da 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java @@ -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; } diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java b/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java index 94527d4086..84edf600e9 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java @@ -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 values) { - addCriterion("info in", values, "info"); - return (Criteria) this; - } - - public Criteria andInfoNotIn(List 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; diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.xml index 575bbd54a9..a60b061203 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.xml @@ -4,8 +4,6 @@ - - @@ -72,7 +70,7 @@ - id, test_resource_pool_id, name, description, status, create_time, update_time + id, test_resource_pool_id, status, create_time, update_time configuration @@ -126,12 +124,12 @@ - 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 into test_resource @@ -142,12 +140,6 @@ test_resource_pool_id, - - name, - - - description, - status, @@ -168,12 +160,6 @@ #{testResourcePoolId,jdbcType=VARCHAR}, - - #{name,jdbcType=VARCHAR}, - - - #{description,jdbcType=VARCHAR}, - #{status,jdbcType=VARCHAR}, @@ -203,12 +189,6 @@ test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}, - - name = #{record.name,jdbcType=VARCHAR}, - - - description = #{record.description,jdbcType=VARCHAR}, - status = #{record.status,jdbcType=VARCHAR}, @@ -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 @@ test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}, - - name = #{name,jdbcType=VARCHAR}, - - - description = #{description,jdbcType=VARCHAR}, - status = #{status,jdbcType=VARCHAR}, @@ -283,8 +253,6 @@ 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 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} diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml index 26dbfd11ed..071918ef1f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml @@ -7,7 +7,6 @@ - @@ -70,7 +69,7 @@ - id, name, type, description, status, info, create_time, update_time + id, name, type, description, status, create_time, update_time + SELECT * FROM test_resource_pool + + + and test_resource_pool.name like CONCAT('%', #{request.name},'%') + + + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java index 656764ee60..efe56fd502 100644 --- a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java +++ b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java @@ -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> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) { + public Pager> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, testResourcePoolService.listResourcePools(request)); } diff --git a/backend/src/main/java/io/metersphere/dto/KubernetesDTO.java b/backend/src/main/java/io/metersphere/dto/KubernetesDTO.java index 2ad1f92de6..5a964d602a 100644 --- a/backend/src/main/java/io/metersphere/dto/KubernetesDTO.java +++ b/backend/src/main/java/io/metersphere/dto/KubernetesDTO.java @@ -5,7 +5,6 @@ public class KubernetesDTO { private String masterUrl; private String token; private Integer maxConcurrency; - private Boolean validate; public String getMasterUrl() { return masterUrl; @@ -31,11 +30,4 @@ public class KubernetesDTO { this.maxConcurrency = maxConcurrency; } - public Boolean getValidate() { - return validate; - } - - public void setValidate(Boolean validate) { - this.validate = validate; - } } diff --git a/backend/src/main/java/io/metersphere/dto/NodeDTO.java b/backend/src/main/java/io/metersphere/dto/NodeDTO.java index cfc141885c..899139afec 100644 --- a/backend/src/main/java/io/metersphere/dto/NodeDTO.java +++ b/backend/src/main/java/io/metersphere/dto/NodeDTO.java @@ -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; - } } diff --git a/backend/src/main/java/io/metersphere/dto/TestResourcePoolDTO.java b/backend/src/main/java/io/metersphere/dto/TestResourcePoolDTO.java new file mode 100644 index 0000000000..2e99214649 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/TestResourcePoolDTO.java @@ -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 resources; + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } +} diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index fdeb025365..f3c4c2a518 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -1,15 +1,16 @@ 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.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 +31,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 +51,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 listResourcePools(QueryResourcePoolRequest request) { - TestResourcePoolExample example = new TestResourcePoolExample(); - if (!StringUtils.isEmpty(request.getName())) { - example.createCriteria().andNameLike("%" + request.getName() + "%"); - } - return testResourcePoolMapper.selectByExample(example); + public List 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 +73,68 @@ public class TestResourcePoolService { validateNodes(testResourcePool); } - private void validateNodes(TestResourcePool testResourcePool) { - List 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 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 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 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); } public TestResourcePool getResourcePool(String resourcePoolId) { diff --git a/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java b/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java new file mode 100644 index 0000000000..28587d695c --- /dev/null +++ b/backend/src/test/java/io/metersphere/service/TestResourcePoolServiceTest.java @@ -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 list = testResourcePoolService.listResourcePools(new QueryResourcePoolRequest()); + System.out.println(list.size()); + } +} \ No newline at end of file diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index 9699ff915f..c166be6f73 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -69,7 +69,7 @@ - @@ -144,7 +144,7 @@ - @@ -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({