From ea595e3df1afcfce258f9433b09923233a156324 Mon Sep 17 00:00:00 2001 From: mmagi Date: Wed, 7 Jun 2023 13:12:55 +0800 Subject: [PATCH 1/5] fix: webhook robot missing impl --- .../cloud/sonic/controller/tools/robot/vendor/WebhookImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/WebhookImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/WebhookImpl.java index 0b7d9c53..2419d873 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/WebhookImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/WebhookImpl.java @@ -5,9 +5,11 @@ import org.cloud.sonic.controller.tools.robot.RobotMessenger; import org.springframework.expression.Expression; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @Slf4j +@Service("WebhookImpl") public class WebhookImpl implements RobotMessenger { @Override public void sendMessage(RestTemplate restTemplate, String token, String secret, Expression messageTemplate, Message message) { From a276a4ded780d5e3ce09672831a843eca8c611a3 Mon Sep 17 00:00:00 2001 From: mmagi Date: Wed, 7 Jun 2023 16:47:05 +0800 Subject: [PATCH 2/5] fix: summary robot not working --- .../cloud/sonic/controller/mapper/AlertRobotsMapper.java | 8 -------- .../controller/services/impl/AlertRobotsServiceImpl.java | 3 +-- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/AlertRobotsMapper.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/AlertRobotsMapper.java index 0d6b3b79..16a82d77 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/AlertRobotsMapper.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/AlertRobotsMapper.java @@ -73,12 +73,4 @@ default List computeAgentRobots(int agentId) { return listAgentRobotsFromIds(ids); } - @Select(""" - select * from alert_robots r where scene = 'summary' - and ( - r.project_id = ${projectId} or - (r.project_id is null and 1 = (select global_robot from projects where id = ${projectId}) - ) - """) - List computeSummaryRobots(@Param("projectId") int projectId); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java index 36523cf8..0d7577b6 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java @@ -32,7 +32,6 @@ import org.cloud.sonic.controller.tools.robot.message.TestSuiteMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -85,7 +84,7 @@ public void sendResultFinishReport(int suitId, String suiteName, int pass, int w @Override public void sendProjectReportMessage(int projectId, String projectName, Date startDate, Date endDate, boolean isWeekly, int pass, int warn, int fail) { - var robots = baseMapper.computeSummaryRobots(projectId); + var robots = findRobots(projectId, SCENE_SUMMARY).list(); if (robots.isEmpty()) return; var total = pass + warn + fail; var rate = total > 0 ? BigDecimal.valueOf(((float) pass / total) * 100).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0; From 779dc79bd2f37068c82dc381160f7a51842d1783 Mon Sep 17 00:00:00 2001 From: mmagi Date: Wed, 7 Jun 2023 20:02:50 +0800 Subject: [PATCH 3/5] fix: bot for agent temperature scale --- .../controller/services/impl/AlertRobotsServiceImpl.java | 3 ++- .../sonic/controller/tools/robot/message/DeviceMessage.java | 4 +++- .../org/cloud/sonic/controller/tools/RobotMsgToolTest.java | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java index 0d7577b6..009469e2 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java @@ -36,6 +36,7 @@ import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; +import java.math.BigInteger; import java.math.RoundingMode; import java.util.Date; import java.util.List; @@ -97,7 +98,7 @@ public void sendProjectReportMessage(int projectId, String projectName, Date sta public void sendErrorDevice(int agentId, int errorType, int tem, String udId) { var robots = baseMapper.computeAgentRobots(agentId); if (robots.isEmpty()) return; - var msg = new DeviceMessage(errorType, tem, udId); + var msg = new DeviceMessage(errorType, new BigDecimal(BigInteger.valueOf(tem), 1), udId); send(robots, msg); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/message/DeviceMessage.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/message/DeviceMessage.java index 3548db9c..29c9dc16 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/message/DeviceMessage.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/message/DeviceMessage.java @@ -20,9 +20,11 @@ import lombok.AllArgsConstructor; import org.cloud.sonic.controller.tools.robot.Message; +import java.math.BigDecimal; + @AllArgsConstructor public class DeviceMessage extends Message { public int errorType; - public int tem; + public BigDecimal tem; public String udId; } diff --git a/sonic-server-controller/src/test/java/org/cloud/sonic/controller/tools/RobotMsgToolTest.java b/sonic-server-controller/src/test/java/org/cloud/sonic/controller/tools/RobotMsgToolTest.java index c94b911c..d6185ac9 100644 --- a/sonic-server-controller/src/test/java/org/cloud/sonic/controller/tools/RobotMsgToolTest.java +++ b/sonic-server-controller/src/test/java/org/cloud/sonic/controller/tools/RobotMsgToolTest.java @@ -30,6 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; +import java.math.BigDecimal; import java.util.Date; @SpringBootTest(classes = ControllerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -37,7 +38,7 @@ public class RobotMsgToolTest { private void testMessage(RobotMessenger bot, String token, String secret) { - for (var msg : new Message[]{new DeviceMessage(0, 0, "test"), new ProjectSummaryMessage(0, "test", new Date(System.currentTimeMillis() - 7 * 24 * 3600 * 1000), new Date(), 1, 3, 4, 1.4, 3, "https://sonic/?#=+", true), new ProjectSummaryMessage(0, "test", new Date(System.currentTimeMillis() - 24 * 3600 * 1000), new Date(), 1, 3, 4, 1.4, 3, "https://sonic/?#=+", false), new TestSuiteMessage("asf", 0, 1, 4, 5, 3, "https://sonic/?#=+"),}) { + for (var msg : new Message[]{new DeviceMessage(0, new BigDecimal(0), "test"), new ProjectSummaryMessage(0, "test", new Date(System.currentTimeMillis() - 7 * 24 * 3600 * 1000), new Date(), 1, 3, 4, 1.4, 3, "https://sonic/?#=+", true), new ProjectSummaryMessage(0, "test", new Date(System.currentTimeMillis() - 24 * 3600 * 1000), new Date(), 1, 3, 4, 1.4, 3, "https://sonic/?#=+", false), new TestSuiteMessage("asf", 0, 1, 4, 5, 3, "https://sonic/?#=+"),}) { bot.sendMessage(new RestTemplate(), token, secret, "", msg); } } From 925d1236058d3b1ae9d3589284ff54327551ffb7 Mon Sep 17 00:00:00 2001 From: mmagi Date: Thu, 8 Jun 2023 12:21:33 +0800 Subject: [PATCH 4/5] fix: default template query api may lose prefix --- .../services/impl/AlertRobotsServiceImpl.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java index 009469e2..a6e64b4e 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/AlertRobotsServiceImpl.java @@ -27,11 +27,14 @@ import org.cloud.sonic.controller.services.impl.base.SonicServiceImpl; import org.cloud.sonic.controller.tools.robot.Message; import org.cloud.sonic.controller.tools.robot.RobotFactory; +import org.cloud.sonic.controller.tools.robot.RobotMessenger; import org.cloud.sonic.controller.tools.robot.message.DeviceMessage; import org.cloud.sonic.controller.tools.robot.message.ProjectSummaryMessage; import org.cloud.sonic.controller.tools.robot.message.TestSuiteMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpression; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -118,11 +121,18 @@ private void send(List robots, Message message) { @Override public String getDefaultNoticeTemplate(int type, String scene) { var messenger = robotFactory.getRobotMessenger(type); - return switch (scene) { - case SCENE_AGENT -> messenger.getDefaultDeviceMessageTemplate().getExpressionString(); - case SCENE_SUMMARY -> messenger.getDefaultProjectSummaryTemplate().getExpressionString(); - case SCENE_TESTSUITE -> messenger.getDefaultTestSuiteTemplate().getExpressionString(); - default -> ""; + var template = switch (scene) { + case SCENE_AGENT -> messenger.getDefaultDeviceMessageTemplate(); + case SCENE_SUMMARY -> messenger.getDefaultProjectSummaryTemplate(); + case SCENE_TESTSUITE -> messenger.getDefaultTestSuiteTemplate(); + default -> null; }; + if (null == template) { + return ""; + } else if (template instanceof SpelExpression) { + return RobotMessenger.templateParserContext.getExpressionPrefix() + template.getExpressionString() + RobotMessenger.templateParserContext.getExpressionSuffix(); + } else { + return template.getExpressionString(); + } } } From a840cacca760787404592c1fd664e9919cec5f1a Mon Sep 17 00:00:00 2001 From: mmagi Date: Thu, 8 Jun 2023 15:25:29 +0800 Subject: [PATCH 5/5] fix: robot delete failed from project menu --- .../sonic/controller/controller/AlertRobotsController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsController.java index 727af057..60a184fa 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsController.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsController.java @@ -17,6 +17,7 @@ */ package org.cloud.sonic.controller.controller; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -93,7 +94,7 @@ public RespModel delete( @Parameter(name = "projectId", description = "项目id") int projectId, @RequestParam(name = "id") int id ) { - if (alertRobotsService.removeByMap(Map.of("id", id, "projectId", projectId))) { + if (alertRobotsService.remove(Wrappers.lambdaQuery(AlertRobots.class).eq(AlertRobots::getId, id).eq(AlertRobots::getProjectId, projectId))) { return new RespModel<>(RespEnum.DELETE_OK); } else { return new RespModel<>(RespEnum.DELETE_FAIL);