feat: add system resource pool service
This commit is contained in:
parent
61fd6ae3be
commit
a8ee2d4621
|
@ -0,0 +1,15 @@
|
||||||
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OrgIdNameDTO {
|
||||||
|
|
||||||
|
@Schema(title = "关联的组织id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(title = "关联的组织名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
package io.metersphere.sdk.dto;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
import io.metersphere.sdk.dto.BasePageRequest;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class QueryResourcePoolRequest extends BasePageRequest {
|
public class QueryResourcePoolRequest extends BasePageRequest {
|
||||||
private String name;
|
@Schema(title = "是否禁用")
|
||||||
private Boolean enable;
|
private Boolean enable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,9 @@ public class TestResourceDTO {
|
||||||
@Schema(title = "UI测试的grid配置")
|
@Schema(title = "UI测试的grid配置")
|
||||||
private String uiGrid;
|
private String uiGrid;
|
||||||
|
|
||||||
|
@Schema(title = "grid最大线程数")
|
||||||
|
private String girdConcurrentNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联的组织id集合
|
* 关联的组织id集合
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,7 +5,6 @@ import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*用来返回TestResourceBlob的结构
|
*用来返回TestResourceBlob的结构
|
||||||
|
@ -84,6 +83,6 @@ public class TestResourceReturnDTO {
|
||||||
/**
|
/**
|
||||||
* 关联的组织id集合
|
* 关联的组织id集合
|
||||||
*/
|
*/
|
||||||
@Schema(title = "关联的组织id和名称map")
|
@Schema(title = "关联的组织id和名称的集合")
|
||||||
private Map<String,String> orgIdNameMap;
|
private List<OrgIdNameDTO> orgIdNameMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,11 @@ public class TestResourcePoolService {
|
||||||
testResourcePoolBlob.setId(id);
|
testResourcePoolBlob.setId(id);
|
||||||
TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO();
|
TestResourceDTO testResourceDTO = testResourcePool.getTestResourceDTO();
|
||||||
checkAndSaveOrgRelation(testResourcePool, id, testResourceDTO);
|
checkAndSaveOrgRelation(testResourcePool, id, testResourceDTO);
|
||||||
|
|
||||||
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
||||||
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
||||||
checkUiConfig(testResourceDTO, testResourcePool);
|
checkUiConfig(testResourceDTO, testResourcePool);
|
||||||
String configuration = JSON.toJSONString(testResourceDTO);
|
String configuration = JSON.toJSONString(testResourceDTO);
|
||||||
testResourcePoolBlob.setConfiguration(configuration.getBytes());
|
testResourcePoolBlob.setConfiguration(configuration.getBytes());
|
||||||
|
|
||||||
buildTestPoolBaseInfo(testResourcePool, id);
|
buildTestPoolBaseInfo(testResourcePool, id);
|
||||||
testResourcePoolMapper.insert(testResourcePool);
|
testResourcePoolMapper.insert(testResourcePool);
|
||||||
testResourcePoolBlobMapper.insert(testResourcePoolBlob);
|
testResourcePoolBlobMapper.insert(testResourcePoolBlob);
|
||||||
|
@ -178,14 +176,21 @@ public class TestResourcePoolService {
|
||||||
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
checkApiConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
||||||
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
checkLoadConfig(testResourceDTO, testResourcePool, testResourcePool.getType());
|
||||||
checkUiConfig(testResourceDTO, testResourcePool);
|
checkUiConfig(testResourceDTO, testResourcePool);
|
||||||
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
|
|
||||||
|
String configuration = JSON.toJSONString(testResourceDTO);
|
||||||
|
TestResourcePoolBlob testResourcePoolBlob = new TestResourcePoolBlob();
|
||||||
|
testResourcePoolBlob.setId(testResourcePool.getId());
|
||||||
|
testResourcePoolBlob.setConfiguration(configuration.getBytes());
|
||||||
|
|
||||||
|
testResourcePoolBlobMapper.updateByPrimaryKeyWithBLOBs(testResourcePoolBlob);
|
||||||
|
testResourcePoolMapper.updateByPrimaryKey(testResourcePool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
|
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
|
||||||
TestResourcePoolExample example = new TestResourcePoolExample();
|
TestResourcePoolExample example = new TestResourcePoolExample();
|
||||||
TestResourcePoolExample.Criteria criteria = example.createCriteria();
|
TestResourcePoolExample.Criteria criteria = example.createCriteria();
|
||||||
if (StringUtils.isNotBlank(request.getName())) {
|
if (StringUtils.isNotBlank(request.getKeyword())) {
|
||||||
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
|
criteria.andNameLike(StringUtils.wrapIfMissing(request.getKeyword(), "%"));
|
||||||
}
|
}
|
||||||
if (request.getEnable() != null) {
|
if (request.getEnable() != null) {
|
||||||
criteria.andEnableEqualTo(request.getEnable());
|
criteria.andEnableEqualTo(request.getEnable());
|
||||||
|
@ -250,15 +255,17 @@ public class TestResourcePoolService {
|
||||||
TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO();
|
TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO();
|
||||||
BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO);
|
BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO);
|
||||||
List<String> orgIds = testResourceDTO.getOrgIds();
|
List<String> orgIds = testResourceDTO.getOrgIds();
|
||||||
Map<String,String> orgIdNameMap = new HashMap<>();
|
List<OrgIdNameDTO>orgIdNameMap = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(orgIds)) {
|
if (CollectionUtils.isNotEmpty(orgIds)) {
|
||||||
for (String orgId : orgIds) {
|
for (String orgId : orgIds) {
|
||||||
|
OrgIdNameDTO orgIdNameDTO = new OrgIdNameDTO();
|
||||||
OrganizationMapper organizationMapper = CommonBeanFactory.getBean(OrganizationMapper.class);
|
OrganizationMapper organizationMapper = CommonBeanFactory.getBean(OrganizationMapper.class);
|
||||||
Organization organization = organizationMapper.selectByPrimaryKey(orgId);
|
Organization organization = organizationMapper.selectByPrimaryKey(orgId);
|
||||||
|
orgIdNameDTO.setId(orgId);
|
||||||
if (organization != null) {
|
if (organization != null) {
|
||||||
orgIdNameMap.put(orgId,organization.getName());
|
orgIdNameDTO.setName(organization.getName());
|
||||||
} else {
|
} else {
|
||||||
orgIdNameMap.put(orgId,Translator.get("organization_not_exists"));
|
orgIdNameDTO.setName(Translator.get("organization_not_exists"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,8 +312,8 @@ public class TestResourcePoolService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogDTO updateLog(TestResourcePoolRequest request) {
|
public LogDTO updateLog(String resourcePoolId) {
|
||||||
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(request.getId());
|
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(resourcePoolId);
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
LogDTO dto = new LogDTO(
|
LogDTO dto = new LogDTO(
|
||||||
"system",
|
"system",
|
||||||
|
@ -324,4 +331,18 @@ public class TestResourcePoolService {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void unableTestResourcePool(String testResourcePoolId) {
|
||||||
|
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(testResourcePoolId);
|
||||||
|
if (testResourcePool == null) {
|
||||||
|
throw new MSException(Translator.get("test_resource_pool_not_exists"));
|
||||||
|
}
|
||||||
|
if (testResourcePool.getEnable()) {
|
||||||
|
testResourcePool.setEnable(false);
|
||||||
|
} else {
|
||||||
|
testResourcePool.setEnable(true);
|
||||||
|
}
|
||||||
|
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class TestResourcePoolController {
|
||||||
@CacheNode // 把监控节点缓存起来
|
@CacheNode // 把监控节点缓存起来
|
||||||
@Operation(summary = "更新资源池")
|
@Operation(summary = "更新资源池")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE)
|
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = TestResourcePoolService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request.getId())", msClass = TestResourcePoolService.class)
|
||||||
public void updateTestResourcePool(@Validated @RequestBody TestResourcePoolRequest request) {
|
public void updateTestResourcePool(@Validated @RequestBody TestResourcePoolRequest request) {
|
||||||
TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO();
|
TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO();
|
||||||
BeanUtils.copyBean(testResourcePool, request);
|
BeanUtils.copyBean(testResourcePool, request);
|
||||||
|
@ -83,5 +83,13 @@ public class TestResourcePoolController {
|
||||||
return testResourcePoolService.getTestResourcePoolDetail(testResourcePoolId);
|
return testResourcePoolService.getTestResourcePoolDetail(testResourcePoolId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/set/enable/{poolId}")
|
||||||
|
@Operation(summary = "资源池禁用")
|
||||||
|
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ_UPDATE)
|
||||||
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#testResourcePoolId)", msClass = TestResourcePoolService.class)
|
||||||
|
public void unableTestResourcePool(@PathVariable(value = "poolId") String testResourcePoolId) {
|
||||||
|
testResourcePoolService.unableTestResourcePool(testResourcePoolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,9 @@ import base.BaseTest;
|
||||||
import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
|
import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
|
||||||
import io.metersphere.sdk.constants.SessionConstants;
|
import io.metersphere.sdk.constants.SessionConstants;
|
||||||
import io.metersphere.sdk.controller.handler.ResultHolder;
|
import io.metersphere.sdk.controller.handler.ResultHolder;
|
||||||
import io.metersphere.sdk.dto.TestResourceDTO;
|
import io.metersphere.sdk.dto.*;
|
||||||
import io.metersphere.sdk.dto.TestResourceNodeDTO;
|
|
||||||
import io.metersphere.sdk.dto.TestResourcePoolRequest;
|
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.dto.QueryResourcePoolRequest;
|
import io.metersphere.sdk.util.Pager;
|
||||||
import io.metersphere.system.domain.TestResourcePoolOrganization;
|
import io.metersphere.system.domain.TestResourcePoolOrganization;
|
||||||
import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
|
import io.metersphere.system.domain.TestResourcePoolOrganizationExample;
|
||||||
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
|
import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper;
|
||||||
|
@ -29,6 +27,7 @@ import org.springframework.test.web.servlet.ResultMatcher;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -222,18 +221,27 @@ class TestResourcePoolControllerTests extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(10)
|
@Order(10)
|
||||||
|
/*@Sql(scripts = {"/dml/init_test_resource_pool.sql"},
|
||||||
|
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
||||||
|
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)*/
|
||||||
void listResourcePoolsWidthSearch() throws Exception {
|
void listResourcePoolsWidthSearch() throws Exception {
|
||||||
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
|
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
|
||||||
request.setCurrent(1);
|
request.setCurrent(1);
|
||||||
request.setPageSize(5);
|
request.setPageSize(5);
|
||||||
request.setName("test_pool");
|
request.setKeyword("test_pool_1");
|
||||||
mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page")
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/page")
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
.content(JSON.toJSONString(request))
|
.content(JSON.toJSONString(request))
|
||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk()).andDo(print())
|
.andExpect(status().isOk()).andDo(print())
|
||||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
|
String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
ResultHolder sortHolder = JsonUtils.parseObject(sortData, ResultHolder.class);
|
||||||
|
Pager<?> sortPageData = JSON.parseObject(JSON.toJSONString(sortHolder.getData()), Pager.class);
|
||||||
|
// 返回值中取出第一条ID最大的数据, 并判断是否是default-admin
|
||||||
|
TestResourcePoolDTO testResourcePoolDTO = JSON.parseArray(JSON.toJSONString(sortPageData.getList()), TestResourcePoolDTO.class).get(0);
|
||||||
|
Assertions.assertTrue(StringUtils.equals(testResourcePoolDTO.getName(), "test_pool_1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -415,6 +423,28 @@ class TestResourcePoolControllerTests extends BaseTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
void unableTestResourcePoolSuccess() throws Exception {
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/set/enable/104")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
void unableTestResourcePoolFiled() throws Exception {
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.post("/test/resource/pool/set/enable/105")
|
||||||
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||||
|
.andExpect(ERROR_REQUEST_MATCHER)
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# 插入测试数据
|
# 插入测试数据
|
||||||
INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
INSERT INTO `test_resource_pool` VALUES ('102','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
||||||
INSERT INTO `test_resource_pool` VALUES ('103','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
INSERT INTO `test_resource_pool` VALUES ('103','test_pool_two', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
||||||
INSERT INTO `test_resource_pool` VALUES ('104','test_pool_one', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
INSERT INTO `test_resource_pool` VALUES ('104','test_pool_three', 'node', '1', 1, '1686634885000', '1686634885000', 'TCP', 0, 0, 0, NULL, 1,0);
|
||||||
|
|
Loading…
Reference in New Issue