1、AlertMessage类移动位置
2、动态规则增加删除判断,如果使用任务处于运行、暂停,不允许删除动态规则。(静态规则不需要删除判断,因为指令已经下发。但动态规则配置不能删除,告警信息过来会找不到动态规则)
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.realtime.protection.configuration.entity.rule.dynamicrule;
|
||||
package com.realtime.protection.configuration.entity.alert;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import com.realtime.protection.configuration.kafka.KafkaMessage;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlertMessage {
|
||||
public class AlertMessage implements KafkaMessage {
|
||||
|
||||
@JsonProperty("task_id")
|
||||
private Long taskId;
|
||||
@@ -31,4 +33,3 @@ public class AlertMessage {
|
||||
private String alertMessageUUID;
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DynamicRuleObject {
|
||||
private Integer dynamicRuleCreateUserId;
|
||||
@JsonProperty("dynamic_rule_used_task_id")
|
||||
@Schema(description = "使用该动态规则的任务ID", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer dynamicRuleUsedTaskId;
|
||||
private Long dynamicRuleUsedTaskId;
|
||||
|
||||
//前端不发送事件类型和来源系统了,而是根据事件类型和来源系统确定策略模板id,发过来template_id
|
||||
@JsonProperty("dynamic_rule_source_system")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.alert.AlertMessage;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.alert.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.alert.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
|
||||
@@ -45,4 +45,6 @@ public interface DynamicRuleMapper {
|
||||
String sourceSystem, String creator);
|
||||
|
||||
List<DynamicRuleObject> queryDynamicRuleByIds(List<Integer> ids);
|
||||
|
||||
Integer queryTaskStatusBydynamicRuleId(Integer dynamicRuleId);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.excel.util.ListUtils;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -72,8 +73,17 @@ public class DynamicRuleService {
|
||||
|
||||
|
||||
public void deleteDynamicRuleObject(Integer dynamicRuleId) {
|
||||
//不需要使用 join
|
||||
//在数据库中设置了级联删除 ON DELETE CASCADE,在删除在从父表中删除数据时自动删除子表中的数据
|
||||
//根据任务状态判断能否删除
|
||||
Integer taskStatus = dynamicRuleMapper.queryTaskStatusBydynamicRuleId(dynamicRuleId);
|
||||
switch (StateEnum.getStateEnumByNum(taskStatus)){
|
||||
case RUNNING:
|
||||
throw new IllegalArgumentException("使用该动态规则的任务处于运行状态");
|
||||
case PAUSED:
|
||||
throw new IllegalArgumentException("使用该动态规则的任务处于暂停状态");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//不需要使用 join,在数据库中设置了级联删除 ON DELETE CASCADE,在删除在从父表中删除数据时自动删除子表中的数据
|
||||
dynamicRuleMapper.deleteDynamicRuleObject(dynamicRuleId);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user