-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from mmagi/feat_bot
feat: configurable alert robot with SpEL template
- Loading branch information
Showing
39 changed files
with
1,510 additions
and
1,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ontroller/src/main/java/org/cloud/sonic/controller/config/mybatis/RobotConfigMigrate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* sonic-server Sonic Cloud Real Machine Platform. | ||
* Copyright (C) 2022 SonicCloudOrg | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.cloud.sonic.controller.config.mybatis; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.cloud.sonic.controller.mapper.AlertRobotsMigrateMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @deprecated 保留此类一段时间,在ActableConfig完成之后执行, | ||
* 如果发现旧的robot_token配置数据,则自动迁移到新的表结构中,并清空robot_token, | ||
* 表结构保留原字段需要暂时保留以免ActableConfig后数据丢失, | ||
* 后续完成过渡后可直接删除此类。 | ||
* 此过程需在ActableConfig完成后才可进行, | ||
* Order等注解某些打包方式可能出现不生效问题,通过直接依赖config确保执行顺序 | ||
*/ | ||
@Configuration | ||
@Slf4j | ||
@Deprecated | ||
public class RobotConfigMigrate { | ||
public RobotConfigMigrate( | ||
@Autowired AlertRobotsMigrateMapper robotsMapper, | ||
@Autowired ActableConfig config | ||
) { | ||
if (null == config) return; | ||
int n; | ||
if ((n = robotsMapper.migrateProjectRobot()) > 0) { | ||
log.warn("legacy project robot found! migrated to {} alert robots", n); | ||
robotsMapper.clearProjectRobot(); | ||
} | ||
if ((n = robotsMapper.migrateAgentRobot()) > 0) { | ||
log.warn("legacy project robot found! migrated to {} alert robots", n); | ||
robotsMapper.clearAgentRobot(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...oller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* sonic-server Sonic Cloud Real Machine Platform. | ||
* Copyright (C) 2022 SonicCloudOrg | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.cloud.sonic.controller.controller; | ||
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.cloud.sonic.common.config.WebAspect; | ||
import org.cloud.sonic.common.config.WhiteUrl; | ||
import org.cloud.sonic.common.http.RespEnum; | ||
import org.cloud.sonic.common.http.RespModel; | ||
import org.cloud.sonic.controller.models.base.CommentPage; | ||
import org.cloud.sonic.controller.models.domain.AlertRobots; | ||
import org.cloud.sonic.controller.models.dto.AlertRobotsDTO; | ||
import org.cloud.sonic.controller.services.AlertRobotsService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Tag(name = "告警通知机器人相关") | ||
@RestController | ||
@RequestMapping("/alertRobotsAdmin") | ||
public class AlertRobotsAdminController { | ||
|
||
@Autowired | ||
private AlertRobotsService alertRobotsService; | ||
|
||
@WebAspect | ||
@Operation(summary = "更新机器人参数", description = "新增或更新对应的机器人") | ||
@PutMapping | ||
public RespModel<String> save(@Validated @RequestBody AlertRobotsDTO alertRobotsDTO) { | ||
alertRobotsService.saveOrUpdate(alertRobotsDTO.convertTo()); | ||
return new RespModel<>(RespEnum.UPDATE_OK); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "查找机器人参数", description = "查找所有机器人参数列表") | ||
@GetMapping("/list") | ||
@Parameters(value = { | ||
@Parameter(name = "scene", allowEmptyValue = true, description = "使用场景"), | ||
@Parameter(name = "page", description = "页码"), | ||
@Parameter(name = "pageSize", description = "页尺寸") | ||
}) | ||
public RespModel<CommentPage<AlertRobots>> listAll( | ||
@RequestParam(name = "scene", required = false) String scene, | ||
@RequestParam(name = "page") int page, | ||
@RequestParam(name = "pageSize", defaultValue = "20") int pageSize | ||
) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.findRobots(new Page<>(page, pageSize), null, scene)); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "查找机器人参数", description = "查找所有机器人参数列表") | ||
@GetMapping("/listAll") | ||
@Parameters(value = { | ||
@Parameter(name = "scene", allowEmptyValue = true, description = "使用场景") | ||
}) | ||
public RespModel<List<AlertRobots>> listAll( | ||
@RequestParam(name = "scene", required = false) String scene | ||
) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.findAllRobots(null, scene)); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "删除机器人参数", description = "删除对应id的机器人参数") | ||
@Parameter(name = "id", description = "id") | ||
@DeleteMapping | ||
public RespModel<String> delete(@RequestParam(name = "id") int id) { | ||
if (alertRobotsService.removeById(id)) { | ||
return new RespModel<>(RespEnum.DELETE_OK); | ||
} else { | ||
return new RespModel<>(RespEnum.DELETE_FAIL); | ||
} | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "获取机器人对类型机器人在相应使用场景下的默认模板", description = "获取机器人对类型机器人在相应使用场景下的默认模板") | ||
@Parameter(name = "type", description = "type") | ||
@Parameter(name = "scene", description = "scene") | ||
@GetMapping("/findDefaultTemplate") | ||
@WhiteUrl | ||
public RespModel<String> getDefaultNoticeTemplate(@RequestParam(name = "type") int type, @RequestParam(name = "scene") String scene) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.getDefaultNoticeTemplate(type, scene)); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...controller/src/main/java/org/cloud/sonic/controller/controller/AlertRobotsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* sonic-server Sonic Cloud Real Machine Platform. | ||
* Copyright (C) 2022 SonicCloudOrg | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.cloud.sonic.controller.controller; | ||
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.cloud.sonic.common.config.WebAspect; | ||
import org.cloud.sonic.common.config.WhiteUrl; | ||
import org.cloud.sonic.common.http.RespEnum; | ||
import org.cloud.sonic.common.http.RespModel; | ||
import org.cloud.sonic.controller.models.base.CommentPage; | ||
import org.cloud.sonic.controller.models.domain.AlertRobots; | ||
import org.cloud.sonic.controller.models.dto.AlertRobotsDTO; | ||
import org.cloud.sonic.controller.services.AlertRobotsService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Tag(name = "告警通知机器人相关") | ||
@RestController | ||
@RequestMapping("/alertRobots") | ||
public class AlertRobotsController { | ||
|
||
@Autowired | ||
private AlertRobotsService alertRobotsService; | ||
|
||
@WebAspect | ||
@Operation(summary = "更新机器人参数", description = "新增或更新对应的机器人") | ||
@PutMapping | ||
public RespModel<String> save(@Validated @RequestBody AlertRobotsDTO alertRobotsDTO) { | ||
alertRobotsService.saveOrUpdate(alertRobotsDTO.convertTo()); | ||
return new RespModel<>(RespEnum.UPDATE_OK); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "查找项目机器人参数", description = "查找对应项目id的机器人参数列表") | ||
@GetMapping("/list") | ||
@Parameters(value = { | ||
@Parameter(name = "projectId", description = "项目id"), | ||
@Parameter(name = "scene", allowEmptyValue = true, description = "使用场景"), | ||
@Parameter(name = "page", description = "页码"), | ||
@Parameter(name = "pageSize", description = "页尺寸") | ||
}) | ||
public RespModel<CommentPage<AlertRobots>> list( | ||
@RequestParam(name = "projectId") int projectId, | ||
@RequestParam(name = "scene", required = false) String scene, | ||
@RequestParam(name = "page") int page, | ||
@RequestParam(name = "pageSize", defaultValue = "20") int pageSize | ||
) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.findRobots(new Page<>(page, pageSize), projectId, scene)); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "查找项目机器人参数", description = "查找对应项目id的机器人参数列表") | ||
@GetMapping("/listAll") | ||
@Parameters(value = { | ||
@Parameter(name = "projectId", allowEmptyValue = true, description = "项目id"), | ||
@Parameter(name = "scene", allowEmptyValue = true, description = "使用场景") | ||
}) | ||
public RespModel<List<AlertRobots>> listAll( | ||
@RequestParam(name = "projectId", required = false, defaultValue = "-1") int projectId, | ||
@RequestParam(name = "scene", required = false) String scene | ||
) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.findAllRobots(projectId, scene)); | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "删除机器人参数", description = "删除对应id的机器人参数") | ||
@Parameter(name = "id", description = "id") | ||
@DeleteMapping | ||
public RespModel<String> delete( | ||
@Parameter(name = "projectId", description = "项目id") int projectId, | ||
@RequestParam(name = "id") int id | ||
) { | ||
if (alertRobotsService.removeByMap(Map.of("id", id, "projectId", projectId))) { | ||
return new RespModel<>(RespEnum.DELETE_OK); | ||
} else { | ||
return new RespModel<>(RespEnum.DELETE_FAIL); | ||
} | ||
} | ||
|
||
@WebAspect | ||
@Operation(summary = "获取机器人对类型机器人在相应使用场景下的默认模板", description = "获取机器人对类型机器人在相应使用场景下的默认模板") | ||
@Parameter(name = "type", description = "type") | ||
@Parameter(name = "scene", description = "scene") | ||
@GetMapping("/findDefaultTemplate") | ||
@WhiteUrl | ||
public RespModel<String> getDefaultNoticeTemplate(@RequestParam(name = "type") int type, @RequestParam(name = "scene") String scene) { | ||
return new RespModel<>(RespEnum.SEARCH_OK, alertRobotsService.getDefaultNoticeTemplate(type, scene)); | ||
} | ||
} |
Oops, something went wrong.