OCT
REM: 1. 新增MsgSerial数据库 2. 增加存储MsgSerial字段和获取最大MsgSerial值方法 3. 修改MsgSerial字段递增方式(不采用redis自增长方式) 4. 数据库操作单元测试
This commit is contained in:
parent
5c492a6c0b
commit
39531233a2
|
@ -47,11 +47,6 @@ kafka.producer.linger=1
|
|||
kafka.producer.buffer.memory=33554432
|
||||
kafka.producer.servers=172.21.44.189:9092,172.21.44.9:9092,172.21.44.244:9092,172.21.44.236:9092,172.21.44.80:9092
|
||||
kafka.dispose.topic=ddos-vip-customer-ck
|
||||
#redis config
|
||||
spring.redis.database=0
|
||||
spring.redis.host=172.21.48.211
|
||||
spring.redis.port=6379
|
||||
spring.redis.password=!Q2w3e4r
|
||||
#信任主机配置
|
||||
# 白名单开关
|
||||
trust.auth-white-list-check=true
|
||||
|
|
|
@ -4,17 +4,16 @@ server.tomcat.basedir=./basedir
|
|||
# 多个项目放在nginx下同个端口,通过该配置区分
|
||||
server.servlet.context-path=/dispose
|
||||
# 配置数据源
|
||||
#spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
|
||||
# =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
|
||||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=h0K0_8u
|
||||
spring.datasource.url=jdbc:mysql://172.21.48.75:3306/ci_dispose_v1?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
|
||||
=convertToNull&useUnicode=true
|
||||
spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
|
||||
=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=BCcf6Dd7&8
|
||||
|
||||
spring.datasource.password=h0K0_8u
|
||||
#spring.datasource.url=jdbc:mysql://172.21.48.75:3306/ci_dispose_v1?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
|
||||
# =convertToNull&useUnicode=true
|
||||
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=BCcf6Dd7&8
|
||||
# 配置连接池
|
||||
spring.datasource.schema=classpath:test_db/unit_test.sql
|
||||
spring.datasource.initialization-mode=always
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -225,10 +225,6 @@
|
|||
<artifactId>dom4j-core</artifactId>
|
||||
<version>1.4-dev-8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -9,14 +9,15 @@ import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
|
|||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
import com.dispose.pojo.dto.protocol.kafka.EmosAlarmInfo;
|
||||
import com.dispose.pojo.dto.protocol.kafka.AlarmInfoReq;
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
import com.dispose.security.annotation.Decryption;
|
||||
import com.dispose.security.annotation.Encryption;
|
||||
import com.dispose.service.MsgSerialService;
|
||||
import com.dispose.validation.group.ValidGroups;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.springframework.kafka.support.SendResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -51,8 +52,11 @@ public class kafkaController {
|
|||
@Resource
|
||||
private KafkaConfiguration kafkaConfiguration;
|
||||
|
||||
/**
|
||||
* The message serial service.
|
||||
*/
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
private MsgSerialService msgSerialService;
|
||||
|
||||
/**
|
||||
* Dispatch command sent to kafka.
|
||||
|
@ -78,8 +82,11 @@ public class kafkaController {
|
|||
rspInfo.setMessage(new String[]{ErrorCode.EMOS_CREATEMESSAGE_ERROR.getMsg()});
|
||||
return ProtocolRespDTO.result(ErrorCode.EMOS_CREATEMESSAGE_ERROR, rspInfo);
|
||||
}
|
||||
//推动数据格式到kafka
|
||||
|
||||
//保存数据格式到数据库
|
||||
log.info("send alarm :{}", content);
|
||||
|
||||
//推动数据格式到kafka
|
||||
ListenableFuture<SendResult<String, String>> sendResult = kafkaConfiguration
|
||||
.kafkaTemplate()
|
||||
.sendDefault(0, System.currentTimeMillis(), "dispose", content);
|
||||
|
@ -90,7 +97,6 @@ public class kafkaController {
|
|||
.topic(), v.getRecordMetadata().partition()),
|
||||
ex -> log.error("Kafka send error: {}", ex.getMessage()));
|
||||
|
||||
//保存数据格式到数据库
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
|
@ -102,13 +108,23 @@ public class kafkaController {
|
|||
*/
|
||||
private String createSendContent(EmosAlarmInfo alarmInfo) {
|
||||
try {
|
||||
//告警序号的最大值2^32-1
|
||||
long indexEnd = 4294967296L;
|
||||
//告警序号的最大值
|
||||
long indexStart = 1L;
|
||||
//编号从1开始,以实时消息发布通道为单位进行编号。如果编号超过最大正整数(2^32-1),重新从1开始编号。
|
||||
Long increment = stringRedisTemplate.opsForValue().increment("SEND_KAFKA_INCREMENT", 1);
|
||||
long increment = msgSerialService.getMaxMessageSerial();
|
||||
increment = increment + 1;
|
||||
if (increment > (indexEnd - 1)) {
|
||||
increment = indexStart;
|
||||
}
|
||||
MsgSerial msgSerial = MsgSerial.builder().msgSerial(increment).build();
|
||||
msgSerialService.addMessageSerial(msgSerial);
|
||||
|
||||
String dstIp = alarmInfo.getDstIp();
|
||||
String alarmId = alarmInfo.getAlarmId();
|
||||
//LocateInfo: 192.168.11.6 ddos attack alarm,Memcache , 2019-08-01 12:31, 2.1Gbps, 1.01Mpps
|
||||
String locateInfo = getAlarmEvent(alarmInfo);
|
||||
|
||||
String eventTime = alarmInfo.getStartTime();
|
||||
String cancelTime = alarmInfo.getEndTime();
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
|
||||
public interface MsgSerialManager {
|
||||
/**
|
||||
* Add user business error code.
|
||||
*
|
||||
* @param msgSerial the message serial
|
||||
*/
|
||||
void addMsgSerialNumber(MsgSerial msgSerial);
|
||||
|
||||
/**
|
||||
* get new max message serial.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
Long getMaxMsgSerial();
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import com.dispose.manager.MsgSerialManager;
|
||||
import com.dispose.mapper.MsgSerialMapper;
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MsgSerialManagerImpl implements MsgSerialManager {
|
||||
/**
|
||||
* The message serial mapper.
|
||||
*/
|
||||
@Resource
|
||||
private MsgSerialMapper msgSerialMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void addMsgSerialNumber(MsgSerial msgSerial) {
|
||||
msgSerialMapper.addMsgSerial(msgSerial);
|
||||
}
|
||||
|
||||
/**
|
||||
* get new max message serial.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
@Override
|
||||
public Long getMaxMsgSerial() {
|
||||
return msgSerialMapper.getMaxMsgSerial();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.dispose.mapper;
|
||||
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
|
||||
public interface MsgSerialMapper {
|
||||
|
||||
/**
|
||||
* Add new task int.
|
||||
*
|
||||
* @param msgSerial the msgSerial number
|
||||
* @return the int
|
||||
*/
|
||||
int addMsgSerial(MsgSerial msgSerial);
|
||||
|
||||
/**
|
||||
* get new max message serial.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
long getMaxMsgSerial();
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.dispose.pojo.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
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 capacity.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Table(name = "msg_serial")
|
||||
@NameStyle(Style.normal)
|
||||
public class MsgSerial 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 msgSerial;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
|
||||
public interface MsgSerialService {
|
||||
/**
|
||||
* add message serial.
|
||||
*
|
||||
* @param msgSerial the message serial
|
||||
*/
|
||||
void addMessageSerial(MsgSerial msgSerial);
|
||||
|
||||
/**
|
||||
* get new max message serial.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
Long getMaxMessageSerial();
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.manager.MsgSerialManager;
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
import com.dispose.service.MsgSerialService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class MsgSerialServiceImpl implements MsgSerialService {
|
||||
@Resource
|
||||
private MsgSerialManager msgSerialManager;
|
||||
|
||||
/**
|
||||
* add message serial.
|
||||
*
|
||||
* @param msgSerial the message serial
|
||||
*/
|
||||
@Override
|
||||
public void addMessageSerial(MsgSerial msgSerial) {
|
||||
msgSerialManager.addMsgSerialNumber(msgSerial);
|
||||
}
|
||||
|
||||
/**
|
||||
* get new max message serial.
|
||||
*
|
||||
* @return the long
|
||||
*/
|
||||
@Override
|
||||
public Long getMaxMessageSerial() {
|
||||
return msgSerialManager.getMaxMsgSerial();
|
||||
}
|
||||
}
|
|
@ -9,3 +9,11 @@ INSERT INTO `user_account`
|
|||
VALUES (1, 'admin', 'c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58', '2020-11-13 09:25:19', '',
|
||||
'2021-01-20 10:18:56', '1db9ddc47de514eb16b7ec07d7f7f96f7a714ae00e1209755bab30d543a0a2c3',
|
||||
'2021-01-20 10:20:57', '1970-01-02 00:00:00', 0, 0);
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of msg_serial
|
||||
-- ----------------------------
|
||||
INSERT INTO `msg_serial` VALUES ('1', '1');
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
SET
|
||||
FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for device_task
|
||||
|
@ -23,23 +24,23 @@ SET FOREIGN_KEY_CHECKS = 0;
|
|||
DROP TABLE IF EXISTS `device_task`;
|
||||
CREATE TABLE `device_task`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符',
|
||||
`taskId` bigint(11) NOT NULL COMMENT '处置任务唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间',
|
||||
`endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间',
|
||||
`taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型',
|
||||
`execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)',
|
||||
`attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)',
|
||||
`execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)',
|
||||
`attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)',
|
||||
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
|
||||
`errRetry` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
`devStatus` int(11) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符',
|
||||
`taskId` bigint(11) NOT NULL COMMENT '处置任务唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间',
|
||||
`endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间',
|
||||
`taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型',
|
||||
`execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)',
|
||||
`attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)',
|
||||
`execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)',
|
||||
`attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)',
|
||||
`externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID',
|
||||
`errRetry` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '任务状态',
|
||||
`devStatus` int(11) NOT NULL DEFAULT 0 COMMENT '设备任务状态',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_1` (`taskId`) USING BTREE,
|
||||
INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE,
|
||||
CONSTRAINT `device_task_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT `device_task_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE = InnoDB
|
||||
|
@ -54,15 +55,15 @@ CREATE TABLE `device_task`
|
|||
DROP TABLE IF EXISTS `dispose_capacity`;
|
||||
CREATE TABLE `dispose_capacity`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '设备ID',
|
||||
`capacityType` int(11) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n',
|
||||
`objectType` int(11) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL',
|
||||
`ipType` int(11) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '设备ID',
|
||||
`capacityType` int(11) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n',
|
||||
`objectType` int(11) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL',
|
||||
`ipType` int(11) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6',
|
||||
`protectIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '该处置能力能够处置的IP',
|
||||
`reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)',
|
||||
`reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `id` (`deviceId`) USING BTREE,
|
||||
INDEX `id` (`deviceId`) USING BTREE,
|
||||
CONSTRAINT `dispose_capacity_ibfk_1` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
|
@ -76,23 +77,23 @@ CREATE TABLE `dispose_capacity`
|
|||
DROP TABLE IF EXISTS `dispose_device`;
|
||||
CREATE TABLE `dispose_device`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符',
|
||||
`ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6',
|
||||
`ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口',
|
||||
`deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备',
|
||||
`areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码',
|
||||
`deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称',
|
||||
`manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商',
|
||||
`model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号',
|
||||
`version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本',
|
||||
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名',
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码',
|
||||
`urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径',
|
||||
`urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS',
|
||||
`readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符',
|
||||
`ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6',
|
||||
`ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口',
|
||||
`deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备',
|
||||
`areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码',
|
||||
`deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称',
|
||||
`manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商',
|
||||
`model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号',
|
||||
`version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本',
|
||||
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名',
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码',
|
||||
`urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径',
|
||||
`urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS',
|
||||
`readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注',
|
||||
`status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `ipAddr` (`ipAddr`) USING BTREE
|
||||
INDEX `ipAddr` (`ipAddr`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
CHARACTER SET = utf8
|
||||
|
@ -105,23 +106,23 @@ CREATE TABLE `dispose_device`
|
|||
DROP TABLE IF EXISTS `dispose_task`;
|
||||
CREATE TABLE `dispose_task`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`accountId` bigint(11) NOT NULL COMMENT '用户唯一标识符',
|
||||
`areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码',
|
||||
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符',
|
||||
`deviceId` bigint(11) NOT NULL COMMENT '处置设备唯一标识符',
|
||||
`accountId` bigint(11) NOT NULL COMMENT '用户唯一标识符',
|
||||
`areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码',
|
||||
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测',
|
||||
`disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象',
|
||||
`objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL',
|
||||
`objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL',
|
||||
`createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间',
|
||||
`planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '计划结束时间',
|
||||
`endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间',
|
||||
`flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向',
|
||||
`attackType` bigint(20) NOT NULL DEFAULT 0 COMMENT '攻击类型,默认0, 全部攻击',
|
||||
`flowBandWidth` int(11) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)',
|
||||
`currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动',
|
||||
`endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间',
|
||||
`flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向',
|
||||
`attackType` bigint(20) NOT NULL DEFAULT 0 COMMENT '攻击类型,默认0, 全部攻击',
|
||||
`flowBandWidth` int(11) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)',
|
||||
`currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `dispose_task_device_capacity_id_fk` (`disposeCapacity`) USING BTREE,
|
||||
INDEX `dispose_task_user_account_id_fk` (`accountId`) USING BTREE
|
||||
INDEX `dispose_task_device_capacity_id_fk` (`disposeCapacity`) USING BTREE,
|
||||
INDEX `dispose_task_user_account_id_fk` (`accountId`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
CHARACTER SET = utf8
|
||||
|
@ -134,10 +135,10 @@ CREATE TABLE `dispose_task`
|
|||
DROP TABLE IF EXISTS `service_group`;
|
||||
CREATE TABLE `service_group`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符',
|
||||
`serviceId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务ID',
|
||||
`serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME',
|
||||
`serviceBandwidth` int(11) NOT NULL DEFAULT 1 COMMENT '业务带宽,单位M',
|
||||
`serviceBandwidth` int(11) NOT NULL DEFAULT 1 COMMENT '业务带宽,单位M',
|
||||
`serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
|
@ -152,17 +153,17 @@ CREATE TABLE `service_group`
|
|||
DROP TABLE IF EXISTS `user_account`;
|
||||
CREATE TABLE `user_account`
|
||||
(
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号',
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号',
|
||||
`username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
|
||||
`password` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码',
|
||||
`createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
|
||||
`operators` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '操作员',
|
||||
`lastLoginTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '最后一次成功登录时间',
|
||||
`token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token',
|
||||
`token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token',
|
||||
`lastAccess` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后一次访问时间戳',
|
||||
`lockTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '账户锁定时间',
|
||||
`pwdErrTimes` int(11) NOT NULL DEFAULT 0 COMMENT '密码错误次数',
|
||||
`status` int(11) NULL DEFAULT 0 COMMENT '账户状态',
|
||||
`pwdErrTimes` int(11) NOT NULL DEFAULT 0 COMMENT '密码错误次数',
|
||||
`status` int(11) NULL DEFAULT 0 COMMENT '账户状态',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `USERNAME` (`username`) USING BTREE
|
||||
) ENGINE = InnoDB
|
||||
|
@ -171,4 +172,16 @@ CREATE TABLE `user_account`
|
|||
COLLATE = utf8_general_ci
|
||||
ROW_FORMAT = DYNAMIC;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
SET
|
||||
FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for msg_serial
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `msg_serial`;
|
||||
CREATE TABLE `msg_serial`
|
||||
(
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`msgSerial` bigint(20) NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?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.dispose.mapper.MsgSerialMapper">
|
||||
<resultMap id="msg_serial" type="com.dispose.pojo.entity.MsgSerial">
|
||||
<id column="id" property="id"/>
|
||||
<result column="msgSerial" property="msgSerial"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="addMsgSerial" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.dispose.pojo.entity.MsgSerial">
|
||||
INSERT
|
||||
IGNORE INTO msg_serial(msgSerial)
|
||||
VALUES (
|
||||
#{msgSerial}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="getMaxMsgSerial" resultType="java.lang.Long">
|
||||
SELECT msgSerial
|
||||
FROM msg_serial
|
||||
ORDER BY ID DESC LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,60 @@
|
|||
package com.dispose.test.dev.mapper;
|
||||
|
||||
import com.dispose.mapper.MsgSerialMapper;
|
||||
import com.dispose.pojo.entity.MsgSerial;
|
||||
import com.dispose.test.dev.Global.InitTestEnvironment;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The message serial test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
public class MsgSerialMapperTest extends InitTestEnvironment {
|
||||
|
||||
/**
|
||||
* The message serial mapper.
|
||||
*/
|
||||
@Resource
|
||||
MsgSerialMapper msgSerialMapper;
|
||||
|
||||
/**
|
||||
* A 1 add new message serial.
|
||||
*/
|
||||
@Test
|
||||
public void a1_addMsgSerial() {
|
||||
for (long i = 1L; i <= 10L; i++) {
|
||||
MsgSerial msgSerial = MsgSerial.builder()
|
||||
.msgSerial(i)
|
||||
.build();
|
||||
log.info("++++++++++++++++++MsgSerial {}", msgSerial.toString());
|
||||
msgSerialMapper.addMsgSerial(msgSerial);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void a2_getMaxMsgSerial() {
|
||||
for (long i = 1L; i <= 16L; i++) {
|
||||
MsgSerial msgSerial = MsgSerial.builder()
|
||||
.msgSerial(i)
|
||||
.build();
|
||||
msgSerialMapper.addMsgSerial(msgSerial);
|
||||
}
|
||||
long maxMsgSerial = msgSerialMapper.getMaxMsgSerial();
|
||||
log.info("+++++++++++++++++++ max MsgSerial {}", maxMsgSerial);
|
||||
Assert.assertEquals(maxMsgSerial, 16);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue