From 928539f1c129a476a02651e0142886956540a6a9 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 25 May 2020 14:31:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=88=9B=E5=BB=BA=E4=BA=BA=E5=92=8C=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=88=9B=E5=BB=BA=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../performance/service/PerformanceTestService.java | 3 +++ 1 file changed, 3 insertions(+) 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 d81d4f2a91..f1ac2c077a 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -8,6 +8,7 @@ import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.DashboardTestDTO; import io.metersphere.dto.LoadTestDTO; import io.metersphere.i18n.Translator; @@ -127,6 +128,7 @@ public class PerformanceTestService { } final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs(); + loadTest.setUserId(SessionUtils.getUser().getId()); loadTest.setId(UUID.randomUUID().toString()); loadTest.setName(request.getName()); loadTest.setProjectId(request.getProjectId()); @@ -210,6 +212,7 @@ public class PerformanceTestService { testReport.setUpdateTime(engine.getStartTime()); testReport.setTestId(loadTest.getId()); testReport.setName(loadTest.getName()); + testReport.setUserId(SessionUtils.getUser().getId()); // 启动测试 try { From e736019e8f57c12f39cddff05bd3fc257d62fda2 Mon Sep 17 00:00:00 2001 From: q4speed Date: Mon, 25 May 2020 15:22:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0BackendListener=EF=BC=8C=E4=BF=9D=E8=AF=81?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=94=9F=E6=88=90=E7=9A=84jmx=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 14 +++++++------- .../io/metersphere/api/jmeter/JMeterService.java | 15 ++++++++++++++- .../metersphere/api/service/APITestService.java | 2 +- .../components/api/test/model/ScenarioModel.js | 7 ------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 96c6be1038..2b88720d76 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -13,19 +13,18 @@ import org.apache.jmeter.visualizers.backend.BackendListenerContext; import java.io.Serializable; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; /** * JMeter BackendListener扩展, jmx脚本中使用 */ public class APIBackendListenerClient extends AbstractBackendListenerClient implements Serializable { + public final static String TEST_ID = "ms.test.id"; + private final static String THREAD_SPLIT = " "; private final static String ID_SPLIT = "-"; - private final static String TEST_ID = "id"; - private final List queue = new ArrayList<>(); private APITestService apiTestService; @@ -33,11 +32,11 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl private APIReportService apiReportService; // 测试ID - private String id; + private String testId; @Override public void setupTest(BackendListenerContext context) throws Exception { - this.id = context.getParameter(TEST_ID); + this.testId = context.getParameter(TEST_ID); apiTestService = CommonBeanFactory.getBean(APITestService.class); if (apiTestService == null) { LogUtil.error("apiTestService is required"); @@ -47,6 +46,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl if (apiReportService == null) { LogUtil.error("apiReportService is required"); } + super.setupTest(context); } @Override @@ -57,7 +57,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl @Override public void teardownTest(BackendListenerContext context) throws Exception { TestResult testResult = new TestResult(); - testResult.setTestId(id); + testResult.setTestId(testId); testResult.setTotal(queue.size()); // 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id @@ -99,7 +99,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl testResult.getScenarios().addAll(scenarios.values()); testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId)); - apiTestService.changeStatus(id, APITestStatus.Completed); + apiTestService.changeStatus(testId, APITestStatus.Completed); apiReportService.complete(testResult); queue.clear(); diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index bc5207fa0a..ceeeab9ed0 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -3,8 +3,10 @@ package io.metersphere.api.jmeter; import io.metersphere.commons.exception.MSException; import io.metersphere.config.JmeterProperties; import io.metersphere.i18n.Translator; +import org.apache.jmeter.config.Arguments; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.util.JMeterUtils; +import org.apache.jmeter.visualizers.backend.BackendListener; import org.apache.jorphan.collections.HashTree; import org.springframework.stereotype.Service; @@ -19,7 +21,7 @@ public class JMeterService { @Resource private JmeterProperties jmeterProperties; - public void run(InputStream is) { + public void run(String testId, InputStream is) { String JMETER_HOME = jmeterProperties.getHome(); String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties"; JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES); @@ -27,6 +29,7 @@ public class JMeterService { try { Object scriptWrapper = SaveService.loadElement(is); HashTree testPlan = getHashTree(scriptWrapper); + addBackendListener(testId, testPlan); LocalRunner runner = new LocalRunner(testPlan); runner.run(); @@ -40,4 +43,14 @@ public class JMeterService { field.setAccessible(true); return (HashTree) field.get(scriptWrapper); } + + private void addBackendListener(String testId, HashTree testPlan) { + BackendListener backendListener = new BackendListener(); + backendListener.setName(testId); + Arguments arguments = new Arguments(); + arguments.addArgument(APIBackendListenerClient.TEST_ID, testId); + backendListener.setArguments(arguments); + backendListener.setClassname(APIBackendListenerClient.class.getCanonicalName()); + testPlan.add(testPlan.getArray()[0], backendListener); + } } diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index db88c9dd11..8b731ab3ee 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -90,7 +90,7 @@ public class APITestService { String reportId = apiReportService.create(get(request.getId())); changeStatus(request.getId(), APITestStatus.Running); - jMeterService.run(is); + jMeterService.run(request.getId(), is); return reportId; } diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index fdeb504d0f..297f6b81b3 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -386,7 +386,6 @@ class JMXGenerator { let testPlan = new TestPlan(test.name); this.addScenarios(testPlan, test.scenarioDefinition); - this.addBackendListener(testPlan, test.id); this.jmeterTestPlan = new JMeterTestPlan(); this.jmeterTestPlan.put(testPlan); @@ -424,12 +423,6 @@ class JMXGenerator { }) } - addBackendListener(testPlan, testId) { - let className = 'io.metersphere.api.jmeter.APIBackendListenerClient'; - let args = [new KeyValue("id", testId)]; - testPlan.put(new BackendListener(testId, className, args)); - } - addScenarioVariables(threadGroup, scenario) { let args = this.replaceKV(scenario.variables); if (args.length > 0) { From 7dce48c7bb42fd914895091abeab353339a4ad96 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 25 May 2020 16:20:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?bug=20fix=20=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E9=87=8D=E5=A4=8D=E8=BF=9B=E5=85=A5=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E8=B7=AF=E7=94=B1=E5=88=B7=E6=96=B0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/settings/organization/OrganizationMember.vue | 2 +- .../components/settings/organization/OrganizationWorkspace.vue | 2 +- .../src/business/components/settings/personal/PersonSetting.vue | 2 +- .../src/business/components/settings/system/Organization.vue | 2 +- .../src/business/components/settings/system/SystemWorkspace.vue | 2 +- .../business/components/settings/system/TestResourcePool.vue | 2 +- frontend/src/business/components/settings/system/User.vue | 2 +- .../business/components/settings/workspace/WorkspaceMember.vue | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/business/components/settings/organization/OrganizationMember.vue b/frontend/src/business/components/settings/organization/OrganizationMember.vue index 17d347d478..e78e5c61f9 100644 --- a/frontend/src/business/components/settings/organization/OrganizationMember.vue +++ b/frontend/src/business/components/settings/organization/OrganizationMember.vue @@ -105,7 +105,7 @@ export default { name: "MsOrganizationMember", components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag, MsTableOperator, MsDialogFooter}, - created() { + activated() { this.initTableData(); }, data() { diff --git a/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue b/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue index 733bf73c2c..0f9f1dc56e 100644 --- a/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue +++ b/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue @@ -156,7 +156,7 @@ export default { name: "MsOrganizationWorkspace", components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag, MsTableOperator, MsDialogFooter}, - mounted() { + activated() { this.list(); }, computed: { diff --git a/frontend/src/business/components/settings/personal/PersonSetting.vue b/frontend/src/business/components/settings/personal/PersonSetting.vue index 952642cc0e..ef6911d872 100644 --- a/frontend/src/business/components/settings/personal/PersonSetting.vue +++ b/frontend/src/business/components/settings/personal/PersonSetting.vue @@ -148,7 +148,7 @@ } }, - created() { + activated() { this.initTableData(); }, methods: { diff --git a/frontend/src/business/components/settings/system/Organization.vue b/frontend/src/business/components/settings/system/Organization.vue index d3032685f1..0a9ee0a582 100644 --- a/frontend/src/business/components/settings/system/Organization.vue +++ b/frontend/src/business/components/settings/system/Organization.vue @@ -231,7 +231,7 @@ } } }, - created() { + activated() { this.initTableData(); }, methods: { diff --git a/frontend/src/business/components/settings/system/SystemWorkspace.vue b/frontend/src/business/components/settings/system/SystemWorkspace.vue index 531d3f5a43..e0cd212b72 100644 --- a/frontend/src/business/components/settings/system/SystemWorkspace.vue +++ b/frontend/src/business/components/settings/system/SystemWorkspace.vue @@ -201,7 +201,7 @@ export default { name: "MsSystemWorkspace", components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag, MsTableOperator, MsDialogFooter}, - mounted() { + activated() { this.list(); }, methods: { diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index 6163c32b79..557944504d 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -256,7 +256,7 @@ } } }, - created() { + activated() { this.initTableData(); }, methods: { diff --git a/frontend/src/business/components/settings/system/User.vue b/frontend/src/business/components/settings/system/User.vue index 6e0bcebc91..9af3d1596e 100644 --- a/frontend/src/business/components/settings/system/User.vue +++ b/frontend/src/business/components/settings/system/User.vue @@ -386,7 +386,7 @@ } } }, - created() { + activated() { this.search(); this.getAllRole(); }, diff --git a/frontend/src/business/components/settings/workspace/WorkspaceMember.vue b/frontend/src/business/components/settings/workspace/WorkspaceMember.vue index fa73572f22..262f5ab49d 100644 --- a/frontend/src/business/components/settings/workspace/WorkspaceMember.vue +++ b/frontend/src/business/components/settings/workspace/WorkspaceMember.vue @@ -130,7 +130,7 @@ total: 0, } }, - created: function () { + activated: function () { this.initTableData(); }, methods: { From a16c0be4066fa26e17f7ce40effd508b7e300deb Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 25 May 2020 17:00:54 +0800 Subject: [PATCH 4/4] i18n --- .../components/settings/system/User.vue | 74 +++++++++---------- frontend/src/i18n/en-US.js | 2 +- frontend/src/i18n/zh-CN.js | 4 +- frontend/src/i18n/zh-TW.js | 3 +- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/frontend/src/business/components/settings/system/User.vue b/frontend/src/business/components/settings/system/User.vue index 9af3d1596e..51fe7b70bf 100644 --- a/frontend/src/business/components/settings/system/User.vue +++ b/frontend/src/business/components/settings/system/User.vue @@ -68,29 +68,29 @@
- - + - {{item.name}} + {{$t('role.' + item.id)}} - 删除 + {{$t('commons.delete')}}
- - +
- - +
- - +
- - + @@ -177,27 +177,27 @@
- - + - 删除 + {{$t('commons.delete')}}
- - +
- - +
- - +
- - + diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 5843bdcb93..c8927fc069 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -56,7 +56,6 @@ export default { 'personal_information': 'Personal Information', 'exit_system': 'Exit System', 'verification': 'Verification', - 'set_admin': 'Set Admin', 'system_parameter_setting': 'System Parameter Setting', 'connection_successful': 'Connection successful', 'connection_failed': 'Connection failed', @@ -163,6 +162,7 @@ export default { 'test_manager': 'Test Manager', 'test_user': 'Test User', 'test_viewer': 'Test Viewer', + 'add': 'Add Role', }, report: { 'recent': 'Recent Report', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 4c8f6b1d50..e76efc3e62 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -80,7 +80,6 @@ export default { 'weeks_5': '周五', 'weeks_6': '周六', 'test_unit': '测试', - 'set_admin': '设置为管理员', 'system_parameter_setting': '系统参数设置', 'connection_successful': '连接成功', 'connection_failed': '连接失败', @@ -160,7 +159,8 @@ export default { 'org_admin': '组织管理员', 'test_manager': '测试经理', 'test_user': '测试人员', - 'test_viewer': 'Viewer' + 'test_viewer': 'Viewer', + 'add': '添加角色', }, report: { 'recent': '最近的报告', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 534a571195..df812a5def 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -152,7 +152,8 @@ export default { 'org_admin': '組織管理員', 'test_manager': '測試經理', 'test_user': '測試人員', - 'test_viewer': 'Viewer' + 'test_viewer': 'Viewer', + 'add': '添加角色', }, report: { 'name': '項目名稱',