refactor(系统管理): 资源池容量接口增加资源池判断
This commit is contained in:
parent
19f7977fe9
commit
ce30bac830
|
@ -2,9 +2,11 @@ package io.metersphere.system.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.pool.ResourcePoolNodeMetric;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.system.domain.TestResourcePool;
|
||||
import io.metersphere.system.dto.pool.TestResourcePoolCapacityRequest;
|
||||
import io.metersphere.system.dto.pool.TestResourcePoolDTO;
|
||||
import io.metersphere.system.dto.pool.TestResourcePoolRequest;
|
||||
|
@ -14,6 +16,7 @@ import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
|
|||
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.service.BaseTaskHubService;
|
||||
import io.metersphere.system.service.TestResourcePoolService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
|
@ -27,6 +30,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "系统设置-系统-资源池")
|
||||
|
@ -38,6 +42,8 @@ public class TestResourcePoolController {
|
|||
private TestResourcePoolService testResourcePoolService;
|
||||
@Resource
|
||||
private BaseTaskHubService baseTaskHubService;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "系统设置-系统-资源池-更新资源池")
|
||||
|
@ -67,27 +73,31 @@ public class TestResourcePoolController {
|
|||
}
|
||||
|
||||
@PostMapping("/capacity/detail")
|
||||
@Operation(summary = "系统-资源池-查看资源池详细")
|
||||
@Operation(summary = "系统-资源池-查看资源池容量内存详细")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ)
|
||||
public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(@Validated @RequestBody TestResourcePoolCapacityRequest request) {
|
||||
return testResourcePoolService.getTestResourcePoolCapacityDetail(request);
|
||||
}
|
||||
|
||||
@PostMapping("/capacity/task/list")
|
||||
@Operation(summary = "系统-资源池-查看资源池详细")
|
||||
@Operation(summary = "系统-资源池-查看资源池节点任务列表")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ)
|
||||
public Pager<List<TaskHubItemDTO>> getCaseTaskItemList(@Validated @RequestBody TestResourcePoolCapacityRequest request) {
|
||||
TaskHubItemRequest taskHubItemRequest = new TaskHubItemRequest();
|
||||
BeanUtils.copyBean(taskHubItemRequest, request);
|
||||
taskHubItemRequest.setResourcePoolIds(List.of(request.getPoolId()));
|
||||
if (StringUtils.isNotBlank(request.getIp()) && StringUtils.isNotBlank(request.getPort())) {
|
||||
String node = new StringBuilder().append(request.getIp()).append(":").append(request.getPort()).toString();
|
||||
String node = request.getIp() + ":" + request.getPort();
|
||||
taskHubItemRequest.setResourcePoolNodes(List.of(node));
|
||||
}
|
||||
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(request.getPoolId());
|
||||
if (testResourcePool == null || !testResourcePool.getEnable() || testResourcePool.getDeleted()) {
|
||||
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
|
||||
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "id asc");
|
||||
return PageUtils.setPageInfo(page, new ArrayList<>());
|
||||
}
|
||||
return baseTaskHubService.getCaseTaskItemList(taskHubItemRequest, null, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package io.metersphere.system.dto.pool;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
|
@ -16,6 +18,7 @@ public class TestResourcePoolCapacityRequest extends BasePageRequest implements
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "资源池id")
|
||||
@NotBlank(message = "{test_resource_pool.id.not_blank}", groups = {Updated.class})
|
||||
private String poolId;
|
||||
|
||||
@Schema(description = "节点IP")
|
||||
|
|
|
@ -350,6 +350,10 @@ public class TestResourcePoolService {
|
|||
}
|
||||
|
||||
public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(TestResourcePoolCapacityRequest request) {
|
||||
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(request.getPoolId());
|
||||
if (testResourcePool == null || !testResourcePool.getEnable() || testResourcePool.getDeleted()) {
|
||||
return null;
|
||||
}
|
||||
return getNodeMetric(request.getIp(), request.getPort());
|
||||
}
|
||||
|
||||
|
|
|
@ -635,9 +635,23 @@ class TestResourcePoolControllerTests extends BaseTest {
|
|||
return testResourcePoolDTO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
public void getTestResourcePoolCapacityDetail() throws Exception {
|
||||
TestResourcePool testResourcePool = new TestResourcePool();
|
||||
testResourcePool.setId("gyq_pool_delete_enable");
|
||||
testResourcePool.setType("NODE");
|
||||
testResourcePool.setEnable(true);
|
||||
testResourcePool.setDeleted(true);
|
||||
testResourcePool.setAllOrg(true);
|
||||
testResourcePool.setName("测试");
|
||||
testResourcePool.setUpdateTime(System.currentTimeMillis());
|
||||
testResourcePool.setCreateTime(System.currentTimeMillis());
|
||||
testResourcePool.setCreateUser("admin");
|
||||
testResourcePool.setServerUrl("172.06.200.15");
|
||||
testResourcePoolMapper.insert(testResourcePool);
|
||||
TestResourcePoolCapacityRequest request = new TestResourcePoolCapacityRequest();
|
||||
request.setPoolId("test_pool_1");
|
||||
request.setIp("172.16.200.8");
|
||||
|
@ -651,6 +665,26 @@ class TestResourcePoolControllerTests extends BaseTest {
|
|||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
request.setPoolId("gyq_pool_delete_enable");
|
||||
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
testResourcePool.setEnable(false);
|
||||
testResourcePool.setDeleted(false);
|
||||
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
|
||||
request.setPoolId("gyq_pool_delete_enable");
|
||||
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
testResourcePool.setEnable(true);
|
||||
testResourcePool.setDeleted(true);
|
||||
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -676,6 +710,33 @@ class TestResourcePoolControllerTests extends BaseTest {
|
|||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
request.setPoolId("null");
|
||||
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
request.setPoolId("gyq_pool_delete_enable");
|
||||
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
TestResourcePool testResourcePool = new TestResourcePool();
|
||||
testResourcePool.setId("gyq_pool_delete_enable");
|
||||
testResourcePool.setDeleted(false);
|
||||
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
|
||||
request.setPoolId("gyq_pool_delete_enable");
|
||||
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
|
||||
// 获取返回值
|
||||
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue