REM:
1. 增加处置设备定时任务接口
2. 优化处置设备心跳检测功能
3. 增加迪普设备功能接口
This commit is contained in:
HuangXin 2021-01-08 13:56:41 +08:00
parent c49cb41146
commit b669c4b374
12 changed files with 254 additions and 21 deletions

View File

@ -98,4 +98,9 @@ public interface DisposeAbility {
* @return the boolean * @return the boolean
*/ */
boolean isCarryProtectIp(String ipAddr); boolean isCarryProtectIp(String ipAddr);
/**
* Period task runtime.
*/
void periodTaskRuntime();
} }

View File

@ -3,6 +3,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.common.CommonEnumHandler; import com.dispose.common.CommonEnumHandler;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType; import com.dispose.common.DisposeObjectType;
import com.dispose.common.DpTechAttackType; import com.dispose.common.DpTechAttackType;
import com.dispose.common.DpTechConfigValue; import com.dispose.common.DpTechConfigValue;
@ -29,7 +30,9 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants;
import javax.xml.ws.BindingProvider; import javax.xml.ws.BindingProvider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -48,12 +51,55 @@ public class DpTechAbilityImpl implements DisposeAbility {
* The Protect ip v 6. * The Protect ip v 6.
*/ */
private final List<String> protectIpV6 = new ArrayList<>(); private final List<String> protectIpV6 = new ArrayList<>();
/**
* The All cleanup devices.
*/
private final HashSet<String> allCleanupDevices = new HashSet<>();
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* The Device link status.
*/
private boolean deviceLinkStatus = false;
/** /**
* The Clean type port. * The Clean type port.
*/ */
private AbnormalFlowCleaningServicePortType cleanTypePort; private AbnormalFlowCleaningServicePortType cleanTypePort;
/**
* Init cleanup devices.
*/
private void initCleanupDevices() {
try {
log.info("++++Begging DPTech Get All Detect Devices");
String dev = cleanTypePort.getAllProtectDevices();
log.info("----Finish DPTech Get All Detect Devices: {}", dev);
Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR));
} catch (Exception ex) {
log.error("----Exception DPTech Get All Detect Devices");
}
}
/**
* Init protection objects.
*/
private void initProtectionObjects() {
try {
log.info("++++Begging DPTech Get All Protection Objects");
ArrayOfProtectionObjectDataForService ret = cleanTypePort.getAllProtectionObjectFromUMC();
String dev = cleanTypePort.getAllProtectDevices();
log.info("----Finish DPTech Get All Protection Objects: {}", dev);
Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR));
} catch (Exception ex) {
log.error("----Exception DPTech Get All Protection Objects");
}
}
/** /**
* Init device env. * Init device env.
* *
@ -93,6 +139,9 @@ public class DpTechAbilityImpl implements DisposeAbility {
//读取超时 //读取超时
policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND); policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND);
conduit.setClient(policy); conduit.setClient(policy);
// 获取所有检测设备
initCleanupDevices();
} }
/** /**
@ -107,7 +156,8 @@ public class DpTechAbilityImpl implements DisposeAbility {
* @return the mul return type * @return the mul return type
*/ */
@Override @Override
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType, public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType,
DisposeCapacityType capType,
NetflowDirection nfDirection, NetflowDirection nfDirection,
Integer attackType, Integer attackType,
Long duration) { Long duration) {
@ -205,15 +255,23 @@ public class DpTechAbilityImpl implements DisposeAbility {
*/ */
@Override @Override
public boolean getDeviceLinkStatus() { public boolean getDeviceLinkStatus() {
return deviceLinkStatus;
}
/**
* Dev get link status.
*/
private void devGetLinkStatus() {
try { try {
// 获取防护对象接口调用成功认为设备心跳正常 // 获取防护对象接口调用成功认为设备心跳正常
cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService(); cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService();
return true; deviceLinkStatus = true;
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
return false; deviceLinkStatus = false;
} }
/** /**
@ -327,4 +385,22 @@ public class DpTechAbilityImpl implements DisposeAbility {
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) { public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L); return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
} }
/**
* Period task runtime.
*/
@Override
public void periodTaskRuntime() {
log.debug("++++DpTech Period Task Running");
// 更新防护对象
getDisposeDeviceProtectObject();
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
devGetLinkStatus();
}
log.debug("----DpTech Period Task Running");
}
} }

View File

@ -2,6 +2,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType; import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
@ -38,6 +39,14 @@ public class HaoHanAbilityImpl implements DisposeAbility {
* The Url root path. * The Url root path.
*/ */
private String urlRootPath; private String urlRootPath;
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* The Device link status.
*/
private boolean deviceLinkStatus = false;
/** /**
* Init device env. * Init device env.
@ -153,14 +162,23 @@ public class HaoHanAbilityImpl implements DisposeAbility {
*/ */
@Override @Override
public boolean getDeviceLinkStatus() { public boolean getDeviceLinkStatus() {
return deviceLinkStatus;
}
/**
* Dev get link status.
*/
private void devGetLinkStatus() {
try { try {
// 获取任务信息接口调用成功认为设备心跳正常 // 获取任务信息接口调用成功认为设备心跳正常
return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); if (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null) {
deviceLinkStatus = true;
}
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
return false; deviceLinkStatus = false;
} }
/** /**
@ -225,4 +243,19 @@ public class HaoHanAbilityImpl implements DisposeAbility {
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) { public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L); return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
} }
/**
* Period task runtime.
*/
@Override
public void periodTaskRuntime() {
log.debug("++++HaoHan Period Task Running");
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
devGetLinkStatus();
}
log.debug("----HaoHan Period Task Running");
}
} }

View File

@ -3,6 +3,7 @@ package com.dispose.ability.impl;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType; import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection; import com.dispose.common.NetflowDirection;
@ -29,6 +30,14 @@ import javax.servlet.http.HttpServletResponse;
@Component @Component
@Slf4j @Slf4j
public class HuaWeiAbilityImpl implements DisposeAbility { public class HuaWeiAbilityImpl implements DisposeAbility {
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* The Device link status.
*/
private boolean deviceLinkStatus = false;
/** /**
* The Restful interface. * The Restful interface.
*/ */
@ -270,12 +279,20 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
*/ */
@Override @Override
public boolean getDeviceLinkStatus() { public boolean getDeviceLinkStatus() {
return deviceLinkStatus;
}
/**
* Dev get link status.
*/
private void devGetLinkStatus() {
try { try {
//查询所有的zone接口调用成功认为设备心跳正常 //查询所有的zone接口调用成功认为设备心跳正常
String url = urlRootPath + "/allzone"; String url = urlRootPath + "/allzone";
if (token == null || token.length() == 0) { if (token == null || token.length() == 0) {
return false; deviceLinkStatus = false;
return;
} }
HttpResponse response = restfulInterface.queryAllZones(url, token); HttpResponse response = restfulInterface.queryAllZones(url, token);
@ -286,13 +303,15 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
response = restfulInterface.queryAllZones(url, token); response = restfulInterface.queryAllZones(url, token);
} }
return response.getStatus() == HttpServletResponse.SC_OK; if (response.getStatus() == HttpServletResponse.SC_OK) {
deviceLinkStatus = true;
}
} catch ( } catch (
Exception ex) { Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
return false; deviceLinkStatus = false;
} }
@ -330,5 +349,20 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
/**
* Period task runtime.
*/
@Override
public void periodTaskRuntime() {
log.debug("++++HuaWei Period Task Running");
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
devGetLinkStatus();
}
log.debug("----HuaWei Period Task Running");
}
} }

View File

@ -2,6 +2,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeConfigValue;
import com.dispose.common.DisposeObjectType; import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper; import com.dispose.common.Helper;
@ -55,6 +56,15 @@ public class PengXinAbilityImpl implements DisposeAbility {
* The Task req id. * The Task req id.
*/ */
private Long taskReqId = System.currentTimeMillis(); private Long taskReqId = System.currentTimeMillis();
/**
* The Timer cnt.
*/
private long timerCnt = 0;
/**
* The Device link status.
*/
private boolean deviceLinkStatus = false;
/** /**
* The Url root path. * The Url root path.
*/ */
@ -310,11 +320,19 @@ public class PengXinAbilityImpl implements DisposeAbility {
*/ */
@Override @Override
public boolean getDeviceLinkStatus() { public boolean getDeviceLinkStatus() {
return deviceLinkStatus;
}
/**
* Dev get link status.
*/
private void devGetLinkStatus() {
try { try {
String url = urlRootPath + "dispose_device/information/linkstatus"; String url = urlRootPath + "dispose_device/information/linkstatus";
if (token == null || token.length() == 0) { if (token == null || token.length() == 0) {
return false; deviceLinkStatus = false;
return;
} }
ErrorCode err = restfulInterface.getLinkStatus(url, token); ErrorCode err = restfulInterface.getLinkStatus(url, token);
@ -325,12 +343,14 @@ public class PengXinAbilityImpl implements DisposeAbility {
err = restfulInterface.getLinkStatus(url, token); err = restfulInterface.getLinkStatus(url, token);
} }
return err == ErrorCode.ERR_OK; if (err == ErrorCode.ERR_OK) {
deviceLinkStatus = true;
}
} catch (Exception ex) { } catch (Exception ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
return false; deviceLinkStatus = false;
} }
/** /**
@ -480,4 +500,22 @@ public class PengXinAbilityImpl implements DisposeAbility {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
/**
* Period task runtime.
*/
@Override
public void periodTaskRuntime() {
log.debug("++++PengXin Period Task Running");
// 更新防护对象
getDisposeDeviceProtectObject();
// 更新心跳状态
if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) {
devGetLinkStatus();
}
log.debug("----PengXin Period Task Running");
}
} }

View File

@ -143,4 +143,12 @@ public class VirtualAbilityImpl implements DisposeAbility {
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) { public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L); return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L);
} }
/**
* Period task runtime.
*/
@Override
public void periodTaskRuntime() {
}
} }

View File

@ -186,6 +186,11 @@ public enum DDoSAttackType implements BaseEnum {
*/ */
IGMP_FLOOD(42, "IGMP_FLOOD"), IGMP_FLOOD(42, "IGMP_FLOOD"),
/**
* None attacks d do s attack type.
*/
NONE_ATTACKS(63, "NONE_ATTACKS"),
/** /**
* The All attacks. * The All attacks.
*/ */
@ -224,7 +229,7 @@ public enum DDoSAttackType implements BaseEnum {
if (types.contains(ALL_ATTACKS)) { if (types.contains(ALL_ATTACKS)) {
for (DDoSAttackType type : DDoSAttackType.values()) { for (DDoSAttackType type : DDoSAttackType.values()) {
if (type.equals(ALL_ATTACKS)) { if (type.equals(ALL_ATTACKS) || type.equals(NONE_ATTACKS)) {
continue; continue;
} }
mask |= (long) 1 << type.getValue(); mask |= (long) 1 << type.getValue();
@ -249,7 +254,8 @@ public enum DDoSAttackType implements BaseEnum {
if (Arrays.asList(types).contains(ALL_ATTACKS)) { if (Arrays.asList(types).contains(ALL_ATTACKS)) {
for (DDoSAttackType type : DDoSAttackType.values()) { for (DDoSAttackType type : DDoSAttackType.values()) {
if (type.equals(ALL_ATTACKS)) { // 掩码处理跳过所有攻击类型与不指定攻击类型
if (type.equals(ALL_ATTACKS) || type.equals(NONE_ATTACKS)) {
continue; continue;
} }
mask |= (long) 1 << type.getValue(); mask |= (long) 1 << type.getValue();
@ -270,8 +276,12 @@ public enum DDoSAttackType implements BaseEnum {
* @return the type mask from attack type * @return the type mask from attack type
*/ */
public static Long getTypeMaskFromAttackType(Integer[] types) { public static Long getTypeMaskFromAttackType(Integer[] types) {
// 如果指定了所有攻击类型选择所有攻击类型
if (Arrays.stream(types).anyMatch(v -> ALL_ATTACKS.getValue().equals(v))) { if (Arrays.stream(types).anyMatch(v -> ALL_ATTACKS.getValue().equals(v))) {
return getTypeMaskFromAttackType(new DDoSAttackType[]{ALL_ATTACKS}); return getTypeMaskFromAttackType(new DDoSAttackType[]{ALL_ATTACKS});
} else if (Arrays.stream(types).anyMatch(v -> NONE_ATTACKS.getValue().equals(v))) {
// 如果不指定攻击类型
return getTypeMaskFromAttackType(new DDoSAttackType[]{NONE_ATTACKS});
} else { } else {
long mask = 0L; long mask = 0L;
for (int i : types) { for (int i : types) {

View File

@ -58,4 +58,9 @@ public class DisposeConfigValue {
* The constant ENABLE_UTEST_MOCK. * The constant ENABLE_UTEST_MOCK.
*/ */
public static volatile boolean ENABLE_UTEST_MOCK = false; public static volatile boolean ENABLE_UTEST_MOCK = false;
/**
* The constant HEART_PERIOD_OF_SECOND.
*/
public static long HEART_PERIOD_OF_SECOND = 30;
} }

View File

@ -57,7 +57,13 @@ public enum DpTechAttackType implements BaseEnum {
/** /**
* The Host total traffic. * The Host total traffic.
*/ */
HOST_TOTAL_TRAFFIC(31, "Host Total Traffic"); HOST_TOTAL_TRAFFIC(31, "Host Total Traffic"),
/**
* The Auto attack type.
*/
AUTO_ATTACK_TYPE(32, "Automatic detect attack type"),
;
/** /**
* The Code. * The Code.
@ -130,10 +136,10 @@ public enum DpTechAttackType implements BaseEnum {
} }
/** /**
* From ddos attack type value stream. * From ddos attack type value list.
* *
* @param type the type * @param type the type
* @return the stream * @return the list
*/ */
public static List<DpTechAttackType> fromDdosAttackTypeValue(DDoSAttackType type) { public static List<DpTechAttackType> fromDdosAttackTypeValue(DDoSAttackType type) {
List<DpTechAttackType> attackList = new ArrayList<>(); List<DpTechAttackType> attackList = new ArrayList<>();
@ -204,6 +210,10 @@ public enum DpTechAttackType implements BaseEnum {
attackList.addAll(Arrays.asList(DpTechAttackType.values())); attackList.addAll(Arrays.asList(DpTechAttackType.values()));
break; break;
case NONE_ATTACKS:
attackList.add(AUTO_ATTACK_TYPE);
break;
default: default:
break; break;
} }

View File

@ -54,4 +54,9 @@ public interface DisposeAbilityRouterService {
* @return the error code * @return the error code
*/ */
ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType); ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType);
/**
* Run period task.
*/
void runPeriodTask();
} }

View File

@ -3,9 +3,9 @@ package com.dispose.service.impl;
import com.dispose.ability.DisposeAbility; import com.dispose.ability.DisposeAbility;
import com.dispose.ability.impl.DpTechAbilityImpl; import com.dispose.ability.impl.DpTechAbilityImpl;
import com.dispose.ability.impl.HaoHanAbilityImpl; import com.dispose.ability.impl.HaoHanAbilityImpl;
import com.dispose.ability.impl.HuaWeiAbilityImpl;
import com.dispose.ability.impl.PengXinAbilityImpl; import com.dispose.ability.impl.PengXinAbilityImpl;
import com.dispose.ability.impl.VirtualAbilityImpl; import com.dispose.ability.impl.VirtualAbilityImpl;
import com.dispose.ability.impl.HuaWeiAbilityImpl;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.HttpType; import com.dispose.common.HttpType;
@ -14,6 +14,8 @@ import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.AbilityInfo; import com.dispose.pojo.po.AbilityInfo;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -171,6 +173,16 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
return ErrorCode.ERR_OK; return ErrorCode.ERR_OK;
} }
/**
* Run period task.
*/
@Override
@Async("deviceTaskExecutor")
@Scheduled(fixedDelay = 1000)
public void runPeriodTask() {
getAllAbilityDevices().forEach(v -> v.getDb().periodTaskRuntime());
}
/** /**
* Gets ability device hash key. * Gets ability device hash key.
* *

View File

@ -57,9 +57,6 @@ public class DeviceManagerTask {
((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" : ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" :
":" + v.getDev().getIpPort()), ":" + v.getDev().getIpPort()),
ret.getFirstParam()); ret.getFirstParam());
// 更新设备保护对象
v.getDb().getDisposeDeviceProtectObject();
}); });
} }
} }