feat(性能测试): 增加资源池限额过滤
This commit is contained in:
parent
83f90d7d12
commit
cb8b73d9ad
|
@ -14,6 +14,7 @@ import org.apache.shiro.authz.annotation.RequiresRoles;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("testresourcepool")
|
||||
|
@ -56,5 +57,11 @@ public class TestResourcePoolController {
|
|||
return testResourcePoolService.listValidResourcePools();
|
||||
}
|
||||
|
||||
@GetMapping("list/quota/valid")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public List<TestResourcePool> listValidQuotaResourcePools() {
|
||||
return testResourcePoolService.listValidQuotaResourcePools();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
@ -44,6 +42,8 @@ import java.time.temporal.ChronoUnit;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class PerformanceTestService {
|
||||
|
@ -131,7 +131,7 @@ public class PerformanceTestService {
|
|||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
|
||||
checkQuota(request);
|
||||
checkQuota(request, true);
|
||||
|
||||
final LoadTestWithBLOBs loadTest = saveLoadTest(request);
|
||||
files.forEach(file -> {
|
||||
|
@ -168,6 +168,7 @@ public class PerformanceTestService {
|
|||
}
|
||||
|
||||
public String edit(EditTestPlanRequest request, List<MultipartFile> files) {
|
||||
checkQuota(request, false);
|
||||
//
|
||||
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(request.getId());
|
||||
if (loadTest == null) {
|
||||
|
@ -363,7 +364,7 @@ public class PerformanceTestService {
|
|||
}
|
||||
|
||||
public void copy(SaveTestPlanRequest request) {
|
||||
checkQuota(request);
|
||||
checkQuota(request, true);
|
||||
// copy test
|
||||
LoadTestWithBLOBs copy = loadTestMapper.selectByPrimaryKey(request.getId());
|
||||
copy.setId(UUID.randomUUID().toString());
|
||||
|
@ -441,10 +442,10 @@ public class PerformanceTestService {
|
|||
return schedules;
|
||||
}
|
||||
|
||||
private void checkQuota(SaveTestPlanRequest request) {
|
||||
private void checkQuota(TestPlanRequest request, boolean create) {
|
||||
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
|
||||
if (quotaService != null) {
|
||||
quotaService.checkLoadTestQuota(request);
|
||||
quotaService.checkLoadTestQuota(request, create);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.TestPlanRequest;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface QuotaService {
|
||||
|
||||
void checkAPITestQuota();
|
||||
|
||||
void checkLoadTestQuota(SaveTestPlanRequest request);
|
||||
void checkLoadTestQuota(TestPlanRequest request, boolean checkPerformance);
|
||||
|
||||
Set<String> getQuotaResourcePools();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID;
|
||||
import static io.metersphere.commons.constants.ResourceStatusEnum.VALID;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.LoadTestMapper;
|
||||
|
@ -7,6 +10,7 @@ import io.metersphere.base.mapper.TestResourceMapper;
|
|||
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.commons.constants.ResourceStatusEnum;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
|
||||
import io.metersphere.dto.NodeDTO;
|
||||
|
@ -21,15 +25,14 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID;
|
||||
import static io.metersphere.commons.constants.ResourceStatusEnum.VALID;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author dongbin
|
||||
|
@ -243,4 +246,19 @@ public class TestResourcePoolService {
|
|||
return testResourcePoolMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<TestResourcePool> listValidQuotaResourcePools() {
|
||||
return filterQuota(listValidResourcePools());
|
||||
}
|
||||
|
||||
private List<TestResourcePool> filterQuota(List<TestResourcePool> list) {
|
||||
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
|
||||
if (quotaService != null) {
|
||||
Set<String> pools = quotaService.getQuotaResourcePools();
|
||||
if (!pools.isEmpty()) {
|
||||
return list.stream().filter(pool -> pools.contains(pool.getId())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@
|
|||
},
|
||||
methods: {
|
||||
getResourcePools() {
|
||||
this.result = this.$get('/testresourcepool/list/all/valid', response => {
|
||||
this.result = this.$get('/testresourcepool/list/quota/valid', response => {
|
||||
this.resourcePools = response.data;
|
||||
// 如果当前的资源池无效 设置 null
|
||||
if (response.data.filter(p => p.id === this.resourcePool).length === 0) {
|
||||
|
|
Loading…
Reference in New Issue