From ef440833a8f26b83c622573764dde54150a44c50 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 25 Sep 2020 14:20:47 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E6=B5=A9?= =?UTF-8?q?=E7=80=9A=E8=AE=BE=E5=A4=87=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/HaoHanAbilityImpl.java | 109 ++++++++++-------- .../impl/DisposeDeviceManagerImpl.java | 15 ++- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index 62757220..082c099b 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -65,33 +65,39 @@ public class HaoHanAbilityImpl implements DisposeAbility { @Nullable NetflowDirection nfDirection, @Nullable Integer attackType, @Nullable Long duration) { - log.info("++++Begging Haohan Start Cleanup Task: {}", ip); + try { + log.info("++++Begging Haohan Start Cleanup Task: {}", ip); - if (capType != DisposeCapacityType.CLEANUP) { - log.error("----Error Haohan don't support dispose capacity type: {}", capType); - return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + if (capType != DisposeCapacityType.CLEANUP) { + log.error("----Error Haohan don't support dispose capacity type: {}", capType); + return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + } + + // 适配处置时间参数, -1为不限制处置时间 + if (duration == null || duration < 0) { + duration = -1L; + } + + HaoHanStartCleanResp resp = restfulInterface.startClean(this.urlRootPath, ip, + Math.max(duration.intValue(), 0), + DISPOSE_PLATFORM_NAME); + + if (resp == null) { + log.error("----Error Haohan start clean {} server return error", ip); + return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + } + + if (resp.getState() != ErrorCode.ERR_OK.getCode()) { + log.error("----Error Haohan start clean {} return error: {}, {}", ip, resp.getState(), resp.getMsg()); + return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + } + + log.debug("----Finish Haohan Start Cleanup Task: {}", ip); + return new MulReturnType<>(ErrorCode.ERR_OK, (long) resp.getCleanTaskId()); + } catch (Exception ex) { + log.error("----Exception Haohan Start Cleanup Task: {}, {}, {}", ip, nfDirection, duration); + return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } - - // 适配处置时间参数, -1为不限制处置时间 - if (duration == null || duration < 0) { - duration = -1L; - } - - HaoHanStartCleanResp resp = restfulInterface.startClean(this.urlRootPath, ip, Math.max(duration.intValue(), 0), - DISPOSE_PLATFORM_NAME); - - if (resp == null) { - log.error("----Error Haohan start clean {} server return error", ip); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - if (resp.getState() != ErrorCode.ERR_OK.getCode()) { - log.error("----Error Haohan start clean {} return error: {}, {}", ip, resp.getState(), resp.getMsg()); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - log.debug("----Finish Haohan Start Cleanup Task: {}", ip); - return new MulReturnType<>(ErrorCode.ERR_OK, (long) resp.getCleanTaskId()); } /** @@ -109,27 +115,32 @@ public class HaoHanAbilityImpl implements DisposeAbility { @Nullable NetflowDirection nfDirection, @Nullable Integer attackType, @Nullable Long taskId) { - log.debug("++++Begging Haohan Stop Cleanup Task: {}", taskId); + try { + log.debug("++++Begging Haohan Stop Cleanup Task: {}", taskId); - if (capType != DisposeCapacityType.CLEANUP) { - log.error("----Error Haohan don't support dispose capacity type: {}", capType); - return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + if (capType != DisposeCapacityType.CLEANUP) { + log.error("----Error Haohan don't support dispose capacity type: {}", capType); + return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + } + + if (taskId == null) { + return new MulReturnType<>(ErrorCode.ERR_PARAMS, null); + } + + HaoHanStopCleanResp resp = restfulInterface.stopClean(this.urlRootPath, taskId.intValue(), + DISPOSE_PLATFORM_NAME); + + if (resp == null) { + log.error("----Error Haohan stop task{} server return error", taskId); + return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); + } + + log.debug("----Finish Haohan Stop Cleanup Task: {}", taskId); + return new MulReturnType<>(ErrorCode.ERR_OK, null); + } catch (Exception ex) { + log.error("----Exception Haohan Stop Cleanup Task: {}, {}, {}", ip, nfDirection, taskId); + return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } - - if (taskId == null) { - return new MulReturnType<>(ErrorCode.ERR_PARAMS, null); - } - - HaoHanStopCleanResp resp = restfulInterface.stopClean(this.urlRootPath, taskId.intValue(), - DISPOSE_PLATFORM_NAME); - - if (resp == null) { - log.error("----Error Haohan stop task{} server return error", taskId); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - - log.debug("----Finish Haohan Stop Cleanup Task: {}", taskId); - return new MulReturnType<>(ErrorCode.ERR_OK, null); } /** @@ -139,8 +150,14 @@ public class HaoHanAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { - // 获取任务信息接口调用成功认为设备心跳正常 - return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); + try { + // 获取任务信息接口调用成功认为设备心跳正常 + return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); + } catch (Exception ex) { + log.error(ex.getMessage()); + } + + return false; } /** diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java index 42f7ced6..b5e89d58 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java @@ -2,6 +2,7 @@ package com.dispose.manager.impl; import com.dispose.common.ErrorCode; import com.dispose.common.HttpType; +import com.dispose.common.IpAddrType; import com.dispose.common.ObjectStatus; import com.dispose.manager.DisposeDeviceManager; import com.dispose.mapper.DisposeCapacityMapper; @@ -77,7 +78,12 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { // 添加设备能力信息 if (err == ErrorCode.ERR_OK) { - dev.getDevCapacity().forEach(v -> v.setDeviceId(dev.getId())); + dev.getDevCapacity().forEach(v -> { + v.setDeviceId(dev.getId()); + if (v.getIpType() == null) { + v.setIpType(IpAddrType.IPV4_IPV6); + } + }); disposeCapacityMapper.addNewDisposeCapacity(dev.getDevCapacity()); } @@ -170,7 +176,12 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { Long devId = tDev.getId(); if (tDev.getDevCapacity().size() != 0) { - tDev.getDevCapacity().forEach(v -> v.setDeviceId(devId)); + tDev.getDevCapacity().forEach(v -> { + v.setDeviceId(dev.getId()); + if (v.getIpType() == null) { + v.setIpType(IpAddrType.IPV4_IPV6); + } + }); disposeCapacityMapper.addNewDisposeCapacity(tDev.getDevCapacity()); }