From 12ba2b9be3b0e5af8a7a38fe8a0dc31739524a6b Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 13 Aug 2020 09:18:38 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=8B=86=E5=88=86=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B0=86=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=8B=86=E5=88=86=E5=88=B0?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=202.=20=E6=96=B0=E5=A2=9Elog4j=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E4=B8=8D=E5=90=8C=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=203.=20=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9B=B8=E5=85=B3=E5=86=85?= =?UTF-8?q?=E5=AE=B9=204.=20=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-dispose.properties | 21 +++ config/application-local.properties | 32 +--- config/application-test.properties | 10 -- config/application.properties | 2 +- config/logback.xml | 2 +- config/logback_debug.xml | 101 ++++++++++++ .../ability/impl/DpTechAbilityImpl.java | 4 +- .../com/dispose/common/DDoSAttackType.java | 148 ++++++++++++------ .../com/dispose/common/DisposeTaskStatus.java | 71 +++++++++ .../com/dispose/common/NetflowDirection.java | 29 ++-- .../com/dispose/mapper/DisposeTaskMapper.java | 47 ++++++ .../dispose/pojo/entity/DisposeCapacity.java | 11 +- .../dispose/pojo/entity/DisposeDevice.java | 8 +- .../com/dispose/pojo/entity/DisposeTask.java | 90 +++++++++++ .../com/dispose/pojo/entity/UserAccount.java | 8 +- src/main/resources/mappers/DisposeTask.xml | 53 +++++++ .../java/com/dispose/test/debug/demo.java | 7 + .../test/mapper/DisposeTaskMapperTest.java | 65 ++++++++ 18 files changed, 592 insertions(+), 117 deletions(-) create mode 100644 config/application-dispose.properties create mode 100644 config/logback_debug.xml create mode 100644 src/main/java/com/dispose/common/DisposeTaskStatus.java create mode 100644 src/main/java/com/dispose/mapper/DisposeTaskMapper.java create mode 100644 src/main/java/com/dispose/pojo/entity/DisposeTask.java create mode 100644 src/main/resources/mappers/DisposeTask.xml create mode 100644 src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java diff --git a/config/application-dispose.properties b/config/application-dispose.properties new file mode 100644 index 00000000..3cf4a4bc --- /dev/null +++ b/config/application-dispose.properties @@ -0,0 +1,21 @@ +#调试配置 +dispose.debug-model=true +dispose.check-protocol-timeout=false +dispose.check-request-token=true +dispose.split_char=, +dispose.request-timeout-second=5 + +dispose.used-privacy-protect=true + +# 迪普设备配置 +# 发送超时时间(s) +dptech.soap-conn-timeout-second=60 +# 接收超时时间(s) +dptech.soap-recv-timeout-second=60 + +# 用户权限配置 +permission.admin-check=true +permission.admin-users=admin + +# 认证配置 +auth.token-timeout-minute=30 \ No newline at end of file diff --git a/config/application-local.properties b/config/application-local.properties index f8741263..5f2f82b3 100644 --- a/config/application-local.properties +++ b/config/application-local.properties @@ -4,11 +4,11 @@ server.tomcat.basedir=./basedir # 多个项目放在nginx下同个端口,通过该配置区分 server.servlet.context-path=/dispose # 配置数据源 -spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose_hx?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ +spring.datasource.url=jdbc:mysql://10.88.77.65:33061/dispose_hx?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.username=phoenix -spring.datasource.password=Hy@rfph32 +spring.datasource.username=root +spring.datasource.password=h0K0_8u # 配置连接池 spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource spring.datasource.dbcp2.max-total=128 @@ -26,7 +26,7 @@ mybatis.mapper-locations=classpath*:mappers/*.xml mybatis.type-aliases-package=com.dispose.pojo.entity mybatis.configuration.default-enum-type-handler=com.dispose.common.CommonEnumHandler #config log -logging.config=file:config/logback.xml +logging.config=file:config/logback_debug.xml #config tomcat server.tomcat.max-threads=128 #Json sort @@ -52,26 +52,4 @@ phoenix.request-dec-switch=false phoenix.response-enc-switch=false #config aes 128 key,用于上述body的加解密 phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ== -#====custom config,begin with phoenix==== - -#调试配置 -dispose.debug-model=true -dispose.check-protocol-timeout=false -dispose.check-request-token=true -dispose.split_char=, -dispose.request-timeout-second=5 - -dispose.used-privacy-protect=true - -# 迪普设备配置 -# 发送超时时间(ms) -dptech.soap-conn-timeout-second=60 -# 接收超时时间(ms) -dptech.soap-recv-timeout-second=60 - -# 用户权限配置 -permission.admin-check=true -permission.admin-users=admin - -# 认证配置 -auth.token-timeout-minute=30 \ No newline at end of file +#====custom config,begin with phoenix==== \ No newline at end of file diff --git a/config/application-test.properties b/config/application-test.properties index 47c2848d..f04eb322 100644 --- a/config/application-test.properties +++ b/config/application-test.properties @@ -51,13 +51,3 @@ phoenix.response-enc-switch=false #config aes 128 key,用于上述body的加解密 phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ== #====custom config,begin with phoenix==== -#调试配置 -dispose.check-protocol-timeout=false -dispose.check-request-token=true -dispose.check-admin-permission=true -# 迪普设备配置 -# 发送超时时间(ms) -#dptech.soap-conn-timeout=5000 -# 接收超时时间(ms) -dptech.soap-recv-timeout=50000 - diff --git a/config/application.properties b/config/application.properties index 07f154c2..b745d9d5 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1 +1 @@ -spring.profiles.active=local \ No newline at end of file +spring.profiles.active=local,dispose \ No newline at end of file diff --git a/config/logback.xml b/config/logback.xml index d5b6e0ca..29cc3007 100644 --- a/config/logback.xml +++ b/config/logback.xml @@ -2,7 +2,7 @@ - + diff --git a/config/logback_debug.xml b/config/logback_debug.xml new file mode 100644 index 00000000..d5b6e0ca --- /dev/null +++ b/config/logback_debug.xml @@ -0,0 +1,101 @@ + + + + + + + + + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n + + + + + ${LOG_PATH}/biz.log + + ${LOG_PATH}/biz.log.%d{yyyyMMdd} + + + + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n + + + + ${LOG_PATH}/system.log + + ${LOG_PATH}/system.log.%d{yyyyMMdd} + + + + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n + + + + + ${LOG_PATH}/data.log + + ${LOG_PATH}/data.log.%d{yyyyMMdd} + + + + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 9af92c86..39c2cf3c 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -118,7 +118,7 @@ public class DpTechAbilityImpl implements DisposeAbility { .collect(Collectors.toList()); dirList.forEach(d -> typeList.forEach(t -> CompletableFuture.supplyAsync(() -> - cleanTypePort.startAbnormalTaskForUMC(ip, t.getValue(), d.getCode())) + cleanTypePort.startAbnormalTaskForUMC(ip, t.getValue(), d.getValue())) .whenComplete((v, ex) -> { if (ex != null) { log.error("DPTech run dispose: {}, {}, error:{}", ip, t.getValue(), @@ -173,7 +173,7 @@ public class DpTechAbilityImpl implements DisposeAbility { .collect(Collectors.toList()); dirList.forEach(d -> typeList.forEach(t -> CompletableFuture.supplyAsync(() -> - cleanTypePort.stopAbnormalTaskForUMC(ipAddr, t.getValue(), d.getCode())) + cleanTypePort.stopAbnormalTaskForUMC(ipAddr, t.getValue(), d.getValue())) .whenComplete((v, ex) -> { if (ex != null) { log.error("DPTech stop dispose: {}, {}, error:{}", ipAddr, t.getValue(), ex.getMessage()); diff --git a/src/main/java/com/dispose/common/DDoSAttackType.java b/src/main/java/com/dispose/common/DDoSAttackType.java index 24fe78d0..49d66017 100644 --- a/src/main/java/com/dispose/common/DDoSAttackType.java +++ b/src/main/java/com/dispose/common/DDoSAttackType.java @@ -1,188 +1,194 @@ package com.dispose.common; +import lombok.extern.slf4j.Slf4j; + +import java.util.Arrays; +import java.util.List; + /** * The enum D do s attack type. * * @author */ -public enum DDoSAttackType implements BaseEnum { +@Slf4j +public enum DDoSAttackType implements BaseEnum { /** * The Host total traffic. */ - HOST_TOTAL_TRAFFIC ( 0, "HOST_TOTAL_TRAFFIC"), + HOST_TOTAL_TRAFFIC(0, "HOST_TOTAL_TRAFFIC"), /** * The Rst flood. */ - RST_FLOOD ( 1, "RST_FLOOD"), + RST_FLOOD(1, "RST_FLOOD"), /** * The Syn flood. */ - SYN_FLOOD ( 2, "SYN_FLOOD"), + SYN_FLOOD(2, "SYN_FLOOD"), /** * The Ack flood. */ - ACK_FLOOD ( 3, "ACK_FLOOD"), + ACK_FLOOD(3, "ACK_FLOOD"), /** * The Tcp null. */ - TCP_NULL ( 4, "TCP_NULL"), + TCP_NULL(4, "TCP_NULL"), /** * The Syn ack amplification. */ - SYN_ACK_AMPLIFICATION ( 5, "SYN/ACK_AMPLIFICATION"), + SYN_ACK_AMPLIFICATION(5, "SYN/ACK_AMPLIFICATION"), /** * The Tcp misuse. */ - TCP_MISUSE ( 6, "TCP_MISUSE"), + TCP_MISUSE(6, "TCP_MISUSE"), /** * The Fin flood. */ - FIN_FLOOD ( 7, "FIN_FLOOD"), + FIN_FLOOD(7, "FIN_FLOOD"), /** * The Tcp fragment. */ - TCP_FRAGMENT ( 8, "TCP_FRAGMENT"), + TCP_FRAGMENT(8, "TCP_FRAGMENT"), /** * The Http flood. */ - HTTP_FLOOD ( 9, "HTTP_FLOOD"), + HTTP_FLOOD(9, "HTTP_FLOOD"), /** * The Https flood. */ - HTTPS_FLOOD ( 10, "HTTPS_FLOOD"), + HTTPS_FLOOD(10, "HTTPS_FLOOD"), /** * The Win nuke. */ - WIN_NUKE ( 11, "WIN_NUKE"), + WIN_NUKE(11, "WIN_NUKE"), /** * The Sip flood. */ - SIP_FLOOD ( 12, "SIP_FLOOD"), + SIP_FLOOD(12, "SIP_FLOOD"), /** * The Dns flood. */ - DNS_FLOOD ( 13, "DNS_FLOOD"), + DNS_FLOOD(13, "DNS_FLOOD"), /** * The Udp fragment. */ - UDP_FRAGMENT ( 14, "UDP_FRAGMENT"), + UDP_FRAGMENT(14, "UDP_FRAGMENT"), /** * The Charged amplification. */ - CHARGED_AMPLIFICATION ( 15, "CHARGED_AMPLIFICATION"), + CHARGED_AMPLIFICATION(15, "CHARGED_AMPLIFICATION"), /** * The L 2 tp amplification. */ - L2TP_AMPLIFICATION ( 16, "L2TP_AMPLIFICATION"), + L2TP_AMPLIFICATION(16, "L2TP_AMPLIFICATION"), /** * The Mdns amplification. */ - MDNS_AMPLIFICATION ( 17, "MDNS_AMPLIFICATION"), + MDNS_AMPLIFICATION(17, "MDNS_AMPLIFICATION"), /** * The Ms sql rs amplification. */ - MS_SQL_RS_AMPLIFICATION ( 18, "MS_SQL_RS_AMPLIFICATION"), + MS_SQL_RS_AMPLIFICATION(18, "MS_SQL_RS_AMPLIFICATION"), /** * The Net bios amplification. */ - NET_BIOS_AMPLIFICATION ( 19, "NET_BIOS_AMPLIFICATION"), + NET_BIOS_AMPLIFICATION(19, "NET_BIOS_AMPLIFICATION"), /** * The Ntp amplification. */ - NTP_AMPLIFICATION ( 20, "NTP_AMPLIFICATION"), + NTP_AMPLIFICATION(20, "NTP_AMPLIFICATION"), /** * The Ripv 1 amplification. */ - RIPV1_AMPLIFICATION ( 21, "RIPV1_AMPLIFICATION"), + RIPV1_AMPLIFICATION(21, "RIPV1_AMPLIFICATION"), /** * The Rpcbind amplification. */ - RPCBIND_AMPLIFICATION ( 22, "RPCBIND_AMPLIFICATION"), + RPCBIND_AMPLIFICATION(22, "RPCBIND_AMPLIFICATION"), /** * The Snmp amplification. */ - SNMP_AMPLIFICATION ( 23, "SNMP_AMPLIFICATION"), + SNMP_AMPLIFICATION(23, "SNMP_AMPLIFICATION"), /** * The Ssdp amplification. */ - SSDP_AMPLIFICATION ( 24, "SSDP_AMPLIFICATION"), + SSDP_AMPLIFICATION(24, "SSDP_AMPLIFICATION"), /** * The Dns amplification. */ - DNS_AMPLIFICATION ( 25, "DNS_AMPLIFICATION"), + DNS_AMPLIFICATION(25, "DNS_AMPLIFICATION"), /** * The Qotd amplification. */ - QOTD_AMPLIFICATION ( 26, "QOTD_AMPLIFICATION"), + QOTD_AMPLIFICATION(26, "QOTD_AMPLIFICATION"), /** * The Quake 3 amplification. */ - QUAKE3_AMPLIFICATION ( 27, "QUAKE3_AMPLIFICATION"), + QUAKE3_AMPLIFICATION(27, "QUAKE3_AMPLIFICATION"), /** * The Steam amplification. */ - STEAM_AMPLIFICATION ( 28, "STEAM_AMPLIFICATION"), + STEAM_AMPLIFICATION(28, "STEAM_AMPLIFICATION"), /** * The Cldap amplification. */ - CLDAP_AMPLIFICATION ( 29, "CLDAP_AMPLIFICATION"), + CLDAP_AMPLIFICATION(29, "CLDAP_AMPLIFICATION"), /** * The Memcache amplification. */ - MEMCACHE_AMPLIFICATION ( 30, "MEMCACHE_AMPLIFICATION"), + MEMCACHE_AMPLIFICATION(30, "MEMCACHE_AMPLIFICATION"), /** * The Tftp amplification. */ - TFTP_AMPLIFICATION ( 31, "TFTP_AMPLIFICATION"), + TFTP_AMPLIFICATION(31, "TFTP_AMPLIFICATION"), /** * The Portmapper amplification. */ - PORTMAPPER_AMPLIFICATION ( 32, "PORTMAPPER_AMPLIFICATION"), + PORTMAPPER_AMPLIFICATION(32, "PORTMAPPER_AMPLIFICATION"), /** * The Sentinel amplification. */ - SENTINEL_AMPLIFICATION ( 33, "SENTINEL_AMPLIFICATION"), + SENTINEL_AMPLIFICATION(33, "SENTINEL_AMPLIFICATION"), /** * The Fraggle flood. */ - FRAGGLE_FLOOD ( 34, "FRAGGLE_FLOOD"), + FRAGGLE_FLOOD(34, "FRAGGLE_FLOOD"), /** * The Udp flood. */ - UDP_FLOOD ( 35, "UDP_FLOOD"), + UDP_FLOOD(35, "UDP_FLOOD"), /** * The Smurf. */ - SMURF ( 36, "SMURF"), + SMURF(36, "SMURF"), /** * The Icmp fragment. */ - ICMP_FRAGMENT ( 37, "ICMP_FRAGMENT"), + ICMP_FRAGMENT(37, "ICMP_FRAGMENT"), /** * The Icmp flood. */ - ICMP_FLOOD ( 38, "ICMP_FLOOD"), + ICMP_FLOOD(38, "ICMP_FLOOD"), /** * The Ipv 4 protocol 0. */ - IPV4_PROTOCOL0 ( 39, "IPV4_PROTOCOL0"), + IPV4_PROTOCOL0(39, "IPV4_PROTOCOL0"), /** * The Ip private. */ - IP_PRIVATE ( 40, "IP_PRIVATE"), + IP_PRIVATE(40, "IP_PRIVATE"), /** * The Land flood. */ - LAND_FLOOD ( 41, "LAND_FLOOD"), + LAND_FLOOD(41, "LAND_FLOOD"), /** * The Igmp flood. */ - IGMP_FLOOD ( 42, "IGMP_FLOOD"), + IGMP_FLOOD(42, "IGMP_FLOOD"), /** - * All attacks d do s attack type. + * The All attacks. */ - ALL_ATTACKS (-1, "ALL_ATTACKS"), + ALL_ATTACKS(-1, "ALL_ATTACKS"), ; @@ -206,6 +212,56 @@ public enum DDoSAttackType implements BaseEnum { this.readme = readme; } + /** + * Gets type mask from attack type. + * + * @param types the types + * @return the type mask from attack type + */ + public static Long getTypeMaskFromAttackType(List types) { + long mask = 0L; + + if (types.contains(ALL_ATTACKS)) { + for (DDoSAttackType type : DDoSAttackType.values()) { + if (type.equals(ALL_ATTACKS)) { + continue; + } + mask |= type.getValue() << 1; + } + } else { + for (DDoSAttackType type : types) { + mask |= type.getValue() << 1; + } + } + + return mask; + } + + /** + * Gets type mask from attack type. + * + * @param types the types + * @return the type mask from attack type + */ + public static Long getTypeMaskFromAttackType(DDoSAttackType[] types) { + long mask = 0L; + + if (Arrays.asList(types).contains(ALL_ATTACKS)) { + for (DDoSAttackType type : DDoSAttackType.values()) { + if (type.equals(ALL_ATTACKS)) { + continue; + } + mask |= (long)1 << type.getValue(); + } + } else { + for (DDoSAttackType type : types) { + mask |= (long)1 << type.getValue(); + } + } + + return mask; + } + /** * Gets value. * diff --git a/src/main/java/com/dispose/common/DisposeTaskStatus.java b/src/main/java/com/dispose/common/DisposeTaskStatus.java new file mode 100644 index 00000000..e0827259 --- /dev/null +++ b/src/main/java/com/dispose/common/DisposeTaskStatus.java @@ -0,0 +1,71 @@ +package com.dispose.common; + +/** + * The enum Task status. + * + * @author + */ +public enum DisposeTaskStatus implements BaseEnum { + /** + * The Task new. + */ + TASK_NEW(0, "新建"), + /** + * The Task starting. + */ + TASK_STARTING(1, "启动中"), + /** + * The Task started. + */ + TASK_STARTED(2, "启动完成"), + /** + * The Task finished. + */ + TASK_FINISHED(3, "结束"), + + /** + * Task canceled task status. + */ + TASK_CANCELED(4, "用户中止"), + ; + + /** + * The Code. + */ + private final Integer code; + /** + * The Readme. + */ + private final String readme; + + /** + * Instantiates a new Task status. + * + * @param code the code + * @param readme the readme + */ + DisposeTaskStatus(int code, String readme) { + this.code = code; + this.readme = readme; + } + + /** + * Gets value. + * + * @return the value + */ + @Override + public Integer getValue() { + return this.code; + } + + /** + * Gets description. + * + * @return the description + */ + @Override + public String getDescription() { + return this.readme; + } +} diff --git a/src/main/java/com/dispose/common/NetflowDirection.java b/src/main/java/com/dispose/common/NetflowDirection.java index dee70fdb..96237ef5 100644 --- a/src/main/java/com/dispose/common/NetflowDirection.java +++ b/src/main/java/com/dispose/common/NetflowDirection.java @@ -5,19 +5,24 @@ package com.dispose.common; * * @author */ -public enum NetflowDirection { +public enum NetflowDirection implements BaseEnum { /** - * Direction in netflow direction. + * The Direction in. */ DIRECTION_IN(0, "入方向"), /** - * Direction out netflow direction. + * The Direction out. */ - DIRECTION_OUT(1, "出方向"); + DIRECTION_OUT(1, "出方向"), + /** + * The Direction bi. + */ + DIRECTION_BI(2, "双向"); + /** * The Code. */ - private final int code; + private final Integer code; /** * The Readme. */ @@ -35,20 +40,22 @@ public enum NetflowDirection { } /** - * Gets code. + * Gets value. * - * @return the code + * @return the value */ - public int getCode() { + @Override + public Integer getValue() { return this.code; } /** - * Gets readme. + * Gets description. * - * @return the readme + * @return the description */ - public String getReadme() { + @Override + public String getDescription() { return this.readme; } } diff --git a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java new file mode 100644 index 00000000..43b4d718 --- /dev/null +++ b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java @@ -0,0 +1,47 @@ +package com.dispose.mapper; + +import com.dispose.common.DisposeTaskStatus; +import com.dispose.pojo.entity.DisposeTask; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface Dispose task mapper. + * + * @author + */ +public interface DisposeTaskMapper { + /** + * Select all list. + * + * @return the list + */ + List selectAll(); + + /** + * Add new task int. + * + * @param task the task + * @return the int + */ + int addNewTask(DisposeTask task); + + /** + * Gets task status. + * + * @param taskId the task id + * @return the task status + */ + DisposeTaskStatus getTaskStatus(@Param("id") Long taskId); + + /** + * Chang task status int. + * + * @param taskId the task id + * @param status the status + * @return the int + */ + int changTaskStatus(@Param("id") Long taskId, + @Param("status") DisposeTaskStatus status); +} diff --git a/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java b/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java index 7b544504..4ddf7907 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeCapacity.java @@ -6,32 +6,29 @@ import com.dispose.common.IpAddrType; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.annotation.NameStyle; import tk.mybatis.mapper.code.Style; import javax.persistence.Id; import javax.persistence.Table; +import java.io.Serializable; /** * The type Dispose capacity. * * @author */ -@Getter -@Setter -@ToString +@Data @NoArgsConstructor @AllArgsConstructor @Builder @JsonInclude(JsonInclude.Include.NON_NULL) @Table(name = "dispose_capacity") @NameStyle(Style.normal) -public class DisposeCapacity { +public class DisposeCapacity implements Serializable { /** * The constant serialVersionUID. diff --git a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java b/src/main/java/com/dispose/pojo/entity/DisposeDevice.java index ae45dc18..42c7953e 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeDevice.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeDevice.java @@ -7,10 +7,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.annotation.NameStyle; import tk.mybatis.mapper.code.Style; @@ -26,9 +24,7 @@ import java.util.List; * * @author */ -@Getter -@Setter -@ToString +@Data @NoArgsConstructor @AllArgsConstructor @Builder diff --git a/src/main/java/com/dispose/pojo/entity/DisposeTask.java b/src/main/java/com/dispose/pojo/entity/DisposeTask.java new file mode 100644 index 00000000..9aa25001 --- /dev/null +++ b/src/main/java/com/dispose/pojo/entity/DisposeTask.java @@ -0,0 +1,90 @@ +package com.dispose.pojo.entity; + +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeTaskStatus; +import com.dispose.common.NetflowDirection; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * The type Dispose task. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "dispose_task") +@NameStyle(Style.normal) +public class DisposeTask implements Serializable { + /** + * The constant serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + /** + * The Device id. + */ + private Long deviceId; + /** + * The Account id. + */ + private Long accountId; + /** + * The Capacity type. + */ + private DisposeCapacityType capacityType; + /** + * The Dispose ip. + */ + private String disposeIp; + /** + * The Create time. + */ + private String createTime; + /** + * The Plan end time. + */ + private String planEndTime; + /** + * The End time. + */ + private String endTime; + /** + * The Flow direction. + */ + private NetflowDirection flowDirection; + /** + * The Attack type. + */ + private Long attackType; + /** + * The Flow band width. + */ + private Integer flowBandWidth; + /** + * The Current status. + */ + private DisposeTaskStatus currentStatus; +} diff --git a/src/main/java/com/dispose/pojo/entity/UserAccount.java b/src/main/java/com/dispose/pojo/entity/UserAccount.java index 4470986b..0ddeb46f 100644 --- a/src/main/java/com/dispose/pojo/entity/UserAccount.java +++ b/src/main/java/com/dispose/pojo/entity/UserAccount.java @@ -3,10 +3,8 @@ package com.dispose.pojo.entity; import com.dispose.common.ObjectStatus; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; import tk.mybatis.mapper.annotation.KeySql; import tk.mybatis.mapper.annotation.NameStyle; import tk.mybatis.mapper.code.Style; @@ -20,9 +18,7 @@ import java.io.Serializable; * * @author */ -@Getter -@Setter -@ToString +@Data @NoArgsConstructor @AllArgsConstructor @Builder diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml new file mode 100644 index 00000000..e5848775 --- /dev/null +++ b/src/main/resources/mappers/DisposeTask.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + INSERT IGNORE INTO dispose_task(deviceId, accountId, capacityType, disposeIp, + planEndTime, flowDirection, attackType, flowBandWidth, + currentStatus) + VALUES (#{deviceId}, #{accountId}, #{capacityType}, #{disposeIp}, + date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType}, + #{flowBandWidth}, ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()}) + + + + UPDATE + dispose_task + SET + currentStatus = #{status, javaType="com.dispose.common.DisposeTaskStatus"} + + , endTime = CURRENT_TIMESTAMP + + WHERE + id = #{id, jdbcType=INTEGER} + + + + + \ No newline at end of file diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java index ffe43a06..d3f6378c 100644 --- a/src/test/java/com/dispose/test/debug/demo.java +++ b/src/test/java/com/dispose/test/debug/demo.java @@ -1,5 +1,6 @@ package com.dispose.test.debug; +import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeDeviceType; import com.dispose.common.HttpType; import com.dispose.common.ObjectStatus; @@ -137,4 +138,10 @@ public class demo { log.info(PrivacyHelper.ipAddressPrivacy("2001:0000:4136:e378:8000:63bf:3fff:fdd2")); log.info(PrivacyHelper.ipAddressPrivacy("3fde::fde2")); } + + @Test + public void getTypeMaskFromAttackType() { + Long ret = DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[] {DDoSAttackType.ALL_ATTACKS}); + log.debug("Ret: 0x{}", Long.toHexString(ret).toUpperCase()); + } } diff --git a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java new file mode 100644 index 00000000..d5059c72 --- /dev/null +++ b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java @@ -0,0 +1,65 @@ +package com.dispose.test.mapper; + +import com.dispose.common.DDoSAttackType; +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.NetflowDirection; +import com.dispose.mapper.DisposeDeviceMapper; +import com.dispose.mapper.DisposeTaskMapper; +import com.dispose.mapper.UserAccountMapper; +import com.dispose.pojo.entity.DisposeTask; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class DisposeTaskMapperTest { + @Resource + private DisposeTaskMapper disposeTaskMapper; + + @Resource + private UserAccountMapper userAccountMapper; + + @Resource + private DisposeDeviceMapper disposeDeviceMapper; + + @Resource + private ObjectMapper objectMapper; + + @Test + public void a1_addNewDisposeTask() throws JsonProcessingException { + Long uId = userAccountMapper.selectAll().get(0).getId(); + Long dId = disposeDeviceMapper.selectAll().get(0).getId(); + DisposeTask task = DisposeTask.builder() + .deviceId(dId) + .accountId(uId) + .capacityType(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.0.1") + .planEndTime("30") + .flowDirection(NetflowDirection.DIRECTION_BI) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[] {DDoSAttackType.ALL_ATTACKS})) + .flowBandWidth(1024) + .build(); + + int ret = disposeTaskMapper.addNewTask(task); + + log.info("add ret {}: {}", ret, + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); + + List taskList = disposeTaskMapper.selectAll(); + + log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); + } + +}