1. application.yml修改为application-dev.yml和application-prod.yml
2. 添加更多Exception拦截器 3. 编写状态模式处理task状态的更改 4. 添加StateChangeService,用以处理所有任务状态转换相关的内容 5. 添加StateEnum, ProtocolEnum,TaskTypeEnum用以处理任务和协议相关的所有状态和类型
This commit is contained in:
4
gradlew.bat
vendored
4
gradlew.bat
vendored
@@ -44,7 +44,7 @@ set JAVA_EXE=java.exe
|
|||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' commandInfo could be found in your PATH.
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
@@ -66,7 +66,7 @@ echo location of your Java installation.
|
|||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the commandInfo line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package com.realtime.protection;
|
package com.realtime.protection;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableAsync
|
||||||
public class ProtectionApplication {
|
public class ProtectionApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ProtectionApplication.class, args);
|
SpringApplicationBuilder builder = new SpringApplicationBuilder(ProtectionApplication.class);
|
||||||
|
|
||||||
|
// 在实际环境中应该修改为prod
|
||||||
|
builder.application().setAdditionalProfiles("dev");
|
||||||
|
|
||||||
|
builder.run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Template {
|
public class Template {
|
||||||
@JsonProperty("template_id")
|
@JsonProperty("template_id")
|
||||||
@@ -37,6 +35,12 @@ public class Template {
|
|||||||
@NotNull(message = "protect_level_high should not be empty. ")
|
@NotNull(message = "protect_level_high should not be empty. ")
|
||||||
private ProtectLevel protectLevelHigh;
|
private ProtectLevel protectLevelHigh;
|
||||||
|
|
||||||
|
@JsonProperty("template_used_times")
|
||||||
|
private Integer usedTimes;
|
||||||
|
|
||||||
|
@JsonProperty("running_tasks")
|
||||||
|
private Integer runningTasks;
|
||||||
|
|
||||||
private Integer createUserId;
|
private Integer createUserId;
|
||||||
|
|
||||||
private String createUsername;
|
private String createUsername;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class DynamicRuleObject {
|
|||||||
@JsonProperty("dynamic_rule_create_username")
|
@JsonProperty("dynamic_rule_create_username")
|
||||||
private String dynamicRuleCreateUsername;
|
private String dynamicRuleCreateUsername;
|
||||||
|
|
||||||
// @JsonProperty("dynamic_rule_audit_status")
|
// @JsonProperty("dynamic_rule_audit_status")
|
||||||
// private Integer dynamicRuleAuditStatus;
|
// private Integer dynamicRuleAuditStatus;
|
||||||
@JsonProperty("dynamic_rule_create_depart")
|
@JsonProperty("dynamic_rule_create_depart")
|
||||||
private String dynamicRuleCreateDepart;
|
private String dynamicRuleCreateDepart;
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
package com.realtime.protection.configuration.entity.task;
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.utils.enums.ProtocolEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Command {
|
public class Command {
|
||||||
private Integer id;
|
private FiveTupleWithMask fiveTupleWithMask;
|
||||||
|
private Long taskId;
|
||||||
|
|
||||||
private Integer type;
|
private String operation;
|
||||||
private String sourceIP;
|
private LocalDateTime validTime;
|
||||||
private String sourcePort;
|
private LocalDateTime invalidTime;
|
||||||
private String destinationIP;
|
|
||||||
private String destinationPort;
|
|
||||||
private Integer protocol;
|
|
||||||
|
|
||||||
private String maskSourceIP;
|
public static Command generateCommand(TaskCommandInfo info, LocalDateTime validTime) {
|
||||||
private String maskSourcePort;
|
Command command = new Command();
|
||||||
private String maskDestinationIP;
|
|
||||||
private String maskDestinationPort;
|
|
||||||
private Integer direction;
|
|
||||||
|
|
||||||
private LocalDateTime datetime;
|
FiveTupleWithMask fiveTupleWithMask = info.getFiveTupleWithMask();
|
||||||
|
if (fiveTupleWithMask.getProtocol() != null)
|
||||||
|
fiveTupleWithMask.setProtocolNum(ProtocolEnum.valueOf(fiveTupleWithMask.getProtocol()).getProtocolNumber());
|
||||||
|
|
||||||
|
command.setFiveTupleWithMask(fiveTupleWithMask);
|
||||||
|
command.setTaskId(info.getTaskId());
|
||||||
|
command.setOperation(info.getOperation());
|
||||||
|
command.setValidTime(validTime);
|
||||||
|
command.setInvalidTime(info.getEndTime());
|
||||||
|
|
||||||
|
return command;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FiveTupleWithMask {
|
||||||
|
private Integer addrType;
|
||||||
|
private String sourceIP;
|
||||||
|
private String sourcePort;
|
||||||
|
private String destinationIP;
|
||||||
|
private String destinationPort;
|
||||||
|
private String protocol;
|
||||||
|
private Integer protocolNum;
|
||||||
|
|
||||||
|
private String maskSourceIP;
|
||||||
|
private String maskSourcePort;
|
||||||
|
private String maskDestinationIP;
|
||||||
|
private String maskDestinationPort;
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class Task {
|
public class Task {
|
||||||
@JsonProperty("task_id")
|
@JsonProperty("task_id")
|
||||||
private Integer taskId;
|
private Long taskId;
|
||||||
|
|
||||||
@JsonProperty("task_name")
|
@JsonProperty("task_name")
|
||||||
@NotNull(message = "task_name should not be empty. ")
|
@NotNull(message = "task_name should not be empty. ")
|
||||||
@@ -19,6 +19,7 @@ public class Task {
|
|||||||
|
|
||||||
@JsonProperty("task_start_time")
|
@JsonProperty("task_start_time")
|
||||||
@NotNull(message = "task_start_time should not be empty. ")
|
@NotNull(message = "task_start_time should not be empty. ")
|
||||||
|
@Future(message = "task_start_time should be a future time")
|
||||||
private LocalDateTime taskStartTime;
|
private LocalDateTime taskStartTime;
|
||||||
|
|
||||||
@JsonProperty("task_end_time")
|
@JsonProperty("task_end_time")
|
||||||
@@ -34,7 +35,7 @@ public class Task {
|
|||||||
|
|
||||||
@JsonProperty("task_type")
|
@JsonProperty("task_type")
|
||||||
@NotNull(message = "task_type should not be empty. ")
|
@NotNull(message = "task_type should not be empty. ")
|
||||||
private String taskType;
|
private Integer taskType;
|
||||||
|
|
||||||
@JsonProperty("task_act")
|
@JsonProperty("task_act")
|
||||||
@NotNull(message = "task_act should not be empty. ")
|
@NotNull(message = "task_act should not be empty. ")
|
||||||
@@ -47,13 +48,13 @@ public class Task {
|
|||||||
private String taskCreateDepart;
|
private String taskCreateDepart;
|
||||||
|
|
||||||
@JsonProperty("task_create_userid")
|
@JsonProperty("task_create_userid")
|
||||||
private Integer taskCreateUserId;
|
private Long taskCreateUserId;
|
||||||
|
|
||||||
@JsonProperty("static_rule_ids")
|
@JsonProperty("static_rule_ids")
|
||||||
private List<Integer> staticRuleIds;
|
private List<Long> staticRuleIds;
|
||||||
|
|
||||||
@JsonProperty("dynamic_rule_ids")
|
@JsonProperty("dynamic_rule_ids")
|
||||||
private List<Integer> dynamicRuleIds;
|
private List<Long> dynamicRuleIds;
|
||||||
|
|
||||||
@JsonProperty("task_status")
|
@JsonProperty("task_status")
|
||||||
private Integer taskStatus;
|
private Integer taskStatus;
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TaskCommandInfo {
|
||||||
|
private FiveTupleWithMask fiveTupleWithMask;
|
||||||
|
|
||||||
|
private Long taskId;
|
||||||
|
private Long ruleId;
|
||||||
|
|
||||||
|
// 额外字段
|
||||||
|
private String operation;
|
||||||
|
private Integer frequency;
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.realtime.protection.configuration.exception;
|
||||||
|
|
||||||
|
public class DorisStartException extends Exception {
|
||||||
|
public Long taskId;
|
||||||
|
|
||||||
|
public DorisStartException(Exception e, Long taskId) {
|
||||||
|
super(e.getMessage(), e.getCause());
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DorisStartException(Exception e) {
|
||||||
|
super(e.getMessage(), e.getCause());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DorisStartException(String message, Long taskId) {
|
||||||
|
super(message);
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.realtime.protection.configuration.exception;
|
|||||||
import cn.dev33.satoken.exception.NotLoginException;
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.dev33.satoken.exception.SaTokenException;
|
import cn.dev33.satoken.exception.SaTokenException;
|
||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.server.task.status.StateChangeService;
|
||||||
import org.apache.ibatis.exceptions.PersistenceException;
|
import org.apache.ibatis.exceptions.PersistenceException;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
@@ -16,20 +18,18 @@ import java.util.stream.Collectors;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
private final StateChangeService stateChangeService;
|
||||||
|
|
||||||
|
public GlobalExceptionHandler(StateChangeService stateChangeService) {
|
||||||
|
this.stateChangeService = stateChangeService;
|
||||||
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
public ResponseResult handleGlobalException(Exception e) {
|
public ResponseResult handleGlobalException(Exception e) {
|
||||||
return ResponseResult.error().setMessage(e.getMessage());
|
return ResponseResult.error().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
|
||||||
@ExceptionHandler(value = NotLoginException.class)
|
|
||||||
public ResponseResult handleNotLoginException(NotLoginException e) {
|
|
||||||
return new ResponseResult(
|
|
||||||
401,
|
|
||||||
e.getMessage()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = PersistenceException.class)
|
@ExceptionHandler(value = PersistenceException.class)
|
||||||
@@ -48,14 +48,42 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = {HandlerMethodValidationException.class, IllegalArgumentException.class})
|
@ExceptionHandler(value = {
|
||||||
public ResponseResult handleHandlerMethodValidationException(HandlerMethodValidationException e) {
|
HandlerMethodValidationException.class,
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
IllegalStateException.class
|
||||||
|
})
|
||||||
|
public ResponseResult handleHandlerMethodValidationException(Exception e) {
|
||||||
return ResponseResult.invalid().setMessage(e.getMessage());
|
return ResponseResult.invalid().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@ExceptionHandler(value = NotLoginException.class)
|
||||||
|
public ResponseResult handleNotLoginException(NotLoginException e) {
|
||||||
|
return new ResponseResult(
|
||||||
|
401,
|
||||||
|
e.getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = SaTokenException.class)
|
@ExceptionHandler(value = SaTokenException.class)
|
||||||
public ResponseResult handleSaTokenException(SaTokenException e) {
|
public ResponseResult handleSaTokenException(SaTokenException e) {
|
||||||
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@ExceptionHandler(value = DorisStartException.class)
|
||||||
|
public ResponseResult handleDorisStartException(DorisStartException e) {
|
||||||
|
ResponseResult responseResult = ResponseResult.error()
|
||||||
|
.setMessage("Doris command creation meets error: " + e.getMessage());
|
||||||
|
|
||||||
|
try {
|
||||||
|
stateChangeService.changeState(StateEnum.FAILED.getStateNum(), e.taskId);
|
||||||
|
} catch (Exception another) {
|
||||||
|
responseResult.setAnother(ResponseResult.error().setMessage(e.getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class ResponseResult implements Serializable {
|
|||||||
private int code;
|
private int code;
|
||||||
private String message;
|
private String message;
|
||||||
private Map<String, Object> data;
|
private Map<String, Object> data;
|
||||||
|
private ResponseResult another;
|
||||||
|
|
||||||
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
|
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.realtime.protection.configuration.satoken;
|
||||||
|
|
||||||
|
public interface Nameable {
|
||||||
|
String name();
|
||||||
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.realtime.protection.configuration.satoken;
|
package com.realtime.protection.configuration.satoken;
|
||||||
|
|
||||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.realtime.protection.configuration.satoken.permission.Permission;
|
import com.realtime.protection.configuration.satoken.permission.Permission;
|
||||||
import com.realtime.protection.configuration.satoken.permission.SystemConfiguration;
|
import com.realtime.protection.configuration.satoken.role.Role;
|
||||||
import com.realtime.protection.configuration.satoken.permission.WhiteList;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
@@ -15,13 +13,15 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new SaInterceptor(handler -> {
|
registry.addInterceptor(new SaInterceptor(handler -> {
|
||||||
SaRouter.match("/whiteobj/new", r ->
|
// SaRouter.match("/**")
|
||||||
this.checkPermissions(SystemConfiguration.NEW, WhiteList.NEW));
|
// .notMatch("/user/doLogin")
|
||||||
SaRouter.match("/whiteobj/update", r ->
|
// .check(r -> StpUtil.checkLogin());
|
||||||
this.checkPermissions(SystemConfiguration.UPDATE, WhiteList.UPDATE));
|
|
||||||
}))
|
// SaRouter.match("/whiteobj/new", r ->
|
||||||
.addPathPatterns("/**")
|
// this.checkPermissions(WhiteList.NEW));
|
||||||
.excludePathPatterns("/user/doLogin");
|
// SaRouter.match("/whiteobj/{id}/update", r ->
|
||||||
|
// this.checkPermissions(WhiteList.UPDATE));
|
||||||
|
})).addPathPatterns("/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkPermissions(Permission... permissions) {
|
void checkPermissions(Permission... permissions) {
|
||||||
@@ -30,5 +30,10 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkRole(Role... roles) {
|
||||||
|
for (Role role : roles) {
|
||||||
|
StpUtil.checkRole(role.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.realtime.protection.configuration.satoken.permission;
|
|
||||||
|
|
||||||
public interface Nameable {
|
|
||||||
String name();
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.realtime.protection.configuration.satoken.permission;
|
package com.realtime.protection.configuration.satoken.permission;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.satoken.Nameable;
|
||||||
|
|
||||||
public interface Permission extends Nameable {
|
public interface Permission extends Nameable {
|
||||||
default String getName() {
|
default String getName() {
|
||||||
return this.getClass().getSimpleName() + ":" + this.name();
|
return this.getClass().getSimpleName() + ":" + this.name();
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.realtime.protection.configuration.satoken.role;
|
||||||
|
|
||||||
|
public enum Admin implements Role {
|
||||||
|
ADMIN
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.realtime.protection.configuration.satoken.role;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.satoken.Nameable;
|
||||||
|
|
||||||
|
public interface Role extends Nameable {
|
||||||
|
default String getName() {
|
||||||
|
return this.getClass().getSimpleName() + ":" + this.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.realtime.protection.configuration.utils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EntityUtils {
|
||||||
|
public static Map<String, Object> entityToMap(Object object) throws IllegalAccessException {
|
||||||
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
for (Field field : object.getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object o = field.get(object);
|
||||||
|
resultMap.put(field.getName(), o);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,9 @@ public class SqlSessionWrapper {
|
|||||||
this.sqlSessionFactory = sqlSessionFactory;
|
this.sqlSessionFactory = sqlSessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 启动批量SQL会话
|
/**
|
||||||
|
* 启动批量SQL会话
|
||||||
|
*
|
||||||
* @param mapperClass MyBatis Mapper类型
|
* @param mapperClass MyBatis Mapper类型
|
||||||
* @param batchFunction 批量函数(批量添加、批量删除、批量更新等)
|
* @param batchFunction 批量函数(批量添加、批量删除、批量更新等)
|
||||||
* @param arguments 函数附带的所有参数,可以使用Map进行包装
|
* @param arguments 函数附带的所有参数,可以使用Map进行包装
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.enums;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum ProtocolEnum {
|
||||||
|
TCP(6),
|
||||||
|
UDP(17);
|
||||||
|
|
||||||
|
private final Integer number;
|
||||||
|
private static final Map<Integer, ProtocolEnum> map = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (ProtocolEnum protocol : ProtocolEnum.values()) {
|
||||||
|
map.put(protocol.getProtocolNumber(), protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolEnum(int protocolNumber) {
|
||||||
|
this.number = protocolNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getProtocolNumber() {
|
||||||
|
return this.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProtocolEnum getProtocolEnumByNumber(Integer protocolNum) {
|
||||||
|
return map.get(protocolNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.enums;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.task.status.states.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum StateEnum {
|
||||||
|
// 仅需修改此处即可将任务状态以及对应的State和Num进行对应
|
||||||
|
PENDING(0, new PendingState()),
|
||||||
|
RUNNING(1, new RunningState()),
|
||||||
|
PAUSED(2, new PauseState()),
|
||||||
|
STOP(3, new StopState()),
|
||||||
|
FINISHED(4, new FinishedState()),
|
||||||
|
FAILED(5, new FailedState());
|
||||||
|
// ----------------------------------------------
|
||||||
|
|
||||||
|
private final State state;
|
||||||
|
private final Integer stateNum;
|
||||||
|
private static final Map<Integer, State> numToStateMap = new HashMap<>();
|
||||||
|
private static final Map<State, Integer> stateToNumMap = new HashMap<>();
|
||||||
|
private static final Map<State, StateEnum> stateToStateEnumMap = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (StateEnum stateEnum : StateEnum.values()) {
|
||||||
|
numToStateMap.put(stateEnum.getStateNum(), stateEnum.getState());
|
||||||
|
stateToNumMap.put(stateEnum.getState(), stateEnum.getStateNum());
|
||||||
|
stateToStateEnumMap.put(stateEnum.getState(), stateEnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StateEnum(int stateNum, State state) {
|
||||||
|
this.stateNum = stateNum;
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static State getStateByNum(Integer stateNum) {
|
||||||
|
return numToStateMap.get(stateNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getNumByState(State state) {
|
||||||
|
return stateToNumMap.get(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StateEnum getStateEnumByState(State state) {
|
||||||
|
return stateToStateEnumMap.get(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum TaskTypeEnum {
|
||||||
|
STATIC(1),
|
||||||
|
DYNAMIC(2),
|
||||||
|
JUDGED(3);
|
||||||
|
|
||||||
|
private final int taskType;
|
||||||
|
private static final Map<Integer, TaskTypeEnum> map = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (TaskTypeEnum taskType : TaskTypeEnum.values()) {
|
||||||
|
map.put(taskType.getTaskType(), taskType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskTypeEnum(int taskType) {
|
||||||
|
this.taskType = taskType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TaskTypeEnum getTaskTypeByNum(Integer taskType) {
|
||||||
|
if (taskType == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return map.get(taskType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.status;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum AuditStatus {
|
||||||
|
PENDING(0),
|
||||||
|
UNAUDITED(1),
|
||||||
|
AUDITED(2);
|
||||||
|
|
||||||
|
private final int auditStatus;
|
||||||
|
|
||||||
|
AuditStatus(int auditStatus) {
|
||||||
|
this.auditStatus = auditStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,9 +14,15 @@ public class AuditStatusValidator {
|
|||||||
|
|
||||||
public Boolean checkValidate(Integer auditStatusNow) {
|
public Boolean checkValidate(Integer auditStatusNow) {
|
||||||
switch (auditStatusNow) {
|
switch (auditStatusNow) {
|
||||||
case 0, 1 -> {return auditStatusOriginal != 2;}
|
case 0, 1 -> {
|
||||||
case 2 -> {return auditStatusOriginal != 1;}
|
return auditStatusOriginal != 2;
|
||||||
default -> {return false;}
|
}
|
||||||
|
case 2 -> {
|
||||||
|
return auditStatusOriginal != 1;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.status;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
|
||||||
|
public interface State {
|
||||||
|
Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.realtime.protection.configuration.utils.status;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum StateNum {
|
||||||
|
PENDING(0),
|
||||||
|
RUNNING(1),
|
||||||
|
PAUSED(2),
|
||||||
|
STOPPED(3),
|
||||||
|
FAILED(4),
|
||||||
|
FINISHED(5);
|
||||||
|
|
||||||
|
private final int stateNum;
|
||||||
|
|
||||||
|
StateNum(int stateNum) {
|
||||||
|
this.stateNum = stateNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.realtime.protection.server.command;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.realtime.protection.configuration.entity.task.Command;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@DS("doris")
|
||||||
|
@Mapper
|
||||||
|
public interface CommandMapper {
|
||||||
|
Boolean createCommand(@Param("command") Command command);
|
||||||
|
|
||||||
|
void createCommands(@Param("commands") List<Command> commands);
|
||||||
|
|
||||||
|
Boolean stopCommandsByTaskId(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
|
Boolean removeCommandsByTaskId(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
|
Boolean startCommandsByTaskId(@Param("task_id") Long taskId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package com.realtime.protection.server.command;
|
||||||
|
|
||||||
|
import com.alibaba.excel.util.ListUtils;
|
||||||
|
import com.realtime.protection.configuration.entity.task.Command;
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class CommandService {
|
||||||
|
|
||||||
|
private final CommandMapper commandMapper;
|
||||||
|
private final SqlSessionWrapper sqlSessionWrapper;
|
||||||
|
private static final int BatchSize = 1000;
|
||||||
|
private final Function<CommandMapper, Function<TaskCommandInfo, Void>> createCommandBatchFunction;
|
||||||
|
|
||||||
|
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper) {
|
||||||
|
this.commandMapper = commandMapper;
|
||||||
|
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||||
|
this.createCommandBatchFunction = mapper -> info -> {
|
||||||
|
if (info.getFrequency() == null) {
|
||||||
|
Command command = Command.generateCommand(info, info.getStartTime());
|
||||||
|
commandMapper.createCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Command> commandBatch = ListUtils.newArrayListWithExpectedSize(BatchSize);
|
||||||
|
LocalDateTime validTime = info.getStartTime();
|
||||||
|
|
||||||
|
while (validTime.isBefore(info.getEndTime())) {
|
||||||
|
Command command = Command.generateCommand(info, validTime);
|
||||||
|
commandBatch.add(command);
|
||||||
|
|
||||||
|
validTime = validTime.plusMinutes(info.getFrequency());
|
||||||
|
|
||||||
|
if (commandBatch.size() < BatchSize) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
commandMapper.createCommands(commandBatch);
|
||||||
|
commandBatch.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!commandBatch.isEmpty()) {
|
||||||
|
commandMapper.createCommands(commandBatch);
|
||||||
|
commandBatch.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug(String.format("create all the commands from task(%d), rule(%d)",
|
||||||
|
info.getTaskId(), info.getRuleId()));
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void createCommand(TaskCommandInfo commandInfo) throws DorisStartException {
|
||||||
|
try {
|
||||||
|
sqlSessionWrapper.startBatchSession(CommandMapper.class, createCommandBatchFunction, commandInfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DorisStartException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void createCommands(List<TaskCommandInfo> taskCommandInfos) throws DorisStartException {
|
||||||
|
Function<CommandMapper, Function<List<TaskCommandInfo>, Void>> function = mapper -> list -> {
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TaskCommandInfo info : list) {
|
||||||
|
createCommandBatchFunction.apply(mapper).apply(info);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
sqlSessionWrapper.startBatchSession(CommandMapper.class, function, taskCommandInfos);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DorisStartException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean startCommandsByTaskId(Long taskId) {
|
||||||
|
return commandMapper.startCommandsByTaskId(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean stopCommandsByTaskId(Long taskId) {
|
||||||
|
return commandMapper.stopCommandsByTaskId(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean removeCommandsByTaskId(Long taskId) {
|
||||||
|
return commandMapper.removeCommandsByTaskId(taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.realtime.protection.server.defense.object;
|
|||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
|
import com.realtime.protection.configuration.utils.EntityUtils;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
@@ -76,21 +77,15 @@ public class ProtectObjectController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/query")
|
@GetMapping("/{protectObjectId}/query")
|
||||||
public ResponseResult queryProtectObject(@PathVariable("id") Integer protectObjectId) {
|
public ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException {
|
||||||
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("proobj_id", protectObject.getProtectObjectId())
|
.setDataMap(EntityUtils.entityToMap(protectObject));
|
||||||
.setData("proobj_name", protectObject.getProtectObjectName())
|
|
||||||
.setData("proobj_system_name", protectObject.getProtectObjectSystemName())
|
|
||||||
.setData("proobj_ip_address", protectObject.getProtectObjectIPAddress())
|
|
||||||
.setData("proobj_port", protectObject.getProtectObjectPort())
|
|
||||||
.setData("proobj_url", protectObject.getProtectObjectURL())
|
|
||||||
.setData("proobj_protocol", protectObject.getProtectObjectProtocol());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/update")
|
@PostMapping("/{protectObjectId}/update")
|
||||||
public ResponseResult updateProtectObject(@PathVariable("id") Integer protectObjectId,
|
public ResponseResult updateProtectObject(@PathVariable Integer protectObjectId,
|
||||||
@RequestBody @Valid ProtectObject protectObject) {
|
@RequestBody @Valid ProtectObject protectObject) {
|
||||||
protectObject.setProtectObjectId(protectObjectId);
|
protectObject.setProtectObjectId(protectObjectId);
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
@@ -98,8 +93,8 @@ public class ProtectObjectController {
|
|||||||
.setData("success", protectObjectService.updateProtectObject(protectObject));
|
.setData("success", protectObjectService.updateProtectObject(protectObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}/delete")
|
@DeleteMapping("/{protectObjectId}/delete")
|
||||||
public ResponseResult deleteProtectObject(@PathVariable("id") Integer protectObjectId) {
|
public ResponseResult deleteProtectObject(@PathVariable Integer protectObjectId) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("proobj_id", protectObjectId)
|
.setData("proobj_id", protectObjectId)
|
||||||
.setData("success", protectObjectService.deleteProtectObject(protectObjectId));
|
.setData("success", protectObjectService.deleteProtectObject(protectObjectId));
|
||||||
@@ -112,9 +107,9 @@ public class ProtectObjectController {
|
|||||||
.setData("success", protectObjectService.deleteProtectObjects(protectObjectIds));
|
.setData("success", protectObjectService.deleteProtectObjects(protectObjectIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/audit/{status}")
|
@PostMapping("/{protectObjectId}/audit/{auditStatus}")
|
||||||
public ResponseResult changeProtectObjectAuditStatus(@PathVariable("id") Integer protectObjectId,
|
public ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
|
||||||
@PathVariable("status") Integer auditStatus) {
|
@PathVariable Integer auditStatus) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setDataMap(protectObjectService.changeProtectObjectAuditStatus(protectObjectId, auditStatus))
|
.setDataMap(protectObjectService.changeProtectObjectAuditStatus(protectObjectId, auditStatus))
|
||||||
.setData("proobj_id", protectObjectId);
|
.setData("proobj_id", protectObjectId);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package com.realtime.protection.server.defense.object;
|
|||||||
|
|
||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class ProtectObjectService {
|
|||||||
protectObjectBatch.clear();
|
protectObjectBatch.clear();
|
||||||
}
|
}
|
||||||
if (!protectObjectBatch.isEmpty()) {
|
if (!protectObjectBatch.isEmpty()) {
|
||||||
mapper.deleteProtectObjects(protectObjectBatch);;
|
mapper.deleteProtectObjects(protectObjectBatch);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.realtime.protection.server.defense.template;
|
|||||||
|
|
||||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
|
import com.realtime.protection.configuration.utils.EntityUtils;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -51,8 +52,14 @@ public class TemplateController {
|
|||||||
.setData("templates", templates);
|
.setData("templates", templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/update")
|
@GetMapping("/{templateId}/query")
|
||||||
public ResponseResult updateTemplate(@PathVariable("id") @Min(1) Integer templateId,
|
public ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException {
|
||||||
|
return ResponseResult.ok()
|
||||||
|
.setDataMap(EntityUtils.entityToMap(templateService.queryTemplate(templateId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{templateId}/update")
|
||||||
|
public ResponseResult updateTemplate(@PathVariable @Min(1) Integer templateId,
|
||||||
@RequestBody @Valid Template template) {
|
@RequestBody @Valid Template template) {
|
||||||
Boolean success = templateService.updateTemplate(templateId, template);
|
Boolean success = templateService.updateTemplate(templateId, template);
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
@@ -60,14 +67,10 @@ public class TemplateController {
|
|||||||
.setData("success", success);
|
.setData("success", success);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/addUsedTimes")
|
@DeleteMapping("/{templateId}/delete")
|
||||||
public ResponseResult addTemplateUsedTimes(@PathVariable("id") @Min(1) Integer templateId,
|
public ResponseResult deleteTemplate(@PathVariable @Min(1) Integer templateId) {
|
||||||
@RequestParam(value = "add_num") @Min(0) Integer addNum) {
|
|
||||||
Boolean success = templateService.addTemplateUsedTimes(templateId, addNum);
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("template_id", templateId)
|
.setData("template_id", templateId)
|
||||||
.setData("success", success);
|
.setData("success", templateService.deleteTemplate(templateId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public interface TemplateMapper {
|
|||||||
|
|
||||||
Boolean updateTemplateInformation(@Param("template") Template template);
|
Boolean updateTemplateInformation(@Param("template") Template template);
|
||||||
|
|
||||||
void countTemplateRunningTasks(@Param("template_id") Integer templateId);
|
Template queryTemplate(@Param("template_id") Integer templateId);
|
||||||
|
|
||||||
Boolean addTemplateUsedTimes(@Param("template_id") Integer templateId, @Param("add_times") Integer addTimes);
|
Boolean deleteTemplate(@Param("template_id") Integer templateId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.realtime.protection.configuration.entity.defense.template.Template;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.beans.Transient;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -41,8 +39,11 @@ public class TemplateService {
|
|||||||
return templateMapper.updateTemplateInformation(template);
|
return templateMapper.updateTemplateInformation(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean addTemplateUsedTimes(Integer templateId, Integer addTimes) {
|
public Template queryTemplate(Integer templateId) {
|
||||||
return templateMapper.addTemplateUsedTimes(templateId, addTimes);
|
return templateMapper.queryTemplate(templateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean deleteTemplate(Integer templateId) {
|
||||||
|
return templateMapper.deleteTemplate(templateId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,9 @@ public class DynamicRuleController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//id删除
|
//id删除
|
||||||
@RequestMapping("/{dynamicRuleId}/delete")
|
@RequestMapping("/{dynamicRuleId}/delete")
|
||||||
public ResponseResult deleteDynamicRuleObject(@PathVariable Integer dynamicRuleId ) {
|
public ResponseResult deleteDynamicRuleObject(@PathVariable Integer dynamicRuleId) {
|
||||||
log.info("删除动态规则: {}", dynamicRuleId);
|
log.info("删除动态规则: {}", dynamicRuleId);
|
||||||
//调用service删除
|
//调用service删除
|
||||||
dynamicRuleService.deleteDynamicRuleObject(dynamicRuleId);
|
dynamicRuleService.deleteDynamicRuleObject(dynamicRuleId);
|
||||||
@@ -62,7 +60,7 @@ public class DynamicRuleController {
|
|||||||
//调用service删除
|
//调用service删除
|
||||||
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("success",dynamicRuleService.deleteDynamicRuleObjects(dynamicRuleIds));
|
.setData("success", dynamicRuleService.deleteDynamicRuleObjects(dynamicRuleIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
//修改
|
//修改
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.alibaba.excel.context.AnalysisContext;
|
|||||||
import com.alibaba.excel.read.listener.ReadListener;
|
import com.alibaba.excel.read.listener.ReadListener;
|
||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ public interface DynamicRuleMapper {
|
|||||||
//新建动态规则与保护对象关联
|
//新建动态规则与保护对象关联
|
||||||
void newDynamicRulProtectObjectConcat(long dynamicRuleId, Integer protectObjectId);
|
void newDynamicRulProtectObjectConcat(long dynamicRuleId, Integer protectObjectId);
|
||||||
|
|
||||||
void deleteDynamicRuleObject( Integer dynamicRuleId);
|
void deleteDynamicRuleObject(Integer dynamicRuleId);
|
||||||
|
|
||||||
DynamicRuleObject queryDynamicRuleById(Integer dynamicRuleId);
|
DynamicRuleObject queryDynamicRuleById(Integer dynamicRuleId);
|
||||||
|
|
||||||
List<ProtectObject> queryProtectObjectByRuleId(Integer dynamicRuleId);
|
List<ProtectObject> queryProtectObjectByRuleId(Integer dynamicRuleId);
|
||||||
|
|
||||||
void updateDynamicRuleObject(@Param("dynamicRuleId") Integer dynamicRuleId,@Param("object") DynamicRuleObject dynamicRuleObject);
|
void updateDynamicRuleObject(@Param("dynamicRuleId") Integer dynamicRuleId, @Param("object") DynamicRuleObject dynamicRuleObject);
|
||||||
|
|
||||||
void newDynamicRules(List<DynamicRuleObject> dynamicRuleObjects);
|
void newDynamicRules(List<DynamicRuleObject> dynamicRuleObjects);
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleOb
|
|||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
public class StaticRuleController {
|
public class StaticRuleController {
|
||||||
|
|
||||||
private final StaticRuleService staticRuleService;
|
private final StaticRuleService staticRuleService;
|
||||||
|
|
||||||
public StaticRuleController(StaticRuleService staticRuleService) {
|
public StaticRuleController(StaticRuleService staticRuleService) {
|
||||||
this.staticRuleService = staticRuleService;
|
this.staticRuleService = staticRuleService;
|
||||||
}
|
}
|
||||||
@@ -30,11 +31,11 @@ public class StaticRuleController {
|
|||||||
* 新增静态规则
|
* 新增静态规则
|
||||||
*/
|
*/
|
||||||
@PostMapping("/new")
|
@PostMapping("/new")
|
||||||
public ResponseResult newStaticRuleObject(@RequestBody @Valid StaticRuleObject object){
|
public ResponseResult newStaticRuleObject(@RequestBody @Valid StaticRuleObject object) {
|
||||||
log.info("新增静态规则: {}" , object);
|
log.info("新增静态规则: {}", object);
|
||||||
//调用service新增
|
//调用service新增
|
||||||
staticRuleService.newStaticRuleObject(object);
|
staticRuleService.newStaticRuleObject(object);
|
||||||
return ResponseResult.ok().setData("static_rule_name",object.getStaticRuleName());
|
return ResponseResult.ok().setData("static_rule_name", object.getStaticRuleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//以Excel方式批量导入静态规则
|
//以Excel方式批量导入静态规则
|
||||||
@@ -44,6 +45,7 @@ public class StaticRuleController {
|
|||||||
new StaticRuleDataListener(staticRuleService)).sheet().doRead();
|
new StaticRuleDataListener(staticRuleService)).sheet().doRead();
|
||||||
return ResponseResult.ok();
|
return ResponseResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//下载模板文件
|
//下载模板文件
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||||||
@@ -62,20 +64,20 @@ public class StaticRuleController {
|
|||||||
* 删除静态规则(有的删了,有的没删,也返回false)
|
* 删除静态规则(有的删了,有的没删,也返回false)
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public ResponseResult delete(@PathVariable List<Integer> ids){
|
public ResponseResult delete(@PathVariable List<Integer> ids) {
|
||||||
log.info("根据id删除静态规则:{}",ids);
|
log.info("根据id删除静态规则:{}", ids);
|
||||||
//
|
//
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("static_rule_id",ids)
|
.setData("static_rule_id", ids)
|
||||||
.setData("success",staticRuleService.deleteStaticRules(ids));
|
.setData("success", staticRuleService.deleteStaticRules(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改静态规则
|
* 修改静态规则
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
public ResponseResult updateStaticRule(@RequestBody @Valid StaticRuleObject object){
|
public ResponseResult updateStaticRule(@RequestBody @Valid StaticRuleObject object) {
|
||||||
log.info("修改静态规则: {}" , object);
|
log.info("修改静态规则: {}", object);
|
||||||
//调用service修改
|
//调用service修改
|
||||||
staticRuleService.updateStaticRule(object);
|
staticRuleService.updateStaticRule(object);
|
||||||
return ResponseResult.ok();
|
return ResponseResult.ok();
|
||||||
@@ -86,10 +88,10 @@ public class StaticRuleController {
|
|||||||
* 路径参数:通过请求URL直接传递参数,使用{…}来标识该路径参数,需要使用 @PathVariable 获取路径参数
|
* 路径参数:通过请求URL直接传递参数,使用{…}来标识该路径参数,需要使用 @PathVariable 获取路径参数
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/{id}/query")
|
@RequestMapping("/{id}/query")
|
||||||
public ResponseResult queryStaticRuleById(@PathVariable Integer id){
|
public ResponseResult queryStaticRuleById(@PathVariable Integer id) {
|
||||||
log.info("根据id查询静态规则:{}",id);
|
log.info("根据id查询静态规则:{}", id);
|
||||||
StaticRuleObject object = staticRuleService.queryStaticRuleById(id);
|
StaticRuleObject object = staticRuleService.queryStaticRuleById(id);
|
||||||
return ResponseResult.ok().setData("static_rule",object);
|
return ResponseResult.ok().setData("static_rule", object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,10 +101,10 @@ public class StaticRuleController {
|
|||||||
public ResponseResult queryStaticRule(String static_rule_name, Integer static_rule_id,
|
public ResponseResult queryStaticRule(String static_rule_name, Integer static_rule_id,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize
|
@RequestParam(defaultValue = "10") Integer pageSize
|
||||||
){
|
) {
|
||||||
log.info("多查询静态规则: {},{},{},{}", static_rule_name,static_rule_id,page,pageSize);
|
log.info("多查询静态规则: {},{},{},{}", static_rule_name, static_rule_id, page, pageSize);
|
||||||
//调用service新增
|
//调用service新增
|
||||||
List<StaticRuleObject> pageResult = staticRuleService.queryStaticRule(static_rule_name,static_rule_id,page,pageSize);
|
List<StaticRuleObject> pageResult = staticRuleService.queryStaticRule(static_rule_name, static_rule_id, page, pageSize);
|
||||||
return ResponseResult.ok().setData("static_rule_list",pageResult);
|
return ResponseResult.ok().setData("static_rule_list", pageResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.alibaba.excel.util.ListUtils;
|
|||||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ public interface StaticRuleMapper {
|
|||||||
Boolean deleteStaticRuleById(Integer id);
|
Boolean deleteStaticRuleById(Integer id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//修改静态规则
|
//修改静态规则
|
||||||
void updateStaticRule(StaticRuleObject object);
|
void updateStaticRule(StaticRuleObject object);
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package com.realtime.protection.server.rule.staticrule;
|
|||||||
|
|
||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -88,7 +87,7 @@ public class StaticRuleService {
|
|||||||
*/
|
*/
|
||||||
public List<StaticRuleObject> queryStaticRule(String static_rule_name, Integer static_rule_id, Integer page, Integer pageSize) {
|
public List<StaticRuleObject> queryStaticRule(String static_rule_name, Integer static_rule_id, Integer page, Integer pageSize) {
|
||||||
|
|
||||||
return staticRuleMapper.queryStaticRule(static_rule_name,static_rule_id,page,pageSize);
|
return staticRuleMapper.queryStaticRule(static_rule_name, static_rule_id, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean newStaticRuleObjects(List<StaticRuleObject> staticRuleList) {
|
public Boolean newStaticRuleObjects(List<StaticRuleObject> staticRuleList) {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.realtime.protection.server.task;
|
|
||||||
|
|
||||||
import com.realtime.protection.server.task.state.State;
|
|
||||||
|
|
||||||
public class StatusChanger {
|
|
||||||
|
|
||||||
private final State state;
|
|
||||||
|
|
||||||
public StatusChanger(State state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StatusChanger setOriginal(State original) {
|
|
||||||
return new StatusChanger(original);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean changeState(State newState) {
|
|
||||||
return this.state.handle(newState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
package com.realtime.protection.server.task;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
|
import com.realtime.protection.configuration.utils.EntityUtils;
|
||||||
|
import com.realtime.protection.server.task.status.StateChangeService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,14 +18,16 @@ import java.util.List;
|
|||||||
public class TaskController {
|
public class TaskController {
|
||||||
|
|
||||||
private final TaskService taskService;
|
private final TaskService taskService;
|
||||||
|
private final StateChangeService stateChangeService;
|
||||||
|
|
||||||
public TaskController(TaskService taskService) {
|
public TaskController(TaskService taskService, StateChangeService stateChangeService) {
|
||||||
this.taskService = taskService;
|
this.taskService = taskService;
|
||||||
|
this.stateChangeService = stateChangeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/new")
|
@PostMapping("/new")
|
||||||
public ResponseResult newTask(@RequestBody @Valid Task task) {
|
public ResponseResult newTask(@RequestBody @Valid Task task) {
|
||||||
Integer taskId = taskService.newTask(task);
|
Long taskId = taskService.newTask(task);
|
||||||
|
|
||||||
if (taskId > 0) {
|
if (taskId > 0) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
@@ -48,7 +55,7 @@ public class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/query")
|
@GetMapping("/{id}/query")
|
||||||
public ResponseResult queryTask(@PathVariable("id") @Min(1) Integer id) {
|
public ResponseResult queryTask(@PathVariable @Min(1) Long id) throws IllegalAccessException {
|
||||||
Task task = taskService.queryTask(id);
|
Task task = taskService.queryTask(id);
|
||||||
|
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
@@ -56,44 +63,39 @@ public class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", task.getTaskId())
|
.setDataMap(EntityUtils.entityToMap(task));
|
||||||
.setData("task_name", task.getTaskName())
|
|
||||||
.setData("task_type", task.getTaskType())
|
|
||||||
.setData("task_status", task.getTaskStatus())
|
|
||||||
.setData("task_creator", task.getTaskCreateUsername())
|
|
||||||
.setData("task_creator_depart", task.getTaskCreateDepart())
|
|
||||||
.setData("task_start_time", task.getTaskStartTime())
|
|
||||||
.setData("task_end_time", task.getTaskEndTime())
|
|
||||||
.setData("task_static_rule_ids", task.getStaticRuleIds())
|
|
||||||
.setData("task_dynamic_rule_ids", task.getDynamicRuleIds());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/update")
|
@PostMapping("/update")
|
||||||
public ResponseResult updateTask(@PathVariable("id") @Min(1) Integer taskId, @RequestBody @Valid Task task) {
|
public ResponseResult updateTask(@RequestBody @Valid Task task) {
|
||||||
task.setTaskId(taskId);
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", task.getTaskId())
|
||||||
.setData("success", taskService.updateTask(task));
|
.setData("success", taskService.updateTask(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{taskId}/audit/{auditStatus}")
|
@GetMapping("/{taskId}/audit/{auditStatus}")
|
||||||
public ResponseResult changeTaskAuditStatus(@PathVariable Integer auditStatus, @PathVariable Integer taskId) {
|
public ResponseResult changeTaskAuditStatus(@PathVariable @NotNull @Max(10) Integer auditStatus,
|
||||||
|
@PathVariable @NotNull @Min(1) Long taskId) {
|
||||||
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
.setData("success", taskService.changeTaskAuditStatus(taskId, auditStatus));
|
.setData("success", taskService.changeTaskAuditStatus(taskId, auditStatus))
|
||||||
|
.setData("audit_status", taskService.queryTaskAuditStatus(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/delete")
|
@GetMapping("/{taskId}/delete")
|
||||||
public ResponseResult deleteTask(@PathVariable("id") Integer taskId) {
|
public ResponseResult deleteTask(@PathVariable @NotNull @Min(1) Long taskId) {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
.setData("success", taskService.deleteTask(taskId));
|
.setData("success", taskService.deleteTask(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{taskId}/running/{state}")
|
@GetMapping("/{taskId}/running/{stateNum}")
|
||||||
public ResponseResult changeTaskStatus(@PathVariable Integer state, @PathVariable Integer taskId) {
|
public ResponseResult changeTaskStatus(@PathVariable @NotNull Integer stateNum,
|
||||||
|
@PathVariable @NotNull Long taskId) throws DorisStartException {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
.setData("success", taskService.changeTaskStatus(taskId, state));
|
.setData("success", stateChangeService.changeState(stateNum, taskId))
|
||||||
|
.setData("status_now", taskService.queryTaskStatus(taskId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.realtime.protection.server.task;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -10,25 +11,33 @@ import java.util.List;
|
|||||||
public interface TaskMapper {
|
public interface TaskMapper {
|
||||||
void newTask(@Param("task") Task task);
|
void newTask(@Param("task") Task task);
|
||||||
|
|
||||||
void newTaskStaticRuleConcat(@Param("task_id") Integer taskId,
|
void newTaskStaticRuleConcat(@Param("task_id") Long taskId,
|
||||||
@Param("rule_ids") List<Integer> staticRuleIds);
|
@Param("rule_ids") List<Long> staticRuleIds);
|
||||||
|
|
||||||
void newTaskDynamicRuleConcat(@Param("task_id") Integer taskId,
|
void newTaskDynamicRuleConcat(@Param("task_id") Long taskId,
|
||||||
@Param("rule_ids") List<Integer> dynamicRuleIds);
|
@Param("rule_ids") List<Long> dynamicRuleIds);
|
||||||
|
|
||||||
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") String task_type,
|
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") String task_type,
|
||||||
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
|
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
|
||||||
@Param("page") Integer page, @Param("page_size") Integer pageSize);
|
@Param("page") Integer page, @Param("page_size") Integer pageSize);
|
||||||
|
|
||||||
Task queryTask(@Param("task_id") Integer taskId);
|
Task queryTask(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
void updateTask(@Param("task") Task task);
|
void updateTask(@Param("task") Task task);
|
||||||
|
|
||||||
void clearTaskConnectedStaticRule(@Param("task_id") Integer taskId);
|
void clearTaskConnectedStaticRule(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
void clearTaskConnectedDynamicRule(@Param("task_id") Integer taskId);
|
void clearTaskConnectedDynamicRule(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
void changeTaskAuditStatus(@Param("task_id") Integer taskId, @Param("audit_status") Integer auditStatus);
|
void changeTaskAuditStatus(@Param("task_id") Long taskId, @Param("audit_status") Integer auditStatus);
|
||||||
|
|
||||||
Boolean deleteTask(@Param("task_id") Integer taskId);
|
Boolean deleteTask(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
|
Boolean changeTaskStatus(@Param("task_id") Long taskId, @Param("state") Integer stateNum);
|
||||||
|
|
||||||
|
List<TaskCommandInfo> getStaticCommands(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
|
Integer queryTaskAuditStatus(@Param("task_id") Long taskId);
|
||||||
|
|
||||||
|
Integer queryTaskStatus(@Param("task_id") Long taskId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package com.realtime.protection.server.task;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
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;
|
||||||
|
|
||||||
@@ -20,7 +17,7 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer newTask(Task task) {
|
public Long newTask(Task task) {
|
||||||
taskMapper.newTask(task);
|
taskMapper.newTask(task);
|
||||||
|
|
||||||
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
||||||
@@ -35,7 +32,7 @@ public class TaskService {
|
|||||||
return taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
return taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task queryTask(Integer id) {
|
public Task queryTask(Long id) {
|
||||||
return taskMapper.queryTask(id);
|
return taskMapper.queryTask(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,47 +43,46 @@ public class TaskService {
|
|||||||
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
||||||
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
||||||
|
|
||||||
|
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
|
||||||
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
||||||
|
|
||||||
|
if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty())
|
||||||
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Boolean changeTaskAuditStatus(Integer taskId, Integer taskAuditStatus) {
|
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
||||||
if (AuditStatusValidator.setOriginal(taskMapper.queryTask(taskId).getTaskAuditStatus()).checkValidate(taskAuditStatus))
|
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
||||||
|
if (originalAuditStatus == null) {
|
||||||
|
throw new IllegalArgumentException("cannot find audit status of task " + taskId + ", maybe task doesn't exist?");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
||||||
taskMapper.changeTaskAuditStatus(taskId, taskAuditStatus);
|
taskMapper.changeTaskAuditStatus(taskId, taskAuditStatus);
|
||||||
else return false;
|
else return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean deleteTask(Integer taskId) {
|
public Boolean deleteTask(Long taskId) {
|
||||||
return taskMapper.deleteTask(taskId);
|
return taskMapper.deleteTask(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
public Boolean changeTaskStatus(Long taskId, Integer stateNum) {
|
||||||
public Boolean changeTaskStatus(Integer taskId, Integer stateNum) {
|
return taskMapper.changeTaskStatus(taskId, 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) {
|
public List<TaskCommandInfo> getStaticCommandInfos(Long taskId) {
|
||||||
// 运行中
|
return taskMapper.getStaticCommands(taskId);
|
||||||
case 1 -> new RunningState();
|
}
|
||||||
// 暂停中
|
|
||||||
case 2 -> new PauseState();
|
|
||||||
// 停止中
|
|
||||||
case 3 -> new StopState();
|
|
||||||
default -> throw new IllegalArgumentException();
|
|
||||||
};
|
|
||||||
|
|
||||||
return StatusChanger.setOriginal(originalState).changeState(newState);
|
public Integer queryTaskAuditStatus(Long taskId) {
|
||||||
|
return taskMapper.queryTaskAuditStatus(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer queryTaskStatus(Long taskId) {
|
||||||
|
return taskMapper.queryTaskStatus(taskId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
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,28 +0,0 @@
|
|||||||
package com.realtime.protection.server.task.state;
|
|
||||||
|
|
||||||
public class RunningState implements State {
|
|
||||||
@Override
|
|
||||||
public Boolean handle(State newState) {
|
|
||||||
if (newState instanceof RunningState) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newState instanceof PauseState) {
|
|
||||||
return handlePause();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newState instanceof StopState) {
|
|
||||||
return handleStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Boolean handlePause() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Boolean handleStop() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.realtime.protection.server.task.state;
|
|
||||||
|
|
||||||
public interface State {
|
|
||||||
|
|
||||||
Boolean handle(State newState);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
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,17 +0,0 @@
|
|||||||
package com.realtime.protection.server.task.state;
|
|
||||||
|
|
||||||
public class StopState implements State {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean handle(State newState) {
|
|
||||||
if (newState instanceof RunningState) {
|
|
||||||
return handleRun();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean handleRun() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.realtime.protection.server.task.status;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class StateChangeService {
|
||||||
|
private final CommandService commandService;
|
||||||
|
private final TaskService taskService;
|
||||||
|
|
||||||
|
public StateChangeService(CommandService commandService, TaskService taskService) {
|
||||||
|
this.commandService = commandService;
|
||||||
|
this.taskService = taskService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DSTransactional
|
||||||
|
public Boolean changeState(Integer stateNum, Long taskId) throws DorisStartException {
|
||||||
|
Integer originalStateNum = taskService.queryTaskStatus(taskId);
|
||||||
|
if (originalStateNum == null) {
|
||||||
|
throw new IllegalArgumentException("cannot find status of task " + taskId + ", maybe task doesn't exist?");
|
||||||
|
}
|
||||||
|
|
||||||
|
State originalState = StateEnum.getStateByNum(originalStateNum);
|
||||||
|
|
||||||
|
State newState = StateEnum.getStateByNum(stateNum);
|
||||||
|
|
||||||
|
if (!originalState.handle(newState, commandService, taskService, taskId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug(String.format("successfully let task(%d) change state from %s to %s",
|
||||||
|
taskId,
|
||||||
|
originalState.getClass().getSimpleName(),
|
||||||
|
newState.getClass().getSimpleName()));
|
||||||
|
|
||||||
|
// 这里一定是handle成功的状态,我们再进行task status的修改,如果handle失败,要么返回false,要么抛出异常,不会进入此处
|
||||||
|
return taskService.changeTaskStatus(taskId, stateNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.realtime.protection.server.task.status;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.TaskTypeEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.AuditStatus;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class StateHandler {
|
||||||
|
|
||||||
|
protected Boolean handleStart(TaskService taskService, CommandService commandService, Long taskId) throws DorisStartException {
|
||||||
|
Task task = taskService.queryTask(taskId);
|
||||||
|
|
||||||
|
if (task == null) {
|
||||||
|
throw new IllegalArgumentException("invalid task id");
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer taskAuditStatus = task.getTaskAuditStatus();
|
||||||
|
|
||||||
|
if (taskAuditStatus == null) {
|
||||||
|
throw new IllegalArgumentException("invalid task id, because task_audit_status is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果审核状态不为已通过审核,则无效
|
||||||
|
if (taskAuditStatus != AuditStatus.AUDITED.getAuditStatus()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch (TaskTypeEnum.getTaskTypeByNum(task.getTaskType())) {
|
||||||
|
case STATIC -> handleStaticTaskStart(commandService, taskService, taskId);
|
||||||
|
case DYNAMIC -> handleDynamicTaskStart(commandService, taskService, taskId);
|
||||||
|
case JUDGED -> handleJudgedTaskStart(commandService, taskService, taskId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean handleResume(CommandService commandService, Long taskId) {
|
||||||
|
commandService.startCommandsByTaskId(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean handlePause(CommandService commandService, Long taskId) {
|
||||||
|
commandService.stopCommandsByTaskId(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean handleStop(CommandService commandService, Long taskId) {
|
||||||
|
commandService.removeCommandsByTaskId(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean handleFinish(CommandService commandService, Long taskId) {
|
||||||
|
commandService.removeCommandsByTaskId(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean handleFailed(CommandService commandService, Long taskId) {
|
||||||
|
commandService.removeCommandsByTaskId(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean handleJudgedTaskStart(CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean handleDynamicTaskStart(CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||||
|
// 如果未能获取staticTaskCommandInfos,需要报错
|
||||||
|
List<TaskCommandInfo> staticTaskCommandInfos = taskService.getStaticCommandInfos(taskId);
|
||||||
|
if (staticTaskCommandInfos == null || staticTaskCommandInfos.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("static rules are empty, need to choose at least one static rule");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
commandService.createCommands(staticTaskCommandInfos);
|
||||||
|
} catch (DorisStartException e) {
|
||||||
|
e.taskId = taskId;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import com.realtime.protection.server.task.status.StateHandler;
|
||||||
|
|
||||||
|
public class FailedState extends StateHandler implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||||
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
|
case RUNNING -> handleStart(taskService, commandService, taskId);
|
||||||
|
case STOP -> handleStop(commandService, taskId);
|
||||||
|
case FAILED -> true;
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
|
||||||
|
public class FinishedState implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
|
return newState instanceof FinishedState;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import com.realtime.protection.server.task.status.StateHandler;
|
||||||
|
|
||||||
|
public class PauseState extends StateHandler implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
|
case RUNNING -> handleResume(commandService, taskId);
|
||||||
|
case STOP -> handleStop(commandService, taskId);
|
||||||
|
case FINISHED -> handleFinish(commandService, taskId);
|
||||||
|
case FAILED -> handleFailed(commandService, taskId);
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import com.realtime.protection.server.task.status.StateHandler;
|
||||||
|
|
||||||
|
public class PendingState extends StateHandler implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||||
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
|
case RUNNING -> handleStart(taskService, commandService, taskId);
|
||||||
|
case FAILED -> handleFailed(commandService, taskId);
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import com.realtime.protection.server.task.status.StateHandler;
|
||||||
|
|
||||||
|
public class RunningState extends StateHandler implements State {
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) {
|
||||||
|
return switch(StateEnum.getStateEnumByState(newState)) {
|
||||||
|
case RUNNING -> true;
|
||||||
|
case PAUSED -> handlePause(commandService, taskId);
|
||||||
|
case STOP -> handleStop(commandService, taskId);
|
||||||
|
case FINISHED -> handleFinish(commandService, taskId);
|
||||||
|
case FAILED -> handleFailed(commandService, taskId);
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.realtime.protection.server.task.status.states;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||||
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
|
import com.realtime.protection.configuration.utils.status.State;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import com.realtime.protection.server.task.TaskService;
|
||||||
|
import com.realtime.protection.server.task.status.StateHandler;
|
||||||
|
|
||||||
|
public class StopState extends StateHandler implements State {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException {
|
||||||
|
return switch (StateEnum.getStateEnumByState(newState)) {
|
||||||
|
case RUNNING -> handleStart(taskService, commandService, taskId);
|
||||||
|
case FAILED -> handleFailed(commandService, taskId);
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -40,6 +39,7 @@ public class WhiteListController {
|
|||||||
new WhiteListDataListener(whiteListService)).sheet().doRead();
|
new WhiteListDataListener(whiteListService)).sheet().doRead();
|
||||||
return ResponseResult.ok();
|
return ResponseResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//下载模板文件
|
//下载模板文件
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||||||
@@ -54,10 +54,10 @@ public class WhiteListController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/query")
|
@RequestMapping("/query")
|
||||||
public ResponseResult queryWhiteListObject(@RequestParam(value = "whiteobj_name", required = false)String whiteListName,
|
public ResponseResult queryWhiteListObject(@RequestParam(value = "whiteobj_name", required = false) String whiteListName,
|
||||||
@RequestParam(value = "page_size", required = false)Integer whiteListId,
|
@RequestParam(value = "page_size", required = false) Integer whiteListId,
|
||||||
@RequestParam(value = "page", defaultValue = "1")Integer page,
|
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||||
@RequestParam(value = "page_size", defaultValue = "10")Integer pageSize) {
|
@RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) {
|
||||||
if (page <= 0 || pageSize <= 0) {
|
if (page <= 0 || pageSize <= 0) {
|
||||||
return new ResponseResult(400, "page or page_size is invalid")
|
return new ResponseResult(400, "page or page_size is invalid")
|
||||||
.setData("whiteobj_list", null);
|
.setData("whiteobj_list", null);
|
||||||
@@ -103,7 +103,7 @@ public class WhiteListController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ResponseResult deleteWhiteListObjects( @RequestBody List<Integer> whiteListObjIds) {
|
public ResponseResult deleteWhiteListObjects(@RequestBody List<Integer> whiteListObjIds) {
|
||||||
//Post不支持body为json。。。 body只能是[9,10]
|
//Post不支持body为json。。。 body只能是[9,10]
|
||||||
|
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
@@ -111,7 +111,7 @@ public class WhiteListController {
|
|||||||
.setData("success", whiteListService.deleteWhiteListObjects(whiteListObjIds));
|
.setData("success", whiteListService.deleteWhiteListObjects(whiteListObjIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping ("/{id}/update")
|
@PostMapping("/{id}/update")
|
||||||
public ResponseResult updateWhiteListObject(@PathVariable Integer id,
|
public ResponseResult updateWhiteListObject(@PathVariable Integer id,
|
||||||
@RequestBody WhiteListObject object) {
|
@RequestBody WhiteListObject object) {
|
||||||
object.setWhiteListId(id);
|
object.setWhiteListId(id);
|
||||||
@@ -124,7 +124,6 @@ public class WhiteListController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//查询ip是否存在于白名单
|
//查询ip是否存在于白名单
|
||||||
@PostMapping("/exist")
|
@PostMapping("/exist")
|
||||||
public ResponseResult existWhiteListObject(@RequestBody List<Integer> ruleIds) {
|
public ResponseResult existWhiteListObject(@RequestBody List<Integer> ruleIds) {
|
||||||
@@ -155,5 +154,4 @@ public class WhiteListController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.alibaba.excel.read.listener.ReadListener;
|
|||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
//import com.alibaba.fastjson2.JSON;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -13,23 +13,26 @@ public interface WhiteListMapper {
|
|||||||
|
|
||||||
//新建
|
//新建
|
||||||
void newWhiteListObject(@Param("object") WhiteListObject object);
|
void newWhiteListObject(@Param("object") WhiteListObject object);
|
||||||
|
|
||||||
//分页查询
|
//分页查询
|
||||||
List<WhiteListObject> queryWhiteListObject(String whiteListName, Integer whiteListId, Integer page, Integer pageSize);
|
List<WhiteListObject> queryWhiteListObject(String whiteListName, Integer whiteListId, Integer page, Integer pageSize);
|
||||||
|
|
||||||
//根据主键查询
|
//根据主键查询
|
||||||
WhiteListObject queryWhiteListObjectById(Integer id);
|
WhiteListObject queryWhiteListObjectById(Integer id);
|
||||||
|
|
||||||
//根据主键删除
|
//根据主键删除
|
||||||
@Delete("delete from t_white_list where white_list_id = #{id}")
|
@Delete("delete from t_white_list where white_list_id = #{id}")
|
||||||
Integer deleteWhiteListObject(Integer id);
|
Integer deleteWhiteListObject(Integer id);
|
||||||
|
|
||||||
Integer updateWhiteListObject(@Param("object") WhiteListObject object);
|
Integer updateWhiteListObject(@Param("object") WhiteListObject object);
|
||||||
|
|
||||||
String existWhiteListObject(@Param("staticRuleObject")StaticRuleObject staticRuleObject);
|
String existWhiteListObject(@Param("staticRuleObject") StaticRuleObject staticRuleObject);
|
||||||
|
|
||||||
Integer queryWhiteListObjectAuditStuatusById(Integer id);
|
Integer queryWhiteListObjectAuditStuatusById(Integer id);
|
||||||
|
|
||||||
Boolean updateWhiteListObjectAuditStatus(Integer id, Integer status);
|
Boolean updateWhiteListObjectAuditStatus(Integer id, Integer status);
|
||||||
|
|
||||||
void newWhiteListObjects(@Param("whiteListObjects")List<WhiteListObject> whiteListBatch);
|
void newWhiteListObjects(@Param("whiteListObjects") List<WhiteListObject> whiteListBatch);
|
||||||
|
|
||||||
void deleteWhiteListObjects(@Param("whiteListIds") List<Integer> whiteListBatch);
|
void deleteWhiteListObjects(@Param("whiteListIds") List<Integer> whiteListBatch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package com.realtime.protection.server.whitelist;
|
|||||||
import com.alibaba.excel.util.ListUtils;
|
import com.alibaba.excel.util.ListUtils;
|
||||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
|
||||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
|
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||||
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -38,6 +38,7 @@ public class WhiteListService {
|
|||||||
|
|
||||||
return object.getWhiteListId();
|
return object.getWhiteListId();
|
||||||
}
|
}
|
||||||
|
|
||||||
//批量新建多个whitelist
|
//批量新建多个whitelist
|
||||||
public Boolean newWhiteListObjects(List<WhiteListObject> whiteListObjectList) {
|
public Boolean newWhiteListObjects(List<WhiteListObject> whiteListObjectList) {
|
||||||
Function<WhiteListMapper, Function<List<WhiteListObject>, Boolean>> newWhiteListObjectFunction =
|
Function<WhiteListMapper, Function<List<WhiteListObject>, Boolean>> newWhiteListObjectFunction =
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8080
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.realtime.protection: debug
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
dynamic:
|
dynamic:
|
||||||
@@ -12,17 +16,10 @@ spring:
|
|||||||
url: jdbc:mysql://192.168.107.89:3306/realtime_protection
|
url: jdbc:mysql://192.168.107.89:3306/realtime_protection
|
||||||
hikari:
|
hikari:
|
||||||
is-auto-commit: false
|
is-auto-commit: false
|
||||||
oracle:
|
|
||||||
driver-class-name: oracle.jdbc.driver.OracleDriver
|
|
||||||
username: z2_509pz
|
|
||||||
password: 123
|
|
||||||
url: jdbc:oracle:thin:@//10.26.22.45:1521/ORCL
|
|
||||||
hikari:
|
|
||||||
is-auto-commit: false
|
|
||||||
doris:
|
doris:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: root
|
username: root
|
||||||
url: jdbc:mysql://10.26.22.133:9030
|
url: jdbc:mysql://10.26.22.133:9030/command
|
||||||
hikari:
|
hikari:
|
||||||
is-auto-commit: false
|
is-auto-commit: false
|
||||||
aop:
|
aop:
|
||||||
37
src/main/resources/config/application-prod.yml
Normal file
37
src/main/resources/config/application-prod.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
server:
|
||||||
|
port: 80
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.realtime.protection: warning
|
||||||
|
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
dynamic:
|
||||||
|
datasource:
|
||||||
|
mysql:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
username: root
|
||||||
|
password: aiihhbfcsy123!@#
|
||||||
|
url: jdbc:mysql://192.168.107.89:3306/realtime_protection
|
||||||
|
hikari:
|
||||||
|
is-auto-commit: false
|
||||||
|
doris:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
username: root
|
||||||
|
url: jdbc:mysql://10.26.22.133:9030/command
|
||||||
|
hikari:
|
||||||
|
is-auto-commit: false
|
||||||
|
aop:
|
||||||
|
enabled: true
|
||||||
|
primary: mysql
|
||||||
|
strict: true
|
||||||
|
grace-destroy: true
|
||||||
|
mvc:
|
||||||
|
servlet:
|
||||||
|
path: /api/v1
|
||||||
|
jackson:
|
||||||
|
default-property-inclusion: non_null
|
||||||
|
|
||||||
|
mybatis:
|
||||||
|
mapper-locations: classpath:mappers/*
|
||||||
58
src/main/resources/mappers/CommandMapper.xml
Normal file
58
src/main/resources/mappers/CommandMapper.xml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?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.command.CommandMapper">
|
||||||
|
<insert id="createCommand" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
||||||
|
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP, MASK_SRC_PORT,
|
||||||
|
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
||||||
|
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
||||||
|
values (UUID(), DEFAULT,
|
||||||
|
#{command.fiveTupleWithMask.sourceIP},
|
||||||
|
#{command.fiveTupleWithMask.sourcePort}, #{command.fiveTupleWithMask.destinationIP},
|
||||||
|
#{command.fiveTupleWithMask.destinationPort},
|
||||||
|
#{command.fiveTupleWithMask.protocolNum}, #{command.fiveTupleWithMask.maskSourceIP},
|
||||||
|
#{command.fiveTupleWithMask.maskSourcePort},
|
||||||
|
#{command.fiveTupleWithMask.maskDestinationIP}, #{command.fiveTupleWithMask.maskDestinationPort}, TRUE,
|
||||||
|
#{command.validTime}, #{command.invalidTime}, FALSE, NOW(), NOW(), FALSE, #{command.taskId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.Command">
|
||||||
|
insert into t_command(COMMAND_ID, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, MASK_SRC_IP, MASK_SRC_PORT,
|
||||||
|
MASK_DST_IP, MASK_DST_PORT, IS_VALID, VALID_TIME, INVALID_TIME, IS_SENT,
|
||||||
|
CREATE_TIME, LAST_UPDATE, IS_DELETED, TASK_ID)
|
||||||
|
values
|
||||||
|
<foreach collection="commands" item="command" separator=",">
|
||||||
|
(UUID(), DEFAULT,
|
||||||
|
#{command.fiveTupleWithMask.sourceIP},
|
||||||
|
#{command.fiveTupleWithMask.sourcePort}, #{command.fiveTupleWithMask.destinationIP},
|
||||||
|
#{command.fiveTupleWithMask.destinationPort},
|
||||||
|
#{command.fiveTupleWithMask.protocolNum}, #{command.fiveTupleWithMask.maskSourceIP},
|
||||||
|
#{command.fiveTupleWithMask.maskSourcePort},
|
||||||
|
#{command.fiveTupleWithMask.maskDestinationIP}, #{command.fiveTupleWithMask.maskDestinationPort}, TRUE,
|
||||||
|
#{command.validTime}, #{command.invalidTime}, FALSE, NOW(), NOW(), FALSE, #{command.taskId})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="stopCommandsByTaskId">
|
||||||
|
UPDATE t_command
|
||||||
|
SET IS_VALID = FALSE
|
||||||
|
WHERE TASK_ID = #{task_id} AND IS_DELETED = FALSE
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="startCommandsByTaskId">
|
||||||
|
UPDATE t_command
|
||||||
|
SET IS_VALID = TRUE
|
||||||
|
WHERE TASK_ID = #{task_id} AND IS_DELETED = FALSE
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="removeCommandsByTaskId">
|
||||||
|
UPDATE t_command
|
||||||
|
SET IS_DELETED = TRUE
|
||||||
|
WHERE TASK_ID = #{task_id}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
-->
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -17,9 +17,7 @@
|
|||||||
|
|
||||||
<update id="newTaskStaticRuleConcat">
|
<update id="newTaskStaticRuleConcat">
|
||||||
UPDATE t_static_rule
|
UPDATE t_static_rule
|
||||||
<set>
|
SET static_rule_used_task_id = #{task_id}
|
||||||
<if test="task_id != null">static_rule_used_task_id = #{task_id},</if>
|
|
||||||
</set>
|
|
||||||
<where>
|
<where>
|
||||||
<if test="rule_ids != null and rule_ids.size() > 0">
|
<if test="rule_ids != null and rule_ids.size() > 0">
|
||||||
AND static_rule_id IN
|
AND static_rule_id IN
|
||||||
@@ -32,9 +30,7 @@
|
|||||||
|
|
||||||
<update id="newTaskDynamicRuleConcat">
|
<update id="newTaskDynamicRuleConcat">
|
||||||
UPDATE t_dynamic_rule
|
UPDATE t_dynamic_rule
|
||||||
<set>
|
SET dynamic_rule_used_task_id = #{task_id}
|
||||||
<if test="task_id != null">dynamic_rule_used_task_id = #{task_id},</if>
|
|
||||||
</set>
|
|
||||||
<where>
|
<where>
|
||||||
<if test="rule_ids != null and rule_ids.size() > 0">
|
<if test="rule_ids != null and rule_ids.size() > 0">
|
||||||
AND dynamic_rule_id IN
|
AND dynamic_rule_id IN
|
||||||
@@ -97,22 +93,34 @@
|
|||||||
WHERE t_task.task_id = #{task_id}
|
WHERE t_task.task_id = #{task_id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="queryTaskAuditStatus" resultType="java.lang.Integer">
|
||||||
|
SELECT task_audit_status
|
||||||
|
FROM t_task
|
||||||
|
WHERE task_id = #{task_id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="queryTaskStatus" resultType="java.lang.Integer">
|
||||||
|
SELECT task_status
|
||||||
|
FROM t_task
|
||||||
|
WHERE task_id = #{task_id}
|
||||||
|
</select>
|
||||||
|
|
||||||
<update id="updateTask">
|
<update id="updateTask">
|
||||||
UPDATE t_task
|
UPDATE t_task
|
||||||
<set>
|
<set>
|
||||||
<if test="task.taskName != null">task_name = #{task.taskName},</if>
|
<if test="task.taskName != null">task_name = #{task.taskName},</if>
|
||||||
<if test="task.taskType != null">task_type = #{task.taskType},</if>
|
<if test="task.taskType != null">task_type = #{task.taskType},</if>
|
||||||
<if test="task.taskAct != null">task_act = #{task.taskAct},</if>
|
<if test="task.taskAct != null">task_act = #{task.taskAct},</if>
|
||||||
<if test="task.taskCreateTime != null">task_create_time = #{task.taskCreateTime},</if>
|
<if test="task.taskStartTime != null">task_start_time = #{task.taskStartTime},</if>
|
||||||
<if test="task.taskEndTime != null">task_end_time = #{task.taskEndTime},</if>
|
<if test="task.taskEndTime != null">task_end_time = #{task.taskEndTime},</if>
|
||||||
task_modify_time = NOW()
|
task_modify_time = NOW(),
|
||||||
</set>
|
</set>
|
||||||
WHERE task_id = #{task.taskId}
|
WHERE task_id = #{task.taskId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="clearTaskConnectedStaticRule">
|
<update id="clearTaskConnectedStaticRule">
|
||||||
UPDATE t_static_rule
|
UPDATE t_static_rule
|
||||||
SET static_rule_used_task_id = null
|
SET static_rule_used_task_id = null, static_rule_modify_time = NOW()
|
||||||
WHERE static_rule_used_task_id = #{task_id}
|
WHERE static_rule_used_task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
@@ -124,7 +132,13 @@
|
|||||||
|
|
||||||
<update id="changeTaskAuditStatus">
|
<update id="changeTaskAuditStatus">
|
||||||
UPDATE t_task
|
UPDATE t_task
|
||||||
SET task_audit_status = #{audit_status}
|
SET task_audit_status = #{audit_status}, task_modify_time = NOW()
|
||||||
|
WHERE task_id = #{task_id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="changeTaskStatus">
|
||||||
|
UPDATE t_task
|
||||||
|
SET task_status = #{state}, task_modify_time = NOW()
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
@@ -132,4 +146,47 @@
|
|||||||
DELETE FROM t_task
|
DELETE FROM t_task
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<resultMap id="staticCommandMap" type="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
||||||
|
<result column="task_act" property="operation"/>
|
||||||
|
<result column="task_id" property="taskId"/>
|
||||||
|
<result column="static_rule_id" property="ruleId"/>
|
||||||
|
<result column="static_rule_frequency" property="frequency"/>
|
||||||
|
<result column="task_start_time" property="startTime"/>
|
||||||
|
<result column="task_end_time" property="endTime"/>
|
||||||
|
|
||||||
|
<association property="fiveTupleWithMask">
|
||||||
|
<result column="addr_type" property="addrType"/>
|
||||||
|
<result column="static_rule_sip" property="sourceIP"/>
|
||||||
|
<result column="static_rule_sport" property="sourcePort"/>
|
||||||
|
<result column="static_rule_dip" property="destinationIP"/>
|
||||||
|
<result column="static_rule_dport" property="destinationPort"/>
|
||||||
|
<result column="static_rule_protocol" property="protocol"/>
|
||||||
|
<result column="static_rule_msip" property="maskSourceIP"/>
|
||||||
|
<result column="static_rule_msport" property="maskSourcePort"/>
|
||||||
|
<result column="static_rule_mdip" property="maskDestinationIP"/>
|
||||||
|
<result column="static_rule_mdport" property="maskDestinationPort"/>
|
||||||
|
</association>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="getStaticCommands" resultMap="staticCommandMap">
|
||||||
|
SELECT t_task.task_id,
|
||||||
|
tsr.static_rule_id,
|
||||||
|
t_task.task_act,
|
||||||
|
t_task.task_start_time,
|
||||||
|
t_task.task_end_time,
|
||||||
|
INET_NTOA(tsr.static_rule_sip) as static_rule_sip,
|
||||||
|
tsr.static_rule_sport,
|
||||||
|
INET_NTOA(tsr.static_rule_dip) as static_rule_dip,
|
||||||
|
tsr.static_rule_dport,
|
||||||
|
tsr.static_rule_protocol,
|
||||||
|
INET_NTOA(tsr.static_rule_msip) as static_rule_msip,
|
||||||
|
tsr.static_rule_msport,
|
||||||
|
INET_NTOA(tsr.static_rule_mdip) as static_rule_mdip,
|
||||||
|
tsr.static_rule_mdport,
|
||||||
|
tsr.static_rule_frequency
|
||||||
|
FROM t_task
|
||||||
|
LEFT JOIN realtime_protection.t_static_rule tsr on t_task.task_id = tsr.static_rule_used_task_id
|
||||||
|
WHERE task_id = #{task_id} AND tsr.static_rule_audit_status = 2
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -27,46 +27,48 @@
|
|||||||
<resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.Template">
|
<resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.Template">
|
||||||
<id column="strategy_template_id" property="templateId"/>
|
<id column="strategy_template_id" property="templateId"/>
|
||||||
<result column="strategy_template_name" property="templateName"/>
|
<result column="strategy_template_name" property="templateName"/>
|
||||||
<result column="strategy_template_used_times" property="templateUsedTimes"/>
|
|
||||||
<result column="strategy_template_running_tasks" property="templateRunningTasks"/>
|
|
||||||
<result column="strategy_template_low_level_id" property="protectLevelLow.protectLevelId"/>
|
<result column="strategy_template_low_level_id" property="protectLevelLow.protectLevelId"/>
|
||||||
<result column="strategy_template_medium_level_id" property="protectLevelMedium.protectLevelId"/>
|
<result column="strategy_template_medium_level_id" property="protectLevelMedium.protectLevelId"/>
|
||||||
<result column="strategy_template_high_level_id" property="protectLevelHigh.protectLevelId"/>
|
<result column="strategy_template_high_level_id" property="protectLevelHigh.protectLevelId"/>
|
||||||
|
|
||||||
|
<result column="strategy_template_used_times" property="usedTimes"/>
|
||||||
|
<result column="strategy_template_running_tasks" property="runningTasks"/>
|
||||||
|
|
||||||
<association property="protectLevelLow"
|
<association property="protectLevelLow"
|
||||||
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
||||||
<id column="protect_level_id" property="protectLevelId"/>
|
<id column="low_protect_level_id" property="protectLevelId"/>
|
||||||
<result column="has_protect_object_ip" property="hasProtectObjectIP"/>
|
<result column="low_has_protect_object_ip" property="hasProtectObjectIP"/>
|
||||||
<result column="has_protect_object_port" property="hasProtectObjectPort"/>
|
<result column="low_has_protect_object_port" property="hasProtectObjectPort"/>
|
||||||
<result column="has_peer_ip" property="hasPeerIP"/>
|
<result column="low_has_peer_ip" property="hasPeerIP"/>
|
||||||
<result column="has_peer_port" property="hasPeerPort"/>
|
<result column="low_has_peer_port" property="hasPeerPort"/>
|
||||||
<result column="has_protocol" property="hasProtocol"/>
|
<result column="low_has_protocol" property="hasProtocol"/>
|
||||||
<result column="has_url" property="hasURL"/>
|
<result column="low_has_url" property="hasURL"/>
|
||||||
<result column="has_dns" property="hasDNS"/>
|
<result column="low_has_dns" property="hasDNS"/>
|
||||||
</association>
|
</association>
|
||||||
|
|
||||||
<association property="protectLevelMedium"
|
<association property="protectLevelMedium"
|
||||||
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
||||||
<id column="protect_level_id" property="protectLevelId"/>
|
<id column="medium_protect_level_id" property="protectLevelId"/>
|
||||||
<result column="has_protect_object_ip" property="hasProtectObjectIP"/>
|
<result column="medium_has_protect_object_ip" property="hasProtectObjectIP"/>
|
||||||
<result column="has_protect_object_port" property="hasProtectObjectPort"/>
|
<result column="medium_has_protect_object_port" property="hasProtectObjectPort"/>
|
||||||
<result column="has_peer_ip" property="hasPeerIP"/>
|
<result column="medium_has_peer_ip" property="hasPeerIP"/>
|
||||||
<result column="has_peer_port" property="hasPeerPort"/>
|
<result column="medium_has_peer_port" property="hasPeerPort"/>
|
||||||
<result column="has_protocol" property="hasProtocol"/>
|
<result column="medium_has_protocol" property="hasProtocol"/>
|
||||||
<result column="has_url" property="hasURL"/>
|
<result column="medium_has_url" property="hasURL"/>
|
||||||
<result column="has_dns" property="hasDNS"/>
|
<result column="medium_has_dns" property="hasDNS"/>
|
||||||
</association>
|
</association>
|
||||||
|
|
||||||
<association property="protectLevelHigh"
|
<association property="protectLevelHigh"
|
||||||
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
||||||
<id column="protect_level_id" property="protectLevelId"/>
|
<id column="protect_level_id" property="protectLevelId"/>
|
||||||
<result column="has_protect_object_ip" property="hasProtectObjectIP"/>
|
<id column="high_protect_level_id" property="protectLevelId"/>
|
||||||
<result column="has_protect_object_port" property="hasProtectObjectPort"/>
|
<result column="high_has_protect_object_ip" property="hasProtectObjectIP"/>
|
||||||
<result column="has_peer_ip" property="hasPeerIP"/>
|
<result column="high_has_protect_object_port" property="hasProtectObjectPort"/>
|
||||||
<result column="has_peer_port" property="hasPeerPort"/>
|
<result column="high_has_peer_ip" property="hasPeerIP"/>
|
||||||
<result column="has_protocol" property="hasProtocol"/>
|
<result column="high_has_peer_port" property="hasPeerPort"/>
|
||||||
<result column="has_url" property="hasURL"/>
|
<result column="high_has_protocol" property="hasProtocol"/>
|
||||||
<result column="has_dns" property="hasDNS"/>
|
<result column="high_has_url" property="hasURL"/>
|
||||||
|
<result column="high_has_dns" property="hasDNS"/>
|
||||||
</association>
|
</association>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
@@ -82,17 +84,10 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="queryTemplates" resultMap="templateMap">
|
<select id="queryTemplates" resultMap="templateMap">
|
||||||
<!-- 关联查询 -->
|
SELECT * FROM template_view
|
||||||
SELECT * FROM t_strategy_template AS tst
|
|
||||||
LEFT JOIN realtime_protection.t_protect_level low_tpl on low_tpl.protect_level_id =
|
|
||||||
tst.strategy_template_low_level_id
|
|
||||||
LEFT JOIN realtime_protection.t_protect_level medium_tpl on medium_tpl.protect_level_id =
|
|
||||||
tst.strategy_template_medium_level_id
|
|
||||||
LEFT JOIN realtime_protection.t_protect_level high_tpl on high_tpl.protect_level_id =
|
|
||||||
tst.strategy_template_high_level_id
|
|
||||||
<where>
|
<where>
|
||||||
<if test="template_name != null">
|
<if test="template_name != null">
|
||||||
AND tst.strategy_template_name LIKE CONCAT('%', #{template_name}, '%')
|
AND strategy_template_name LIKE CONCAT('%', #{template_name}, '%')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
LIMIT ${(page - 1) * page_size}, #{page_size}
|
LIMIT ${(page - 1) * page_size}, #{page_size}
|
||||||
@@ -115,10 +110,4 @@
|
|||||||
AND strategy_template_id = #{template.templateId}
|
AND strategy_template_id = #{template.templateId}
|
||||||
</where>
|
</where>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="addTemplateUsedTimes">
|
|
||||||
UPDATE t_strategy_template
|
|
||||||
SET strategy_template_used_times = strategy_template_used_times + #{add_times}
|
|
||||||
WHERE strategy_template_id = #{template_id}
|
|
||||||
</update>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -2,6 +2,7 @@ package com.realtime.protection.server.defense.template;
|
|||||||
|
|
||||||
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
|
||||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -16,6 +17,8 @@ class TemplateServiceTest {
|
|||||||
|
|
||||||
private final TemplateService templateService;
|
private final TemplateService templateService;
|
||||||
private Template template;
|
private Template template;
|
||||||
|
private Long startTime;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TemplateServiceTest(TemplateService templateService) {
|
TemplateServiceTest(TemplateService templateService) {
|
||||||
@@ -42,6 +45,14 @@ class TemplateServiceTest {
|
|||||||
template.setProtectLevelLow(protectLevelLow);
|
template.setProtectLevelLow(protectLevelLow);
|
||||||
template.setProtectLevelMedium(protectLevelMedium);
|
template.setProtectLevelMedium(protectLevelMedium);
|
||||||
template.setProtectLevelHigh(protectLevelHigh);
|
template.setProtectLevelHigh(protectLevelHigh);
|
||||||
|
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void summary() {
|
||||||
|
Long endTime = System.currentTimeMillis();
|
||||||
|
System.out.printf("total time: %d ms", endTime - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -56,6 +67,8 @@ class TemplateServiceTest {
|
|||||||
assertEquals(5, templates.size());
|
assertEquals(5, templates.size());
|
||||||
for (Template template : templates) {
|
for (Template template : templates) {
|
||||||
assertTrue(template.getTemplateId() > 0);
|
assertTrue(template.getTemplateId() > 0);
|
||||||
|
assertNotNull(template.getTemplateRunningTasks());
|
||||||
|
assertNotNull(template.getTemplateUsedTimes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,16 +81,4 @@ class TemplateServiceTest {
|
|||||||
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
assertTrue(templateService.updateTemplate(testTemplate.getTemplateId(), testTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testAddTemplateUsedTimes() {
|
|
||||||
template.setTemplateName("add test");
|
|
||||||
templateService.newTemplate(template);
|
|
||||||
|
|
||||||
List<Template> templates = templateService.queryTemplates("add", 1, 1);
|
|
||||||
Template originalTemplate = templates.get(0);
|
|
||||||
Boolean success = templateService.addTemplateUsedTimes(originalTemplate.getTemplateId(), 4);
|
|
||||||
templates = templateService.queryTemplates("add", 1, 1);
|
|
||||||
assertEquals(originalTemplate.getTemplateUsedTimes() + 4, templates.get(0).getTemplateUsedTimes());
|
|
||||||
assertTrue(success);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.realtime.protection.server.task;
|
package com.realtime.protection.server.task;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
import org.apache.ibatis.exceptions.PersistenceException;
|
import org.apache.ibatis.exceptions.PersistenceException;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@@ -27,31 +28,37 @@ class TaskServiceTest {
|
|||||||
this.task = new Task();
|
this.task = new Task();
|
||||||
task.setTaskName("静态测试");
|
task.setTaskName("静态测试");
|
||||||
|
|
||||||
LocalDateTime taskStartTime = LocalDateTime.parse("2023-12-24T11:45:14");
|
LocalDateTime taskStartTime = LocalDateTime.now().plusDays(1);
|
||||||
LocalDateTime taskEndTime = LocalDateTime.parse("2023-12-29T11:45:12");
|
LocalDateTime taskEndTime = LocalDateTime.now().plusDays(5);
|
||||||
|
|
||||||
task.setTaskStartTime(taskStartTime);
|
task.setTaskStartTime(taskStartTime);
|
||||||
task.setTaskEndTime(taskEndTime);
|
task.setTaskEndTime(taskEndTime);
|
||||||
task.setTaskAct("阻断");
|
task.setTaskAct("阻断");
|
||||||
task.setTaskType("静态任务");
|
task.setTaskType(1);
|
||||||
task.setStaticRuleIds(List.of(1, 2));
|
task.setStaticRuleIds(List.of(1L, 2L));
|
||||||
task.setDynamicRuleIds(List.of());
|
task.setDynamicRuleIds(List.of());
|
||||||
task.setTaskCreateUserId(1);
|
task.setTaskCreateUserId(1L);
|
||||||
task.setTaskCreateUsername("xxx");
|
task.setTaskCreateUsername("xxx");
|
||||||
task.setTaskCreateDepart("xxx");;
|
task.setTaskCreateDepart("xxx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewTaskSuccess() {
|
void testNewTaskSuccess() {
|
||||||
assertDoesNotThrow(() -> {Integer taskId = taskService.newTask(task); assertTrue(taskId > 0);});
|
for (int i = 0; i < 100; i++){
|
||||||
|
LocalDateTime taskStartTime = LocalDateTime.now().plusDays(i);
|
||||||
|
LocalDateTime taskEndTime = LocalDateTime.now().plusDays(i+10);
|
||||||
|
task.setTaskStartTime(taskStartTime);
|
||||||
|
task.setTaskEndTime(taskEndTime);
|
||||||
|
assertDoesNotThrow(() -> {Long taskId = taskService.newTask(task); assertTrue(taskId > 0);});
|
||||||
assertTrue(task.getTaskId() > 0);
|
assertTrue(task.getTaskId() > 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewTaskLostData() {
|
void testNewTaskLostData() {
|
||||||
this.task.setTaskStartTime(null);
|
this.task.setTaskStartTime(null);
|
||||||
assertThrows(PersistenceException.class, () -> {
|
assertThrows(PersistenceException.class, () -> {
|
||||||
Integer taskId = taskService.newTask(task);
|
Long taskId = taskService.newTask(task);
|
||||||
assertTrue(taskId > 0);
|
assertTrue(taskId > 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,30 +71,37 @@ class TaskServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpdateTasks() {
|
void testUpdateTasks() {
|
||||||
task.setStaticRuleIds(List.of(6, 7, 8));
|
Task originalTask = taskService.queryTask(38L);
|
||||||
task.setTaskId(26);
|
|
||||||
task.setTaskName("修改测试");
|
|
||||||
|
|
||||||
assertTrue(taskService.updateTask(task));
|
originalTask.setStaticRuleIds(List.of(16L, 17L, 18L, 19L));
|
||||||
assertEquals("修改测试", taskService.queryTask(26).getTaskName());
|
originalTask.setTaskName("修改测试");
|
||||||
|
|
||||||
|
assertTrue(taskService.updateTask(originalTask));
|
||||||
|
assertEquals("修改测试", taskService.queryTask(38L).getTaskName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeleteTask() {
|
void testDeleteTask() {
|
||||||
int testNum = taskService.queryTasks(null, null, null, null, 1, 10)
|
long testNum = taskService.queryTasks(null, null, null, null, 1, 10)
|
||||||
.get(0).getTaskId();
|
.get(0).getTaskId();
|
||||||
|
|
||||||
assertTrue(taskService.deleteTask(testNum));
|
assertTrue(taskService.deleteTask(testNum));
|
||||||
assertFalse(taskService.deleteTask(235235));
|
assertFalse(taskService.deleteTask(235235L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testChangeAuditStatus() {
|
void testChangeAuditStatus() {
|
||||||
int testNum = taskService.queryTasks(null, null, null, null, 1, 1)
|
long testNum = taskService.queryTasks(null, null, null, null, 1, 1)
|
||||||
.get(0).getTaskId();
|
.get(0).getTaskId();
|
||||||
|
|
||||||
assertTrue(taskService.changeTaskAuditStatus(testNum, 2));
|
assertTrue(taskService.changeTaskAuditStatus(testNum, 2));
|
||||||
assertFalse(taskService.changeTaskAuditStatus(testNum, 0));
|
assertFalse(taskService.changeTaskAuditStatus(testNum, 0));
|
||||||
assertFalse(taskService.changeTaskAuditStatus(testNum, 1));
|
assertFalse(taskService.changeTaskAuditStatus(testNum, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetStaticCommands() {
|
||||||
|
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(26L);
|
||||||
|
assertEquals(3, taskCommandInfos.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.realtime.protection.server.task.status;
|
||||||
|
|
||||||
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
|
import com.realtime.protection.configuration.entity.task.Command;
|
||||||
|
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||||
|
import com.realtime.protection.server.command.CommandService;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class CommandServiceTest {
|
||||||
|
|
||||||
|
private final CommandService commandService;
|
||||||
|
private TaskCommandInfo taskCommandInfo;
|
||||||
|
private Command command;
|
||||||
|
|
||||||
|
private Long startTime;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CommandServiceTest(CommandService commandService) {
|
||||||
|
this.commandService = commandService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void mockCommand() {
|
||||||
|
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||||
|
fiveTupleWithMask.setMaskSourceIP("192.168.155.24");
|
||||||
|
|
||||||
|
taskCommandInfo = new TaskCommandInfo();
|
||||||
|
taskCommandInfo.setFrequency(30);
|
||||||
|
taskCommandInfo.setTaskId(30L);
|
||||||
|
taskCommandInfo.setFiveTupleWithMask(fiveTupleWithMask);
|
||||||
|
taskCommandInfo.setOperation("阻断");
|
||||||
|
taskCommandInfo.setEndTime(LocalDateTime.now().plusDays(1));
|
||||||
|
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void summary() {
|
||||||
|
Long endTime = System.currentTimeMillis();
|
||||||
|
System.out.printf("total time: %d ms", endTime - startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createCommand() {
|
||||||
|
assertDoesNotThrow(() -> commandService.createCommand(taskCommandInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createCommands() {
|
||||||
|
List<TaskCommandInfo> taskCommandInfos = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
int port = i + 1000;
|
||||||
|
taskCommandInfo = new TaskCommandInfo();
|
||||||
|
taskCommandInfo.setFiveTupleWithMask(new FiveTupleWithMask());
|
||||||
|
taskCommandInfo.setTaskId(24L);
|
||||||
|
taskCommandInfo.getFiveTupleWithMask().setSourcePort(Integer.toString(port));
|
||||||
|
taskCommandInfo.setStartTime(LocalDateTime.now().plusDays(5));
|
||||||
|
taskCommandInfo.setEndTime(LocalDateTime.now().plusDays(10));
|
||||||
|
taskCommandInfo.setFrequency(20);
|
||||||
|
|
||||||
|
taskCommandInfos.add(taskCommandInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> commandService.createCommands(taskCommandInfos));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user