From 9e912dcfc3bda1dab4ff8f8fc4e5b2cc73725057 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 9 Oct 2020 11:13:21 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=94=B9=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E4=BB=BB=E5=8A=A1=E5=88=A4=E6=96=AD=E5=A4=84=E7=BD=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=98=AF=E5=90=A6=E6=94=AF=E6=8C=81=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DeviceTaskManagerServiceImpl.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 7bfc8429..700febe9 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -97,10 +97,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { MulReturnType ret; // 调用设备执行处置任务 - ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, null); + ret = ai.getDb() + .stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, null); if (ret.getFirstParam() == ErrorCode.ERR_OK) { - deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),disposeTask.getFlowDirection(), 0L); + deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); log.info("VIRTUAL_DISPOSE stop task succeed: {}", deviceTask); } else { log.error("VIRTUAL_DISPOSE stop task error {}: {}", ret.getFirstParam(), deviceTask); @@ -183,7 +184,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 设置任务状态为结束 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); - deviceTaskManager.setAttackTypeStatus(deviceTask.getId(),disposeTask.getFlowDirection(), 0L); + deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { // 记录任务出错重试次数 deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); @@ -293,7 +294,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { if (!devTask.getExecAttackTypeOut().equals(devTask.getTaskAttackType()) - || !devTask.getExecAttackTypeOut().equals(devTask.getAttackTypeStatusOut())) { + || !devTask.getExecAttackTypeOut().equals(devTask.getAttackTypeStatusOut())) { taskSetupSucceed = false; } } @@ -301,7 +302,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { if (!devTask.getExecAttackTypeIn().equals(devTask.getTaskAttackType()) - || !devTask.getExecAttackTypeIn().equals(devTask.getAttackTypeStatusIn())) { + || !devTask.getExecAttackTypeIn().equals(devTask.getAttackTypeStatusIn())) { taskSetupSucceed = false; } } @@ -431,22 +432,26 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 设置任务状态, 开始创建任务 disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_STARTING); - // 为当前所有可用处置设备创建对应的处置任务 - disposeAbilityRouterService.getAllAbilityDevices().stream() - // 判断是否是当前设备的处置任务 - .filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId())) - // 当前设备是否支持该处置能力 - .filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v - .getDisposeCapacity())) - .filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject())) - .forEach(d -> { - log.info("Add dispose task for device: {}", d.getDev()); + // 检查改任务是否能够被处置 + ErrorCode ret = disposeAbilityRouterService.verifyDisposeCapacity(v.getDeviceId(), + v.getDisposeObject(), + v.getDisposeCapacity()); - if (!deviceTaskManager.addDisposeDeviceTaskInfo(v.getId(), d.getDev().getId(), - d.getDb().toDeviceAttackType(v.getAttackType()))) { - log.error("Add task {} to device {} error", v, d); - } - }); + if (ret != ErrorCode.ERR_OK) { + log.warn("{}: Not found support dispose device for [{}]", ret, v); + continue; + } + + // 为当前所有可用处置设备创建对应的处置任务 + disposeAbilityRouterService.getAllAbilityDevices().forEach(d -> { + log.info("Add dispose task for device: {}", d.getDev()); + + if (!deviceTaskManager.addDisposeDeviceTaskInfo(v.getId(), d.getDev().getId(), + d.getDb() + .toDeviceAttackType(v.getAttackType()))) { + log.error("Add task {} to device {} error", v, d); + } + }); } } @@ -467,7 +472,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId()); // 如果设备已经删除或者禁用,跳过处理 - if(ai == null) { + if (ai == null) { continue; } @@ -519,8 +524,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 判断任务是否应当停止 if (DisposeTaskStatus.TASK_NEW.equals(task.getCurrentStatus()) - || DisposeTaskStatus.TASK_STARTING.equals(task.getCurrentStatus()) - || DisposeTaskStatus.TASK_STARTED.equals(task.getCurrentStatus())) { + || DisposeTaskStatus.TASK_STARTING.equals(task.getCurrentStatus()) + || DisposeTaskStatus.TASK_STARTED.equals(task.getCurrentStatus())) { // 判断任务是否到达停止时间 if (Helper.getTimestampDiffNow(task.getPlanEndTime()) < 0) { continue;