Skip to content

Commit c5b84ec

Browse files
[INLONG-11997][Manager] Add comprehensive audit alert rule management API (#11978)
* [INLONG-11923][Manager] Add audit alert rule management API - Add AuditAlertRule POJO class with validation annotations - Add AuditAlertRuleEntity for database mapping - Add AuditAlertRuleEntityMapper with CRUD operations - Add MyBatis XML mapping file - Implement audit alert rule management in AuditServiceImpl - Add REST API endpoints in AuditController - Add comprehensive unit tests - Add API test scripts for validation * [INLONG-11923][Manager] Add comprehensive audit alert rule management API Fixes #11923 ### Motivation Currently, Apache InLong lacks a comprehensive audit alert rule management system to monitor data quality, detect anomalies, and provide real-time alerting capabilities. Users need the ability to create, manage, and monitor audit alert rules to ensure data pipeline reliability and quality. This enhancement adds a complete audit alert rule management API that allows users to: - Configure alert rules for data count, delay, and quality metrics - Set up notification channels (EMAIL, SMS, etc.) - Manage alert rule lifecycle (create, update, delete, enable/disable) - Query and filter alert rules by group and stream ### Modifications **1. Data Model Layer** - Added [AuditAlertRule](file://e:\inlong\inlong-manager\manager-pojo\src\main\java\org\apache\inlong\manager\pojo\audit\AuditAlertRule.java#L25-L63) POJO class in `manager-pojo` module with comprehensive validation annotations - Added [AuditAlertRuleEntity](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\entity\AuditAlertRuleEntity.java#L23-L39) database entity in `manager-dao` module for MyBatis mapping - Added [AuditAlertRuleEntityMapper](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\mapper\AuditAlertRuleEntityMapper.java#L24-L32) interface with full CRUD operations - Added MyBatis XML mapping file [AuditAlertRuleEntityMapper.xml](file://e:\inlong\inlong-manager\manager-dao\src\main\resources\mappers\AuditAlertRuleEntityMapper.xml) with optimized SQL queries **2. Service Layer** - Extended [AuditService](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L31-L103) interface with audit alert rule management methods - Implemented audit alert rule management in [AuditServiceImpl](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\impl\AuditServiceImpl.java#L78-L446) class: - [createAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L87-L87) - Create new alert rules with validation - [getAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L92-L92) - Retrieve alert rule by ID - [updateAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L97-L97) - Update existing alert rules - [deleteAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L102-L102) - Delete alert rules - [listAlertRules()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L82-L82) - Query alert rules with filtering support **3. Web Layer** - Added REST API endpoints in [AuditController](file://e:\inlong\inlong-manager\manager-web\src\main\java\org\apache\inlong\manager\web\controller\AuditController.java#L51-L137): - `POST /api/audit/alert/rule` - Create alert rule - `GET /api/audit/alert/rule/{id}` - Get alert rule by ID - `PUT /api/audit/alert/rule` - Update alert rule - `DELETE /api/audit/alert/rule/{id}` - Delete alert rule - `GET /api/audit/alert/rule/list` - List alert rules with filtering - `GET /api/audit/alert/rule/enabled` - Get all enabled alert rules **4. Database Schema** - Database table `audit_alert_rule` with optimized indexes - Support for MySQL with proper charset and collation **5. Testing** - Comprehensive unit tests in [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class - API integration test scripts for manual validation - Database initialization SQL scripts **6. Configuration** - MyBatis configuration for audit alert rule mapping - Spring Boot auto-configuration support ### Verifying this change - [x] This change added tests and can be verified as follows: **Unit Tests:** - Added [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class with comprehensive test coverage: - Test alert rule creation with validation - Test alert rule retrieval and updates - Test alert rule deletion and lifecycle management - Test query operations with filtering - Test error handling and edge cases **Integration Tests:** - Added API test scripts ([test-audit-alert-api.sh](file://e:\inlong\inlong-manager\test-audit-alert-api.sh) and [test-audit-alert-api.ps1](file://e:\inlong\inlong-manager\test-audit-alert-api.ps1)) - Added database initialization script ([init-audit-alert-test-data.sql](file://e:\inlong\inlong-manager\init-audit-alert-test-data.sql)) - Manual testing workflow documented **Test Coverage:** - Service layer: Full CRUD operations testing - Controller layer: HTTP endpoint testing with various scenarios - Data layer: MyBatis mapping and SQL query validation - Error handling: Input validation and exception scenarios * [INLONG-11923][Manager] Add comprehensive audit alert rule management API Fixes #11923 ### Motivation Currently, Apache InLong lacks a comprehensive audit alert rule management system to monitor data quality, detect anomalies, and provide real-time alerting capabilities. Users need the ability to create, manage, and monitor audit alert rules to ensure data pipeline reliability and quality. This enhancement adds a complete audit alert rule management API that allows users to: - Configure alert rules for data count, delay, and quality metrics - Set up notification channels (EMAIL, SMS, etc.) - Manage alert rule lifecycle (create, update, delete, enable/disable) - Query and filter alert rules by group and stream ### Modifications **1. Data Model Layer** - Added [AuditAlertRule](file://e:\inlong\inlong-manager\manager-pojo\src\main\java\org\apache\inlong\manager\pojo\audit\AuditAlertRule.java#L25-L63) POJO class in `manager-pojo` module with comprehensive validation annotations - Added [AuditAlertRuleEntity](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\entity\AuditAlertRuleEntity.java#L23-L39) database entity in `manager-dao` module for MyBatis mapping - Added [AuditAlertRuleEntityMapper](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\mapper\AuditAlertRuleEntityMapper.java#L24-L32) interface with full CRUD operations - Added MyBatis XML mapping file [AuditAlertRuleEntityMapper.xml](file://e:\inlong\inlong-manager\manager-dao\src\main\resources\mappers\AuditAlertRuleEntityMapper.xml) with optimized SQL queries **2. Service Layer** - Extended [AuditService](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L31-L103) interface with audit alert rule management methods - Implemented audit alert rule management in [AuditServiceImpl](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\impl\AuditServiceImpl.java#L78-L446) class: - [createAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L87-L87) - Create new alert rules with validation - [getAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L92-L92) - Retrieve alert rule by ID - [updateAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L97-L97) - Update existing alert rules - [deleteAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L102-L102) - Delete alert rules - [listAlertRules()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L82-L82) - Query alert rules with filtering support **3. Web Layer** - Added REST API endpoints in [AuditController](file://e:\inlong\inlong-manager\manager-web\src\main\java\org\apache\inlong\manager\web\controller\AuditController.java#L51-L137): - `POST /api/audit/alert/rule` - Create alert rule - `GET /api/audit/alert/rule/{id}` - Get alert rule by ID - `PUT /api/audit/alert/rule` - Update alert rule - `DELETE /api/audit/alert/rule/{id}` - Delete alert rule - `GET /api/audit/alert/rule/list` - List alert rules with filtering - `GET /api/audit/alert/rule/enabled` - Get all enabled alert rules **4. Database Schema** - Database table `audit_alert_rule` with optimized indexes - Support for MySQL with proper charset and collation **5. Testing** - Comprehensive unit tests in [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class - API integration test scripts for manual validation - Database initialization SQL scripts **6. Configuration** - MyBatis configuration for audit alert rule mapping - Spring Boot auto-configuration support ### Verifying this change - [x] This change added tests and can be verified as follows: **Unit Tests:** - Added [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class with comprehensive test coverage: - Test alert rule creation with validation - Test alert rule retrieval and updates - Test alert rule deletion and lifecycle management - Test query operations with filtering - Test error handling and edge cases **Integration Tests:** - Added API test scripts ([test-audit-alert-api.sh](file://e:\inlong\inlong-manager\test-audit-alert-api.sh) and [test-audit-alert-api.ps1](file://e:\inlong\inlong-manager\test-audit-alert-api.ps1)) - Added database initialization script ([init-audit-alert-test-data.sql](file://e:\inlong\inlong-manager\init-audit-alert-test-data.sql)) - Manual testing workflow documented **Test Coverage:** - Service layer: Full CRUD operations testing - Controller layer: HTTP endpoint testing with various scenarios - Data layer: MyBatis mapping and SQL query validation - Error handling: Input validation and exception scenarios * [INLONG-11923][Manager] Add comprehensive audit alert rule management API Fixes #11923 Motivation Currently, Apache InLong lacks a comprehensive audit alert rule management system to monitor data quality, detect anomalies, and provide real-time alerting capabilities. Users need the ability to create, manage, and monitor audit alert rules to ensure data pipeline reliability and quality. This enhancement adds a complete audit alert rule management API that allows users to: Configure alert rules for data count, delay, and quality metrics Set up notification channels (EMAIL, SMS, etc.) Manage alert rule lifecycle (create, update, delete, enable/disable) Query and filter alert rules by group and stream Modifications 1. Data Model Layer Added AuditAlertRule POJO class in manager-pojo module with comprehensive validation annotations Added AuditAlertRuleEntity database entity in manager-dao module for MyBatis mapping Added AuditAlertRuleEntityMapper interface with full CRUD operations Added MyBatis XML mapping file AuditAlertRuleEntityMapper.xml with optimized SQL queries 2. Service Layer Extended AuditService interface with audit alert rule management methods Implemented audit alert rule management in AuditServiceImpl class: createAlertRule() - Create new alert rules with validation getAlertRule() - Retrieve alert rule by ID updateAlertRule() - Update existing alert rules deleteAlertRule() - Delete alert rules listAlertRules() - Query alert rules with filtering support 3. Web Layer Added REST API endpoints in AuditController: POST /api/audit/alert/rule - Create alert rule GET /api/audit/alert/rule/{id} - Get alert rule by ID PUT /api/audit/alert/rule - Update alert rule DELETE /api/audit/alert/rule/{id} - Delete alert rule GET /api/audit/alert/rule/list - List alert rules with filtering GET /api/audit/alert/rule/enabled - Get all enabled alert rules 4. Database Schema Database table audit_alert_rule with optimized indexes Support for MySQL with proper charset and collation 5. Testing Comprehensive unit tests in AuditAlertRuleTest class API integration test scripts for manual validation Database initialization SQL scripts 6. Configuration MyBatis configuration for audit alert rule mapping Spring Boot auto-configuration support Verifying this change This change added tests and can be verified as follows: Unit Tests: Added AuditAlertRuleTest class with comprehensive test coverage: Test alert rule creation with validation Test alert rule retrieval and updates Test alert rule deletion and lifecycle management Test query operations with filtering Test error handling and edge cases Integration Tests: Added API test scripts (test-audit-alert-api.sh and test-audit-alert-api.ps1) Added database initialization script (init-audit-alert-test-data.sql) Manual testing workflow documented Test Coverage: Service layer: Full CRUD operations testing Controller layer: HTTP endpoint testing with various scenarios Data layer: MyBatis mapping and SQL query validation Error handling: Input validation and exception scenarios * [INLONG-11923][Manager] Add comprehensive audit alert rule management API Fixes #11923 ### Motivation Currently, Apache InLong lacks a comprehensive audit alert rule management system to monitor data quality, detect anomalies, and provide real-time alerting capabilities. Users need the ability to create, manage, and monitor audit alert rules to ensure data pipeline reliability and quality. This enhancement adds a complete audit alert rule management API that allows users to: - Configure alert rules for data count, delay, and quality metrics - Set up notification channels (EMAIL, SMS, etc.) - Manage alert rule lifecycle (create, update, delete, enable/disable) - Query and filter alert rules by group and stream ### Modifications **1. Data Model Layer** - Added [AuditAlertRule](file://e:\inlong\inlong-manager\manager-pojo\src\main\java\org\apache\inlong\manager\pojo\audit\AuditAlertRule.java#L25-L63) POJO class in `manager-pojo` module with comprehensive validation annotations - Added [AuditAlertRuleEntity](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\entity\AuditAlertRuleEntity.java#L23-L39) database entity in `manager-dao` module for MyBatis mapping - Added [AuditAlertRuleEntityMapper](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\mapper\AuditAlertRuleEntityMapper.java#L24-L32) interface with full CRUD operations - Added MyBatis XML mapping file [AuditAlertRuleEntityMapper.xml](file://e:\inlong\inlong-manager\manager-dao\src\main\resources\mappers\AuditAlertRuleEntityMapper.xml) with optimized SQL queries **2. Service Layer** - Extended [AuditService](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L31-L103) interface with audit alert rule management methods - Implemented audit alert rule management in [AuditServiceImpl](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\impl\AuditServiceImpl.java#L78-L446) class: - [createAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L87-L87) - Create new alert rules with validation - [getAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L92-L92) - Retrieve alert rule by ID - [updateAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L97-L97) - Update existing alert rules - [deleteAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L102-L102) - Delete alert rules - [listAlertRules()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L82-L82) - Query alert rules with filtering support **3. Web Layer** - Added REST API endpoints in [AuditController](file://e:\inlong\inlong-manager\manager-web\src\main\java\org\apache\inlong\manager\web\controller\AuditController.java#L51-L137): - `POST /api/audit/alert/rule` - Create alert rule - `GET /api/audit/alert/rule/{id}` - Get alert rule by ID - `PUT /api/audit/alert/rule` - Update alert rule - `DELETE /api/audit/alert/rule/{id}` - Delete alert rule - `GET /api/audit/alert/rule/list` - List alert rules with filtering - `GET /api/audit/alert/rule/enabled` - Get all enabled alert rules **4. Database Schema** - Database table `audit_alert_rule` with optimized indexes - Support for MySQL with proper charset and collation **5. Testing** - Comprehensive unit tests in [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class - API integration test scripts for manual validation - Database initialization SQL scripts **6. Configuration** - MyBatis configuration for audit alert rule mapping - Spring Boot auto-configuration support ### Verifying this change - [x] This change added tests and can be verified as follows: **Unit Tests:** - Added [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class with comprehensive test coverage: - Test alert rule creation with validation - Test alert rule retrieval and updates - Test alert rule deletion and lifecycle management - Test query operations with filtering - Test error handling and edge cases **Integration Tests:** - Added API test scripts ([test-audit-alert-api.sh](file://e:\inlong\inlong-manager\test-audit-alert-api.sh) and [test-audit-alert-api.ps1](file://e:\inlong\inlong-manager\test-audit-alert-api.ps1)) - Added database initialization script ([init-audit-alert-test-data.sql](file://e:\inlong\inlong-manager\init-audit-alert-test-data.sql)) - Manual testing workflow documented **Test Coverage:** - Service layer: Full CRUD operations testing - Controller layer: HTTP endpoint testing with various scenarios - Data layer: MyBatis mapping and SQL query validation - Error handling: Input validation and exception scenarios * refactor: 拆分审计告警规则控制器 - 将 AuditController 中的审计告警规则相关方法拆分到新的 AuditAlertRuleController - 保持原有 API 路径不变,确保向后兼容 - 修复 AuditController 中缺失的导入语句 - 更新相关测试文件引用 * [INLONG-11923][Manager] Add comprehensive audit alert rule management API Fixes #11923 ### Motivation Currently, Apache InLong lacks a comprehensive audit alert rule management system to monitor data quality, detect anomalies, and provide real-time alerting capabilities. Users need the ability to create, manage, and monitor audit alert rules to ensure data pipeline reliability and quality. This enhancement adds a complete audit alert rule management API that allows users to: - Configure alert rules for data count, delay, and quality metrics - Set up notification channels (EMAIL, SMS, etc.) - Manage alert rule lifecycle (create, update, delete, enable/disable) - Query and filter alert rules by group and stream ### Modifications **1. Data Model Layer** - Added [AuditAlertRule](file://e:\inlong\inlong-manager\manager-pojo\src\main\java\org\apache\inlong\manager\pojo\audit\AuditAlertRule.java#L25-L63) POJO class in `manager-pojo` module with comprehensive validation annotations - Added [AuditAlertRuleEntity](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\entity\AuditAlertRuleEntity.java#L23-L39) database entity in `manager-dao` module for MyBatis mapping - Added [AuditAlertRuleEntityMapper](file://e:\inlong\inlong-manager\manager-dao\src\main\java\org\apache\inlong\manager\dao\mapper\AuditAlertRuleEntityMapper.java#L24-L32) interface with full CRUD operations - Added MyBatis XML mapping file [AuditAlertRuleEntityMapper.xml](file://e:\inlong\inlong-manager\manager-dao\src\main\resources\mappers\AuditAlertRuleEntityMapper.xml) with optimized SQL queries **2. Service Layer** - Extended [AuditService](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L31-L103) interface with audit alert rule management methods - Implemented audit alert rule management in [AuditServiceImpl](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\impl\AuditServiceImpl.java#L78-L446) class: - [createAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L87-L87) - Create new alert rules with validation - [getAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L92-L92) - Retrieve alert rule by ID - [updateAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L97-L97) - Update existing alert rules - [deleteAlertRule()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L102-L102) - Delete alert rules - [listAlertRules()](file://e:\inlong\inlong-manager\manager-service\src\main\java\org\apache\inlong\manager\service\core\AuditService.java#L82-L82) - Query alert rules with filtering support **3. Web Layer** - Added REST API endpoints in [AuditController](file://e:\inlong\inlong-manager\manager-web\src\main\java\org\apache\inlong\manager\web\controller\AuditController.java#L51-L137): - `POST /api/audit/alert/rule` - Create alert rule - `GET /api/audit/alert/rule/{id}` - Get alert rule by ID - `PUT /api/audit/alert/rule` - Update alert rule - `DELETE /api/audit/alert/rule/{id}` - Delete alert rule - `GET /api/audit/alert/rule/list` - List alert rules with filtering - `GET /api/audit/alert/rule/enabled` - Get all enabled alert rules **4. Database Schema** - Database table `audit_alert_rule` with optimized indexes - Support for MySQL with proper charset and collation **5. Testing** - Comprehensive unit tests in [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class - API integration test scripts for manual validation - Database initialization SQL scripts **6. Configuration** - MyBatis configuration for audit alert rule mapping - Spring Boot auto-configuration support ### Verifying this change - [x] This change added tests and can be verified as follows: **Unit Tests:** - Added [AuditAlertRuleTest](file://e:\inlong\inlong-manager\manager-service\src\test\java\org\apache\inlong\manager\service\core\AuditAlertRuleTest.java#L34-L152) class with comprehensive test coverage: - Test alert rule creation with validation - Test alert rule retrieval and updates - Test alert rule deletion and lifecycle management - Test query operations with filtering - Test error handling and edge cases **Integration Tests:** - Added API test scripts ([test-audit-alert-api.sh](file://e:\inlong\inlong-manager\test-audit-alert-api.sh) and [test-audit-alert-api.ps1](file://e:\inlong\inlong-manager\test-audit-alert-api.ps1)) - Added database initialization script ([init-audit-alert-test-data.sql](file://e:\inlong\inlong-manager\init-audit-alert-test-data.sql)) - Manual testing workflow documented **Test Coverage:** - Service layer: Full CRUD operations testing - Controller layer: HTTP endpoint testing with various scenarios - Data layer: MyBatis mapping and SQL query validation - Error handling: Input validation and exception scenarios * Refactor (audit): Simplify the audit alert rule code and remove deprecated components - Delete the AuditAlertRuleUpdateRequest class and related references, and uniformly use AuditAlertRuleRequest as the request parameter. - Modify the Mapper XML to adjust the increment logic of the optimistic lock version field. - Adjust the AuditAlertRuleRequest, add id and version fields, and add support for validation groups. - Delete the old interfaces and implementations related to the alert rules in AuditService, and switch to using the AuditAlertRuleService interface. - Simplify AuditServiceImpl, remove the implementations related to the alert rules, and optimize some log information and code structure. - Adjust the AuditAlertRuleController, switch to injecting AuditAlertRuleService, and update the interface calls. - Modify the test code, update the use of the old AuditAlertRuleUpdateRequest to AuditAlertRuleRequest. - Code cleaning: Delete unused imports and test classes, and simplify useless comments and constructors. - Optimize the log output level to improve the clarity and accuracy of runtime logs. * improve * Fix the path issue * Improve code format * improve path * improve path * Fix AuditControllerTest.testUpdateAlertRule * improve * MyBatis * final * make it concise * add selectbycondition * Improve manager-client-test * Improve manager-client-test * imporve * Improve webtest * improve page logic * import * update * improve * update * notifytype enum * delete chinese * improve * update * improve * update * fix * update notifytype * improve * update * update * update * update * final * improve * update * update * improve * improve * improve * update * improve * improve * improve * improve * improve * improve * improve * improve --------- Co-authored-by: shuideyimei <13124552057@163.com>
1 parent c96830d commit c5b84ec

File tree

28 files changed

+2928
-6
lines changed

28 files changed

+2928
-6
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.client.api.inner.client;
19+
20+
import org.apache.inlong.manager.client.api.ClientConfiguration;
21+
import org.apache.inlong.manager.client.api.service.AuditAlertRuleApi;
22+
import org.apache.inlong.manager.client.api.util.ClientUtils;
23+
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
24+
import org.apache.inlong.manager.common.util.Preconditions;
25+
import org.apache.inlong.manager.pojo.audit.AuditAlertRule;
26+
import org.apache.inlong.manager.pojo.audit.AuditAlertRulePageRequest;
27+
import org.apache.inlong.manager.pojo.audit.AuditAlertRuleRequest;
28+
import org.apache.inlong.manager.pojo.common.PageResult;
29+
import org.apache.inlong.manager.pojo.common.Response;
30+
31+
/**
32+
* Client for {@link AuditAlertRuleApi}.
33+
*/
34+
public class AuditAlertRuleClient {
35+
36+
private final AuditAlertRuleApi auditAlertRuleApi;
37+
38+
public AuditAlertRuleClient(ClientConfiguration configuration) {
39+
auditAlertRuleApi = ClientUtils.createRetrofit(configuration).create(AuditAlertRuleApi.class);
40+
}
41+
42+
/**
43+
* Create an audit alert rule
44+
*
45+
* @param request The audit alert rule to create
46+
* @return The created audit alert rule ID
47+
*/
48+
public Integer create(AuditAlertRuleRequest request) {
49+
Preconditions.expectNotNull(request, "audit alert rule request cannot be null");
50+
Preconditions.expectNotBlank(request.getInlongGroupId(), ErrorCodeEnum.INVALID_PARAMETER,
51+
"inlong group id cannot be empty");
52+
Preconditions.expectNotBlank(request.getAuditId(), ErrorCodeEnum.INVALID_PARAMETER,
53+
"audit id cannot be empty");
54+
Preconditions.expectNotBlank(request.getAlertName(), ErrorCodeEnum.INVALID_PARAMETER,
55+
"alert name cannot be empty");
56+
Preconditions.expectNotNull(request.getCondition(), ErrorCodeEnum.INVALID_PARAMETER,
57+
"condition cannot be null");
58+
Response<Integer> response = ClientUtils.executeHttpCall(auditAlertRuleApi.create(request));
59+
ClientUtils.assertRespSuccess(response);
60+
return response.getData();
61+
}
62+
63+
/**
64+
* Get an audit alert rule by ID
65+
*
66+
* @param id The rule ID
67+
* @return The audit alert rule
68+
*/
69+
public AuditAlertRule get(Integer id) {
70+
Preconditions.expectNotNull(id, "rule id cannot be null");
71+
Response<AuditAlertRule> response = ClientUtils.executeHttpCall(auditAlertRuleApi.get(id));
72+
ClientUtils.assertRespSuccess(response);
73+
return response.getData();
74+
}
75+
76+
/**
77+
* Select audit alert rules by condition with pagination
78+
*
79+
* @param request The condition to filter audit alert rules
80+
* @return Page result of audit alert rules
81+
*/
82+
public PageResult<AuditAlertRule> listByCondition(AuditAlertRulePageRequest request) {
83+
Response<PageResult<AuditAlertRule>> response = ClientUtils.executeHttpCall(
84+
auditAlertRuleApi.listByCondition(request));
85+
ClientUtils.assertRespSuccess(response);
86+
return response.getData();
87+
}
88+
89+
/**
90+
* Update an audit alert rule
91+
*
92+
* @param rule The audit alert rule to update
93+
* @return True if update is successful, false otherwise
94+
*/
95+
public Boolean update(AuditAlertRuleRequest rule) {
96+
Preconditions.expectNotNull(rule, "audit alert rule cannot be null");
97+
Preconditions.expectNotNull(rule.getId(), "rule id cannot be null");
98+
Response<Boolean> response = ClientUtils.executeHttpCall(auditAlertRuleApi.update(rule));
99+
ClientUtils.assertRespSuccess(response);
100+
return response.getData();
101+
}
102+
103+
/**
104+
* Delete an audit alert rule by ID
105+
*
106+
* @param id The rule ID
107+
* @return True if deletion is successful, false otherwise
108+
*/
109+
public Boolean delete(Integer id) {
110+
Preconditions.expectNotNull(id, "rule id cannot be null");
111+
Response<Boolean> response = ClientUtils.executeHttpCall(auditAlertRuleApi.delete(id));
112+
ClientUtils.assertRespSuccess(response);
113+
return response.getData();
114+
}
115+
}

inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/AuditClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ public Boolean refreshCache(AuditRequest request) {
8383
ClientUtils.assertRespSuccess(response);
8484
return response.getData();
8585
}
86-
}
86+
}

inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ClientFactory {
5656
private final InlongTenantClient inlongTenantClient;
5757
private final InlongTenantRoleClient inlongTenantRoleClient;
5858
private final InLongScheduleClient inLongScheduleClient;
59+
private final AuditAlertRuleClient auditAlertRuleClient;
5960

6061
public ClientFactory(ClientConfiguration configuration) {
6162
groupClient = new InlongGroupClient(configuration);
@@ -76,5 +77,6 @@ public ClientFactory(ClientConfiguration configuration) {
7677
inlongTenantClient = new InlongTenantClient(configuration);
7778
inlongTenantRoleClient = new InlongTenantRoleClient(configuration);
7879
inLongScheduleClient = new InLongScheduleClient(configuration);
80+
auditAlertRuleClient = new AuditAlertRuleClient(configuration);
7981
}
80-
}
82+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.client.api.service;
19+
20+
import org.apache.inlong.manager.pojo.audit.AuditAlertRule;
21+
import org.apache.inlong.manager.pojo.audit.AuditAlertRulePageRequest;
22+
import org.apache.inlong.manager.pojo.audit.AuditAlertRuleRequest;
23+
import org.apache.inlong.manager.pojo.common.PageResult;
24+
import org.apache.inlong.manager.pojo.common.Response;
25+
26+
import retrofit2.Call;
27+
import retrofit2.http.Body;
28+
import retrofit2.http.DELETE;
29+
import retrofit2.http.GET;
30+
import retrofit2.http.POST;
31+
import retrofit2.http.PUT;
32+
import retrofit2.http.Path;
33+
34+
public interface AuditAlertRuleApi {
35+
36+
@POST("audit/alert/rule")
37+
Call<Response<Integer>> create(@Body AuditAlertRuleRequest request);
38+
39+
@GET("audit/alert/rule/get/{id}")
40+
Call<Response<AuditAlertRule>> get(@Path("id") Integer id);
41+
42+
@POST("audit/alert/rule/list")
43+
Call<Response<PageResult<AuditAlertRule>>> listByCondition(@Body AuditAlertRulePageRequest request);
44+
45+
@PUT("audit/alert/rule/update")
46+
Call<Response<Boolean>> update(@Body AuditAlertRuleRequest request);
47+
48+
@DELETE("audit/delete/{id}")
49+
Call<Response<Boolean>> delete(@Path("id") Integer id);
50+
51+
}

inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/AuditApi.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ public interface AuditApi {
3737

3838
@POST("audit/refreshCache")
3939
Call<Response<Boolean>> refreshCache();
40-
41-
}
40+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.client.api.inner;
19+
20+
import org.apache.inlong.manager.client.api.ClientConfiguration;
21+
import org.apache.inlong.manager.client.api.impl.InlongClientImpl;
22+
import org.apache.inlong.manager.client.api.inner.client.AuditAlertRuleClient;
23+
import org.apache.inlong.manager.client.api.inner.client.ClientFactory;
24+
import org.apache.inlong.manager.client.api.util.ClientUtils;
25+
import org.apache.inlong.manager.common.auth.DefaultAuthentication;
26+
import org.apache.inlong.manager.common.util.JsonUtils;
27+
import org.apache.inlong.manager.pojo.audit.AuditAlertCondition;
28+
import org.apache.inlong.manager.pojo.audit.AuditAlertRule;
29+
import org.apache.inlong.manager.pojo.audit.AuditAlertRulePageRequest;
30+
import org.apache.inlong.manager.pojo.audit.AuditAlertRuleRequest;
31+
import org.apache.inlong.manager.pojo.common.PageResult;
32+
import org.apache.inlong.manager.pojo.common.Response;
33+
34+
import com.github.tomakehurst.wiremock.WireMockServer;
35+
import com.google.common.collect.Lists;
36+
import org.junit.jupiter.api.AfterAll;
37+
import org.junit.jupiter.api.Assertions;
38+
import org.junit.jupiter.api.BeforeAll;
39+
import org.junit.jupiter.api.Test;
40+
41+
import java.util.Date;
42+
import java.util.List;
43+
44+
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
45+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
46+
import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
47+
import static com.github.tomakehurst.wiremock.client.WireMock.post;
48+
import static com.github.tomakehurst.wiremock.client.WireMock.put;
49+
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
50+
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
51+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
52+
53+
/** Unit test for {@link org.apache.inlong.manager.client.api.inner.AuditAlertRuleClient} */
54+
public class AuditAlertRuleClientTest {
55+
56+
private static final int SERVICE_PORT = 8085;
57+
private static WireMockServer wireMockServer;
58+
private static AuditAlertRuleClient auditAlertRuleClient;
59+
60+
@BeforeAll
61+
static void setup() {
62+
wireMockServer = new WireMockServer(options().port(SERVICE_PORT));
63+
wireMockServer.start();
64+
com.github.tomakehurst.wiremock.client.WireMock.configureFor(wireMockServer.port());
65+
66+
String serviceUrl = "127.0.0.1:" + SERVICE_PORT;
67+
ClientConfiguration configuration = new ClientConfiguration();
68+
configuration.setAuthentication(new DefaultAuthentication("admin", "inlong"));
69+
InlongClientImpl inlongClient = new InlongClientImpl(serviceUrl, configuration);
70+
ClientFactory clientFactory = ClientUtils.getClientFactory(inlongClient.getConfiguration());
71+
72+
auditAlertRuleClient = clientFactory.getAuditAlertRuleClient();
73+
}
74+
75+
@AfterAll
76+
static void teardown() {
77+
wireMockServer.stop();
78+
}
79+
80+
@Test
81+
void testCreate() {
82+
AuditAlertRuleRequest request = new AuditAlertRuleRequest();
83+
request.setInlongGroupId("test_group");
84+
request.setAuditId("test_audit");
85+
request.setAlertName("test_alert");
86+
request.setCondition(new AuditAlertCondition());
87+
request.setEnabled(true);
88+
89+
stubFor(
90+
post(urlMatching("/inlong/manager/api/audit/alert/rule.*"))
91+
.willReturn(
92+
okJson(JsonUtils.toJsonString(
93+
Response.success(1)))));
94+
95+
Integer result = auditAlertRuleClient.create(request);
96+
Assertions.assertEquals(1, result);
97+
}
98+
99+
@Test
100+
void testGet() {
101+
AuditAlertRule rule = new AuditAlertRule();
102+
rule.setId(1);
103+
rule.setInlongGroupId("test_group");
104+
rule.setAuditId("test_audit");
105+
rule.setAlertName("test_alert");
106+
rule.setCondition(new AuditAlertCondition());
107+
rule.setEnabled(true);
108+
rule.setCreateTime(new Date());
109+
rule.setModifyTime(new Date());
110+
111+
stubFor(
112+
get(urlMatching("/inlong/manager/api/audit/alert/rule/get/1.*"))
113+
.willReturn(
114+
okJson(JsonUtils.toJsonString(
115+
Response.success(rule)))));
116+
117+
AuditAlertRule result = auditAlertRuleClient.get(1);
118+
Assertions.assertEquals(1, result.getId());
119+
Assertions.assertEquals("test_group", result.getInlongGroupId());
120+
Assertions.assertEquals("test_audit", result.getAuditId());
121+
Assertions.assertEquals("test_alert", result.getAlertName());
122+
}
123+
124+
@Test
125+
void testListByCondition() {
126+
AuditAlertRule rule = new AuditAlertRule();
127+
rule.setId(1);
128+
rule.setInlongGroupId("test_group");
129+
rule.setAuditId("test_audit");
130+
rule.setAlertName("test_alert");
131+
rule.setCondition(new AuditAlertCondition());
132+
rule.setEnabled(true);
133+
rule.setCreateTime(new Date());
134+
rule.setModifyTime(new Date());
135+
136+
List<AuditAlertRule> rules = Lists.newArrayList(rule);
137+
PageResult<AuditAlertRule> pageResult = new PageResult<>(rules, 1L, 1, 10);
138+
139+
stubFor(
140+
post(urlMatching("/inlong/manager/api/audit/alert/rule/list.*"))
141+
.willReturn(
142+
okJson(JsonUtils.toJsonString(
143+
Response.success(pageResult)))));
144+
145+
AuditAlertRulePageRequest request = new AuditAlertRulePageRequest();
146+
request.setInlongGroupId("test_group");
147+
PageResult<AuditAlertRule> result = auditAlertRuleClient.listByCondition(request);
148+
Assertions.assertEquals(1, result.getList().size());
149+
Assertions.assertEquals(1L, result.getTotal());
150+
}
151+
152+
@Test
153+
void testUpdate() {
154+
AuditAlertRuleRequest request = new AuditAlertRuleRequest();
155+
request.setId(1);
156+
request.setInlongGroupId("test_group");
157+
request.setAuditId("test_audit");
158+
request.setAlertName("test_alert");
159+
request.setCondition(new AuditAlertCondition());
160+
request.setEnabled(true);
161+
request.setVersion(1);
162+
163+
stubFor(
164+
put(urlMatching("/inlong/manager/api/audit/alert/rule/update.*"))
165+
.willReturn(
166+
okJson(JsonUtils.toJsonString(
167+
Response.success(true)))));
168+
169+
Boolean result = auditAlertRuleClient.update(request);
170+
Assertions.assertTrue(result);
171+
}
172+
173+
@Test
174+
void testDelete() {
175+
stubFor(
176+
delete(urlMatching("/inlong/manager/api/audit/delete/1.*"))
177+
.willReturn(
178+
okJson(JsonUtils.toJsonString(
179+
Response.success(true)))));
180+
181+
Boolean result = auditAlertRuleClient.delete(1);
182+
Assertions.assertTrue(result);
183+
}
184+
}

0 commit comments

Comments
 (0)