REM:
1. 增加浩瀚设备异常处理
This commit is contained in:
HuangXin 2020-09-25 14:20:47 +08:00
parent ec838d467e
commit ef440833a8
2 changed files with 76 additions and 48 deletions

View File

@ -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;
}
/**

View File

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