summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliukai <[email protected]>2024-10-24 09:16:16 +0800
committerliukai <[email protected]>2024-10-24 09:16:16 +0800
commita79ca58f861dbf275e2a47b5034357cadaa1f4d1 (patch)
tree037bf009d438c61057adb3746d423cbcfad546cb
parent0960ef089df1c92353f56c3e60a497c062c23ea9 (diff)
修改ddos相关代码
-rw-r--r--src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java3
-rw-r--r--src/main/java/com/realtime/protection/configuration/utils/DdosUtil.java7
-rw-r--r--src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java2
-rw-r--r--src/main/java/com/realtime/protection/server/task/TaskController.java115
-rw-r--r--src/main/java/com/realtime/protection/server/task/TaskMapper.java2
-rw-r--r--src/main/java/com/realtime/protection/server/task/TaskService.java9
-rw-r--r--src/main/java/com/realtime/protection/server/task/status/StateChangeService.java74
-rw-r--r--src/main/java/com/realtime/protection/server/task/status/StateHandler.java8
8 files changed, 127 insertions, 93 deletions
diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java
index d46ed61..0f0ed7e 100644
--- a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java
+++ b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java
@@ -139,6 +139,8 @@ public class TaskCommandInfo {
private String logUUID;
+ private String commandGroup;
+
// private String hashValue;
@@ -172,6 +174,7 @@ public class TaskCommandInfo {
this.displayId = original.displayId;
this.sipInt = original.sipInt;
this.dipInt = original.dipInt;
+ this.commandGroup = original.commandGroup;
}
public void setProtocolNum() {
diff --git a/src/main/java/com/realtime/protection/configuration/utils/DdosUtil.java b/src/main/java/com/realtime/protection/configuration/utils/DdosUtil.java
index 392e14c..17b4801 100644
--- a/src/main/java/com/realtime/protection/configuration/utils/DdosUtil.java
+++ b/src/main/java/com/realtime/protection/configuration/utils/DdosUtil.java
@@ -80,8 +80,7 @@ public class DdosUtil {
public void sendTaskStateInfo(Long taskId, Integer auditStatus, Integer stateNum) throws NoSuchAlgorithmException, KeyManagementException {
-// String token = getToken2(getToken1());
- String token = "";
+ String token = getToken2(getToken1());
try {
WebClient webClient = WebClient.create();
// 构建 form-data 请求体
@@ -92,7 +91,7 @@ public class DdosUtil {
log.info("请求体:" + requestData);
// 发送 POST 请求
String block = webClient.post()
- .uri("https://10.58.48.92:443/api/v1/center/scrubbingmonitorgroups/status")
+ .uri("https://10.58.48.92:443/api/v1/center/scrubbingmonitorgroups/status/")
// .uri("http://127.0.0.1:8082/yy/api/algo/task2")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
@@ -118,7 +117,7 @@ public class DdosUtil {
log.info("请求体:" + requestData);
// 发送 POST 请求
String block = webClient.post()
- .uri("http://10.58.48.92:443/api/v1/center/disposal/status")
+ .uri("http://10.58.48.92:443/api/v1/center/disposal/status/")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "token " + token)
diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java
index 70f0a9c..b6d0cec 100644
--- a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java
+++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java
@@ -166,6 +166,7 @@ public class AlertMessageService {
// }
//指令拆分局点,拆分后的指令放入staticTaskCommandInfosSplitDistributePoint
List<TaskCommandInfo> dynamicCommandInfoListSplitDistributePoint = new ArrayList<>();
+ String commandGroup =UUID.randomUUID().toString();
for (TaskCommandInfo taskCommandInfo : dynamicCommandInfoList) {
//判断是否多局点
if (taskCommandInfo.getDistributePoint().contains(",")) {
@@ -174,6 +175,7 @@ public class AlertMessageService {
TaskCommandInfo taskCommandInfoSplit = new TaskCommandInfo();
taskCommandInfoSplit.copyTaskCommandInfo(taskCommandInfo);
taskCommandInfoSplit.setDistributePoint(distributePoint);
+ taskCommandInfoSplit.setCommandGroup(commandGroup);
dynamicCommandInfoListSplitDistributePoint.add(taskCommandInfoSplit);
}
}
diff --git a/src/main/java/com/realtime/protection/server/task/TaskController.java b/src/main/java/com/realtime/protection/server/task/TaskController.java
index 89f1ec1..a930ccb 100644
--- a/src/main/java/com/realtime/protection/server/task/TaskController.java
+++ b/src/main/java/com/realtime/protection/server/task/TaskController.java
@@ -6,6 +6,7 @@ import com.realtime.protection.configuration.entity.user.UserFull;
import com.realtime.protection.configuration.exception.DorisStartException;
import com.realtime.protection.configuration.response.ResponseResult;
import com.realtime.protection.configuration.utils.File;
+import com.realtime.protection.configuration.utils.DdosUtil;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.server.command.CommandService;
@@ -21,6 +22,8 @@ import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
@@ -37,7 +40,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.file.Paths;
-import java.util.Base64;
+import java.util.*;
import javax.crypto.Mac;
@@ -45,15 +48,13 @@ import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/task")
public class TaskController implements TaskControllerApi {
+ private static final Logger log = LoggerFactory.getLogger(TaskController.class);
private final TaskService taskService;
private final StaticRuleService staticRuleService;
private final DynamicRuleService dynamicRuleService;
@@ -64,7 +65,7 @@ public class TaskController implements TaskControllerApi {
private final CommandService commandService;
private final StateChangeService stateChangeService;
- public TaskController(TaskService taskService, StaticRuleService staticRuleService, DynamicRuleService dynamicRuleService, ProtectObjectService protectObjectService, WhiteListService whiteListService, TemplateService templateService, CommandService commandService, StateChangeService stateChangeService) {
+ public TaskController(TaskService taskService, StaticRuleService staticRuleService, DynamicRuleService dynamicRuleService, ProtectObjectService protectObjectService, WhiteListService whiteListService, TemplateService templateService, CommandService commandService, StateChangeService stateChangeService) {
this.taskService = taskService;
this.staticRuleService = staticRuleService;
this.dynamicRuleService = dynamicRuleService;
@@ -112,6 +113,7 @@ public class TaskController implements TaskControllerApi {
.setData("task_id", 0)
.setData("success", false);
}
+
private boolean verifyHmac(String data, String signature, String key) throws NoSuchAlgorithmException, InvalidKeyException {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "HmacSHA256");
@@ -121,6 +123,7 @@ public class TaskController implements TaskControllerApi {
System.out.println(expectedSignature);
return expectedSignature.equals(signature);
}
+
// API推送Endpoint
@Override
@PostMapping("/api/new")
@@ -129,13 +132,13 @@ public class TaskController implements TaskControllerApi {
String signature = request.getHeader("X-Signature");
- if (signature == null){
+ if (signature == null) {
throw new IllegalArgumentException("HMAC签名值为空,认证失败");
}
String data = String.valueOf(taskCommandInfo.hashCode());
String apiKey = "gyusygwefweuu2135634";
if (!verifyHmac(data, signature, apiKey)) {
- throw new IllegalArgumentException("HMAC签名校验失败,认证失败"+String.valueOf(taskCommandInfo.hashCode()));
+ throw new IllegalArgumentException("HMAC签名校验失败,认证失败" + String.valueOf(taskCommandInfo.hashCode()));
}
Long taskId = taskService.newTaskUsingCommandInfo(taskCommandInfo);
// Long taskId =45377L;
@@ -144,18 +147,18 @@ public class TaskController implements TaskControllerApi {
.setData("taskId", -1)
.setData("success", false);
}
-
+ taskCommandInfo.setCommandGroup(UUID.randomUUID().toString());
commandService.createCommand(taskCommandInfo);
return ResponseResult.ok()
.setData("taskId", taskId)
.setData("success", true)
- .setData("command_hash",taskCommandInfo.hashCode());
+ .setData("command_hash", taskCommandInfo.hashCode());
}
@GetMapping("/queryAttachment")
@Override
- public ResponseResult queryAttachment(@RequestParam("task_id") Long taskId) {
+ public ResponseResult queryAttachment(@RequestParam("task_id") Long taskId) {
List<File> files = taskService.selectFilesByStaticRuleId(taskId);
return ResponseResult.ok()
@@ -171,14 +174,14 @@ public class TaskController implements TaskControllerApi {
// String uploadPath = "d:\\";
String uploadPath = "/task_file";
//获取文件上传名称
- String fileName=file.getOriginalFilename();
+ String fileName = file.getOriginalFilename();
//获取文件保存全路径
- String savePath=uploadPath+"/"+fileName;
+ String savePath = uploadPath + "/" + fileName;
//获取文件大小
- Long fileSize=file.getSize();
+ Long fileSize = file.getSize();
//获取文件类型
- String fileType=file.getContentType();
- java.io.File newFile=new java.io.File(savePath);
+ String fileType = file.getContentType();
+ java.io.File newFile = new java.io.File(savePath);
// 获取文件的父目录
java.io.File parentDir = newFile.getParentFile();
// 如果父目录不存在,则创建该目录
@@ -187,7 +190,7 @@ public class TaskController implements TaskControllerApi {
}
//TODO 注意要将文件保存到本地路径中
file.transferTo(newFile);
- File saveFile=new File();
+ File saveFile = new File();
saveFile.setFileName(fileName);
saveFile.setFileSize(fileSize);
saveFile.setFileType(fileType);
@@ -199,24 +202,23 @@ public class TaskController implements TaskControllerApi {
}
-
//文件下载
@GetMapping("downAttachment")
@Override
public ResponseEntity<Resource> downFile(@RequestParam Integer id) throws MalformedURLException, UnsupportedEncodingException {
//首先根据id,从数据库获取文件信息
- File downFile=taskService.selectFileById(id);
- if (downFile!=null){
- String path= downFile.getFilePath();
+ File downFile = taskService.selectFileById(id);
+ if (downFile != null) {
+ String path = downFile.getFilePath();
//本地路径地址转为url编码路径
- URI urlPath= Paths.get(path).toUri();
- Resource resource=new UrlResource(urlPath);
- if (resource.exists()){
- HttpHeaders headers=new HttpHeaders();
- headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM+"");
- headers.add(HttpHeaders.CONTENT_LENGTH,downFile.getFileSize()+"");
+ URI urlPath = Paths.get(path).toUri();
+ Resource resource = new UrlResource(urlPath);
+ if (resource.exists()) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM + "");
+ headers.add(HttpHeaders.CONTENT_LENGTH, downFile.getFileSize() + "");
//注意文件名处要改为URL编码
- headers.add(HttpHeaders.CONTENT_DISPOSITION,"attachment; filename=\"" +
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" +
URLEncoder.encode(downFile.getFileName(), "utf-8") + "\"");
return ResponseEntity.ok().headers(headers).body(resource);
}
@@ -244,20 +246,20 @@ public class TaskController implements TaskControllerApi {
@RequestParam("page_size") @Min(1) Integer pageSize) {
- String createDateStr = null , startTimeStr = null;
+ String createDateStr = null, startTimeStr = null;
if (createTime != null) {
createDateStr = createTime.toString();
}
- if(startTime != null) {
+ if (startTime != null) {
startTimeStr = startTime.toString();
}
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus,
taskAct, taskAuditor, taskSource, ruleName,
- eventType, createDateStr, startTimeStr,protectLevel, page, pageSize);
+ eventType, createDateStr, startTimeStr, protectLevel, page, pageSize);
return ResponseResult.ok()
.setData("task_list", tasks)
.setData("total_num", taskService.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator, auditStatus,
- taskAct, taskAuditor, taskSource, ruleName,eventType, createDateStr, startTimeStr,protectLevel));
+ taskAct, taskAuditor, taskSource, ruleName, eventType, createDateStr, startTimeStr, protectLevel));
}
@Override
@@ -282,7 +284,6 @@ public class TaskController implements TaskControllerApi {
}
-
@Override
@GetMapping("/{taskId}/audit/{auditStatus}")
public ResponseResult changeTaskAuditStatus(@PathVariable @NotNull @Max(10) Integer auditStatus,
@@ -295,14 +296,25 @@ public class TaskController implements TaskControllerApi {
String auditUserId = null;
String auditUserDepart = null;
if (user != null) {
- auditUserName= user.name;
+ auditUserName = user.name;
auditUserId = user.uid;
auditUserDepart = user.getOrgName();
}
+ Boolean auditState = taskService.changeTaskAuditStatus(taskId, auditStatus,
+ auditUserName, auditUserId, auditUserDepart);
+ Task task = taskService.queryTask(taskId);
+ //如果任务是ddos系统推送的,需要将审核信息发送到ddos系统
+ if (task != null && "ddos".equals(task.getTaskSource()) && auditState) {
+ try {
+ DdosUtil ddosUtil = new DdosUtil();
+ ddosUtil.sendTaskStateInfo(taskId, task.getTaskAuditStatus(), task.getTaskStatus());
+ } catch (Exception e) {
+ log.error("向ddos系统发送审核信息异常");
+ }
+ }
return ResponseResult.ok()
.setData("task_id", taskId)
- .setData("success", taskService.changeTaskAuditStatus(taskId, auditStatus,
- auditUserName, auditUserId, auditUserDepart))
+ .setData("success", auditState)
.setData("audit_status", taskService.queryTaskAuditStatus(taskId));
}
@@ -354,7 +366,7 @@ public class TaskController implements TaskControllerApi {
@GetMapping("/{commandId}/valid2/{isValid}")
public ResponseResult setCommandValid(@PathVariable Integer isValid,
- @PathVariable String commandId) {
+ @PathVariable String commandId) {
if (isValid < 0 || isValid > 1) {
return ResponseResult.invalid()
.setData("success", false)
@@ -376,7 +388,7 @@ public class TaskController implements TaskControllerApi {
public ResponseResult updateTaskAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
@Autowired HttpServletRequest request) {
List<Integer> errorIds = new ArrayList<>();
- for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
+ for (Map.Entry<Integer, Integer> entry : idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
@@ -395,7 +407,7 @@ public class TaskController implements TaskControllerApi {
String auditUserId = null;
String auditUserDepart = null;
if (user != null) {
- auditUserName= user.name;
+ auditUserName = user.name;
auditUserId = user.uid;
auditUserDepart = user.getOrgName();
}
@@ -413,18 +425,18 @@ public class TaskController implements TaskControllerApi {
public ResponseResult statistics() {
return ResponseResult.ok()
.setData("total_num", taskService.queryTaskTotalNum(null, null, null, null, null,
- null, null, null, null,null,null,null,null))
+ null, null, null, null, null, null, null, null))
.setData("running_num",
taskService.queryTaskTotalNum(StateEnum.RUNNING.getStateNum(), null, null, null, null,
- null, null, null, null,null,null,null,null)
+ null, null, null, null, null, null, null, null)
+ taskService.queryTaskTotalNum(StateEnum.RUNNING_PARTIAL_SUCCESS.getStateNum(), null, null, null, null,
- null, null, null, null,null,null,null,null)
+ null, null, null, null, null, null, null, null)
+ taskService.queryTaskTotalNum(StateEnum.RUNNING_SUCCESS.getStateNum(), null, null, null, null,
- null, null, null, null,null,null,null,null)
+ null, null, null, null, null, null, null, null)
+ taskService.queryTaskTotalNum(StateEnum.RUNNING_FAILED.getStateNum(), null, null, null, null,
- null, null, null, null,null,null,null,null))
+ null, null, null, null, null, null, null, null))
.setData("finished_num", taskService.queryTaskTotalNum(StateEnum.FINISHED.getStateNum(), null, null, null, null,
- null, null, null, null,null,null,null,null))
+ null, null, null, null, null, null, null, null))
.setData("unaudit_num", taskService.queryAuditTaskTotalNum(AuditStatusEnum.PENDING.getNum()))
.setData("audited_num", taskService.queryAuditTaskTotalNum(AuditStatusEnum.AUDITED.getNum()))
.setData("rejected_num", taskService.queryAuditTaskTotalNum(AuditStatusEnum.RETURNED.getNum()))
@@ -477,7 +489,7 @@ public class TaskController implements TaskControllerApi {
@Override
@PostMapping("/send-pcap")
- public ResponseEntity<String> uploadPcap( MultipartFile file) {
+ public ResponseEntity<String> uploadPcap(MultipartFile file) {
if (file.isEmpty()) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("文件为空");
}
@@ -493,7 +505,9 @@ public class TaskController implements TaskControllerApi {
// Files.write(path, file.getBytes());
// Here you can add logic to send the file to a server or process it as needed
- if(true) {throw new IllegalArgumentException("DNS报文校验失败");}
+ if (true) {
+ throw new IllegalArgumentException("DNS报文校验失败");
+ }
return ResponseEntity.status(HttpStatus.OK).body("文件发送处置服务器成功: " + file.getOriginalFilename());
}
@@ -511,7 +525,7 @@ public class TaskController implements TaskControllerApi {
@Override
@GetMapping("/auditinfo/alert/{userId}")
- public ResponseResult auditInfoNotification(@PathVariable String userId){
+ public ResponseResult auditInfoNotification(@PathVariable String userId) {
return ResponseResult.ok()
.setData("success", true)
@@ -521,7 +535,7 @@ public class TaskController implements TaskControllerApi {
@Override
@PostMapping("/result/{systemName}")
public ResponseResult receiveOtherSystemResult(@PathVariable String systemName,
- @RequestBody Map<String, String> auditInfo){
+ @RequestBody Map<String, String> auditInfo) {
return ResponseResult.ok()
.setData("success", true)
@@ -530,10 +544,10 @@ public class TaskController implements TaskControllerApi {
@Override
@GetMapping("/query/log/status")
- public ResponseResult queryTaskStausLog(@RequestParam("id") @Min(1) Long id ,
+ public ResponseResult queryTaskStausLog(@RequestParam("id") @Min(1) Long id,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize) {
- List<Task> taskLog = taskService.queryTaskStausLog(id,page,pageSize);
+ List<Task> taskLog = taskService.queryTaskStausLog(id, page, pageSize);
if (taskLog == null) {
return ResponseResult.invalid().setMessage("无效Task ID,也许该ID对应的任务不存在?");
@@ -544,5 +558,4 @@ public class TaskController implements TaskControllerApi {
}
-
} \ No newline at end of file
diff --git a/src/main/java/com/realtime/protection/server/task/TaskMapper.java b/src/main/java/com/realtime/protection/server/task/TaskMapper.java
index 800ab28..4874189 100644
--- a/src/main/java/com/realtime/protection/server/task/TaskMapper.java
+++ b/src/main/java/com/realtime/protection/server/task/TaskMapper.java
@@ -153,4 +153,6 @@ public interface TaskMapper {
List<Long> queryRunningTasks(Integer running, Integer allSuccess, Integer partSuccess, Integer allFail);
Integer queryIpTotalNum(Long taskId);
+
+ List<Task> queryDdosTask();
}
diff --git a/src/main/java/com/realtime/protection/server/task/TaskService.java b/src/main/java/com/realtime/protection/server/task/TaskService.java
index 0fcd6d2..7dbf919 100644
--- a/src/main/java/com/realtime/protection/server/task/TaskService.java
+++ b/src/main/java/com/realtime/protection/server/task/TaskService.java
@@ -861,4 +861,13 @@ public class TaskService {
ipTotalNum = ipTotalNum + taskIpNum;
taskMapper.setIpTotalNum(ipTotalNum, taskId);
}
+
+ public HashMap<Long, Integer> queryDdosTask() {
+ List<Task> tasks = taskMapper.queryDdosTask();
+ HashMap<Long, Integer> taskStateMap = new HashMap<>();
+ tasks.forEach(task -> {
+ taskStateMap.put(task.getTaskId(), task.getTaskAuditStatus());
+ });
+ return taskStateMap;
+ }
}
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 25ac973..4a92bef 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
@@ -3,6 +3,7 @@ package com.realtime.protection.server.task.status;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.exception.DorisStartException;
+import com.realtime.protection.configuration.utils.DdosUtil;
import com.realtime.protection.configuration.utils.enums.CommandStatusEnum;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.server.task.status.states.State;
@@ -14,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
+import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@@ -108,10 +110,14 @@ public class StateChangeService {
protected void finishTasks() {
List<Long> finishedTaskIds = taskService.getFinishedTasks();
log.debug("成功扫描出所有需要变为结束状态的任务:{}", finishedTaskIds);
-
+ HashMap<Long, Integer> ddosTaskMap = taskService.queryDdosTask();
for (Long taskId : finishedTaskIds) {
try {
changeState(StateEnum.FINISHED.getStateNum(), taskId, true);
+ if (ddosTaskMap.get(taskId) != null) {
+ DdosUtil ddosUtil = new DdosUtil();
+ ddosUtil.sendTaskStateInfo(taskId, 2, StateEnum.FINISHED.getStateNum());
+ }
} catch (Exception e) {
log.warn(String.format("任务%d从%s状态变为FINISHED状态遭遇异常:%s",
taskId, taskService.queryTaskStatus(taskId), e.getMessage()));
@@ -128,10 +134,14 @@ public class StateChangeService {
protected void startTasks() {
List<Long> runnableTaskIds = taskService.getRunnableTasks();
log.debug("成功扫描出所有需要变为开始状态的任务:{}", runnableTaskIds);
-
+ HashMap<Long, Integer> ddosTaskMap = taskService.queryDdosTask();
for (Long taskId : runnableTaskIds) {
try {
changeState(StateEnum.RUNNING.getStateNum(), taskId, true);
+ if (ddosTaskMap.get(taskId) != null) {
+ DdosUtil ddosUtil = new DdosUtil();
+ ddosUtil.sendTaskStateInfo(taskId, 2, StateEnum.RUNNING.getStateNum());
+ }
} catch (Exception e) {
log.warn(String.format("任务%d从%s状态变为运行中RUNNING状态遭遇异常:%s",
taskId, taskService.queryTaskStatus(taskId), e.getMessage()));
@@ -140,6 +150,7 @@ public class StateChangeService {
}
}
+
/**
* 更新任务状态,要么加字段(运行中加两个)、“要么改状态模式(字典表也要改)”
*/
@@ -153,7 +164,7 @@ public class StateChangeService {
for (Long taskId : runningTaskIds) {
//查询任务下所有的正在下发的指令(isjudge = 1 ,isvalid=1, is_deleted=0)的本次是否下发成功字段(t_command加个字段)
List<Integer> commandStatusList = commandService.queryRunningCommandsDistributeStatusByTaskId(taskId);
- if (commandStatusList == null){
+ if (commandStatusList.isEmpty()) {
continue;
}
//判断是否全为成功
@@ -204,7 +215,7 @@ public class StateChangeService {
for (TaskCommandInfo taskCommandInfo : runningCommandList) {
//查询状态表,查看本次下发周期内是否已经记录了命中状态。查询最近的两条日志记录
List<TaskCommandInfo> commandLogs = commandService.queryCommandLogLastTwoRecord(taskCommandInfo.getUUID());
- if (commandLogs.size()<2){
+ if (commandLogs.size() < 2) {
continue;
}
TaskCommandInfo commandLogLatest = commandLogs.get(0);
@@ -213,18 +224,17 @@ public class StateChangeService {
//如果日志状态为SEND、SUCCESS 或者 SEND、FAIL,则要根据当前t_command表的最新记录,和上次下发状态的命中计数相比判断是否有变化
- if (commandLogLatest2.getCommandStatus()==CommandStatusEnum.SEND.getCommandStatusNum()
- && (commandLogLatest.getCommandStatus()==CommandStatusEnum.SUCCESS.getCommandStatusNum()
- || commandLogLatest.getCommandStatus()==CommandStatusEnum.FAIL.getCommandStatusNum()))
- {
- log.info("rcp命中查询:{},{}",taskCommandInfo.getRcpHitCount(), commandLogLatest.getRcpHitCount());
- if (taskCommandInfo.getRcpHitCount()!=null && commandLogLatest.getRcpHitCount()==null) {
+ if (commandLogLatest2.getCommandStatus() == CommandStatusEnum.SEND.getCommandStatusNum()
+ && (commandLogLatest.getCommandStatus() == CommandStatusEnum.SUCCESS.getCommandStatusNum()
+ || commandLogLatest.getCommandStatus() == CommandStatusEnum.FAIL.getCommandStatusNum())) {
+ log.info("rcp命中查询:{},{}", taskCommandInfo.getRcpHitCount(), commandLogLatest.getRcpHitCount());
+ if (taskCommandInfo.getRcpHitCount() != null && commandLogLatest.getRcpHitCount() == null) {
//更新log表,rcp命中
commandService.insertCommandHistoryWithTimeWithTraffic(taskCommandInfo.getUUID(),
CommandStatusEnum.RCPHIT.getCommandStatusNum(), taskCommandInfo.getLastRCPQueryTime(),
commandLogLatest.getTotalPacketNum());
}
- if (taskCommandInfo.getRcpHitCount()!=null && commandLogLatest.getRcpHitCount()!=null) {
+ if (taskCommandInfo.getRcpHitCount() != null && commandLogLatest.getRcpHitCount() != null) {
if (taskCommandInfo.getRcpHitCount() > commandLogLatest.getRcpHitCount()) {
//更新log表,rcp命中
commandService.insertCommandHistoryWithTimeWithTraffic(taskCommandInfo.getUUID(),
@@ -234,17 +244,17 @@ public class StateChangeService {
}
- log.info("流量命中查询:{},{}",taskCommandInfo.getTotalPacketNum(), commandLogLatest.getTotalPacketNum());
- if (taskCommandInfo.getTotalPacketNum()!=null && commandLogLatest.getTotalPacketNum()==null) {
+ log.info("流量命中查询:{},{}", taskCommandInfo.getTotalPacketNum(), commandLogLatest.getTotalPacketNum());
+ if (taskCommandInfo.getTotalPacketNum() != null && commandLogLatest.getTotalPacketNum() == null) {
//更新log表,流量命中
commandService.insertCommandHistoryWithTime(taskCommandInfo.getUUID(),
- CommandStatusEnum.FLOWHIT.getCommandStatusNum(),taskCommandInfo.getLastTrafficQueryTime());
+ CommandStatusEnum.FLOWHIT.getCommandStatusNum(), taskCommandInfo.getLastTrafficQueryTime());
}
- if (taskCommandInfo.getTotalPacketNum()!=null && commandLogLatest.getTotalPacketNum()!=null) {
+ if (taskCommandInfo.getTotalPacketNum() != null && commandLogLatest.getTotalPacketNum() != null) {
if (taskCommandInfo.getTotalPacketNum() > commandLogLatest.getTotalPacketNum()) {
//更新log表,流量命中
commandService.insertCommandHistoryWithTime(taskCommandInfo.getUUID(),
- CommandStatusEnum.FLOWHIT.getCommandStatusNum(),taskCommandInfo.getLastTrafficQueryTime());
+ CommandStatusEnum.FLOWHIT.getCommandStatusNum(), taskCommandInfo.getLastTrafficQueryTime());
}
}
@@ -253,19 +263,18 @@ public class StateChangeService {
//如果日志状态为SUCCESS/FAIL、RCPHIT/UNRCPHIT,则判断是否更新流量命中状态
- if ((commandLogLatest2.getCommandStatus()==CommandStatusEnum.SUCCESS.getCommandStatusNum()
- || commandLogLatest2.getCommandStatus()==CommandStatusEnum.FAIL.getCommandStatusNum())
- && (commandLogLatest.getCommandStatus()==CommandStatusEnum.RCPHIT.getCommandStatusNum()
- || commandLogLatest.getCommandStatus()==CommandStatusEnum.UNRCPHIT.getCommandStatusNum()))
- {
-
- log.info("流量命中查询:{},{}",taskCommandInfo.getTotalPacketNum(), commandLogLatest.getTotalPacketNum());
- if (taskCommandInfo.getTotalPacketNum()!=null && commandLogLatest.getTotalPacketNum()==null) {
+ if ((commandLogLatest2.getCommandStatus() == CommandStatusEnum.SUCCESS.getCommandStatusNum()
+ || commandLogLatest2.getCommandStatus() == CommandStatusEnum.FAIL.getCommandStatusNum())
+ && (commandLogLatest.getCommandStatus() == CommandStatusEnum.RCPHIT.getCommandStatusNum()
+ || commandLogLatest.getCommandStatus() == CommandStatusEnum.UNRCPHIT.getCommandStatusNum())) {
+
+ log.info("流量命中查询:{},{}", taskCommandInfo.getTotalPacketNum(), commandLogLatest.getTotalPacketNum());
+ if (taskCommandInfo.getTotalPacketNum() != null && commandLogLatest.getTotalPacketNum() == null) {
//更新log表,流量命中
commandService.insertCommandHistory(taskCommandInfo.getUUID(),
CommandStatusEnum.FLOWHIT.getCommandStatusNum());
}
- if (taskCommandInfo.getTotalPacketNum()!=null && commandLogLatest.getTotalPacketNum()!=null) {
+ if (taskCommandInfo.getTotalPacketNum() != null && commandLogLatest.getTotalPacketNum() != null) {
if (taskCommandInfo.getTotalPacketNum() > commandLogLatest.getTotalPacketNum()) {
//更新log表,流量命中
commandService.insertCommandHistory(taskCommandInfo.getUUID(),
@@ -275,18 +284,17 @@ public class StateChangeService {
continue;
}
//如果日志状态为SUCCESS/FAIL、FLOWHIT/UNFLOWHIT,则判断是否更新rcp命中状态
- if ((commandLogLatest2.getCommandStatus()==CommandStatusEnum.SUCCESS.getCommandStatusNum()
- || commandLogLatest2.getCommandStatus()==CommandStatusEnum.FAIL.getCommandStatusNum())
- && (commandLogLatest.getCommandStatus()==CommandStatusEnum.FLOWHIT.getCommandStatusNum()
- || commandLogLatest.getCommandStatus()==CommandStatusEnum.UNFLOWHIT.getCommandStatusNum()))
- {
- log.info("rcp命中查询:{},{}",taskCommandInfo.getRcpHitCount(), commandLogLatest.getRcpHitCount());
- if (taskCommandInfo.getRcpHitCount()!=null && commandLogLatest.getRcpHitCount()==null) {
+ if ((commandLogLatest2.getCommandStatus() == CommandStatusEnum.SUCCESS.getCommandStatusNum()
+ || commandLogLatest2.getCommandStatus() == CommandStatusEnum.FAIL.getCommandStatusNum())
+ && (commandLogLatest.getCommandStatus() == CommandStatusEnum.FLOWHIT.getCommandStatusNum()
+ || commandLogLatest.getCommandStatus() == CommandStatusEnum.UNFLOWHIT.getCommandStatusNum())) {
+ log.info("rcp命中查询:{},{}", taskCommandInfo.getRcpHitCount(), commandLogLatest.getRcpHitCount());
+ if (taskCommandInfo.getRcpHitCount() != null && commandLogLatest.getRcpHitCount() == null) {
//更新log表,rcp命中
commandService.insertCommandHistoryWithTime(taskCommandInfo.getUUID(),
CommandStatusEnum.RCPHIT.getCommandStatusNum(), taskCommandInfo.getLastRCPQueryTime());
}
- if (taskCommandInfo.getRcpHitCount()!=null && commandLogLatest.getRcpHitCount()!=null) {
+ if (taskCommandInfo.getRcpHitCount() != null && commandLogLatest.getRcpHitCount() != null) {
if (taskCommandInfo.getRcpHitCount() > commandLogLatest.getRcpHitCount()) {
//更新log表,rcp命中
commandService.insertCommandHistoryWithTime(taskCommandInfo.getUUID(),
diff --git a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java
index f4802f1..9dcb5ab 100644
--- a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java
+++ b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java
@@ -20,10 +20,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import java.time.Duration;
import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
@Slf4j
@@ -114,7 +111,6 @@ public class StateHandler {
taskService.updateStaticRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
taskService.removeStaticRuleUsedTaskIdInTask(taskId);
-
return true;
}
@@ -232,11 +228,13 @@ public class StateHandler {
for (TaskCommandInfo taskCommandInfo : staticTaskCommandInfos) {
//判断是否多局点
if (taskCommandInfo.getDistributePoint().contains(",")) {
+ String commandGroup = UUID.randomUUID().toString();
List<String> distributePointArray = Arrays.asList(taskCommandInfo.getDistributePoint().split(","));
for (String distributePoint : distributePointArray) {
TaskCommandInfo taskCommandInfoSplit = new TaskCommandInfo();
taskCommandInfoSplit.copyTaskCommandInfo(taskCommandInfo);
taskCommandInfoSplit.setDistributePoint(distributePoint);
+ taskCommandInfoSplit.setCommandGroup(commandGroup);
staticTaskCommandInfosSplitDistributePoint.add(taskCommandInfoSplit);
}
} else {