From 37bd4aacb6d631d45a7d402417e461097b1504e6 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Wed, 25 Nov 2020 17:28:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?OCT=20REM:=201.=E5=A2=9E=E5=8A=A0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81=202.=E4=BF=AE=E6=94=B9=E9=B9=8F=E4=BF=A1?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=89=A7=E8=A1=8C=E4=BB=BB=E5=8A=A1=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=94=99=E8=AF=AF=E7=A0=81=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=B9=8F=E4=BF=A1=E8=AE=BE=E5=A4=87=E5=90=AF=E5=8A=A8=E3=80=81?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1=204.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6=E6=9B=B4=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=A4=84=E7=BD=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/PengXinAbilityImpl.java | 10 +++--- .../java/com/dispose/common/ErrorCode.java | 6 +++- .../dispose/manager/DeviceTaskManager.java | 7 ++-- .../manager/impl/DeviceTaskManagerImpl.java | 6 ++-- .../com/dispose/mapper/DeviceTaskMapper.java | 3 +- .../impl/DeviceTaskManagerServiceImpl.java | 34 +++---------------- src/main/resources/mappers/DeviceTask.xml | 11 +++--- 7 files changed, 26 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java index 29577d18..a86c66d5 100644 --- a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java @@ -179,18 +179,18 @@ public class PengXinAbilityImpl implements DisposeAbility { if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) { log.error("----Error PengXin start clean {} server return error", disposeObject); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null); } if (rspInfo.getMsgContent().getItems().size() == 0) { log.error("----Error PengXin start clean {} server return nothing", disposeObject); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null); } else { int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus(); if (errCode != ErrorCode.ERR_OK.getCode()) { log.error("----Error PengXin start clean {} server return error: {}", disposeObject, errCode); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null); } log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject); @@ -252,13 +252,13 @@ public class PengXinAbilityImpl implements DisposeAbility { if (rspInfo.getMsgContent().getItems().size() == 0) { log.error("----Error PengXin stop clean {} server return nothing", disposeObject); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null); } else { int errCode = rspInfo.getMsgContent().getItems().get(0).getStatus(); if (errCode != ErrorCode.ERR_OK.getCode()) { log.error("----Error PengXin stop clean {} server return error: {}", disposeObject, errCode); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + return new MulReturnType<>(ErrorCode.ERR_PENGXIN_ERROR, null); } log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId); diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index 4928dda4..4880b744 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -235,7 +235,11 @@ public enum ErrorCode { /** * The Err huawei error. */ - ERR_HUAWEI_ERROR(34, "华为设备返回错误"), + ERR_HUAWEI_ERROR(116, "华为设备返回错误"), + /** + * The Err pengxin error. + */ + ERR_PENGXIN_ERROR(117, "鹏信设备返回错误"), ; /** diff --git a/src/main/java/com/dispose/manager/DeviceTaskManager.java b/src/main/java/com/dispose/manager/DeviceTaskManager.java index 9f313ad2..1e9f555b 100644 --- a/src/main/java/com/dispose/manager/DeviceTaskManager.java +++ b/src/main/java/com/dispose/manager/DeviceTaskManager.java @@ -137,10 +137,9 @@ public interface DeviceTaskManager { DeviceTask getTaskById(Long id); /** - * Gets peng xin task by id. + * Gets peng xin task. * - * @param startId the start id - * @return the peng xin task by id + * @return the peng xin task */ - List getPengXinTaskById(Long startId); + List getPengXinTask(); } diff --git a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java index 1615e20f..608040c6 100644 --- a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java @@ -297,12 +297,12 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { } /** - * Gets PengXin device task info by startId. + * Gets PengXin device task info. * * @return the minId task info. */ @Override - public List getPengXinTaskById(Long startId){ - return deviceTaskMapper.getPengXinTask(startId); + public List getPengXinTask(){ + return deviceTaskMapper.getPengXinTask(); } } diff --git a/src/main/java/com/dispose/mapper/DeviceTaskMapper.java b/src/main/java/com/dispose/mapper/DeviceTaskMapper.java index 7e1cec48..35602485 100644 --- a/src/main/java/com/dispose/mapper/DeviceTaskMapper.java +++ b/src/main/java/com/dispose/mapper/DeviceTaskMapper.java @@ -158,8 +158,7 @@ public interface DeviceTaskMapper { /** * Gets PengXin device task info. * - * @param startId the start id * @return PengXin device task info */ - List getPengXinTask(Long startId); + List getPengXinTask(); } diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index b929ec4a..67b12001 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -14,15 +14,12 @@ import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DeviceTaskManagerService; import com.dispose.service.DisposeAbilityRouterService; -import com.pengxin.dispose.common.PengXinTaskStatus; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; /** @@ -443,8 +440,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 设置任务状态为启动中 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); - // 设置设备任务状态为启动中 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), (long) PengXinTaskStatus.TASK_STARTING.getValue()); // 设置启动任务攻击类型状态 deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI, deviceTask.getTaskAttackType()); @@ -471,9 +466,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { // 设置该任务为新任务,待下次重试启动 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW); - // 设置设备任务状态为启动处置任务失败 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), - (long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue()); + // 记录任务出错重试次数 deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); log.error("PENGXIN_PLATFORM setup task times {} error {}: {}", deviceTask.getErrRetry(), @@ -482,9 +475,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 任务出错,不在重试,当做失败任务处理 deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); - // 设置设备任务状态为启动处置任务失败 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), - (long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue()); + log.error("PENGXIN_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask); } } @@ -499,10 +490,6 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { private void pengXinDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) { MulReturnType ret; - // 设置设备任务状态为解封中 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), - (long) PengXinTaskStatus.TASK_UNBLOCKING.getValue()); - // 停止处置任务 ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, deviceTask.getExternId()); @@ -514,17 +501,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { - // 设置设备任务状态为解封失败 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), - (long) PengXinTaskStatus.TASK_UNBLOCKED_FAILED.getValue()); // 记录任务出错重试次数 deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); log.error("PENGXIN_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(), ret.getSecondParam(), deviceTask); } else { - // 设置设备任务状态为解封失败 - deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), - (long) PengXinTaskStatus.TASK_UNBLOCKED_FAILED.getValue()); log.error("PENGXIN_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask); } } @@ -796,15 +777,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { * Device task status schedule. */ public void deviceTaskStatusSchedule() { - List taskList = new ArrayList<>(); - //处置任务设备类型为鹏信设备,任务状态不再变更 - for (Long i = 1L; deviceTaskManager.getPengXinTaskById(i).size() != 0; i = taskList.get(taskList.size() - 1).getId() + 1) { - log.debug("startId:{}", i); - taskList.addAll(deviceTaskManager.getPengXinTaskById(i)); - } - - for (DeviceTask v : taskList) { + for (DeviceTask v : deviceTaskManager.getPengXinTask()) { // 获取设备 AbilityInfo ai = disposeAbilityRouterService.getAbilityDevice(v.getDeviceId()); @@ -827,6 +801,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { MulReturnType ret = ai.getDb().taskStatus(v.getExternId()); if (ret.getFirstParam() == ErrorCode.ERR_OK) { + log.debug("id:{}, before devStatus:{}, after devStatus:{}", v.getId(), + v.getDevStatus(), ret.getSecondParam()); deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(v.getId(), ret.getSecondParam()); } diff --git a/src/main/resources/mappers/DeviceTask.xml b/src/main/resources/mappers/DeviceTask.xml index 04c4c88b..b161b379 100644 --- a/src/main/resources/mappers/DeviceTask.xml +++ b/src/main/resources/mappers/DeviceTask.xml @@ -29,15 +29,15 @@ VALUES (#{task.taskId}, #{task.deviceId}, #{task.taskAttackType}, - ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, 0) + ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1) - INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status) + INSERT IGNORE INTO device_task(taskId, deviceId, taskAttackType, status, devStatus) VALUES (#{taskId}, #{deviceId}, #{taskAttackType}, - ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}) + ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()}, -1) \ No newline at end of file From 54c2837f7ff5fd3b9f504f296dabcdb45899299a Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Thu, 26 Nov 2020 17:11:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9=E9=B9=8F?= =?UTF-8?q?=E4=BF=A1=E8=AE=BE=E5=A4=87=E5=90=AF=E5=8A=A8=E3=80=81=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=80=BB=E8=BE=91=202.=E5=A2=9E=E5=8A=A0=E9=B9=8F=E4=BF=A1?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E7=A0=81?= =?UTF-8?q?=203.=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=AC=A6=E5=90=88=E6=9D=A1=E4=BB=B6=E7=9A=84=E9=B9=8F?= =?UTF-8?q?=E4=BF=A1=E8=AE=BE=E5=A4=87=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?SQL=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DeviceTaskManagerServiceImpl.java | 25 +++++++++++++++++-- .../dispose/common/PengXinTaskStatus.java | 4 +++ src/main/resources/mappers/DeviceTask.xml | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 67b12001..41b8bfcc 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -14,6 +14,7 @@ import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.DeviceTaskManagerService; import com.dispose.service.DisposeAbilityRouterService; +import com.pengxin.dispose.common.PengXinTaskStatus; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; @@ -434,7 +435,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { MulReturnType ret; // 重试错误次数过多 - if (deviceTask.getErrRetry() >= DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { + if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { return; } @@ -476,6 +477,14 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); + // 设置该任务为启动失败 + deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_NEW); + //任务出错,设备任务状态为启动处置任务失败 + deviceTaskManager.changeDisposeDeviceTaskInfoDevStatus(deviceTask.getId(), + (long) PengXinTaskStatus.TASK_STARTED_FAILED.getValue()); + // 记录任务出错重试次数 + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); + log.error("PENGXIN_PLATFORM setup task error {}: {}", ret.getFirstParam(), deviceTask); } } @@ -490,6 +499,11 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { private void pengXinDeviceTaskStop(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) { MulReturnType ret; + // 重试错误次数过多 + if (deviceTask.getErrRetry() > DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 2) { + return; + } + // 停止处置任务 ret = ai.getDb().stopDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, deviceTask.getExternId()); @@ -500,12 +514,19 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), disposeTask.getFlowDirection(), 0L); - } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { + } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 2) { // 记录任务出错重试次数 deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); + // 设置任务状态为启动中 + deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); log.error("PENGXIN_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(), ret.getSecondParam(), deviceTask); } else { + // 记录任务出错重试次数 + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); + // 设置该任务为停止失败 + deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_FINISHED); + log.error("PENGXIN_PLATFORM stop task error {}: {}", ret.getFirstParam(), deviceTask); } } diff --git a/src/main/java/com/pengxin/dispose/common/PengXinTaskStatus.java b/src/main/java/com/pengxin/dispose/common/PengXinTaskStatus.java index 179068aa..ac00e250 100644 --- a/src/main/java/com/pengxin/dispose/common/PengXinTaskStatus.java +++ b/src/main/java/com/pengxin/dispose/common/PengXinTaskStatus.java @@ -48,6 +48,10 @@ public enum PengXinTaskStatus implements BaseEnum { * The Task unblocking. */ TASK_UNBLOCKING(9, "解封中"), + /** + * The Task unknown. + */ + TASK_UNKNOWN(-1, "未知状态"), ; /** diff --git a/src/main/resources/mappers/DeviceTask.xml b/src/main/resources/mappers/DeviceTask.xml index b161b379..d1631748 100644 --- a/src/main/resources/mappers/DeviceTask.xml +++ b/src/main/resources/mappers/DeviceTask.xml @@ -136,6 +136,6 @@ WHERE dd.deviceType = 2 AND - dt.devStatus != 8 AND dt.devStatus != 7 AND dt.devStatus != -1 + dt.devStatus != 2 AND dt.devStatus != 3 AND dt.devStatus != 6 \ No newline at end of file From b061b6d6ecd2da8c3512731643fa0f2b7eca4d98 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Thu, 26 Nov 2020 17:30:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispose/service/impl/DeviceTaskManagerServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 41b8bfcc..fcea7aac 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -517,8 +517,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 2) { // 记录任务出错重试次数 deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry() + 1); - // 设置任务状态为启动中 - deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); + // 设置任务状态为处置中,待下次重试停止 + deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTED); log.error("PENGXIN_PLATFORM stop task times {} error {}: {}", deviceTask.getErrRetry(), ret.getSecondParam(), deviceTask); } else {