fix(系统设置): 配额检查

This commit is contained in:
shiziyuan9527 2022-04-14 16:41:37 +08:00 committed by 刘瑞斌
parent 4e2f7dce20
commit 60076f10e1
3 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.performance.service;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.constants.ReportKeys; import io.metersphere.commons.constants.ReportKeys;
@ -28,6 +29,8 @@ public class LoadTestVumEvent implements LoadTestFinishEvent {
private ExtLoadTestReportMapper extLoadTestReportMapper; private ExtLoadTestReportMapper extLoadTestReportMapper;
@Resource @Resource
private RedissonClient redissonClient; private RedissonClient redissonClient;
@Resource
private ProjectMapper projectMapper;
private void handleVum(LoadTestReport report) { private void handleVum(LoadTestReport report) {
if (report == null) { if (report == null) {
@ -51,7 +54,8 @@ public class LoadTestVumEvent implements LoadTestFinishEvent {
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
String projectId = report.getProjectId(); String projectId = report.getProjectId();
RLock lock = redissonClient.getLock(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
RLock lock = redissonClient.getLock(project.getWorkspaceId());
if (quotaService != null) { if (quotaService != null) {
try { try {
lock.lock(); lock.lock();

View File

@ -80,6 +80,8 @@ public class PerformanceReportService {
private TestResourcePoolMapper testResourcePoolMapper; private TestResourcePoolMapper testResourcePoolMapper;
@Resource @Resource
private RedissonClient redissonClient; private RedissonClient redissonClient;
@Resource
private ProjectMapper projectMapper;
public List<ReportDTO> getRecentReportList(ReportRequest request) { public List<ReportDTO> getRecentReportList(ReportRequest request) {
List<OrderRequest> orders = new ArrayList<>(); List<OrderRequest> orders = new ArrayList<>();
@ -169,7 +171,8 @@ public class PerformanceReportService {
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(report.getTestId()); LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(report.getTestId());
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
String projectId = report.getProjectId(); String projectId = report.getProjectId();
RLock lock = redissonClient.getLock(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
RLock lock = redissonClient.getLock(project.getWorkspaceId());
if (quotaService != null) { if (quotaService != null) {
try { try {
lock.lock(); lock.lock();

View File

@ -539,7 +539,8 @@ public class PerformanceTestService {
if (quotaService != null) { if (quotaService != null) {
quotaService.checkLoadTestQuota(checkRequest, false); quotaService.checkLoadTestQuota(checkRequest, false);
String projectId = testReport.getProjectId(); String projectId = testReport.getProjectId();
RLock lock = redissonClient.getLock(projectId); Project project = projectMapper.selectByPrimaryKey(projectId);
RLock lock = redissonClient.getLock(project.getWorkspaceId());
try { try {
lock.lock(); lock.lock();
BigDecimal toUsed = quotaService.checkVumUsed(checkRequest, projectId); BigDecimal toUsed = quotaService.checkVumUsed(checkRequest, projectId);