REM:
1. 备份代码
This commit is contained in:
HuangXin 2020-09-27 14:36:03 +08:00
parent 6667ae9735
commit f7599efa4b
15 changed files with 126 additions and 114 deletions

View File

@ -18,7 +18,7 @@
</parent> </parent>
<groupId>com.dispose</groupId> <groupId>com.dispose</groupId>
<artifactId>phoenix_ddos_handle</artifactId> <artifactId>phoenix_ddos_handle</artifactId>
<version>2.0.0</version> <version>2.0.1</version>
<name>phoenix_ddos_handle</name> <name>phoenix_ddos_handle</name>
<description>Dispose Platform</description> <description>Dispose Platform</description>
<dependencies> <dependencies>

View File

@ -4,6 +4,7 @@ import com.dispose.common.CommonEnumHandler;
import com.dispose.common.DDoSAttackType; import com.dispose.common.DDoSAttackType;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
@ -96,30 +97,31 @@ 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")))
.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()))
.disposeIp(Helper.ipAddressNormalize(req.getDisposeIp())) .disposeObject(Helper.ipAddressNormalize(req.getDisposeIp()))
.planEndTime(String.valueOf(req.getDisposeTime())) .objectType(DisposeObjectType.IP)
.flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class, .planEndTime(String.valueOf(req.getDisposeTime()))
Optional.ofNullable(req.getFlowDirection()) .flowDirection(CommonEnumHandler.codeOf(NetflowDirection.class,
.orElse(2))) Optional.ofNullable(req.getFlowDirection())
.attackType(DDoSAttackType.getTypeMaskFromAttackType( .orElse(2)))
Optional.ofNullable(req.getAttackType()) .attackType(DDoSAttackType.getTypeMaskFromAttackType(
.orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))) Optional.ofNullable(req.getAttackType())
.flowBandWidth(Optional.ofNullable(req.getFlowBandwidth()) .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})))
.orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH)) .flowBandWidth(Optional.ofNullable(req.getFlowBandwidth())
.build(); .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH))
.build();
// 创建处置任务 // 创建处置任务
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.createTask(task); MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.createTask(task);
// 设置返回消息 // 设置返回消息
TaskStartRsp rspInfo = TaskStartRsp.builder() TaskStartRsp rspInfo = TaskStartRsp.builder()
.disposeIp(task.getDisposeIp()) .disposeIp(task.getDisposeObject())
.build(); .build();
rspInfo.setStatus(ret.getFirstParam().getCode()); rspInfo.setStatus(ret.getFirstParam().getCode());
rspInfo.setMessage(new String[]{ret.getFirstParam().getMsg()}); rspInfo.setMessage(new String[]{ret.getFirstParam().getMsg()});
@ -157,40 +159,41 @@ 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);
TaskStartMulRsp mulRsp = TaskStartMulRsp.builder() TaskStartMulRsp mulRsp = TaskStartMulRsp.builder()
.items(new ArrayList<>()) .items(new ArrayList<>())
.build(); .build();
for (String ip : req.getMulDisposeIp()) { for (String ip : req.getMulDisposeIp()) {
// 构造处置任务参数 // 构造处置任务参数
DisposeTask task = DisposeTask.builder() DisposeTask task = DisposeTask.builder()
.deviceId(devId) .deviceId(devId)
.accountId(aId) .accountId(aId)
.disposeCapacity(capType) .disposeCapacity(capType)
.disposeIp(Helper.ipAddressNormalize(ip)) .disposeObject(Helper.ipAddressNormalize(ip))
.planEndTime(endTime) .objectType(DisposeObjectType.IP)
.flowDirection(netDir) .planEndTime(endTime)
.attackType(attackType) .flowDirection(netDir)
.flowBandWidth(flowBand) .attackType(attackType)
.build(); .flowBandWidth(flowBand)
.build();
// 创建处置任务 // 创建处置任务
MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.createTask(task); MulReturnType<ErrorCode, DisposeTask> ret = disposeTaskService.createTask(task);
// 设置返回消息 // 设置返回消息
TaskStartRsp rspInfo = TaskStartRsp.builder() TaskStartRsp rspInfo = TaskStartRsp.builder()
.disposeIp(ip) .disposeIp(ip)
.build(); .build();
// 启动任务成功 // 启动任务成功
if (ret.getFirstParam() == ErrorCode.ERR_OK || if (ret.getFirstParam() == ErrorCode.ERR_OK ||
ret.getFirstParam() == ErrorCode.ERR_TASKRUNNING) { ret.getFirstParam() == ErrorCode.ERR_TASKRUNNING) {
rspInfo.setTaskId(ret.getSecondParam().getId().toString()); rspInfo.setTaskId(ret.getSecondParam().getId().toString());
rspInfo.setExpireTime(ret.getSecondParam().getPlanEndTime()); rspInfo.setExpireTime(ret.getSecondParam().getPlanEndTime());
} }
@ -231,13 +234,13 @@ 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().getDisposeIp()); rspInfo.setDisposeIp(ret.getSecondParam().getDisposeObject());
rspInfo.setLeftTime(String.valueOf(Math.abs( rspInfo.setLeftTime(String.valueOf(Math.abs(
Helper.getTimestampDiffNow(ret.getSecondParam().getPlanEndTime())) / 60)); Helper.getTimestampDiffNow(ret.getSecondParam().getPlanEndTime())) / 60));
} }
rspInfo.setTaskId(tId); rspInfo.setTaskId(tId);
@ -260,26 +263,27 @@ public class DisposeTaskController {
@ResponseBody @ResponseBody
@ApiOperation("获取处置任务") @ApiOperation("获取处置任务")
public ProtocolRespDTO<GetTaskRsp> getAllDisposeTask( public ProtocolRespDTO<GetTaskRsp> getAllDisposeTask(
@Validated(ValidGroups.ProtocolCommonValid.class) @Validated(ValidGroups.ProtocolCommonValid.class)
@RequestBody ProtocolReqDTO<BasePagesGetReq> mr @RequestBody ProtocolReqDTO<BasePagesGetReq> mr
) { ) {
GetTaskRsp rspInfo = GetTaskRsp.builder().build(); GetTaskRsp rspInfo = GetTaskRsp.builder().build();
List<GetTaskDetail> getTaskDetail = new ArrayList<>(); List<GetTaskDetail> getTaskDetail = new ArrayList<>();
//获取TaskId列表 //获取TaskId列表
List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId()).orElse(new String[]{})). List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId())
map(Long::parseLong).collect(Collectors.toList()); .orElse(new String[]{})).
map(Long::parseLong).collect(Collectors.toList());
//获取所有可用处置任务 //获取所有可用处置任务
List<DisposeTask> taskList = disposeTaskService.getAllDisposeTask(); List<DisposeTask> taskList = disposeTaskService.getAllDisposeTask();
List<Long> idArray = taskList.stream().filter(v -> reqTaskIds.size() == 0 || reqTaskIds.contains(v.getId())) List<Long> idArray = taskList.stream().filter(v -> reqTaskIds.size() == 0 || reqTaskIds.contains(v.getId()))
.map(DisposeTask::getId).collect(Collectors.toList()); .map(DisposeTask::getId).collect(Collectors.toList());
if (idArray.size() > 0) { if (idArray.size() > 0) {
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret = MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret =
disposeTaskService.getPageDisposeTask(idArray, disposeTaskService.getPageDisposeTask(idArray,
mr.getMsgContent().getStartPage(), mr.getMsgContent().getStartPage(),
mr.getMsgContent().getPageSize()); mr.getMsgContent().getPageSize());
// 分页信息 // 分页信息
rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum()); rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum());
@ -289,29 +293,29 @@ public class DisposeTaskController {
ret.getSecondParam().forEach(v -> { ret.getSecondParam().forEach(v -> {
GetTaskDetail taskDetail = GetTaskDetail.builder() GetTaskDetail taskDetail = GetTaskDetail.builder()
.taskId(String.valueOf(v.getId())) .taskId(String.valueOf(v.getId()))
.accountId(String.valueOf(v.getAccountId())) .accountId(String.valueOf(v.getAccountId()))
.disposeCapacity(v.getDisposeCapacity().getValue()) .disposeCapacity(v.getDisposeCapacity().getValue())
.disposeIp(v.getDisposeIp()) .disposeIp(v.getDisposeObject())
.createTime(v.getCreateTime()) .createTime(v.getCreateTime())
.planEndTime(v.getPlanEndTime()) .planEndTime(v.getPlanEndTime())
.endTime(v.getEndTime()) .endTime(v.getEndTime())
.flowDirection(v.getFlowDirection().getValue()) .flowDirection(v.getFlowDirection().getValue())
.attackType(v.getAttackType().toString()) .attackType(v.getAttackType().toString())
.flowBandWidth(v.getFlowBandWidth()) .flowBandWidth(v.getFlowBandWidth())
.currentStatus(v.getCurrentStatus().getValue()) .currentStatus(v.getCurrentStatus().getValue())
.deviceTask(new ArrayList<>()) .deviceTask(new ArrayList<>())
.build(); .build();
taskDetail.setStatus(ErrorCode.ERR_OK.getCode()); taskDetail.setStatus(ErrorCode.ERR_OK.getCode());
taskDetail.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()}); taskDetail.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
v.getDeviceTask().forEach(k -> { v.getDeviceTask().forEach(k -> {
GetDeviceTaskDetail deviceTaskDetail = GetDeviceTaskDetail.builder() GetDeviceTaskDetail deviceTaskDetail = GetDeviceTaskDetail.builder()
.devTaskId(String.valueOf(k.getId())) .devTaskId(String.valueOf(k.getId()))
.devId(String.valueOf(k.getDeviceId())) .devId(String.valueOf(k.getDeviceId()))
.externId(String.valueOf(k.getExternId())) .externId(String.valueOf(k.getExternId()))
.status(k.getStatus()) .status(k.getStatus())
.build(); .build();
taskDetail.getDeviceTask().add(deviceTaskDetail); taskDetail.getDeviceTask().add(deviceTaskDetail);
}); });
@ -322,19 +326,19 @@ public class DisposeTaskController {
// 设置不存在taskId的错误码 // 设置不存在taskId的错误码
if (reqTaskIds.stream().anyMatch(v -> taskList.stream().noneMatch(k -> k.getId().equals(v)))) { if (reqTaskIds.stream().anyMatch(v -> taskList.stream().noneMatch(k -> k.getId().equals(v)))) {
reqTaskIds.stream() reqTaskIds.stream()
.filter(v -> taskList.stream().noneMatch(k -> k.getId().equals(v))) .filter(v -> taskList.stream().noneMatch(k -> k.getId().equals(v)))
.forEach(v -> { .forEach(v -> {
GetTaskDetail td = GetTaskDetail.builder().build(); GetTaskDetail td = GetTaskDetail.builder().build();
td.setTaskId(String.valueOf(v)); td.setTaskId(String.valueOf(v));
td.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); td.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
td.setMessage(new String[]{ErrorCode.ERR_NOSUCHTASK.getMsg()}); td.setMessage(new String[]{ErrorCode.ERR_NOSUCHTASK.getMsg()});
getTaskDetail.add(td); getTaskDetail.add(td);
}); });
} }
// 对返回的信息按照TaskID排序 // 对返回的信息按照TaskID排序
rspInfo.setItems(getTaskDetail.stream().sorted(Comparator.comparing(GetTaskDetail::getTaskId)) rspInfo.setItems(getTaskDetail.stream().sorted(Comparator.comparing(GetTaskDetail::getTaskId))
.collect(Collectors.toList())); .collect(Collectors.toList()));
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
} }

View File

@ -1,6 +1,7 @@
package com.dispose.pojo.entity; package com.dispose.pojo.entity;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@ -56,9 +57,13 @@ public class DisposeTask implements Serializable {
*/ */
private DisposeCapacityType disposeCapacity; private DisposeCapacityType disposeCapacity;
/** /**
* The Dispose ip. * The Dispose object.
*/ */
private String disposeIp; private String disposeObject;
/**
* The Object type.
*/
private DisposeObjectType objectType;
/** /**
* The Create time. * The Create time.
*/ */
@ -88,7 +93,7 @@ public class DisposeTask implements Serializable {
*/ */
private DisposeTaskStatus currentStatus; private DisposeTaskStatus currentStatus;
/** /**
* The Task info. * The Device task.
*/ */
private List<DeviceTask> deviceTask; private List<DeviceTask> deviceTask;
} }

View File

@ -68,7 +68,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTask.getTaskAttackType()); deviceTask.getTaskAttackType());
// 调用设备执行处置任务 // 调用设备执行处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), null, null, null); ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果 // 设置攻击类型任务启动结果
@ -97,7 +97,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
MulReturnType<ErrorCode, Long> ret; MulReturnType<ErrorCode, Long> ret;
// 调用设备执行处置任务 // 调用设备执行处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), null, null, null); ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),disposeTask.getFlowDirection(), 0L); deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),disposeTask.getFlowDirection(), 0L);
@ -132,7 +132,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI, deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType()); deviceTask.getTaskAttackType());
ret = ai.getDb().runDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), null, null, ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
(long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60)); (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -175,7 +175,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
MulReturnType<ErrorCode, Long> ret; MulReturnType<ErrorCode, Long> ret;
// 停止处置任务 // 停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), null, null, ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
deviceTask.getExternId()); deviceTask.getExternId());
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -219,7 +219,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue()); t.getValue());
// 调用迪普设备启动处置任务 // 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_OUT, t.getValue(), null); NetflowDirection.DIRECTION_OUT, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -256,7 +256,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue()); t.getValue());
// 调用迪普设备启动处置任务 // 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_IN, t.getValue(), null); NetflowDirection.DIRECTION_IN, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -331,7 +331,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 出方向 // 出方向
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) {
// 调用迪普设备停止处置任务 // 调用迪普设备停止处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_OUT, t.getValue(), null); NetflowDirection.DIRECTION_OUT, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -357,7 +357,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 入方向 // 入方向
if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) {
// 调用迪普设备启动处置任务 // 调用迪普设备启动处置任务
ret = ai.getDb().stopDispose(disposeTask.getDisposeIp(), disposeTask.getDisposeCapacity(), ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_IN, t.getValue(), null); NetflowDirection.DIRECTION_IN, t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) { if (ret.getFirstParam() == ErrorCode.ERR_OK) {
@ -421,7 +421,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 清理过期任务 // 清理过期任务
for (DisposeTask v : disposeTaskManager.getExpiredTasks()) { for (DisposeTask v : disposeTaskManager.getExpiredTasks()) {
log.info("Task {} {} {} is expired, expect finished at {}", log.info("Task {} {} {} is expired, expect finished at {}",
v.getId(), v.getDisposeCapacity(), v.getDisposeIp(), v.getPlanEndTime()); v.getId(), v.getDisposeCapacity(), v.getDisposeObject(), v.getPlanEndTime());
// 设置任务状态过期任务不再为设备创建处置任务 // 设置任务状态过期任务不再为设备创建处置任务
disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED); disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_EXPIRED);
} }
@ -438,7 +438,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
// 当前设备是否支持该处置能力 // 当前设备是否支持该处置能力
.filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v .filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v
.getDisposeCapacity())) .getDisposeCapacity()))
.filter(c -> c.getDb().isCarryProtectIp(v.getDisposeIp())) .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());
@ -467,7 +467,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId()); AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId());
// 对处置IP生成一个唯一的操作标识符 // 对处置IP生成一个唯一的操作标识符
String taskStartKey = task.getDisposeIp() + "Start" + ai.getDev().getDeviceType().getDescription(); String taskStartKey = task.getDisposeObject() + "Start" + ai.getDev().getDeviceType().getDescription();
if (taskCache.containsKey(taskStartKey)) { if (taskCache.containsKey(taskStartKey)) {
continue; continue;
@ -526,7 +526,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId()); AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId());
// 对处置IP生成一个唯一的操作标识符 // 对处置IP生成一个唯一的操作标识符
String taskStopKey = task.getDisposeIp() + "Stop" + ai.getDev().getDeviceType().getDescription(); String taskStopKey = task.getDisposeObject() + "Stop" + ai.getDev().getDeviceType().getDescription();
if (taskCache.containsKey(taskStopKey)) { if (taskCache.containsKey(taskStopKey)) {
continue; continue;

View File

@ -41,14 +41,14 @@ 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.getDisposeIp(), 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.getDisposeIp(), task.getDisposeCapacity() task.getDeviceId(), task.getDisposeObject(), task.getDisposeCapacity()
); );
if (err != ErrorCode.ERR_OK) { if (err != ErrorCode.ERR_OK) {
@ -100,6 +100,7 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
* *
* @return the dispose task list * @return the dispose task list
*/ */
@Override
public List<DisposeTask> getAllDisposeTask() { public List<DisposeTask> getAllDisposeTask() {
return disposeTaskManager.getDisposeTasks(); return disposeTaskManager.getDisposeTasks();
} }

View File

@ -1,8 +1,8 @@
-- ---------------------------- -- ----------------------------
-- Records of dispose_device -- Records of dispose_device
-- ---------------------------- -- ----------------------------
INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0); -- INSERT INTO `dispose_device` VALUES (1, '10.88.77.88:18080', 1, 1, 0, '中移杭研实验室浩瀚清洗设备', 'HaoHan', 'Unknown', 'Unknown', '', '', 'http://%s/DDoSClean/clean', '实验室测试设备', 0);
INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 1, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0); -- INSERT INTO `dispose_device` VALUES (2, '10.88.77.15', 0, 1, 0, '中移杭研实验室迪普清洗设备', 'DPTech', 'UMC', 'B5.2.27.7', 'admin', 'UMCAdministrator', 'http://%s/UMC/service/AbnormalFlowCleaningService', '实验室测试设备', 0);
-- ---------------------------- -- ----------------------------

View File

@ -6,7 +6,8 @@
<id column="deviceId" property="deviceId"/> <id column="deviceId" property="deviceId"/>
<id column="accountId" property="accountId"/> <id column="accountId" property="accountId"/>
<result column="disposeCapacity" property="disposeCapacity" javaType="com.dispose.common.DisposeCapacityType"/> <result column="disposeCapacity" property="disposeCapacity" javaType="com.dispose.common.DisposeCapacityType"/>
<result column="disposeIp" property="disposeIp"/> <result column="disposeObject" property="disposeObject"/>
<result column="objectType" property="objectType" javaType="com.dispose.common.DisposeObjectType"/>
<result column="createTime" property="createTime"/> <result column="createTime" property="createTime"/>
<result column="planEndTime" property="planEndTime"/> <result column="planEndTime" property="planEndTime"/>
<result column="endTime" property="endTime"/> <result column="endTime" property="endTime"/>
@ -103,7 +104,7 @@
FROM dispose_task dt LEFT JOIN device_task ti on dt.id = ti.taskId FROM dispose_task dt LEFT JOIN device_task ti on dt.id = ti.taskId
WHERE WHERE
dt.disposeCapacity = #{capType} AND dt.disposeCapacity = #{capType} AND
dt.disposeIp = #{disposeIp} AND dt.disposeObject = #{disposeObject} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()} AND dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISHED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_CANCELED.getValue()} AND dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_CANCELED.getValue()} AND
dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_EXPIRED.getValue()} AND dt.currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_EXPIRED.getValue()} AND
@ -130,10 +131,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, disposeIp, INSERT IGNORE INTO dispose_task(deviceId, accountId, disposeCapacity, disposeObject, objectType,
planEndTime, flowDirection, attackType, flowBandWidth, planEndTime, flowDirection, attackType, flowBandWidth,
currentStatus) currentStatus)
VALUES (#{deviceId}, #{accountId}, #{disposeCapacity}, #{disposeIp}, VALUES (#{deviceId}, #{accountId}, #{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

@ -116,7 +116,8 @@ CREATE TABLE `dispose_task` (
`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 '用户唯一标识符',
`disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测', `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型0清洗 1高防 2黑洞 3检测',
`disposeIp` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置IP', `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',
`createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间', `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间',
`planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' 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 '实际结束时间', `endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间',
@ -132,8 +133,8 @@ CREATE TABLE `dispose_task` (
-- ---------------------------- -- ----------------------------
-- Records of dispose_task -- Records of dispose_task
-- ---------------------------- -- ----------------------------
INSERT INTO `dispose_task` VALUES (1, -1, 1, 0, '192.168.10.1', CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); 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, 1024, 0);
INSERT INTO `dispose_task` VALUES (2, -1, 1, 0, '192.168.10.2', CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); 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, 1024, 0);
-- ---------------------------- -- ----------------------------
-- Table structure for user_account -- Table structure for user_account

View File

@ -144,7 +144,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
disposeTaskMapper.selectAll().forEach(v -> { disposeTaskMapper.selectAll().forEach(v -> {
if (v.getDeviceId().equals(Long.valueOf(req.getId())) && if (v.getDeviceId().equals(Long.valueOf(req.getId())) &&
v.getDisposeIp().equals(req.getDisposeIp()) && v.getDisposeObject().equals(req.getDisposeIp()) &&
v.getAttackType().equals((long) DDoSAttackType.ACK_FLOOD.getValue())) { v.getAttackType().equals((long) DDoSAttackType.ACK_FLOOD.getValue())) {
Assert.assertEquals(Long.valueOf(rspInfo.getMsgContent().getTaskId()), v.getId()); Assert.assertEquals(Long.valueOf(rspInfo.getMsgContent().getTaskId()), v.getId());
} }
@ -164,7 +164,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
TaskStartReq req = TaskStartReq.builder() TaskStartReq req = TaskStartReq.builder()
.id(String.valueOf(disposeTask.getDeviceId())) .id(String.valueOf(disposeTask.getDeviceId()))
.type(disposeTask.getDisposeCapacity().getValue()) .type(disposeTask.getDisposeCapacity().getValue())
.disposeIp(disposeTask.getDisposeIp()) .disposeIp(disposeTask.getDisposeObject())
.disposeTime(60) .disposeTime(60)
.flowDirection(NetflowDirection.DIRECTION_IN.getValue()) .flowDirection(NetflowDirection.DIRECTION_IN.getValue())
.attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()}) .attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()})

View File

@ -75,7 +75,7 @@ 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.getDisposeIp(), DisposeTask runningResult = disposeTaskManager.getDisposeTask(v.getDeviceId(), v.getDisposeObject(),
v.getDisposeCapacity()); v.getDisposeCapacity());
log.info("runningResult-->{}", runningResult); log.info("runningResult-->{}", runningResult);
@ -178,7 +178,7 @@ public class DisposeTaskManagerTest extends InitTestEnvironment {
.deviceId(dId) .deviceId(dId)
.accountId(uId) .accountId(uId)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.0.1") .disposeObject("192.168.0.1")
.planEndTime("30") .planEndTime("30")
.flowDirection(NetflowDirection.DIRECTION_BI) .flowDirection(NetflowDirection.DIRECTION_BI)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS}))

View File

@ -76,7 +76,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
.deviceId(dId) .deviceId(dId)
.accountId(uId) .accountId(uId)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.0.1") .disposeObject("192.168.0.1")
.planEndTime("30") .planEndTime("30")
.flowDirection(NetflowDirection.DIRECTION_BI) .flowDirection(NetflowDirection.DIRECTION_BI)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS}))

View File

@ -98,7 +98,7 @@ public class DeviceTaskManagerServiceTest extends InitTestEnvironment {
.deviceId(dId) .deviceId(dId)
.accountId(uId) .accountId(uId)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.0.1") .disposeObject("192.168.0.1")
.planEndTime("30") .planEndTime("30")
.flowDirection(NetflowDirection.DIRECTION_BI) .flowDirection(NetflowDirection.DIRECTION_BI)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS}))

View File

@ -99,7 +99,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
.accountId(1L) .accountId(1L)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.5.2") .disposeObject("192.168.5.2")
.planEndTime("30") .planEndTime("30")
.flowDirection(NetflowDirection.DIRECTION_IN) .flowDirection(NetflowDirection.DIRECTION_IN)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))
@ -124,7 +124,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
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(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(),
newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); newTask.getDisposeObject(), newTask.getDisposeCapacity()).getId());
}); });
} }
@ -137,7 +137,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
.accountId(1L) .accountId(1L)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.5.2") .disposeObject("192.168.5.2")
.planEndTime("30") .planEndTime("30")
.flowDirection(NetflowDirection.DIRECTION_IN) .flowDirection(NetflowDirection.DIRECTION_IN)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))
@ -175,7 +175,7 @@ public class DisposeTaskServiceTest extends InitTestEnvironment {
.deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId()) .deviceId(disposeDeviceManager.getAllNormalDisposeDevices().get(0).getId())
.accountId(1L) .accountId(1L)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.10.2") .disposeObject("192.168.10.2")
.planEndTime("60") .planEndTime("60")
.flowDirection(NetflowDirection.DIRECTION_IN) .flowDirection(NetflowDirection.DIRECTION_IN)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))

View File

@ -54,7 +54,7 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
/** /**
* The constant jsonIdFilter. * The constant jsonIdFilter.
*/ */
private static final Integer[] jsonIdFilter = new Integer[]{}; private static final Integer[] jsonIdFilter = new Integer[]{5};
/** /**
* The Spring method rule. * The Spring method rule.
*/ */

View File

@ -100,7 +100,7 @@ public class P2TaskList {
.deviceId(1L) .deviceId(1L)
.accountId(1L) .accountId(1L)
.disposeCapacity(DisposeCapacityType.CLEANUP) .disposeCapacity(DisposeCapacityType.CLEANUP)
.disposeIp("192.168.0." + i) .disposeObject("192.168.0." + i)
.planEndTime("60") .planEndTime("60")
.flowDirection(NetflowDirection.DIRECTION_BI) .flowDirection(NetflowDirection.DIRECTION_BI)
.attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS}))