From cb8b73d9add184b266d71db78ea02eaada22221b Mon Sep 17 00:00:00 2001 From: q4speed Date: Fri, 21 Aug 2020 11:14:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90=E6=B1=A0=E9=99=90?= =?UTF-8?q?=E9=A2=9D=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestResourcePoolController.java | 7 ++++++ .../service/PerformanceTestService.java | 13 +++++----- .../io/metersphere/service/QuotaService.java | 8 +++++-- .../service/TestResourcePoolService.java | 24 ++++++++++++++++--- .../components/PerformancePressureConfig.vue | 2 +- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java index 2ce7bf4ff2..48f461b56c 100644 --- a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java +++ b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java @@ -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 listValidQuotaResourcePools() { + return testResourcePoolService.listValidQuotaResourcePools(); + } + } diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 52f405b47c..08c36d9281 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -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 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); } } } diff --git a/backend/src/main/java/io/metersphere/service/QuotaService.java b/backend/src/main/java/io/metersphere/service/QuotaService.java index d3e94c7240..c570cac3d2 100644 --- a/backend/src/main/java/io/metersphere/service/QuotaService.java +++ b/backend/src/main/java/io/metersphere/service/QuotaService.java @@ -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 getQuotaResourcePools(); } diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index d7919de2f7..84aefa198b 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -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 listValidQuotaResourcePools() { + return filterQuota(listValidResourcePools()); + } + + private List filterQuota(List list) { + QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); + if (quotaService != null) { + Set pools = quotaService.getQuotaResourcePools(); + if (!pools.isEmpty()) { + return list.stream().filter(pool -> pools.contains(pool.getId())).collect(Collectors.toList()); + } + } + return list; + } + } diff --git a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue index a39e546498..71c1b091f8 100644 --- a/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformancePressureConfig.vue @@ -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) { From be574b1b401e1c78028d16a639318f199e821742 Mon Sep 17 00:00:00 2001 From: q4speed Date: Fri, 21 Aug 2020 14:29:00 +0800 Subject: [PATCH 2/3] chore: update submodule --- backend/src/main/java/io/metersphere/xpack | 2 +- frontend/src/business/components/xpack | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index defbf12ffa..ecb30d83c5 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit defbf12ffac99eef6a026b87491090f2263b769d +Subproject commit ecb30d83c575c6ed14adb1a1ebea389730f410a9 diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 06fc0a321a..390943d21e 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 06fc0a321a9886419be5c607ddaa6b40efb5179b +Subproject commit 390943d21e7d0196e0d7d5faa66f0131cb631614 From 857295608347fe5a2d14ddd04d7161eff27fe829 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 21 Aug 2020 14:46:50 +0800 Subject: [PATCH 3/3] refactor: i18n --- .../track/plan/view/comonents/TestPlanTestCaseEdit.vue | 6 ++---- .../track/plan/view/comonents/TestPlanTestCaseList.vue | 6 ++---- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue index 1833e18f47..8d89b2aed3 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseEdit.vue @@ -208,7 +208,7 @@ - + diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue index d662ca0206..977d553eaa 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue @@ -113,7 +113,7 @@ trigger="hover"> - + diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index e4fa8f2cd7..9a8c2d2f6d 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -729,6 +729,7 @@ export default { close: "Close", title_description_required: "Title and description are required", close_success: "Closed successfully", + preview: "Preview" } }, test_resource_pool: { diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index ebbbb03eab..900e4dc00b 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -732,6 +732,7 @@ export default { close: "关闭缺陷", title_description_required: "标题和描述必填", close_success: "关闭成功", + preview: "预览" } }, test_resource_pool: { diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 16cc3592a0..bb9c917c7c 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -729,6 +729,7 @@ export default { close: "關閉缺陷", title_description_required: "標題和描述必填", close_success: "關閉成功", + preview: "預覽" } }, test_resource_pool: {