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()); }