Merge branch 'v2.0.2_dev' into 'master'

V2.0.2 dev

See merge request DDOSAQ/phoenix_ddos_handle!12
This commit is contained in:
黄昕 2020-11-03 15:27:57 +08:00
commit 98aafca281
21 changed files with 211 additions and 85 deletions

View File

@ -216,6 +216,10 @@ public enum ErrorCode {
* The Err decrypt aes 256. * The Err decrypt aes 256.
*/ */
ERR_DECRYPT_AES256(111, "AES256解密失败"), ERR_DECRYPT_AES256(111, "AES256解密失败"),
/**
* The Err no device by areaCode.
*/
ERR_NODEVICE_AREACODE(111, "区域无该设备"),
; ;
/** /**

View File

@ -103,9 +103,9 @@ public class DisposeTaskController {
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType()); DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
String endTime = String.valueOf(req.getDisposeTime()); String endTime = String.valueOf(req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2)); Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);
@ -120,6 +120,7 @@ public class DisposeTaskController {
DisposeTask task = DisposeTask.builder() DisposeTask task = DisposeTask.builder()
.deviceId(devId) .deviceId(devId)
.accountId(aId) .accountId(aId)
.areaCode(v.getAreaCode() == null ? -1 : v.getAreaCode())
.disposeCapacity(capType) .disposeCapacity(capType)
.disposeObject(Helper.ipAddressNormalize(v.getDisposeObject())) .disposeObject(Helper.ipAddressNormalize(v.getDisposeObject()))
.objectType(t) .objectType(t)
@ -172,21 +173,22 @@ public class DisposeTaskController {
// 构造处置任务参数 // 构造处置任务参数
DisposeTask task = DisposeTask.builder() DisposeTask task = DisposeTask.builder()
.deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1"))) .deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1")))
.areaCode(-1)
.accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization")) .accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization"))
.get(0))) .get(0)))
.disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class, .disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class,
req.getType())) req.getType()))
.disposeObject(Helper.ipAddressNormalize(req.getDisposeIp())) .disposeObject(Helper.ipAddressNormalize(req.getDisposeIp()))
.objectType(DisposeObjectType.IP) .objectType(DisposeObjectType.IP)
.planEndTime(String.valueOf(req.getDisposeTime())) .planEndTime(String.valueOf(req.getDisposeTime()))
.flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class, .flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()) Optional.ofNullable(req.getFlowDirection())
.orElse(2))) .orElse(2)))
.attackType(DDoSAttackType.getTypeMaskFromAttackType( .attackType(DDoSAttackType.getTypeMaskFromAttackType(
Optional.ofNullable(req.getAttackType()) Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))) .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})))
.flowBandWidth(Optional.ofNullable(req.getFlowBandwidth()) .flowBandWidth(Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH)) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH))
.build(); .build();
// 创建处置任务 // 创建处置任务
@ -233,9 +235,9 @@ public class DisposeTaskController {
DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType()); DisposeCapacityType capType = CommonEnumHandler.codeOf(DisposeCapacityType.class, req.getType());
String endTime = String.valueOf(req.getDisposeTime()); String endTime = String.valueOf(req.getDisposeTime());
NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class,
Optional.ofNullable(req.getFlowDirection()).orElse(2)); Optional.ofNullable(req.getFlowDirection()).orElse(2));
Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType())
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}));
Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) Integer flowBand = Optional.ofNullable(req.getFlowBandwidth())
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH);
@ -248,6 +250,7 @@ public class DisposeTaskController {
DisposeTask task = DisposeTask.builder() DisposeTask task = DisposeTask.builder()
.deviceId(devId) .deviceId(devId)
.accountId(aId) .accountId(aId)
.areaCode(-1)
.disposeCapacity(capType) .disposeCapacity(capType)
.disposeObject(Helper.ipAddressNormalize(ip)) .disposeObject(Helper.ipAddressNormalize(ip))
.objectType(DisposeObjectType.IP) .objectType(DisposeObjectType.IP)
@ -308,9 +311,9 @@ public class DisposeTaskController {
// 停止成功 // 停止成功
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
rspInfo.setDisposeDevice(ret.getSecondParam().getDeviceTask().stream() rspInfo.setDisposeDevice(ret.getSecondParam().getDeviceTask().stream()
.map(DeviceTask::getDeviceId) .map(DeviceTask::getDeviceId)
.map(String::valueOf) .map(String::valueOf)
.toArray(String[]::new)); .toArray(String[]::new));
rspInfo.setType(ret.getSecondParam().getDisposeCapacity().getValue()); rspInfo.setType(ret.getSecondParam().getDisposeCapacity().getValue());
rspInfo.setDisposeIp(ret.getSecondParam().getDisposeObject()); rspInfo.setDisposeIp(ret.getSecondParam().getDisposeObject());
rspInfo.setLeftTime(String.valueOf(Math.abs( rspInfo.setLeftTime(String.valueOf(Math.abs(
@ -347,14 +350,14 @@ public class DisposeTaskController {
//获取TaskId列表 //获取TaskId列表
List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId()) List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId())
.orElse(new String[]{})) .orElse(new String[]{}))
.map(Long::parseLong) .map(Long::parseLong)
.collect(Collectors.toList()); .collect(Collectors.toList());
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret = MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret =
disposeTaskService.getPageDisposeTask(reqTaskIds, disposeTaskService.getPageDisposeTask(reqTaskIds,
mr.getMsgContent().getStartPage(), mr.getMsgContent().getStartPage(),
mr.getMsgContent().getPageSize()); mr.getMsgContent().getPageSize());
// 分页信息 // 分页信息
rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum()); rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum());
@ -404,7 +407,7 @@ public class DisposeTaskController {
} }
rspInfo.getItems().addAll(getTaskDetail.stream().sorted(Comparator.comparingLong((GetTaskDetail v) -> Long.parseLong(v.getTaskId()))) rspInfo.getItems().addAll(getTaskDetail.stream().sorted(Comparator.comparingLong((GetTaskDetail v) -> Long.parseLong(v.getTaskId())))
.collect(Collectors.toList())); .collect(Collectors.toList()));
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
} }

View File

@ -50,9 +50,18 @@ public interface DisposeDeviceManager {
Integer pageSize); Integer pageSize);
/** /**
* Gets all dispose devices. * Gets all normal dispose devices.
* *
* @return the all dispose devices * @return the all normal dispose devices
*/ */
List<DisposeDevice> getAllNormalDisposeDevices(); List<DisposeDevice> getAllNormalDisposeDevices();
/**
* Gets dispose devices.
*
* @param devId the dev id
* @param areaCode the area code
* @return the dispose devices
*/
List<DisposeDevice> getDisposeDevices(Long devId, Integer areaCode);
} }

View File

@ -19,11 +19,12 @@ public interface DisposeTaskManager {
* Gets dispose task. * Gets dispose task.
* *
* @param deviceId the device id * @param deviceId the device id
* @param areaCode the area code
* @param disposeIp the dispose ip * @param disposeIp the dispose ip
* @param capType the cap type * @param capType the cap type
* @return the dispose task * @return the dispose task
*/ */
DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType); DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType);
/** /**
* Add dispose task error code. * Add dispose task error code.
@ -65,16 +66,16 @@ public interface DisposeTaskManager {
DisposeTask getDisposeTaskById(Long taskId); DisposeTask getDisposeTaskById(Long taskId);
/** /**
* Gets dispose task by id. * Gets dispose tasks.
* *
* @return the dispose task list * @return the dispose tasks
*/ */
List<DisposeTask> getDisposeTasks(); List<DisposeTask> getDisposeTasks();
/** /**
* Gets pages of task. * Gets pages of task.
* *
* @param taskId the task id * @param taskId the task id
* @param startPage the start page * @param startPage the start page
* @param pageSize the page size * @param pageSize the page size
* @return the pages of task * @return the pages of task

View File

@ -264,14 +264,27 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
} }
/** /**
* Gets all dispose devices. * Gets all normal dispose devices.
* *
* @return the all dispose devices * @return the all normal dispose devices
*/ */
@Override @Override
public List<DisposeDevice> getAllNormalDisposeDevices() { public List<DisposeDevice> getAllNormalDisposeDevices() {
return disposeDeviceMapper.selectAll().stream() return disposeDeviceMapper.selectAll().stream()
.filter(v -> v.getStatus() == ObjectStatus.NORMAL) .filter(v -> v.getStatus() == ObjectStatus.NORMAL)
.collect(Collectors.toList()); .collect(Collectors.toList());
}
/**
* Gets dispose devices.
*
* @param devId the dev id
* @param areaCode the area code
* @return the dispose devices
*/
@Override
public List<DisposeDevice> getDisposeDevices(Long devId, Integer areaCode) {
return disposeDeviceMapper.getDeviceByAreaCode(devId, areaCode);
} }
} }

View File

@ -34,13 +34,14 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
* Gets dispose task. * Gets dispose task.
* *
* @param deviceId the device id * @param deviceId the device id
* @param areaCode the area code
* @param disposeIp the dispose ip * @param disposeIp the dispose ip
* @param capType the cap type * @param capType the cap type
* @return the dispose task * @return the dispose task
*/ */
@Override @Override
public DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType) { public DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType) {
return disposeTaskMapper.getRunningTask(deviceId, capType, disposeIp); return disposeTaskMapper.getRunningTask(deviceId, areaCode, capType, disposeIp);
} }
/** /**
@ -102,9 +103,9 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
} }
/** /**
* Gets dispose task by id. * Gets dispose tasks.
* *
* @return the dispose task list * @return the dispose tasks
*/ */
@Override @Override
public List<DisposeTask> getDisposeTasks() { public List<DisposeTask> getDisposeTasks() {
@ -114,7 +115,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
/** /**
* Gets pages of task. * Gets pages of task.
* *
* @param taskId the task id * @param taskId the task id
* @param startPage the start page * @param startPage the start page
* @param pageSize the page size * @param pageSize the page size
* @return the pages of task * @return the pages of task
@ -129,7 +130,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
// 设置分页信息 // 设置分页信息
PageHelper.startPage(startPage, pageSize); PageHelper.startPage(startPage, pageSize);
if(taskId.size() > 0) { if (taskId.size() > 0) {
preList = disposeTaskMapper.selectPageById(taskId); preList = disposeTaskMapper.selectPageById(taskId);
} else { } else {
preList = disposeTaskMapper.selectPageAll(); preList = disposeTaskMapper.selectPageAll();
@ -138,8 +139,8 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
pageInfo = new PageInfo<>(preList); pageInfo = new PageInfo<>(preList);
if(taskId.size() == 0){ if (taskId.size() == 0) {
return new MulReturnType<>(pageInfo, new ArrayList<>()); return new MulReturnType<>(pageInfo, new ArrayList<>());
} }
List<DisposeTask> taskList = new ArrayList<>(disposeTaskMapper.selectByIdSet(taskId)); List<DisposeTask> taskList = new ArrayList<>(disposeTaskMapper.selectByIdSet(taskId));

View File

@ -94,4 +94,13 @@ public interface DisposeDeviceMapper {
*/ */
DisposeDevice getDeviceById(@Param("id") Long id); DisposeDevice getDeviceById(@Param("id") Long id);
/**
* Gets deviceId by areaCode.
*
* @param areaCode the areaCode
* @return the list
*/
List<DisposeDevice> getDeviceByAreaCode(@Param("id") Long id, @Param("areaCode") Integer areaCode);
} }

View File

@ -86,6 +86,7 @@ public interface DisposeTaskMapper {
* @return the running task * @return the running task
*/ */
DisposeTask getRunningTask(@Param("deviceId") Long deviceId, DisposeTask getRunningTask(@Param("deviceId") Long deviceId,
@Param("areaCode") Integer areaCode,
@Param("capType") DisposeCapacityType capType, @Param("capType") DisposeCapacityType capType,
@Param("disposeObject") String disposeObject); @Param("disposeObject") String disposeObject);

View File

@ -38,4 +38,9 @@ public class DisposeObject {
@NotNull(message = "objectType 处置类型不能为空", groups = ValidGroups.TaskStartReqValid.class) @NotNull(message = "objectType 处置类型不能为空", groups = ValidGroups.TaskStartReqValid.class)
@ValidBaseEnum(enumClass = DisposeObjectType.class, groups = ValidGroups.TaskStartReqValid.class) @ValidBaseEnum(enumClass = DisposeObjectType.class, groups = ValidGroups.TaskStartReqValid.class)
private Integer objectType; private Integer objectType;
/**
* The Area code.
*/
private Integer areaCode;
} }

View File

@ -52,6 +52,10 @@ public class DisposeTask implements Serializable {
* The Account id. * The Account id.
*/ */
private Long accountId; private Long accountId;
/**
* The Area code.
*/
private Integer areaCode;
/** /**
* The Dispose capacity. * The Dispose capacity.
*/ */

View File

@ -55,4 +55,13 @@ public interface DisposeDeviceManagerService {
* @return the all dispose device * @return the all dispose device
*/ */
List<DisposeDevice> getAllDisposeDevice(); List<DisposeDevice> getAllDisposeDevice();
/**
* Gets dispose device by area code.
*
* @param devId the dev id
* @param areaCode the area code
* @return the dispose device by area code
*/
List<DisposeDevice> getDisposeDeviceByAreaCode(Long devId, Integer areaCode);
} }

View File

@ -531,9 +531,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
disposeAbilityRouterService.getAllAbilityDevices().stream() disposeAbilityRouterService.getAllAbilityDevices().stream()
// 判断是否是当前设备的处置任务 // 判断是否是当前设备的处置任务
.filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId())) .filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId()))
// 判断是否是当前区域处置
.filter(f -> v.getAreaCode() == -1 || f.getDev().getAreaCode().equals(v.getAreaCode()))
// 当前设备是否支持该处置能力 // 当前设备是否支持该处置能力
.filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v .filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v
.getDisposeCapacity())) .getDisposeCapacity()))
// 当前设备是否支持处置该IP
.filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject())) .filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject()))
.forEach(d -> { .forEach(d -> {
log.info("Add dispose task for device: {}", d.getDev()); log.info("Add dispose task for device: {}", d.getDev());

View File

@ -89,7 +89,7 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
DisposeDevice dev = new DisposeDevice(); DisposeDevice dev = new DisposeDevice();
MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v, MulReturnType<ErrorCode, ObjectStatus> ret = disposeDeviceManager.changeDisposeDeviceStatus(v,
ObjectStatus.DELETED); ObjectStatus.DELETED);
dev.setId(v); dev.setId(v);
dev.setStatus(ret.getSecondParam()); dev.setStatus(ret.getSecondParam());
@ -128,4 +128,22 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
return disposeDevices; return disposeDevices;
} }
} }
/**
* Gets dispose device by area code.
*
* @param devId the dev id
* @param areaCode the area code
* @return the dispose device by area code
*/
@Override
public List<DisposeDevice> getDisposeDeviceByAreaCode(Long devId, Integer areaCode) {
List<DisposeDevice> disposeDevices = disposeDeviceManager.getDisposeDevices(devId, areaCode);
if (disposeDevices == null) {
return new ArrayList<>();
} else {
return disposeDevices;
}
}
} }

View File

@ -3,9 +3,11 @@ package com.dispose.service.impl;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.manager.DisposeTaskManager; import com.dispose.manager.DisposeTaskManager;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.entity.DisposeTask; import com.dispose.pojo.entity.DisposeTask;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
import com.dispose.service.DisposeDeviceManagerService;
import com.dispose.service.DisposeTaskService; import com.dispose.service.DisposeTaskService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -32,6 +34,12 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
@Resource @Resource
DisposeAbilityRouterService disposeAbilityRouterService; DisposeAbilityRouterService disposeAbilityRouterService;
/**
* The Dispose device manager service.
*/
@Resource
DisposeDeviceManagerService disposeDeviceManagerService;
/** /**
* Create task mul return type. * Create task mul return type.
* *
@ -40,23 +48,31 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
*/ */
@Override @Override
public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) { public MulReturnType<ErrorCode, DisposeTask> createTask(DisposeTask task) {
DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(),
task.getDisposeObject(), task.getDisposeCapacity()); task.getDisposeObject(), task.getDisposeCapacity());
if (exitTask != null) { if (exitTask != null) {
return new MulReturnType<>(ErrorCode.ERR_TASKRUNNING, exitTask); return new MulReturnType<>(ErrorCode.ERR_TASKRUNNING, exitTask);
} }
ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity( ErrorCode err = disposeAbilityRouterService.verifyDisposeCapacity(
task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity() task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity()
); );
if (err != ErrorCode.ERR_OK) { if (err != ErrorCode.ERR_OK) {
return new MulReturnType<>(err, task); return new MulReturnType<>(err, task);
} }
return new MulReturnType<>(disposeTaskManager.addDisposeTask(task), //areaCode获取对应的deviceId
disposeTaskManager.getDisposeTaskById(task.getId())); List<DisposeDevice> devices = disposeDeviceManagerService.getDisposeDeviceByAreaCode(task.getDeviceId(),
task.getAreaCode());
if (devices.size() == 0) {
return new MulReturnType<>(ErrorCode.ERR_NODEVICE_AREACODE, task);
} else {
return new MulReturnType<>(disposeTaskManager.addDisposeTask(task),
disposeTaskManager.getDisposeTaskById(task.getId()));
}
} }
/** /**

View File

@ -107,6 +107,7 @@ CREATE TABLE `dispose_task`
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符',
`deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符',
`accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符',
`areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码',
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测', `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测',
`disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象',
`objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0IP\r\n1域名 \r\n2URL', `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0IP\r\n1域名 \r\n2URL',

View File

@ -35,15 +35,15 @@
<select id="selectByIdSet" resultMap="dispose_device"> <select id="selectByIdSet" resultMap="dispose_device">
SELECT d.*, SELECT d.*,
c.id c_id, c.id c_id,
c.deviceId deviceId, c.deviceId deviceId,
c.capacityType capacityType, c.capacityType capacityType,
c.objectType objectType, c.objectType objectType,
c.ipType ipType, c.ipType ipType,
c.protectIp protectIp, c.protectIp protectIp,
c.reserveNetflow reserveNetflow c.reserveNetflow reserveNetflow
FROM dispose_device d FROM dispose_device d
LEFT JOIN dispose_capacity c ON d.id = c.deviceId LEFT JOIN dispose_capacity c ON d.id = c.deviceId
WHERE d.id IN WHERE d.id IN
<foreach collection="idList" item="id" index="index" open="(" close=")" separator=","> <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
#{id} #{id}
@ -129,4 +129,23 @@
SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()} SET status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
WHERE id = #{id} WHERE id = #{id}
</update> </update>
</mapper>
<select id="getDeviceByAreaCode" resultMap="dispose_device">
SELECT d.*,
c.id c_id,
c.deviceId deviceId,
c.capacityType capacityType,
c.objectType objectType,
c.ipType ipType,
c.protectIp protectIp,
c.reserveNetflow reserveNetflow
FROM dispose_device d
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
<if test="areaCode != -1">
WHERE d.areaCode = #{areaCode}
<if test="id != -1">
AND d.id = #{id}
</if>
</if>
</select>
</mapper>

View File

@ -5,6 +5,7 @@
<id column="id" property="id"/> <id column="id" property="id"/>
<id column="deviceId" property="deviceId"/> <id column="deviceId" property="deviceId"/>
<id column="accountId" property="accountId"/> <id column="accountId" property="accountId"/>
<result column="areaCode" property="areaCode"/>
<result column="disposeCapacity" property="disposeCapacity" javaType="com.dispose.common.DisposeCapacityType"/> <result column="disposeCapacity" property="disposeCapacity" javaType="com.dispose.common.DisposeCapacityType"/>
<result column="disposeObject" property="disposeObject"/> <result column="disposeObject" property="disposeObject"/>
<result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/> <result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/>
@ -121,6 +122,9 @@
<if test="deviceId != -1"> <if test="deviceId != -1">
AND dt.deviceId = #{deviceId} AND dt.deviceId = #{deviceId}
</if> </if>
<if test="areaCode != -1">
AND dt.areaCode = #{areaCode}
</if>
</select> </select>
<select id="getNewTask" resultType="com.dispose.pojo.entity.DisposeTask"> <select id="getNewTask" resultType="com.dispose.pojo.entity.DisposeTask">
@ -140,10 +144,10 @@
<insert id="addNewTask" useGeneratedKeys="true" keyProperty="id" <insert id="addNewTask" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.DisposeTask"> parameterType="com.dispose.pojo.entity.DisposeTask">
INSERT IGNORE INTO dispose_task(deviceId, accountId, disposeCapacity, disposeObject, objectType, INSERT IGNORE INTO dispose_task(deviceId, accountId, areaCode, disposeCapacity, disposeObject, objectType,
planEndTime, flowDirection, attackType, flowBandWidth, planEndTime, flowDirection, attackType, flowBandWidth,
currentStatus) currentStatus)
VALUES (#{deviceId}, #{accountId}, #{disposeCapacity}, #{disposeObject}, #{objectType}, VALUES (#{deviceId}, #{accountId}, #{areaCode}, #{disposeCapacity}, #{disposeObject}, #{objectType},
date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType}, date_add(now(), interval #{planEndTime} MINUTE), #{flowDirection}, #{attackType},
#{flowBandWidth}, ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}) #{flowBandWidth}, ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()})
</insert> </insert>

View File

@ -146,6 +146,7 @@ CREATE TABLE `dispose_task`
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符',
`deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符',
`accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符',
`areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码',
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测', `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测',
`disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象',
`objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0IP\r\n1域名 \r\n2URL', `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0IP\r\n1域名 \r\n2URL',
@ -169,10 +170,11 @@ CREATE TABLE `dispose_task`
-- Records of dispose_task -- Records of dispose_task
-- ---------------------------- -- ----------------------------
INSERT INTO `dispose_task` INSERT INTO `dispose_task`
VALUES (1, -1, 1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, VALUES (1, -1, 1, -1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2,
8796093022207,
1024, 0); 1024, 0);
INSERT INTO `dispose_task` INSERT INTO `dispose_task`
VALUES (2, -1, 1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, VALUES (2, -1, 1, -1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207,
1024, 0); 1024, 0);
-- ---------------------------- -- ----------------------------

View File

@ -76,8 +76,8 @@ public class DisposeTaskManagerTest extends InitTestEnvironment {
@Test @Test
public void a1_disposeIpRunning() { public void a1_disposeIpRunning() {
disposeTaskMapper.selectAll().forEach(v -> { disposeTaskMapper.selectAll().forEach(v -> {
DisposeTask runningResult = disposeTaskManager.getDisposeTask(v.getDeviceId(), v.getDisposeObject(), DisposeTask runningResult = disposeTaskManager.getDisposeTask(v.getDeviceId(), v.getAreaCode(),
v.getDisposeCapacity()); v.getDisposeObject(), v.getDisposeCapacity());
log.info("runningResult-->{}", runningResult); log.info("runningResult-->{}", runningResult);

View File

@ -125,25 +125,25 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
*/ */
@Test @Test
public void a3_getRunningTask() throws JsonProcessingException { public void a3_getRunningTask() throws JsonProcessingException {
DisposeTask taskList = disposeTaskMapper.getRunningTask(-1L, DisposeTask taskList = disposeTaskMapper.getRunningTask(-1L, -1,
DisposeCapacityType.CLEANUP, DisposeCapacityType.CLEANUP,
"192.168.0.1"); "192.168.0.1");
log.info("Step1: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); log.info("Step1: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
taskList = disposeTaskMapper.getRunningTask(570L, taskList = disposeTaskMapper.getRunningTask(570L, -1,
DisposeCapacityType.CLEANUP, DisposeCapacityType.CLEANUP,
"192.168.0.1"); "192.168.0.1");
log.info("Step2: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); log.info("Step2: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
taskList = disposeTaskMapper.getRunningTask(-1L, taskList = disposeTaskMapper.getRunningTask(-1L, -1,
DisposeCapacityType.HIDEPEND, DisposeCapacityType.HIDEPEND,
"192.168.0.1"); "192.168.0.1");
log.info("Step3: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); log.info("Step3: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
taskList = disposeTaskMapper.getRunningTask(-1L, taskList = disposeTaskMapper.getRunningTask(-1L, -1,
DisposeCapacityType.HIDEPEND, DisposeCapacityType.HIDEPEND,
"192.168.0.12"); "192.168.0.12");

View File

@ -83,7 +83,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
@Before @Before
public void userLoginTest() throws NoSuchAlgorithmException { public void userLoginTest() throws NoSuchAlgorithmException {
MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(), MulReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
getPASSWORD()); getPASSWORD());
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
DisposeTaskServiceTest.token = ret.getSecondParam(); DisposeTaskServiceTest.token = ret.getSecondParam();
@ -114,19 +114,24 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(ret.getSecondParam()); Assert.assertNotNull(ret.getSecondParam());
Assert.assertEquals(String.valueOf(ret.getSecondParam().getDisposeCapacity()), String.valueOf(DisposeCapacityType.CLEANUP)); Assert.assertEquals(String.valueOf(ret.getSecondParam()
.getDisposeCapacity()),
String.valueOf(DisposeCapacityType.CLEANUP));
} else { } else {
Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode()); Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode());
} }
disposeTaskManager.getExpiredTasks().forEach(v->{ disposeTaskManager.getExpiredTasks().forEach(v -> {
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_NEW); disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_NEW);
MulReturnType<ErrorCode, DisposeTask> result = disposeTaskService.createTask(v); MulReturnType<ErrorCode, DisposeTask> result = disposeTaskService.createTask(v);
Assert.assertEquals(result.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode()); Assert.assertEquals(result.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode());
Assert.assertEquals(result.getSecondParam().getId(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(), Assert.assertEquals(result.getSecondParam().getId(),
newTask.getDisposeObject(), newTask.getDisposeCapacity()).getId()); disposeTaskManager.getDisposeTask(newTask.getDeviceId(), v.getAreaCode(),
newTask.getDisposeObject(),
newTask.getDisposeCapacity())
.getId());
}); });
} }
@ -134,7 +139,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
* creat task mul return type. * creat task mul return type.
*/ */
@Test @Test
public void a2_stopTask(){ public void a2_stopTask() {
DisposeTask newTask = DisposeTask.builder() DisposeTask newTask = DisposeTask.builder()
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
.accountId(1L) .accountId(1L)
@ -149,7 +154,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
disposeTaskService.createTask(newTask); disposeTaskService.createTask(newTask);
disposeTaskManager.getExpiredTasks().forEach(v->{ disposeTaskManager.getExpiredTasks().forEach(v -> {
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(v.getId()); MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(v.getId());
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_TASKNOTRUNNING); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_TASKNOTRUNNING);
@ -157,23 +162,24 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
}); });
disposeTaskManager.getNewDisposeTasks().forEach(k->{ disposeTaskManager.getNewDisposeTasks().forEach(k -> {
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(k.getId()); MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(k.getId());
if(ret.getFirstParam() == ErrorCode.ERR_OK){ if (ret.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(ret.getSecondParam()); Assert.assertNotNull(ret.getSecondParam());
Assert.assertEquals(disposeTaskManager.getDisposeTaskById(k.getId()).getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED); Assert.assertEquals(disposeTaskManager.getDisposeTaskById(k.getId())
}else{ .getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED);
Assert.assertNull(ret.getSecondParam()); } else {
} Assert.assertNull(ret.getSecondParam());
}); }
});
} }
/** /**
* get dispose task. * get dispose task.
*/ */
@Test @Test
public void a3_getDisposeTask(){ public void a3_getDisposeTask() {
DisposeTask newTask = DisposeTask.builder() DisposeTask newTask = DisposeTask.builder()
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
.accountId(1L) .accountId(1L)
@ -188,7 +194,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
disposeTaskService.createTask(newTask); disposeTaskService.createTask(newTask);
disposeTaskManager.getNewDisposeTasks().forEach(v->{ disposeTaskManager.getNewDisposeTasks().forEach(v -> {
DisposeTask task = disposeTaskService.getDisposeTask(v.getId()); DisposeTask task = disposeTaskService.getDisposeTask(v.getId());
Assert.assertNotNull(task); Assert.assertNotNull(task);
Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_NEW); Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_NEW);
@ -201,15 +207,15 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
*/ */
@Test @Test
public void a4_stopTaskTest() { public void a4_stopTaskTest() {
if(disposeTaskManager.getNewDisposeTasks().size() == 0){ if (disposeTaskManager.getNewDisposeTasks().size() == 0) {
return; return;
} }
Long taskId = disposeTaskManager.getNewDisposeTasks().get(0).getId(); Long taskId = disposeTaskManager.getNewDisposeTasks().get(0).getId();
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(taskId-1); MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.stopTask(taskId - 1);
if (ret.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) { if (ret.getFirstParam() == ErrorCode.ERR_NOSUCHTASK) {
Assert.assertNull(disposeTaskManager.getDisposeTaskById(taskId-1)); Assert.assertNull(disposeTaskManager.getDisposeTaskById(taskId - 1));
} }
ret = disposeTaskService.stopTask(taskId); ret = disposeTaskService.stopTask(taskId);
@ -219,14 +225,12 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
if (ret.getFirstParam() == ErrorCode.ERR_TASKNOTRUNNING) { if (ret.getFirstParam() == ErrorCode.ERR_TASKNOTRUNNING) {
Assert.assertNotNull(task); Assert.assertNotNull(task);
Assert.assertFalse(task.getCurrentStatus().taskIsRunning()); Assert.assertFalse(task.getCurrentStatus().taskIsRunning());
} } else if (ret.getFirstParam() == ErrorCode.ERR_DATABASE) {
else if(ret.getFirstParam() == ErrorCode.ERR_DATABASE){
Assert.assertNull(task); Assert.assertNull(task);
Assert.assertFalse(disposeTaskManager.changeDisposeTaskStatus(taskId, DisposeTaskStatus.TASK_CANCELED)); Assert.assertFalse(disposeTaskManager.changeDisposeTaskStatus(taskId, DisposeTaskStatus.TASK_CANCELED));
} } else if (ret.getFirstParam() == ErrorCode.ERR_OK) {
else if(ret.getFirstParam() == ErrorCode.ERR_OK){
Assert.assertNotNull(task); Assert.assertNotNull(task);
Assert.assertEquals(task.getCurrentStatus(),DisposeTaskStatus.TASK_CANCELED); Assert.assertEquals(task.getCurrentStatus(), DisposeTaskStatus.TASK_CANCELED);
} }
} }
} }