1. 添加doris数据源
2. 添加StateMapper,准备进行oracle数据库对接
This commit is contained in:
@@ -46,4 +46,4 @@ dependencies {
|
|||||||
|
|
||||||
tasks.named('test') {
|
tasks.named('test') {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Command {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer type;
|
||||||
|
private String sourceIP;
|
||||||
|
private String sourcePort;
|
||||||
|
private String destinationIP;
|
||||||
|
private String destinationPort;
|
||||||
|
private Integer protocol;
|
||||||
|
|
||||||
|
private String maskSourceIP;
|
||||||
|
private String maskSourcePort;
|
||||||
|
private String maskDestinationIP;
|
||||||
|
private String maskDestinationPort;
|
||||||
|
private Integer direction;
|
||||||
|
|
||||||
|
private LocalDateTime datetime;
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.realtime.protection.configuration.utils.status.state;
|
|
||||||
|
|
||||||
public class PauseState implements State {
|
|
||||||
@Override
|
|
||||||
public Boolean handle(State newState) {
|
|
||||||
if (!(newState instanceof RunningState)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return handleRun();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Boolean handleRun() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.realtime.protection.configuration.utils.status.state;
|
|
||||||
|
|
||||||
public interface State {
|
|
||||||
|
|
||||||
Boolean handle(State newState);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.realtime.protection.configuration.utils.status;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
import com.realtime.protection.configuration.utils.status.state.State;
|
import com.realtime.protection.server.task.state.State;
|
||||||
|
|
||||||
public class StatusChanger {
|
public class StatusChanger {
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class TaskController {
|
|||||||
.setData("success", taskService.updateTask(task));
|
.setData("success", taskService.updateTask(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{taskId}/{auditStatus}/audit")
|
@GetMapping("/{taskId}/audit/{auditStatus}")
|
||||||
public ResponseResult changeTaskAuditStatus(@PathVariable Integer auditStatus, @PathVariable Integer taskId) {
|
public ResponseResult changeTaskAuditStatus(@PathVariable Integer auditStatus, @PathVariable Integer taskId) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
@@ -89,4 +89,11 @@ public class TaskController {
|
|||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
.setData("success", taskService.deleteTask(taskId));
|
.setData("success", taskService.deleteTask(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{taskId}/running/{state}")
|
||||||
|
public ResponseResult changeTaskStatus(@PathVariable Integer state, @PathVariable Integer taskId) {
|
||||||
|
return ResponseResult.ok()
|
||||||
|
.setData("task_id", taskId)
|
||||||
|
.setData("success", taskService.changeTaskStatus(taskId, state));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.realtime.protection.server.task;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||||
|
import com.realtime.protection.server.task.state.PauseState;
|
||||||
|
import com.realtime.protection.server.task.state.RunningState;
|
||||||
|
import com.realtime.protection.server.task.state.State;
|
||||||
|
import com.realtime.protection.server.task.state.StopState;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -61,4 +64,29 @@ public class TaskService {
|
|||||||
public Boolean deleteTask(Integer taskId) {
|
public Boolean deleteTask(Integer taskId) {
|
||||||
return taskMapper.deleteTask(taskId);
|
return taskMapper.deleteTask(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Boolean changeTaskStatus(Integer taskId, Integer stateNum) {
|
||||||
|
State originalState = switch (taskMapper.queryTask(taskId).getTaskStatus()) {
|
||||||
|
// 运行中
|
||||||
|
case 1 -> new RunningState();
|
||||||
|
// 暂停中
|
||||||
|
case 2 -> new PauseState();
|
||||||
|
// 停止中
|
||||||
|
case 3 -> new StopState();
|
||||||
|
default -> throw new IllegalArgumentException();
|
||||||
|
};
|
||||||
|
|
||||||
|
State newState = switch (stateNum) {
|
||||||
|
// 运行中
|
||||||
|
case 1 -> new RunningState();
|
||||||
|
// 暂停中
|
||||||
|
case 2 -> new PauseState();
|
||||||
|
// 停止中
|
||||||
|
case 3 -> new StopState();
|
||||||
|
default -> throw new IllegalArgumentException();
|
||||||
|
};
|
||||||
|
|
||||||
|
return StatusChanger.setOriginal(originalState).changeState(newState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.realtime.protection.server.task.state;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
|
||||||
|
public class PauseState implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState) {
|
||||||
|
if (newState instanceof RunningState) {
|
||||||
|
return handleRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DS("oracle")
|
||||||
|
private Boolean handleRun() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.realtime.protection.configuration.utils.status.state;
|
package com.realtime.protection.server.task.state;
|
||||||
|
|
||||||
public class RunningState implements State {
|
public class RunningState implements State {
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.realtime.protection.server.task.state;
|
||||||
|
|
||||||
|
public interface State {
|
||||||
|
|
||||||
|
Boolean handle(State newState);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.realtime.protection.server.task.state;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.entity.task.Command;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
public interface StateMapper {
|
||||||
|
Boolean sendCommand(@Param("command") Command command);
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.realtime.protection.configuration.utils.status.state;
|
package com.realtime.protection.server.task.state;
|
||||||
|
|
||||||
public class StopState implements State {
|
public class StopState implements State {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean handle(State newState) {
|
public Boolean handle(State newState) {
|
||||||
if (!(newState instanceof RunningState)) {
|
if (newState instanceof RunningState) {
|
||||||
return false;
|
return handleRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleRun();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean handleRun() {
|
public Boolean handleRun() {
|
||||||
@@ -19,6 +19,12 @@ spring:
|
|||||||
url: jdbc:oracle:thin:@//10.26.22.45:1521/ORCL
|
url: jdbc:oracle:thin:@//10.26.22.45:1521/ORCL
|
||||||
hikari:
|
hikari:
|
||||||
is-auto-commit: false
|
is-auto-commit: false
|
||||||
|
doris:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
username: root
|
||||||
|
url: jdbc:mysql://10.26.22.133:9030
|
||||||
|
hikari:
|
||||||
|
is-auto-commit: false
|
||||||
aop:
|
aop:
|
||||||
enabled: true
|
enabled: true
|
||||||
primary: mysql
|
primary: mysql
|
||||||
|
|||||||
9
src/main/resources/mappers/StateMapper.xml
Normal file
9
src/main/resources/mappers/StateMapper.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.realtime.protection.server.task.state.StateMapper">
|
||||||
|
<insert id="sendCommand" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
||||||
@@ -53,22 +53,31 @@ class TemplateServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void testQueryTemplate() {
|
void testQueryTemplate() {
|
||||||
List<Template> templates = templateService.queryTemplates("DDOS", 1, 5);
|
List<Template> templates = templateService.queryTemplates("DDOS", 1, 5);
|
||||||
System.out.println(templates);
|
assertEquals(5, templates.size());
|
||||||
|
for (Template template : templates) {
|
||||||
|
assertTrue(template.getTemplateId() > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpdateTemplateSuccess() {
|
void testUpdateTemplateSuccess() {
|
||||||
template.setTemplateName("洪泛型DDOS攻击");
|
List<Template> templates = templateService.queryTemplates("反射", 1, 6);
|
||||||
assertTrue(templateService.updateTemplate(3, template));
|
Template testTemplate = templates.get(0);
|
||||||
|
testTemplate.setTemplateName("洪泛型DDOS攻击");
|
||||||
|
|
||||||
|
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddTemplateUsedTimes() {
|
void testAddTemplateUsedTimes() {
|
||||||
List<Template> templates = templateService.queryTemplates("洪泛型DDOS攻击", 1, 1);
|
template.setTemplateName("add test");
|
||||||
|
templateService.newTemplate(template);
|
||||||
|
|
||||||
|
List<Template> templates = templateService.queryTemplates("add", 1, 1);
|
||||||
Template originalTemplate = templates.get(0);
|
Template originalTemplate = templates.get(0);
|
||||||
Boolean success = templateService.addTemplateUsedTimes(3, 4);
|
Boolean success = templateService.addTemplateUsedTimes(originalTemplate.getTemplateId(), 4);
|
||||||
templates = templateService.queryTemplates("洪泛型DDOS攻击", 1, 1);
|
templates = templateService.queryTemplates("add", 1, 1);
|
||||||
assertEquals(templates.get(0).getTemplateUsedTimes(), originalTemplate.getTemplateUsedTimes() + 4);
|
assertEquals(originalTemplate.getTemplateUsedTimes() + 4, templates.get(0).getTemplateUsedTimes());
|
||||||
assertTrue(success);
|
assertTrue(success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user