From eecc351061396bcac31427de9bb746a3a767c975 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 17 Sep 2020 15:52:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E9=A1=B5=E9=9D=A2=E5=8F=AF=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xml/reader/jmx/JmeterDocumentParser.java | 6 +- .../components/PerformanceAdvancedConfig.vue | 297 +++++++++--------- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 5 files changed, 163 insertions(+), 143 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index fa090c5af1..3b19b1b30b 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -442,8 +442,10 @@ public class JmeterDocumentParser implements DocumentParser { // 增加一个response_timeout,避免目标网站不反回结果导致测试不能结束 if (item instanceof Element && nodeNameEquals(item, STRING_PROP) && StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.response_timeout")) { - removeChildren(item); - item.appendChild(ele.getOwnerDocument().createTextNode("")); + if (context.getProperty("responseTimeout") != null) { + removeChildren(item); + item.appendChild(ele.getOwnerDocument().createTextNode(context.getProperty("responseTimeout").toString())); + } } } } diff --git a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue index ea28c41c89..5429c37056 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue @@ -90,6 +90,20 @@ + + + +
{{ $t('load_test.response_timeout') }}
+
+ + + + + ms + +
+
@@ -109,169 +123,170 @@ diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index c580a0f5e0..dc26cbd7f1 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -378,6 +378,7 @@ export default { domain_ip_is_empty: 'Domain and IP cannot be empty', param_name_value_is_empty: 'Parameters cannot be empty', connect_timeout: 'Timeout to establish a connection', + response_timeout: 'Timeout to response', custom_http_code: 'Custom HTTP response success status code', separated_by_commas: 'Separated by commas', create: 'Create Test', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 619d479765..d1857d72d6 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -377,6 +377,7 @@ export default { domain_ip_is_empty: '域名和IP不能为空', param_name_value_is_empty: '参数名和参数值不能为空', connect_timeout: '建立连接超时时间', + response_timeout: '响应超时时间', custom_http_code: '自定义 HTTP 响应成功状态码', separated_by_commas: '按逗号分隔', create: '创建测试', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index ffed703ea6..13897a56bf 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -377,6 +377,7 @@ export default { domain_ip_is_empty: '域名和IP不能為空', param_name_value_is_empty: '參數名和參數值不能為空', connect_timeout: '建立連接超時時間', + response_timeout: '響應超時時間', custom_http_code: '自定義 HTTP 響應成功狀態碼', separated_by_commas: '按逗號分隔', create: '創建測試', From f0198ccb6828108132927fdff15041bc2ad9193a Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 17 Sep 2020 16:05:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=E5=90=8C=E6=AD=A5submodule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/business/components/xpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 0a375848d0..f2d5a342c8 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 0a375848d034d20eaf05caf11769e1c75c39235c +Subproject commit f2d5a342c82e629f510550d5778d752bb73bf5e7 From 167dd8d0e8c185e652bcde7778ccbb0627d88e1c Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Thu, 17 Sep 2020 16:14:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 11 ++- .../api/service/APITestService.java | 4 +- .../notice/service/MailService.java | 80 ++++++++++--------- .../notice/service/NoticeService.java | 76 ++++++++++++------ .../service/PerformanceTestService.java | 2 +- .../common/components/MsScheduleEdit.vue | 5 +- 6 files changed, 107 insertions(+), 71 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 40fc87a64c..0549b16b61 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -3,16 +3,20 @@ package io.metersphere.api.jmeter; import io.metersphere.api.service.APIReportService; import io.metersphere.api.service.APITestService; import io.metersphere.base.domain.ApiTestReport; +import io.metersphere.base.domain.Notice; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.notice.service.MailService; +import io.metersphere.notice.service.NoticeService; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.assertions.AssertionResult; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient; import org.apache.jmeter.visualizers.backend.BackendListenerContext; +import javax.annotation.Resource; import java.io.Serializable; import java.util.*; @@ -113,9 +117,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl report = apiReportService.getRunningReport(testResult.getTestId()); } apiReportService.complete(testResult, report); - queue.clear(); super.teardownTest(context); + NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class); + List notice = noticeService.queryNotice(testResult.getTestId()); + MailService mailService = CommonBeanFactory.getBean(MailService.class); + mailService.sendHtml(report.getId(), notice, report.getStatus(), "api"); } private RequestResult getRequestResult(SampleResult result) { @@ -170,7 +177,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl this.runMode = context.getParameter("runMode"); this.debugReportId = context.getParameter("debugReportId"); if (StringUtils.isBlank(this.runMode)) { - this.runMode = ApiRunMode.RUN.name(); + this.runMode = ApiRunMode.RUN.name(); } } 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 003f7b213d..ab2d8e2302 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -223,10 +223,10 @@ public class APITestService { apiTest.setUserId(request.getUserId()); } String reportId = apiReportService.create(apiTest, request.getTriggerMode()); - if (request.getTriggerMode().equals("SCHEDULE")) { + /*if (request.getTriggerMode().equals("SCHEDULE")) { List notice = noticeService.queryNotice(request.getId()); mailService.sendHtml(reportId,notice,"api"); - } + }*/ changeStatus(request.getId(), APITestStatus.Running); jMeterService.run(request.getId(), null, is); return reportId; diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index efee1a4519..8a27cd23b3 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -9,6 +9,7 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.LoadTestDTO; import io.metersphere.service.SystemParameterService; import io.metersphere.service.UserService; +import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; @@ -30,25 +31,25 @@ public class MailService { @Resource private SystemParameterService systemParameterService; - public void sendHtml(String id, List notice,String type) { + public void sendHtml(String id, List notice, String status, String type) { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); - List paramList=systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue()); + List paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue()); javaMailSender.setDefaultEncoding("UTF-8"); javaMailSender.setProtocol("smtps"); - for(SystemParameter p:paramList){ - if(p.getParamKey().equals("smtp.host")){ - javaMailSender.setHost(p.getParamValue()); - } - if(p.getParamKey().equals("smtp.port")){ - javaMailSender.setPort(Integer.parseInt(p.getParamValue())); - } - if(p.getParamKey().equals("smtp.account")){ - javaMailSender.setUsername(p.getParamValue()); - } - if(p.getParamKey().equals("smtp.password")){ - javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString()); - } + for (SystemParameter p : paramList) { + if (p.getParamKey().equals("smtp.host")) { + javaMailSender.setHost(p.getParamValue()); } + if (p.getParamKey().equals("smtp.port")) { + javaMailSender.setPort(Integer.parseInt(p.getParamValue())); + } + if (p.getParamKey().equals("smtp.account")) { + javaMailSender.setUsername(p.getParamValue()); + } + if (p.getParamKey().equals("smtp.password")) { + javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString()); + } + } Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); @@ -58,15 +59,12 @@ public class MailService { javaMailSender.setJavaMailProperties(props); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); String testName = ""; - String state = ""; if (type.equals("api")) { APIReportResult reportResult = apiAndPerformanceHelper.getApi(id); testName = reportResult.getTestName(); - state = reportResult.getStatus(); } else if (type.equals("performance")) { LoadTestDTO performanceResult = apiAndPerformanceHelper.getPerformance(id); testName = performanceResult.getName(); - state = performanceResult.getStatus(); } String html1 = "\n" + "\n" + @@ -76,12 +74,12 @@ public class MailService { "\n" + "\n" + "
\n" + - "

"+type+"定时任务结果通知

\n" + - "

尊敬的用户:您好,您所执行的"+testName+"运行失败,请点击报告链接查看

\n" + + "

" + type + "定时任务结果通知

\n" + + "

尊敬的用户:您好,您所执行的" + testName + "运行失败,请点击报告链接查看

\n" + "
\n" + "\n" + ""; - String html2="\n" + + String html2 = "\n" + "\n" + "\n" + " \n" + @@ -89,8 +87,8 @@ public class MailService { "\n" + "\n" + "
\n" + - "

"+type+"定时任务结果通知

\n" + - "

尊敬的用户:您好,"+testName+"运行成功,请点击报告链接查看

\n" + + "

" + type + "定时任务结果通知

\n" + + "

尊敬的用户:您好," + testName + "运行成功,请点击报告链接查看

\n" + "
\n" + "\n" + ""; @@ -99,36 +97,40 @@ public class MailService { helper.setFrom(javaMailSender.getUsername()); helper.setSubject("MeterSphere定时任务结果通知"); String users[] = {}; - List successEmailList=new ArrayList<>(); - List failEmailList=new ArrayList<>(); - if(notice.size()>0){ - for(Notice n:notice){ - if (n.getEnable().equals("true")&&n.getEvent().equals("执行成功")) { - successEmailList=userService.queryEmail(n.getNames()); + List successEmailList = new ArrayList<>(); + List failEmailList = new ArrayList<>(); + if (notice.size() > 0) { + for (Notice n : notice) { + if (n.getEnable().equals("true") && n.getEvent().equals("执行成功")) { + successEmailList = userService.queryEmail(n.getNames()); } - if (n.getEnable().equals("true")&&n.getEvent().equals("执行失败")) { - failEmailList=userService.queryEmail(n.getNames()); + if (n.getEnable().equals("true") && n.getEvent().equals("执行失败")) { + failEmailList = userService.queryEmail(n.getNames()); } } - }else{ + } else { LogUtil.error("Recipient information is empty"); } - if(state.equals("success")){ - users=successEmailList.toArray(new String[successEmailList.size()]); - helper.setText(html2,true); - }else{ - users=failEmailList.toArray(new String[failEmailList.size()]); - helper.setText(html1,true); + if (status.equals("Success")) { + users = successEmailList.toArray(new String[successEmailList.size()]); + helper.setText(html2, true); + } else { + users = failEmailList.toArray(new String[failEmailList.size()]); + helper.setText(html1, true); } helper.setTo(users); - javaMailSender.send(mimeMessage); } catch (MessagingException e) { e.printStackTrace(); } + try { + javaMailSender.send(mimeMessage); + } catch (MailException e) { + e.printStackTrace(); + } } diff --git a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java index cbac52e361..07cc829ce8 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -16,53 +16,77 @@ import java.util.List; public class NoticeService { @Resource private NoticeMapper noticeMapper; + public void saveNotice(NoticeRequest noticeRequest) { + Notice notice = new Notice(); NoticeExample example = new NoticeExample(); example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId()); List notices = noticeMapper.selectByExample(example); - if (notices != null) { + if (notices.size() > 0) { noticeMapper.deleteByExample(example); - noticeRequest.getNotices().forEach(notice -> { - for(String x:notice.getNames()){ - notice.setEvent(notice.getEvent()); - notice.setEmail(notice.getEmail()); - notice.setEnable(notice.getEnable()); + noticeRequest.getNotices().forEach(n -> { + if (n.getNames().length > 0) { + for (String x : n.getNames()) { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); + notice.setTestId(noticeRequest.getTestId()); + notice.setName(x); + noticeMapper.insert(notice); + } + } else { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); notice.setTestId(noticeRequest.getTestId()); - notice.setName(x); + notice.setName(""); noticeMapper.insert(notice); } }); } else { - noticeRequest.getNotices().forEach(notice -> { - notice.setEvent(noticeRequest.getEvent()); - notice.setTestId(noticeRequest.getTestId()); - noticeMapper.insert(notice); + noticeRequest.getNotices().forEach(n -> { + if (n.getNames().length > 0) { + for (String x : n.getNames()) { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); + notice.setTestId(noticeRequest.getTestId()); + notice.setName(x); + noticeMapper.insert(notice); + } + } else { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); + notice.setTestId(noticeRequest.getTestId()); + notice.setName(""); + noticeMapper.insert(notice); + } }); } - } public List queryNotice(String id) { NoticeExample example = new NoticeExample(); example.createCriteria().andTestIdEqualTo(id); - List notices=noticeMapper.selectByExample(example); - List notice=new ArrayList<>(); - List success=new ArrayList<>(); - List fail=new ArrayList<>(); - String[] successArray=new String[success.size()]; - String[] failArray=new String[fail.size()]; - Notice notice1=new Notice(); - Notice notice2=new Notice(); - if(notices.size()>0){ - for(Notice n:notices){ - if(n.getEvent().equals("执行成功")){ + List notices = noticeMapper.selectByExample(example); + List notice = new ArrayList<>(); + List success = new ArrayList<>(); + List fail = new ArrayList<>(); + String[] successArray = new String[success.size()]; + String[] failArray = new String[fail.size()]; + Notice notice1 = new Notice(); + Notice notice2 = new Notice(); + if (notices.size() > 0) { + for (Notice n : notices) { + if (n.getEvent().equals("执行成功")) { success.add(n.getName()); notice1.setEnable(n.getEnable()); notice1.setTestId(id); notice1.setEvent(n.getEvent()); notice1.setEmail(n.getEmail()); } - if(n.getEvent().equals("执行失败")){ + if (n.getEvent().equals("执行失败")) { fail.add(n.getName()); notice2.setEnable(n.getEnable()); notice2.setTestId(id); @@ -70,8 +94,8 @@ public class NoticeService { notice2.setEmail(n.getEmail()); } } - successArray=success.toArray(new String[success.size()]); - failArray=fail.toArray(new String[fail.size()]); + successArray = success.toArray(new String[success.size()]); + failArray = fail.toArray(new String[fail.size()]); notice1.setNames(successArray); notice2.setNames(failArray); notice.add(notice1); 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 97b73d1b87..75cbb42b16 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -239,7 +239,7 @@ public class PerformanceTestService { startEngine(loadTest, engine, request.getTriggerMode()); if (request.getTriggerMode().equals("SCHEDULE")) { List notice = noticeService.queryNotice(request.getId()); - mailService.sendHtml(engine.getReportId(),notice,"performance"); + mailService.sendHtml(engine.getReportId(), notice, "success", "performance"); } return engine.getReportId(); } diff --git a/frontend/src/business/components/common/components/MsScheduleEdit.vue b/frontend/src/business/components/common/components/MsScheduleEdit.vue index 4da1b2c248..cb6d6bd411 100644 --- a/frontend/src/business/components/common/components/MsScheduleEdit.vue +++ b/frontend/src/business/components/common/components/MsScheduleEdit.vue @@ -71,6 +71,7 @@ + {{$t('commons.save')}} @@ -206,9 +207,11 @@ return false; } }); + }, + saveNotice(){ let param = this.buildParam(); this.result = this.$post("notice/save", param, () => { - + this.$success(this.$t('commons.save_success')); }) }, close() {