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() {

View File

@@ -1,39 +0,0 @@
upstream server_list {
least_conn;
server 192.168.107.89:8081;
}
server {
listen 8080;
server_name localhost;
location / {
root /root/nginx/defense;
index index.html;
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /index.html last;
}
location /api/ {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 5;
proxy_pass http://server_list/api/v1/;
}
}

View File

@@ -58,7 +58,7 @@ http {
# include /etc/nginx/conf.d/*.conf;
# include /etc/nginx/sites-enabled/*;
include /root/nginx/configs/*.conf;
include /root/nginx/configs/project.conf;
}