1. 暂时去除AlertMessage.java中的implements以便于SpringBoot构建成功

2. 修改project.conf.template为project_template.conf
3. 修改README.md,添加大量项目部署解释
4. 添加StateChangeService.java中关于状态模式的相关解释
This commit is contained in:
EnderByEndera
2024-01-25 19:55:23 +08:00
parent 37b9e1f146
commit e48f837b64
11 changed files with 97 additions and 55 deletions

View File

@@ -3,11 +3,10 @@ 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 implements KafkaMessage {
public class AlertMessage {
@JsonProperty("task_id")
private Long taskId;

View File

@@ -10,6 +10,7 @@ import java.util.Map;
@Getter
public enum StateEnum {
// 仅需修改此处即可将任务状态以及对应的State和Num进行对应
// 使用状态模式进行任务状态的管理和切换
PENDING(0, new PendingState()),
GENERATING(1, new GeneratingState()),
RUNNING(2, new RunningState()),

View File

@@ -15,6 +15,9 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* 任务状态管理服务类
*/
@Service
@EnableScheduling
@Slf4j
@@ -27,6 +30,14 @@ public class StateChangeService {
this.taskService = taskService;
}
/**
* 切换任务状态
* @param stateNum 欲切换的任务状态编号编号对应的状态请查看configuration/utils/enums/StateEnum类
* @param taskId 任务ID
* @param inner 此接口是否为内部调用,如果为内部调用,则取消所有的状态检查
* @return 状态切换是否成功
* @throws DorisStartException Doris数据库异常
*/
@DSTransactional
public Boolean changeState(Integer stateNum, Long taskId, Boolean inner) throws DorisStartException {
Integer originalStateNum = taskService.queryTaskStatus(taskId);
@@ -49,6 +60,7 @@ public class StateChangeService {
return true;
}
// 切换到states文件夹中查看每一个状态的handle函数
if (!originalState.handle(newState, commandService, taskService, taskId)) {
return false;
}
@@ -79,6 +91,9 @@ public class StateChangeService {
return !Objects.equals(originalState, StateEnum.GENERATING.getState());
}
/**
* 将任务切换为结束状态
*/
@Scheduled(cron = "0 0/10 * * * ?")
@Async
protected void finishTasks() {