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/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 75914f9a28..bba35f816f 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; @@ -130,6 +131,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()); @@ -213,6 +215,7 @@ public class PerformanceTestService { testReport.setUpdateTime(engine.getStartTime()); testReport.setTestId(loadTest.getId()); testReport.setName(loadTest.getName()); + testReport.setUserId(SessionUtils.getUser().getId()); // 启动测试 try { 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) { 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..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')}}
- - +
- - +
- - +
- - + @@ -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: { diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index f879729e03..2acd9b6790 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', @@ -164,6 +163,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 bfd2a5f835..9380409342 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': '连接失败', @@ -161,7 +160,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 3229826df1..39863ce760 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -153,7 +153,8 @@ export default { 'org_admin': '組織管理員', 'test_manager': '測試經理', 'test_user': '測試人員', - 'test_viewer': 'Viewer' + 'test_viewer': 'Viewer', + 'add': '添加角色', }, report: { 'name': '項目名稱',