summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEnderByEndera <[email protected]>2024-01-25 19:55:23 +0800
committerEnderByEndera <[email protected]>2024-01-25 19:55:23 +0800
commite48f837b64c55ebd2f6e4182e2ea53f9bb825f7f (patch)
tree67626398c7afaf0fc19d74fe04a46999d52176e5 /src
parent37b9e1f14672d71608347e594ef604859ad9b360 (diff)
1. 暂时去除AlertMessage.java中的implements以便于SpringBoot构建成功
2. 修改project.conf.template为project_template.conf 3. 修改README.md,添加大量项目部署解释 4. 添加StateChangeService.java中关于状态模式的相关解释
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java3
-rw-r--r--src/main/java/com/realtime/protection/configuration/utils/enums/StateEnum.java1
-rw-r--r--src/main/java/com/realtime/protection/server/task/status/StateChangeService.java15
-rw-r--r--src/main/resources/nginx/configs/project.conf39
-rw-r--r--src/main/resources/nginx/configs/project_template.conf (renamed from src/main/resources/nginx/configs/project.conf.template)0
-rw-r--r--src/main/resources/nginx/nginx.conf2
6 files changed, 18 insertions, 42 deletions
diff --git a/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java b/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java
index c9c36cf..890e00a 100644
--- a/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java
+++ b/src/main/java/com/realtime/protection/configuration/entity/alert/AlertMessage.java
@@ -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;
diff --git a/src/main/java/com/realtime/protection/configuration/utils/enums/StateEnum.java b/src/main/java/com/realtime/protection/configuration/utils/enums/StateEnum.java
index bae9ac5..386762a 100644
--- a/src/main/java/com/realtime/protection/configuration/utils/enums/StateEnum.java
+++ b/src/main/java/com/realtime/protection/configuration/utils/enums/StateEnum.java
@@ -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()),
diff --git a/src/main/java/com/realtime/protection/server/task/status/StateChangeService.java b/src/main/java/com/realtime/protection/server/task/status/StateChangeService.java
index 0b4a609..85c4ed5 100644
--- a/src/main/java/com/realtime/protection/server/task/status/StateChangeService.java
+++ b/src/main/java/com/realtime/protection/server/task/status/StateChangeService.java
@@ -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() {
diff --git a/src/main/resources/nginx/configs/project.conf b/src/main/resources/nginx/configs/project.conf
deleted file mode 100644
index ed7f1cc..0000000
--- a/src/main/resources/nginx/configs/project.conf
+++ /dev/null
@@ -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/;
- }
-}
diff --git a/src/main/resources/nginx/configs/project.conf.template b/src/main/resources/nginx/configs/project_template.conf
index 9b10583..9b10583 100644
--- a/src/main/resources/nginx/configs/project.conf.template
+++ b/src/main/resources/nginx/configs/project_template.conf
diff --git a/src/main/resources/nginx/nginx.conf b/src/main/resources/nginx/nginx.conf
index 7a0485b..836f226 100644
--- a/src/main/resources/nginx/nginx.conf
+++ b/src/main/resources/nginx/nginx.conf
@@ -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;
}