From b669c4b374b8195eeda720c08d76145c30dea182 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 8 Jan 2021 13:56:41 +0800 Subject: [PATCH 01/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3=202.=20=E4=BC=98=E5=8C=96=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E8=AE=BE=E5=A4=87=E5=BF=83=E8=B7=B3=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=203.=20=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=8A=9F=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/ability/DisposeAbility.java | 5 ++ .../ability/impl/DpTechAbilityImpl.java | 84 ++++++++++++++++++- .../ability/impl/HaoHanAbilityImpl.java | 37 +++++++- .../ability/impl/HuaWeiAbilityImpl.java | 40 ++++++++- .../ability/impl/PengXinAbilityImpl.java | 44 +++++++++- .../ability/impl/VirtualAbilityImpl.java | 8 ++ .../com/dispose/common/DDoSAttackType.java | 14 +++- .../dispose/common/DisposeConfigValue.java | 5 ++ .../com/dispose/common/DpTechAttackType.java | 16 +++- .../service/DisposeAbilityRouterService.java | 5 ++ .../impl/DisposeAbilityRouterServiceImpl.java | 14 +++- .../com/dispose/task/DeviceManagerTask.java | 3 - 12 files changed, 254 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index 4fdb4b8c..b55f4feb 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -98,4 +98,9 @@ public interface DisposeAbility { * @return the boolean */ boolean isCarryProtectIp(String ipAddr); + + /** + * Period task runtime. + */ + void periodTaskRuntime(); } diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 41b27a13..06c738c3 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -3,6 +3,7 @@ package com.dispose.ability.impl; import com.dispose.ability.DisposeAbility; import com.dispose.common.CommonEnumHandler; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.DpTechAttackType; import com.dispose.common.DpTechConfigValue; @@ -29,7 +30,9 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants; import javax.xml.ws.BindingProvider; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -48,12 +51,55 @@ public class DpTechAbilityImpl implements DisposeAbility { * The Protect ip v 6. */ private final List protectIpV6 = new ArrayList<>(); - + /** + * The All cleanup devices. + */ + private final HashSet allCleanupDevices = new HashSet<>(); + /** + * The Timer cnt. + */ + private long timerCnt = 0; + /** + * The Device link status. + */ + private boolean deviceLinkStatus = false; /** * The Clean type port. */ 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. * @@ -93,6 +139,9 @@ public class DpTechAbilityImpl implements DisposeAbility { //读取超时 policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND); conduit.setClient(policy); + + // 获取所有检测设备 + initCleanupDevices(); } /** @@ -107,7 +156,8 @@ public class DpTechAbilityImpl implements DisposeAbility { * @return the mul return type */ @Override - public MulReturnType runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType, + public MulReturnType runDispose(String disposeObject, DisposeObjectType objectType, + DisposeCapacityType capType, NetflowDirection nfDirection, Integer attackType, Long duration) { @@ -205,15 +255,23 @@ public class DpTechAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { + return deviceLinkStatus; + + } + + /** + * Dev get link status. + */ + private void devGetLinkStatus() { try { // 获取防护对象接口调用成功认为设备心跳正常 cleanTypePort.getAllProtectionObjectFromUMC().getProtectionObjectDataForService(); - return true; + deviceLinkStatus = true; } catch (Exception ex) { log.error(ex.getMessage()); } - return false; + deviceLinkStatus = false; } /** @@ -327,4 +385,22 @@ public class DpTechAbilityImpl implements DisposeAbility { public MulReturnType taskStatus(String taskId) { 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"); + } } diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index 2242cfbc..c0156ea6 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -2,6 +2,7 @@ package com.dispose.ability.impl; import com.dispose.ability.DisposeAbility; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; @@ -38,6 +39,14 @@ public class HaoHanAbilityImpl implements DisposeAbility { * The Url root path. */ private String urlRootPath; + /** + * The Timer cnt. + */ + private long timerCnt = 0; + /** + * The Device link status. + */ + private boolean deviceLinkStatus = false; /** * Init device env. @@ -153,14 +162,23 @@ public class HaoHanAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { + return deviceLinkStatus; + } + + /** + * Dev get link status. + */ + private void devGetLinkStatus() { try { // 获取任务信息接口调用成功认为设备心跳正常 - return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); + if (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null) { + deviceLinkStatus = true; + } } catch (Exception ex) { log.error(ex.getMessage()); } - return false; + deviceLinkStatus = false; } /** @@ -225,4 +243,19 @@ public class HaoHanAbilityImpl implements DisposeAbility { public MulReturnType taskStatus(String taskId) { 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"); + } } diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java index 4fdf3ba8..e3086a18 100644 --- a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -3,6 +3,7 @@ package com.dispose.ability.impl; import cn.hutool.http.HttpResponse; import com.dispose.ability.DisposeAbility; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; @@ -29,6 +30,14 @@ import javax.servlet.http.HttpServletResponse; @Component @Slf4j public class HuaWeiAbilityImpl implements DisposeAbility { + /** + * The Timer cnt. + */ + private long timerCnt = 0; + /** + * The Device link status. + */ + private boolean deviceLinkStatus = false; /** * The Restful interface. */ @@ -270,12 +279,20 @@ public class HuaWeiAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { + return deviceLinkStatus; + } + + /** + * Dev get link status. + */ + private void devGetLinkStatus() { try { //查询所有的zone接口调用成功认为设备心跳正常 String url = urlRootPath + "/allzone"; if (token == null || token.length() == 0) { - return false; + deviceLinkStatus = false; + return; } HttpResponse response = restfulInterface.queryAllZones(url, token); @@ -286,13 +303,15 @@ public class HuaWeiAbilityImpl implements DisposeAbility { response = restfulInterface.queryAllZones(url, token); } - return response.getStatus() == HttpServletResponse.SC_OK; + if (response.getStatus() == HttpServletResponse.SC_OK) { + deviceLinkStatus = true; + } } catch ( Exception ex) { log.error(ex.getMessage()); } - return false; + deviceLinkStatus = false; } @@ -330,5 +349,20 @@ public class HuaWeiAbilityImpl implements DisposeAbility { } 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"); + } } diff --git a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java index b40b55cd..58f3491b 100644 --- a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java @@ -2,6 +2,7 @@ package com.dispose.ability.impl; import com.dispose.ability.DisposeAbility; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.Helper; @@ -55,6 +56,15 @@ public class PengXinAbilityImpl implements DisposeAbility { * The Task req id. */ private Long taskReqId = System.currentTimeMillis(); + /** + * The Timer cnt. + */ + private long timerCnt = 0; + /** + * The Device link status. + */ + private boolean deviceLinkStatus = false; + /** * The Url root path. */ @@ -310,11 +320,19 @@ public class PengXinAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { + return deviceLinkStatus; + } + + /** + * Dev get link status. + */ + private void devGetLinkStatus() { try { String url = urlRootPath + "dispose_device/information/linkstatus"; if (token == null || token.length() == 0) { - return false; + deviceLinkStatus = false; + return; } ErrorCode err = restfulInterface.getLinkStatus(url, token); @@ -325,12 +343,14 @@ public class PengXinAbilityImpl implements DisposeAbility { err = restfulInterface.getLinkStatus(url, token); } - return err == ErrorCode.ERR_OK; + if (err == ErrorCode.ERR_OK) { + deviceLinkStatus = true; + } } catch (Exception ex) { log.error(ex.getMessage()); } - return false; + deviceLinkStatus = false; } /** @@ -480,4 +500,22 @@ public class PengXinAbilityImpl implements DisposeAbility { } 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"); + } } diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index d9520f65..ed1b480b 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -143,4 +143,12 @@ public class VirtualAbilityImpl implements DisposeAbility { public MulReturnType taskStatus(String taskId) { return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, -1L); } + + /** + * Period task runtime. + */ + @Override + public void periodTaskRuntime() { + + } } diff --git a/src/main/java/com/dispose/common/DDoSAttackType.java b/src/main/java/com/dispose/common/DDoSAttackType.java index 07bfb4a8..5ba86204 100644 --- a/src/main/java/com/dispose/common/DDoSAttackType.java +++ b/src/main/java/com/dispose/common/DDoSAttackType.java @@ -186,6 +186,11 @@ public enum DDoSAttackType implements BaseEnum { */ IGMP_FLOOD(42, "IGMP_FLOOD"), + + /** + * None attacks d do s attack type. + */ + NONE_ATTACKS(63, "NONE_ATTACKS"), /** * The All attacks. */ @@ -224,7 +229,7 @@ public enum DDoSAttackType implements BaseEnum { if (types.contains(ALL_ATTACKS)) { for (DDoSAttackType type : DDoSAttackType.values()) { - if (type.equals(ALL_ATTACKS)) { + if (type.equals(ALL_ATTACKS) || type.equals(NONE_ATTACKS)) { continue; } mask |= (long) 1 << type.getValue(); @@ -249,7 +254,8 @@ public enum DDoSAttackType implements BaseEnum { if (Arrays.asList(types).contains(ALL_ATTACKS)) { for (DDoSAttackType type : DDoSAttackType.values()) { - if (type.equals(ALL_ATTACKS)) { + // 掩码处理跳过所有攻击类型与不指定攻击类型 + if (type.equals(ALL_ATTACKS) || type.equals(NONE_ATTACKS)) { continue; } mask |= (long) 1 << type.getValue(); @@ -270,8 +276,12 @@ public enum DDoSAttackType implements BaseEnum { * @return the type mask from attack type */ public static Long getTypeMaskFromAttackType(Integer[] types) { + // 如果指定了所有攻击类型,选择所有攻击类型 if (Arrays.stream(types).anyMatch(v -> ALL_ATTACKS.getValue().equals(v))) { 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 { long mask = 0L; for (int i : types) { diff --git a/src/main/java/com/dispose/common/DisposeConfigValue.java b/src/main/java/com/dispose/common/DisposeConfigValue.java index 57fe3b43..c5525dfe 100644 --- a/src/main/java/com/dispose/common/DisposeConfigValue.java +++ b/src/main/java/com/dispose/common/DisposeConfigValue.java @@ -58,4 +58,9 @@ public class DisposeConfigValue { * The constant ENABLE_UTEST_MOCK. */ public static volatile boolean ENABLE_UTEST_MOCK = false; + + /** + * The constant HEART_PERIOD_OF_SECOND. + */ + public static long HEART_PERIOD_OF_SECOND = 30; } diff --git a/src/main/java/com/dispose/common/DpTechAttackType.java b/src/main/java/com/dispose/common/DpTechAttackType.java index e04e3ef0..72e35cab 100644 --- a/src/main/java/com/dispose/common/DpTechAttackType.java +++ b/src/main/java/com/dispose/common/DpTechAttackType.java @@ -57,7 +57,13 @@ public enum DpTechAttackType implements BaseEnum { /** * 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. @@ -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 - * @return the stream + * @return the list */ public static List fromDdosAttackTypeValue(DDoSAttackType type) { List attackList = new ArrayList<>(); @@ -204,6 +210,10 @@ public enum DpTechAttackType implements BaseEnum { attackList.addAll(Arrays.asList(DpTechAttackType.values())); break; + case NONE_ATTACKS: + attackList.add(AUTO_ATTACK_TYPE); + break; + default: break; } diff --git a/src/main/java/com/dispose/service/DisposeAbilityRouterService.java b/src/main/java/com/dispose/service/DisposeAbilityRouterService.java index 14442e4b..71464590 100644 --- a/src/main/java/com/dispose/service/DisposeAbilityRouterService.java +++ b/src/main/java/com/dispose/service/DisposeAbilityRouterService.java @@ -54,4 +54,9 @@ public interface DisposeAbilityRouterService { * @return the error code */ ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType); + + /** + * Run period task. + */ + void runPeriodTask(); } diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index 78943217..f59ce5d1 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -3,9 +3,9 @@ package com.dispose.service.impl; import com.dispose.ability.DisposeAbility; import com.dispose.ability.impl.DpTechAbilityImpl; import com.dispose.ability.impl.HaoHanAbilityImpl; +import com.dispose.ability.impl.HuaWeiAbilityImpl; import com.dispose.ability.impl.PengXinAbilityImpl; import com.dispose.ability.impl.VirtualAbilityImpl; -import com.dispose.ability.impl.HuaWeiAbilityImpl; import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.HttpType; @@ -14,6 +14,8 @@ import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.po.AbilityInfo; import com.dispose.service.DisposeAbilityRouterService; 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.PostConstruct; @@ -171,6 +173,16 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ 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. * diff --git a/src/main/java/com/dispose/task/DeviceManagerTask.java b/src/main/java/com/dispose/task/DeviceManagerTask.java index ec16c939..960fdae2 100644 --- a/src/main/java/com/dispose/task/DeviceManagerTask.java +++ b/src/main/java/com/dispose/task/DeviceManagerTask.java @@ -57,9 +57,6 @@ public class DeviceManagerTask { ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" : ":" + v.getDev().getIpPort()), ret.getFirstParam()); - - // 更新设备保护对象 - v.getDb().getDisposeDeviceProtectObject(); }); } } From 8d95610e377040a2d27579cff934f7ab6606e6e3 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 13 Jan 2021 15:18:24 +0800 Subject: [PATCH 02/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=98=AF=E5=90=A6=E5=B0=B1=E7=BB=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=202.=20=E5=A2=9E=E5=8A=A0=E5=8D=8E=E4=B8=BA=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E8=AE=BE=E5=A4=87=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= =?UTF-8?q?=203.=20=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/ability/DisposeAbility.java | 7 ++++ .../ability/impl/DpTechAbilityImpl.java | 10 +++++ .../ability/impl/HaoHanAbilityImpl.java | 10 +++++ .../ability/impl/HuaWeiAbilityImpl.java | 25 ++++++++++--- .../ability/impl/PengXinAbilityImpl.java | 10 +++++ .../ability/impl/VirtualAbilityImpl.java | 10 +++++ .../device/ability/DpProtectObject.java | 37 +++++++++++++++++++ .../dispose/protocol/HuaWeiInterface.java | 5 +++ 8 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index b55f4feb..ee81b79d 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -103,4 +103,11 @@ public interface DisposeAbility { * Period task runtime. */ void periodTaskRuntime(); + + /** + * Device ready boolean. + * + * @return the boolean + */ + Boolean deviceReady(); } diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 06c738c3..718151f8 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -403,4 +403,14 @@ public class DpTechAbilityImpl implements DisposeAbility { log.debug("----DpTech Period Task Running"); } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public Boolean deviceReady() { + return true; + } } diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index c0156ea6..1721bd14 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -258,4 +258,14 @@ public class HaoHanAbilityImpl implements DisposeAbility { log.debug("----HaoHan Period Task Running"); } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public Boolean deviceReady() { + return true; + } } diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java index e3086a18..4bca4e2b 100644 --- a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -149,10 +149,13 @@ public class HuaWeiAbilityImpl implements DisposeAbility { return new MulReturnType<>(ErrorCode.ERR_HUAWEI_ERROR, null); } - log.debug("----Finish HuaWei Start Cleanup Task: {}", disposeObject); + log.info("----Finish HuaWei Start Cleanup Task: {}", disposeObject); return new MulReturnType<>(ErrorCode.ERR_OK, null); } catch (Exception ex) { - log.error("----Exception HuaWei Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration); + log.error("----Exception HuaWei Start Cleanup Task [{}]: {}, {}, {}, {}, {}", ex.getMessage(), + disposeObject, + nfDirection, + duration, url, token); return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } } @@ -190,7 +193,7 @@ public class HuaWeiAbilityImpl implements DisposeAbility { } try { - log.debug("++++Begging HuaWei Stop Cleanup Task: {}", taskId); + log.info("++++Begging HuaWei Stop Cleanup Task: {}", taskId); if (capType != DisposeCapacityType.CLEANUP) { log.error("----Error HuaWei don't support dispose capacity type: {}", capType); @@ -220,10 +223,12 @@ public class HuaWeiAbilityImpl implements DisposeAbility { return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); } - log.debug("----Finish HuaWei Stop Cleanup Task: {}", taskId); + log.info("----Finish HuaWei Stop Cleanup Task: {}", taskId); return new MulReturnType<>(ErrorCode.ERR_OK, null); } catch (Exception ex) { - log.error("----Exception HuaWei Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId); + log.error("----Exception HuaWei Stop Cleanup Task [{}]: {}, {}, {}, {}", ex.getMessage(), + disposeObject, + nfDirection, url, token); return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } } @@ -364,5 +369,15 @@ public class HuaWeiAbilityImpl implements DisposeAbility { log.debug("----HuaWei Period Task Running"); } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public Boolean deviceReady() { + return true; + } } diff --git a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java index 58f3491b..19431d8d 100644 --- a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java @@ -518,4 +518,14 @@ public class PengXinAbilityImpl implements DisposeAbility { log.debug("----PengXin Period Task Running"); } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public Boolean deviceReady() { + return true; + } } diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index ed1b480b..25e28c77 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -151,4 +151,14 @@ public class VirtualAbilityImpl implements DisposeAbility { public void periodTaskRuntime() { } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public Boolean deviceReady() { + return true; + } } diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java new file mode 100644 index 00000000..8f1bce47 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java @@ -0,0 +1,37 @@ +package com.dispose.pojo.dto.protocol.device.ability; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Hashtable; + +/** + * The type Dp protect object. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DpProtectObject { + /** + * The Protect name. + */ + private String protectName; + + /** + * The Detection devices. + */ + private String detectionDevices; + + /** + * The Cleanup devices. + */ + private String cleanupDevices; + + /** + * The Ip segment v 4. + */ + private Hashtable ipSegment; +} diff --git a/src/main/java/com/huawei/dispose/protocol/HuaWeiInterface.java b/src/main/java/com/huawei/dispose/protocol/HuaWeiInterface.java index 7807454d..af0bd037 100644 --- a/src/main/java/com/huawei/dispose/protocol/HuaWeiInterface.java +++ b/src/main/java/com/huawei/dispose/protocol/HuaWeiInterface.java @@ -5,6 +5,7 @@ import com.dispose.common.ErrorCode; import com.dispose.restful.RestfulInterface; import com.huawei.dispose.common.HuaWeiCreatDivertReq; import com.huawei.dispose.common.HuaWeiLoginReq; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMethod; import javax.servlet.http.HttpServletResponse; @@ -14,6 +15,7 @@ import javax.servlet.http.HttpServletResponse; * * @author */ +@Slf4j public class HuaWeiInterface { /** * Auth http response. @@ -60,6 +62,8 @@ public class HuaWeiInterface { } } + log.error("----HuaWei response [{}]: {}", response == null ? -1 : response.getStatus(), response); + return ErrorCode.ERR_UNKNOWNCMD; } @@ -92,6 +96,7 @@ public class HuaWeiInterface { } } + log.error("----HuaWei response [{}]: {}", response == null ? -1 : response.getStatus(), response); return ErrorCode.ERR_UNKNOWNCMD; } From 346c604165dc9b41614b41c763c7a7454768a382 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 13 Jan 2021 16:03:46 +0800 Subject: [PATCH 03/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BB=84=E4=BF=A1=E6=81=AF=E8=A1=A8=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=9A=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=AF=B9=E8=B1=A1=203.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BB=84Mapper=204.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=205.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/common/DisposeDeviceType.java | 6 +- .../java/com/dispose/common/ServiceType.java | 68 +++++++++++++++++++ .../dispose/mapper/ServiceGroupMapper.java | 44 ++++++++++++ .../com/dispose/pojo/entity/ServiceInfo.java | 62 +++++++++++++++++ src/main/resources/db/schema.sql | 18 +++++ src/main/resources/mappers/ServiceGroup.xml | 43 ++++++++++++ src/main/resources/test_db/unit_test.sql | 18 +++++ 7 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/dispose/common/ServiceType.java create mode 100644 src/main/java/com/dispose/mapper/ServiceGroupMapper.java create mode 100644 src/main/java/com/dispose/pojo/entity/ServiceInfo.java create mode 100644 src/main/resources/mappers/ServiceGroup.xml diff --git a/src/main/java/com/dispose/common/DisposeDeviceType.java b/src/main/java/com/dispose/common/DisposeDeviceType.java index afa2fbfb..7a93db61 100644 --- a/src/main/java/com/dispose/common/DisposeDeviceType.java +++ b/src/main/java/com/dispose/common/DisposeDeviceType.java @@ -19,9 +19,13 @@ public enum DisposeDeviceType implements BaseEnum { */ PENGXIN_PLATFORM(2, "鹏信处置设备"), /** - * The HuaWei platform. + * The Huawei platform. */ HUAWEI_PLATFORM(3, "华为处置设备"), + /** + * Dptech bypass umc dispose device type. + */ + DPTECH_BYPASS_UMC(4, "迪普旁路牵引UMC管理平台"), /** * The Virtual dispose. */ diff --git a/src/main/java/com/dispose/common/ServiceType.java b/src/main/java/com/dispose/common/ServiceType.java new file mode 100644 index 00000000..2c316137 --- /dev/null +++ b/src/main/java/com/dispose/common/ServiceType.java @@ -0,0 +1,68 @@ +package com.dispose.common; + +/** + * The enum Service type. + * + * @author + */ +public enum ServiceType implements BaseEnum { + /** + * The Service and others. + */ + SERVICE_AND_OTHERS(0, "服务器以及其它类型"), + + /** + * Web site service type. + */ + WEB_SITE(1, "网站"), + + /** + * Dns service service type. + */ + DNS_SERVICE(2, "DNS 服务"), + + /** + * Game service service type. + */ + GAME_SERVICE(3, "游戏 服务"), + ; + /** + * The Code. + */ + private final Integer code; + /** + * The Readme. + */ + private final String readme; + + /** + * Instantiates a new Service type. + * + * @param code the code + * @param readme the readme + */ + ServiceType(int code, String readme) { + this.code = code; + this.readme = readme; + } + + /** + * Gets value. + * + * @return the value + */ + @Override + public Integer getValue() { + return this.code; + } + + /** + * Gets description. + * + * @return the description + */ + @Override + public String getDescription() { + return this.readme; + } +} diff --git a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java new file mode 100644 index 00000000..a6dad4db --- /dev/null +++ b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java @@ -0,0 +1,44 @@ +package com.dispose.mapper; + +import com.dispose.pojo.entity.ServiceInfo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface Service group mapper. + * + * @author + */ +public interface ServiceGroupMapper { + /** + * Select all list. + * + * @return the list + */ + List selectAll(); + + /** + * Add service group int. + * + * @param svrGrps the svr grps + * @return the int + */ + int addServiceGroup(@Param("svrGrps") List svrGrps); + + /** + * Del service group by id int. + * + * @param id the id + * @return the int + */ + int delServiceGroupById(@Param("id") Long id); + + /** + * Del service group by service id int. + * + * @param serviceId the service id + * @return the int + */ + int delServiceGroupByServiceId(@Param("serviceId") Long serviceId); +} diff --git a/src/main/java/com/dispose/pojo/entity/ServiceInfo.java b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java new file mode 100644 index 00000000..973789c5 --- /dev/null +++ b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java @@ -0,0 +1,62 @@ +package com.dispose.pojo.entity; + +import com.dispose.common.ServiceType; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * The type Service info. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "service_group") +@NameStyle(Style.normal) +public class ServiceInfo { + /** + * The constant serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + /** + * The Service id. + */ + private Long serviceId; + + /** + * The Service type. + */ + private ServiceType serviceType; + + /** + * The Service bandwidth. + */ + private Long serviceBandwidth; + + /** + * The Service ip. + */ + private String serviceIp; +} diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index b3e85c69..752ed366 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -128,6 +128,24 @@ CREATE TABLE `dispose_task` COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC; +-- ---------------------------- +-- Table structure for service_group +-- ---------------------------- +DROP TABLE IF EXISTS `service_group`; +CREATE TABLE `service_group` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', + `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', + `serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0:SEVER\r\n1:WEB\r\n2:DNS\r\n3:GAME', + `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', + `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = DYNAMIC; + -- ---------------------------- -- Table structure for user_account -- ---------------------------- diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml new file mode 100644 index 00000000..ea3e1630 --- /dev/null +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp) + VALUES + + (#{svg.deviceId}, #{svg.serviceType}, #{svg.serviceBandwidth}, #{svg.serviceIp}) + + + + + DELETE + FROM service_group + WHERE service_group.id = #{id} + + + + DELETE + FROM service_group + WHERE service_group.serviceId = #{serviceId} + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/test_db/unit_test.sql b/src/main/resources/test_db/unit_test.sql index 595e5178..80d93e4a 100644 --- a/src/main/resources/test_db/unit_test.sql +++ b/src/main/resources/test_db/unit_test.sql @@ -204,6 +204,24 @@ CREATE TABLE `user_account` COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +-- ---------------------------- +-- Table structure for service_group +-- ---------------------------- +DROP TABLE IF EXISTS `service_group`; +CREATE TABLE `service_group` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', + `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', + `serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0:SEVER\r\n1:WEB\r\n2:DNS\r\n3:GAME', + `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', + `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = DYNAMIC; + -- ---------------------------- -- Records of user_account -- ---------------------------- From 6a173c0504d930bd8315909c88c0dded0a6a6668 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 13 Jan 2021 18:25:25 +0800 Subject: [PATCH 04/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=202.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=203.=20=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE?= =?UTF-8?q?=E9=98=B2=E6=8A=A4=E6=A8=A1=E6=9D=BF=E6=98=A0=E5=B0=84=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=204.=20=E4=BF=AE=E6=94=B9=E4=B8=9A=E5=8A=A1=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=205.=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=8D=95=E6=B5=8B=E6=A1=86=E6=9E=B6=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E8=BD=BD=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=206.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-template.properties | 51 ++++++++++++++ config/application.properties | 2 +- .../java/com/dispose/common/ServiceType.java | 68 ------------------- .../com/dispose/config/TemplateConfigure.java | 27 ++++++++ .../com/dispose/pojo/entity/ServiceInfo.java | 3 +- .../com/dispose/pojo/vo/TemplateInfo.java | 34 ++++++++++ .../com/dispose/service/TemplateService.java | 17 +++++ .../service/impl/TemplateServiceImpl.java | 50 ++++++++++++++ src/main/resources/db/schema.sql | 2 +- src/main/resources/mappers/ServiceGroup.xml | 2 +- src/main/resources/test_db/unit_test.sql | 2 +- .../test/common/CommonEnvironment.java | 2 +- .../test/dev/Global/InitTestEnvironment.java | 2 +- .../dev/config/TemplateConfigureTest.java | 37 ++++++++++ 14 files changed, 223 insertions(+), 76 deletions(-) create mode 100644 config/application-template.properties delete mode 100644 src/main/java/com/dispose/common/ServiceType.java create mode 100644 src/main/java/com/dispose/config/TemplateConfigure.java create mode 100644 src/main/java/com/dispose/pojo/vo/TemplateInfo.java create mode 100644 src/main/java/com/dispose/service/TemplateService.java create mode 100644 src/main/java/com/dispose/service/impl/TemplateServiceImpl.java create mode 100644 src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java diff --git a/config/application-template.properties b/config/application-template.properties new file mode 100644 index 00000000..8a1618c3 --- /dev/null +++ b/config/application-template.properties @@ -0,0 +1,51 @@ +template.testValue=12345 +template.templateInfo.name=Game_Server_10G +template.templateInfo.bandMin=1500 +template.templateInfo.bandMax=-1 +template.templateInfo.type=GAME +#模板配置 +template.umcTemplate[0].name=Game_Server_10G +template.umcTemplate[0].bandMin=1500 +template.umcTemplate[0].bandMax=-1 +template.umcTemplate[0].type=GAME + +template.umcTemplate[1].name=Game_Server_1G +template.umcTemplate[1].bandMin=0 +template.umcTemplate[1].bandMax=1500 +template.umcTemplate[1].type=GAME + +template.umcTemplate[2].name=DNS_Server_10G +template.umcTemplate[2].bandMin=1500 +template.umcTemplate[2].bandMax=-1 +template.umcTemplate[2].type=DNS + +template.umcTemplate[3].name=DNS_Server_1G +template.umcTemplate[3].bandMin=0 +template.umcTemplate[3].bandMax=1500 +template.umcTemplate[3].type=DNS + +template.umcTemplate[4].name=WEB_Server_10G +template.umcTemplate[4].bandMin=1500 +template.umcTemplate[4].bandMax=-1 +template.umcTemplate[4].type=WEB + +template.umcTemplate[5].name=WEB_Server_1G +template.umcTemplate[5].bandMin=0 +template.umcTemplate[5].bandMax=1500 +template.umcTemplate[5].type=WEB + +template.umcTemplate[6].name=General_Server_10G +template.umcTemplate[6].bandMin=1500 +template.umcTemplate[6].bandMax=-1 +template.umcTemplate[6].type=SERVER + +template.umcTemplate[7].name=General_Server_1G +template.umcTemplate[7].bandMin=500 +template.umcTemplate[7].bandMax=1500 +template.umcTemplate[7].type=SERVER + +template.umcTemplate[8].name=General_Server_100M +template.umcTemplate[8].bandMin=0 +template.umcTemplate[8].bandMax=500 +template.umcTemplate[8].type=SERVER + diff --git a/config/application.properties b/config/application.properties index b745d9d5..793906d1 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1 +1 @@ -spring.profiles.active=local,dispose \ No newline at end of file +spring.profiles.active=local,dispose,template \ No newline at end of file diff --git a/src/main/java/com/dispose/common/ServiceType.java b/src/main/java/com/dispose/common/ServiceType.java deleted file mode 100644 index 2c316137..00000000 --- a/src/main/java/com/dispose/common/ServiceType.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.dispose.common; - -/** - * The enum Service type. - * - * @author - */ -public enum ServiceType implements BaseEnum { - /** - * The Service and others. - */ - SERVICE_AND_OTHERS(0, "服务器以及其它类型"), - - /** - * Web site service type. - */ - WEB_SITE(1, "网站"), - - /** - * Dns service service type. - */ - DNS_SERVICE(2, "DNS 服务"), - - /** - * Game service service type. - */ - GAME_SERVICE(3, "游戏 服务"), - ; - /** - * The Code. - */ - private final Integer code; - /** - * The Readme. - */ - private final String readme; - - /** - * Instantiates a new Service type. - * - * @param code the code - * @param readme the readme - */ - ServiceType(int code, String readme) { - this.code = code; - this.readme = readme; - } - - /** - * Gets value. - * - * @return the value - */ - @Override - public Integer getValue() { - return this.code; - } - - /** - * Gets description. - * - * @return the description - */ - @Override - public String getDescription() { - return this.readme; - } -} diff --git a/src/main/java/com/dispose/config/TemplateConfigure.java b/src/main/java/com/dispose/config/TemplateConfigure.java new file mode 100644 index 00000000..4b64344b --- /dev/null +++ b/src/main/java/com/dispose/config/TemplateConfigure.java @@ -0,0 +1,27 @@ +package com.dispose.config; + +import com.dispose.pojo.vo.TemplateInfo; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * The type Template configure. + * + * @author + */ +@Getter +@Setter +@Component +@ConfigurationProperties(prefix = "template") +@Configuration +public class TemplateConfigure { + /** + * The Umc template. + */ + List umcTemplate; +} diff --git a/src/main/java/com/dispose/pojo/entity/ServiceInfo.java b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java index 973789c5..40fb81ab 100644 --- a/src/main/java/com/dispose/pojo/entity/ServiceInfo.java +++ b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java @@ -1,6 +1,5 @@ package com.dispose.pojo.entity; -import com.dispose.common.ServiceType; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; @@ -48,7 +47,7 @@ public class ServiceInfo { /** * The Service type. */ - private ServiceType serviceType; + private String serviceType; /** * The Service bandwidth. diff --git a/src/main/java/com/dispose/pojo/vo/TemplateInfo.java b/src/main/java/com/dispose/pojo/vo/TemplateInfo.java new file mode 100644 index 00000000..42a6a0f0 --- /dev/null +++ b/src/main/java/com/dispose/pojo/vo/TemplateInfo.java @@ -0,0 +1,34 @@ +package com.dispose.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Template info. + * + * @author + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TemplateInfo { + /** + * The Name. + */ + private String name; + /** + * The Band min. + */ + private Long bandMin; + /** + * The Band max. + */ + private Long bandMax; + /** + * The Type. + */ + private String type; +} diff --git a/src/main/java/com/dispose/service/TemplateService.java b/src/main/java/com/dispose/service/TemplateService.java new file mode 100644 index 00000000..865e0535 --- /dev/null +++ b/src/main/java/com/dispose/service/TemplateService.java @@ -0,0 +1,17 @@ +package com.dispose.service; + +/** + * The interface Template service. + * + * @author + */ +public interface TemplateService { + /** + * Gets template. + * + * @param type the type + * @param bandWidth the band width + * @return the template + */ + String getTemplate(String type, Long bandWidth); +} diff --git a/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java new file mode 100644 index 00000000..a7386ee5 --- /dev/null +++ b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java @@ -0,0 +1,50 @@ +package com.dispose.service.impl; + +import com.dispose.config.TemplateConfigure; +import com.dispose.pojo.vo.TemplateInfo; +import com.dispose.service.TemplateService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * The type Template service. + * + * @author + */ +@Service +@Slf4j +public class TemplateServiceImpl implements TemplateService { + @Resource + TemplateConfigure templateConfigure; + + /** + * Gets template. + * + * @param type the type + * @param bandWidth the band width + * @return the template + */ + @Override + public String getTemplate(String type, Long bandWidth) { + // 遍历所有模板 + for (TemplateInfo v : templateConfigure.getUmcTemplate()) { + // 判断类型是否一致 + if (v.getType().equals(type)) { + // 当前带宽大于当前模板最小值 + if (bandWidth > v.getBandMin()) { + // 模板最大值为-1或者带宽小于等于模板最小值,返回模板名称 + if (v.getBandMax() == -1 || bandWidth <= v.getBandMax()) { + log.debug("Template analyze: {}, {} match {}", type, bandWidth, v); + return v.getName(); + } + } + } + } + + // 纪录异常日志 + log.error("Template analyze: {}, {} match nothing!!!", type, bandWidth); + return null; + } +} diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 752ed366..9b4f4db1 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -136,7 +136,7 @@ CREATE TABLE `service_group` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', - `serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0:SEVER\r\n1:WEB\r\n2:DNS\r\n3:GAME', + `serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME', `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', PRIMARY KEY (`id`) USING BTREE diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index ea3e1630..029a0a6a 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/resources/test_db/unit_test.sql b/src/main/resources/test_db/unit_test.sql index 80d93e4a..a8d2f48c 100644 --- a/src/main/resources/test_db/unit_test.sql +++ b/src/main/resources/test_db/unit_test.sql @@ -212,7 +212,7 @@ CREATE TABLE `service_group` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', - `serviceType` int(11) NOT NULL COMMENT '业务类型:\r\n0:SEVER\r\n1:WEB\r\n2:DNS\r\n3:GAME', + `serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME', `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', PRIMARY KEY (`id`) USING BTREE diff --git a/src/test/java/com/dispose/test/common/CommonEnvironment.java b/src/test/java/com/dispose/test/common/CommonEnvironment.java index 1eb16bc5..ae946cf7 100644 --- a/src/test/java/com/dispose/test/common/CommonEnvironment.java +++ b/src/test/java/com/dispose/test/common/CommonEnvironment.java @@ -26,7 +26,7 @@ import java.util.Optional; @Data @Slf4j @EnableEncryptableProperties -@ActiveProfiles({"test", "dispose"}) +@ActiveProfiles({"test", "dispose", "template"}) public class CommonEnvironment { /** diff --git a/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java b/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java index f852e0b1..bd4215bf 100644 --- a/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java +++ b/src/test/java/com/dispose/test/dev/Global/InitTestEnvironment.java @@ -26,7 +26,7 @@ import javax.annotation.Resource; @Slf4j @Getter @EnableEncryptableProperties -@ActiveProfiles({"test", "dispose"}) +@ActiveProfiles({"test", "dispose", "template"}) public class InitTestEnvironment { /** * The constant HTTP_CONNECT_TIMEOUT. diff --git a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java new file mode 100644 index 00000000..3051166a --- /dev/null +++ b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java @@ -0,0 +1,37 @@ +package com.dispose.test.dev.config; + +import com.dispose.config.TemplateConfigure; +import com.dispose.test.dev.Global.InitTestEnvironment; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * The type Template configure test. + * + * @author + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +public class TemplateConfigureTest extends InitTestEnvironment { + /** + * The Template configure. + */ + @Resource + TemplateConfigure templateConfigure; + + /** + * Template loads test. + */ + @Test + public void templateLoadsTest() { + log.info("Load template: {}", templateConfigure.getUmcTemplate()); + Assert.assertEquals(9, templateConfigure.getUmcTemplate().size()); + } +} From c76599e5d8330dd5f121c75caa4bcdeace00f3bc Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 13 Jan 2021 18:25:54 +0800 Subject: [PATCH 05/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-template.properties | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config/application-template.properties b/config/application-template.properties index 8a1618c3..942415b4 100644 --- a/config/application-template.properties +++ b/config/application-template.properties @@ -1,8 +1,3 @@ -template.testValue=12345 -template.templateInfo.name=Game_Server_10G -template.templateInfo.bandMin=1500 -template.templateInfo.bandMax=-1 -template.templateInfo.type=GAME #模板配置 template.umcTemplate[0].name=Game_Server_10G template.umcTemplate[0].bandMin=1500 From ef48a292f5eff966ddc94d4ffb087db4950f6a6a Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 13 Jan 2021 18:40:18 +0800 Subject: [PATCH 06/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E6=97=81=E8=B7=AF=E7=89=B5=E5=BC=95=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 17 +++++++++++++++++ .../impl/DeviceTaskManagerServiceImpl.java | 2 ++ .../impl/DisposeAbilityRouterServiceImpl.java | 4 ++++ 3 files changed, 23 insertions(+) create mode 100644 src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java new file mode 100644 index 00000000..516ca674 --- /dev/null +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -0,0 +1,17 @@ +package com.dispose.ability.impl; + +/** + * The type Dp tech bypass ability. + * + * @author + */ +public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { + + /** + * Period task runtime. + */ + @Override + public void periodTaskRuntime() { + super.periodTaskRuntime(); + } +} diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index c5fa9287..f8fa0f7a 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -531,6 +531,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 启动新任务 switch (ai.getDev().getDeviceType()) { case DPTECH_UMC: + case DPTECH_BYPASS_UMC: dpTechDeviceTaskRun(ai, v, task); break; @@ -604,6 +605,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { switch (ai.getDev().getDeviceType()) { case DPTECH_UMC: + case DPTECH_BYPASS_UMC: dpTechDeviceTaskStop(ai, v, task); break; diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index f59ce5d1..e35afa02 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -2,6 +2,7 @@ package com.dispose.service.impl; import com.dispose.ability.DisposeAbility; import com.dispose.ability.impl.DpTechAbilityImpl; +import com.dispose.ability.impl.DpTechBypassAbilityImpl; import com.dispose.ability.impl.HaoHanAbilityImpl; import com.dispose.ability.impl.HuaWeiAbilityImpl; import com.dispose.ability.impl.PengXinAbilityImpl; @@ -124,6 +125,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ case VIRTUAL_DISPOSE: db = new VirtualAbilityImpl(); break; + case DPTECH_BYPASS_UMC: + db = new DpTechBypassAbilityImpl(); + break; default: log.error("Unknown dispose device type: {}", dev.getDeviceType()); return ErrorCode.ERR_PARAMS; From 7bc5f2ef1a6ad6e3cbb7f647f442a559d39b799a Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 09:58:15 +0800 Subject: [PATCH 07/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechAbilityImpl.java | 41 +----- .../ability/impl/DpTechBypassAbilityImpl.java | 136 +++++++++++++++++- .../com/dispose/common/DpTechConfigValue.java | 5 + .../device/ability/DpProtectObject.java | 10 +- .../java/com/dispose/test/dev/debug/demo.java | 18 +++ 5 files changed, 172 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 718151f8..a68f9025 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -30,9 +30,7 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants; import javax.xml.ws.BindingProvider; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; @@ -51,10 +49,6 @@ public class DpTechAbilityImpl implements DisposeAbility { * The Protect ip v 6. */ private final List protectIpV6 = new ArrayList<>(); - /** - * The All cleanup devices. - */ - private final HashSet allCleanupDevices = new HashSet<>(); /** * The Timer cnt. */ @@ -69,36 +63,14 @@ public class DpTechAbilityImpl implements DisposeAbility { private AbnormalFlowCleaningServicePortType cleanTypePort; /** - * Init cleanup devices. + * Gets clean type port. + * + * @return the clean type port */ - 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"); - } + public AbnormalFlowCleaningServicePortType getCleanTypePort() { + return cleanTypePort; } - /** - * 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. @@ -139,9 +111,6 @@ public class DpTechAbilityImpl implements DisposeAbility { //读取超时 policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND); conduit.setClient(policy); - - // 获取所有检测设备 - initCleanupDevices(); } /** diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 516ca674..a0a13a73 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -1,17 +1,151 @@ package com.dispose.ability.impl; +import com.dispose.common.DisposeConfigValue; +import com.dispose.common.DpTechConfigValue; +import com.dispose.common.IpAddrType; +import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject; +import com.dptech.dispose.ArrayOfProtectionObjectDataForService; +import com.dptech.dispose.NtcRequestResultInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Hashtable; + /** * The type Dp tech bypass ability. * * @author */ +@Slf4j public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { + /** + * The Obj prefix. + */ + private final String OBJ_PREFIX = "CMHI"; + /** + * The All cleanup devices. + */ + private final HashSet allCleanupDevices = new HashSet<>(); + + /** + * The Umc object. + */ + private final Hashtable umcObject = new Hashtable<>(); + /** + * The Timer cnt. + */ + private long timerCnt = 0; + + /** + * Init cleanup devices. + */ + private void initCleanupDevices() { + try { + log.info("++++Begging DPTech Get All Protection Devices"); + String dev = getCleanTypePort().getAllProtectDevices(); + log.info("----Finish DPTech Get All Protection Devices: {}", dev); + + Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR)); + } catch (Exception ex) { + log.error("----Exception DPTech Get All Protection Devices: {}", ex.getMessage()); + } + } + + /** + * Init device env. + * + * @param urlPath the url path + * @param username the username + * @param password the password + */ + @Override + public void initDeviceEnv(String urlPath, String username, String password) { + super.initDeviceEnv(urlPath, username, password); + + // 获取所有检测设备 + initCleanupDevices(); + } + + /** + * Gets dispose device protect object. + * 防护对象命名规则 前缀_对象唯一名称_IP地址类型 + * CMHI_xxxx_V4 + * CMHI_XXXX_V6 + */ + @Override + public void getDisposeDeviceProtectObject() { + try { + log.info("++++Begging DPTech Get All Protection Objects"); + ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC(); + + if (ret == null) { + log.error("----Finish DPTech Get All Protection Objects error"); + return; + } + + ret.getProtectionObjectDataForService().forEach(k -> { + String objName = k.getProtectionName().getValue(); + // 删除非法的防护对象 + if (!objName.startsWith(OBJ_PREFIX)) { + log.error("!!!!Found Unexpect Protection Object [{}, {}], Deleted it.", + objName, + k.getIpSegment().getValue()); + + NtcRequestResultInfo rsp = getCleanTypePort().deleteProtectionObjectForUMC(objName); + + if (rsp.getResultRetVal() == 0) { + log.warn("!!!!Remove Protection Object {} Succeed", objName); + } else { + log.error("!!!!Remove Protection Object {} Error: {}", objName, rsp.getResultInfo().getValue()); + } + } else { + // 缓存所有防护对象 + DpProtectObject obj = DpProtectObject.builder() + .cleanupDevices(k.getCleaningDevices().getValue()) + .protectName(objName) + .detectionDevices(k.getDetectionDevices().getValue()) + .ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6) + .ipSegment(new Hashtable<>()) + .build(); + + String ipSeg = k.getIpSegment().getValue(); + log.debug("DpTech response type: {}, value: {}", k.getIpType(), ipSeg); + // 分割IP段 + Arrays.stream(StringUtils.deleteWhitespace(ipSeg).split(",")).forEach(v -> { + String ipValue = v.replaceAll("\\d+_", ""); + String key = v.replace(ipValue, "").replace("_", ""); + // 添加到缓存 + obj.getIpSegment().put(key, ipValue); + }); + + // 添加到缓存 + umcObject.put(objName, obj); + } + }); + + log.info("----Finish DPTech Get All Protection Objects: {}", ret.getProtectionObjectDataForService() + .size()); + } catch (Exception ex) { + log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage()); + } + } + /** * Period task runtime. */ @Override public void periodTaskRuntime() { - super.periodTaskRuntime(); + synchronized (this) { + super.periodTaskRuntime(); + + if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) { + // 定时检测防护对象 + getDisposeDeviceProtectObject(); + } + } } } diff --git a/src/main/java/com/dispose/common/DpTechConfigValue.java b/src/main/java/com/dispose/common/DpTechConfigValue.java index 18c297a4..14a45166 100644 --- a/src/main/java/com/dispose/common/DpTechConfigValue.java +++ b/src/main/java/com/dispose/common/DpTechConfigValue.java @@ -21,4 +21,9 @@ public class DpTechConfigValue { * The constant SOAP_RECEIVE_TIMEOUT_SECOND. */ public static volatile long SOAP_RECEIVE_TIMEOUT_SECOND = 60; + + /** + * The Protection upgrade period. + */ + public static final long PROTECTION_UPGRADE_PERIOD = 10; } diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java index 8f1bce47..018eee75 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectObject.java @@ -1,6 +1,8 @@ package com.dispose.pojo.dto.protocol.device.ability; +import com.dispose.common.IpAddrType; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,6 +16,7 @@ import java.util.Hashtable; @Data @NoArgsConstructor @AllArgsConstructor +@Builder public class DpProtectObject { /** * The Protect name. @@ -31,7 +34,12 @@ public class DpProtectObject { private String cleanupDevices; /** - * The Ip segment v 4. + * The Ip type. + */ + private IpAddrType ipType; + + /** + * The Ip segment. */ private Hashtable ipSegment; } diff --git a/src/test/java/com/dispose/test/dev/debug/demo.java b/src/test/java/com/dispose/test/dev/debug/demo.java index 3461517f..1f251c2c 100644 --- a/src/test/java/com/dispose/test/dev/debug/demo.java +++ b/src/test/java/com/dispose/test/dev/debug/demo.java @@ -607,4 +607,22 @@ public class demo { @Test public void codeDebug() { } + + @Test + public void dpIpSegmentTest() { + String ipSegmentString = "1_192.168.10.1-192.168.10.12,2_192.168.1.2-192.168.1.20,3_-"; + + Arrays.stream(ipSegmentString.split(",")).forEach( + k -> { + String value = k.replaceAll("\\d+_", ""); + String key = k.replace(value, "").replace("_", ""); + + if (Pattern.matches(ConstValue.ipAddrSegmentReg(), value)) { + log.info("Result: {}, {}", key, value); + } else { + log.error("Result: {}, {} error", key, value); + } + } + ); + } } From 1f1abbfe4b1b39a1dd80d734337195d3ca6922fb Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 10:18:44 +0800 Subject: [PATCH 08/67] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index a0a13a73..189d3225 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -1,5 +1,6 @@ package com.dispose.ability.impl; +import com.dispose.common.ConstValue; import com.dispose.common.DisposeConfigValue; import com.dispose.common.DpTechConfigValue; import com.dispose.common.IpAddrType; @@ -13,6 +14,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Hashtable; +import java.util.regex.Pattern; /** * The type Dp tech bypass ability. @@ -79,7 +81,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { @Override public void getDisposeDeviceProtectObject() { try { - log.info("++++Begging DPTech Get All Protection Objects"); + log.debug("++++Begging DPTech Get All Protection Objects"); ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC(); if (ret == null) { @@ -103,32 +105,58 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { log.error("!!!!Remove Protection Object {} Error: {}", objName, rsp.getResultInfo().getValue()); } } else { - // 缓存所有防护对象 - DpProtectObject obj = DpProtectObject.builder() - .cleanupDevices(k.getCleaningDevices().getValue()) - .protectName(objName) - .detectionDevices(k.getDetectionDevices().getValue()) - .ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6) - .ipSegment(new Hashtable<>()) - .build(); + DpProtectObject obj; + + if (!umcObject.contains(objName)) { + // 获取防护对象 + obj = umcObject.get(objName); + } else { + obj = DpProtectObject.builder() + .cleanupDevices(k.getCleaningDevices().getValue()) + .protectName(objName) + .detectionDevices(k.getDetectionDevices().getValue()) + .ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6) + .ipSegment(new Hashtable<>()) + .build(); + // 添加到缓存 + umcObject.put(objName, obj); + } String ipSeg = k.getIpSegment().getValue(); log.debug("DpTech response type: {}, value: {}", k.getIpType(), ipSeg); + Hashtable tmpTable = new Hashtable<>(); + // 分割IP段 Arrays.stream(StringUtils.deleteWhitespace(ipSeg).split(",")).forEach(v -> { String ipValue = v.replaceAll("\\d+_", ""); String key = v.replace(ipValue, "").replace("_", ""); - // 添加到缓存 - obj.getIpSegment().put(key, ipValue); + + if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) { + // 添加到缓存 + tmpTable.put(key, ipValue); + } else { + // 删除异常段 + NtcRequestResultInfo rsp = getCleanTypePort().deleteProtectionObjectIPRangeForUMC(objName + , key); + + if (rsp.getResultRetVal() == 0) { + log.warn("!!!!Remove Exception Protection IpSegment {}, {} Succeed", objName, v); + } else { + log.warn("!!!!Remove Exception Protection IpSegment {}, {} Error: {}", objName, v, + rsp.getResultInfo().getValue()); + } + } + }); - // 添加到缓存 - umcObject.put(objName, obj); + // 判断是否需要更新IP段信息 + if(!obj.getIpSegment().equals(tmpTable)) { + obj.setIpSegment(tmpTable); + } } }); - log.info("----Finish DPTech Get All Protection Objects: {}", ret.getProtectionObjectDataForService() - .size()); + log.debug("----Finish DPTech Get All Protection Objects Succeed"); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage()); } From b640ce5f277e5e48cb7a0f42c46fccf7ba683f85 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 14:37:13 +0800 Subject: [PATCH 09/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E4=B8=9A=E5=8A=A1=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=202.=20=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE?= =?UTF-8?q?=E6=97=81=E8=B7=AF=E7=89=B5=E5=BC=95=E8=AE=BE=E5=A4=87=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-template.properties | 6 +- .../com/dispose/ability/DisposeAbility.java | 11 ++- .../ability/impl/DpTechAbilityImpl.java | 13 +++- .../ability/impl/DpTechBypassAbilityImpl.java | 73 ++++++++++++++++--- .../ability/impl/HaoHanAbilityImpl.java | 14 +++- .../ability/impl/HuaWeiAbilityImpl.java | 14 +++- .../ability/impl/PengXinAbilityImpl.java | 13 +++- .../ability/impl/VirtualAbilityImpl.java | 14 +++- .../com/dispose/config/TemplateConfigure.java | 17 ++++- .../device/ability/DpBypassManager.java | 34 +++++++++ .../ability/DpProtectionStrategyInfo.java | 26 +++++++ .../device/ability/DpTractionStrategy.java | 34 +++++++++ .../impl/DisposeAbilityRouterServiceImpl.java | 8 ++ 13 files changed, 258 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpBypassManager.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectionStrategyInfo.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpTractionStrategy.java diff --git a/config/application-template.properties b/config/application-template.properties index 942415b4..22532c3e 100644 --- a/config/application-template.properties +++ b/config/application-template.properties @@ -32,15 +32,15 @@ template.umcTemplate[5].type=WEB template.umcTemplate[6].name=General_Server_10G template.umcTemplate[6].bandMin=1500 template.umcTemplate[6].bandMax=-1 -template.umcTemplate[6].type=SERVER +template.umcTemplate[6].type=GENERAL template.umcTemplate[7].name=General_Server_1G template.umcTemplate[7].bandMin=500 template.umcTemplate[7].bandMax=1500 -template.umcTemplate[7].type=SERVER +template.umcTemplate[7].type=GENERAL template.umcTemplate[8].name=General_Server_100M template.umcTemplate[8].bandMin=0 template.umcTemplate[8].bandMax=500 -template.umcTemplate[8].type=SERVER +template.umcTemplate[8].type=GENERAL diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index ee81b79d..58b68cc9 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -4,10 +4,12 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import javax.annotation.Nullable; +import java.util.List; /** * The interface Dispose ability. @@ -109,5 +111,12 @@ public interface DisposeAbility { * * @return the boolean */ - Boolean deviceReady(); + boolean deviceReady(); + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + void upgradeServiceGroup(List svrList); } diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index a68f9025..600d8535 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -10,6 +10,7 @@ import com.dispose.common.DpTechConfigValue; import com.dispose.common.ErrorCode; import com.dispose.common.Helper; import com.dispose.common.NetflowDirection; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import com.dptech.dispose.AbnormalFlowCleaningServicePortType; @@ -379,7 +380,17 @@ public class DpTechAbilityImpl implements DisposeAbility { * @return the boolean */ @Override - public Boolean deviceReady() { + public boolean deviceReady() { return true; } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + + } } diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 189d3225..fa0f5298 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -4,8 +4,11 @@ import com.dispose.common.ConstValue; import com.dispose.common.DisposeConfigValue; import com.dispose.common.DpTechConfigValue; import com.dispose.common.IpAddrType; +import com.dispose.pojo.dto.protocol.device.ability.DpBypassManager; import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject; +import com.dispose.pojo.entity.ServiceInfo; import com.dptech.dispose.ArrayOfProtectionObjectDataForService; +import com.dptech.dispose.ArrayOfProtectionTargetWithStrategyForService; import com.dptech.dispose.NtcRequestResultInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -14,6 +17,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Hashtable; +import java.util.List; import java.util.regex.Pattern; /** @@ -24,6 +28,11 @@ import java.util.regex.Pattern; @Slf4j public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { + /** + * The Dispose service group. + */ + private final Hashtable disposeServiceGroup = new Hashtable<>(); + /** * The Obj prefix. */ @@ -34,9 +43,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { private final HashSet allCleanupDevices = new HashSet<>(); /** - * The Umc object. + * The Dp bypass manager. */ - private final Hashtable umcObject = new Hashtable<>(); + private DpBypassManager dpBypassManager; /** * The Timer cnt. */ @@ -57,6 +66,31 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } + /** + * Gets protection strategy template. + */ + private void getProtectionStrategyTemplate() { + try { + log.debug("++++Begging DPTech Get All Protection Strategy Association Relation"); + + ArrayOfProtectionTargetWithStrategyForService ret = + getCleanTypePort().getAllProtectionTargetWithStrategyAssociationRelationshipForUMC(); + + if (ret == null) { + log.error("----Finish DPTech Get All Protection Strategy Association Relation error"); + return; + } + + log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); + + + } catch (Exception ex) { + log.error("----Exception Begging DPTech Get All Protection Strategy Association Relation: {}", + ex.getMessage()); + } + } + + /** * Init device env. * @@ -66,6 +100,11 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ @Override public void initDeviceEnv(String urlPath, String username, String password) { + dpBypassManager = DpBypassManager.builder() + .protectObject(new Hashtable<>()) + .protectStrategy(new Hashtable<>()) + .tractionStrategyName(new Hashtable<>()) + .build(); super.initDeviceEnv(urlPath, username, password); // 获取所有检测设备 @@ -74,9 +113,6 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { /** * Gets dispose device protect object. - * 防护对象命名规则 前缀_对象唯一名称_IP地址类型 - * CMHI_xxxx_V4 - * CMHI_XXXX_V6 */ @Override public void getDisposeDeviceProtectObject() { @@ -107,9 +143,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } else { DpProtectObject obj; - if (!umcObject.contains(objName)) { + if (!dpBypassManager.getProtectObject().containsKey(objName)) { // 获取防护对象 - obj = umcObject.get(objName); + obj = dpBypassManager.getProtectObject().get(objName); } else { obj = DpProtectObject.builder() .cleanupDevices(k.getCleaningDevices().getValue()) @@ -119,7 +155,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { .ipSegment(new Hashtable<>()) .build(); // 添加到缓存 - umcObject.put(objName, obj); + dpBypassManager.getProtectObject().put(objName, obj); } String ipSeg = k.getIpSegment().getValue(); @@ -150,7 +186,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { }); // 判断是否需要更新IP段信息 - if(!obj.getIpSegment().equals(tmpTable)) { + if (!obj.getIpSegment().equals(tmpTable)) { obj.setIpSegment(tmpTable); } } @@ -176,4 +212,23 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + for (ServiceInfo v : svrList) { + if (disposeServiceGroup.containsKey(v.getServiceId())) { + if (!disposeServiceGroup.get(v.getServiceId()).equals(v)) { + disposeServiceGroup.remove(v.getServiceId()); + disposeServiceGroup.put(v.getServiceId(), v); + } + } else { + disposeServiceGroup.put(v.getServiceId(), v); + } + } + } } diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index 1721bd14..f41d45fe 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -6,6 +6,7 @@ import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import com.haohan.dispose.common.HaoHanStartCleanResp; @@ -17,6 +18,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.Nullable; +import java.util.List; /** * The type Hao han ability. @@ -265,7 +267,17 @@ public class HaoHanAbilityImpl implements DisposeAbility { * @return the boolean */ @Override - public Boolean deviceReady() { + public boolean deviceReady() { return true; } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + + } } diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java index 4bca4e2b..09400234 100644 --- a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -7,6 +7,7 @@ import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Nullable; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * The type Hua wei ability. @@ -376,8 +378,18 @@ public class HuaWeiAbilityImpl implements DisposeAbility { * @return the boolean */ @Override - public Boolean deviceReady() { + public boolean deviceReady() { return true; } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + + } } diff --git a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java index 19431d8d..bb2c6b0d 100644 --- a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java @@ -9,6 +9,7 @@ import com.dispose.common.Helper; import com.dispose.common.IpAddrType; import com.dispose.common.NetflowDirection; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import com.pengxin.dispose.common.PengXinDisposeAbilityRsp; @@ -525,7 +526,17 @@ public class PengXinAbilityImpl implements DisposeAbility { * @return the boolean */ @Override - public Boolean deviceReady() { + public boolean deviceReady() { return true; } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + + } } diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index 25e28c77..852244a8 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -5,10 +5,12 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; +import com.dispose.pojo.entity.ServiceInfo; import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import javax.annotation.Nullable; +import java.util.List; /** * The type Virtual ability. @@ -158,7 +160,17 @@ public class VirtualAbilityImpl implements DisposeAbility { * @return the boolean */ @Override - public Boolean deviceReady() { + public boolean deviceReady() { return true; } + + /** + * Upgrade service group. + * + * @param svrList the svr list + */ + @Override + public void upgradeServiceGroup(List svrList) { + + } } diff --git a/src/main/java/com/dispose/config/TemplateConfigure.java b/src/main/java/com/dispose/config/TemplateConfigure.java index 4b64344b..ffb1f664 100644 --- a/src/main/java/com/dispose/config/TemplateConfigure.java +++ b/src/main/java/com/dispose/config/TemplateConfigure.java @@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; import java.util.List; /** @@ -20,8 +21,22 @@ import java.util.List; @ConfigurationProperties(prefix = "template") @Configuration public class TemplateConfigure { + /** * The Umc template. */ - List umcTemplate; + public static List UMC_TEMPLATE; + + /** + * The Umc template. + */ + private List umcTemplate; + + /** + * Init template configure. + */ + @PostConstruct + private void initTemplateConfigure() { + TemplateConfigure.UMC_TEMPLATE = umcTemplate; + } } diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpBypassManager.java b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpBypassManager.java new file mode 100644 index 00000000..8c4898a7 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpBypassManager.java @@ -0,0 +1,34 @@ +package com.dispose.pojo.dto.protocol.device.ability; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Hashtable; + +/** + * The type Dp bypass manager. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DpBypassManager { + /** + * The Protect object. + */ + Hashtable protectObject; + + /** + * The Protect strategy. + */ + Hashtable protectStrategy; + + /** + * The Traction strategy name. + */ + Hashtable tractionStrategyName; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectionStrategyInfo.java b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectionStrategyInfo.java new file mode 100644 index 00000000..72e5fa07 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpProtectionStrategyInfo.java @@ -0,0 +1,26 @@ +package com.dispose.pojo.dto.protocol.device.ability; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Dp protection strategy info. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DpProtectionStrategyInfo { + /** + * The Protect target name. + */ + private String protectTargetName; + /** + * The Protect strategy name. + */ + private String protectStrategyName; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpTractionStrategy.java b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpTractionStrategy.java new file mode 100644 index 00000000..edd4f2be --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/ability/DpTractionStrategy.java @@ -0,0 +1,34 @@ +package com.dispose.pojo.dto.protocol.device.ability; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Dp traction strategy. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DpTractionStrategy { + /** + * The Policy name. + */ + private String policyName; + /** + * The Protect name. + */ + private String protectName; + /** + * The Ip range. + */ + private String ipRange; + /** + * The Running. + */ + private boolean running; +} diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index e35afa02..c2fd1f9f 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -11,6 +11,7 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.HttpType; import com.dispose.manager.DisposeDeviceManager; +import com.dispose.mapper.ServiceGroupMapper; import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.po.AbilityInfo; import com.dispose.service.DisposeAbilityRouterService; @@ -44,6 +45,12 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ @Resource private DisposeDeviceManager disposeDeviceManager; + /** + * The Service group mapper. + */ + @Resource + private ServiceGroupMapper serviceGroupMapper; + /** * Init dispose ability. */ @@ -127,6 +134,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ break; case DPTECH_BYPASS_UMC: db = new DpTechBypassAbilityImpl(); + db.upgradeServiceGroup(serviceGroupMapper.selectAll()); break; default: log.error("Unknown dispose device type: {}", dev.getDeviceType()); From 3625cf00692c99acb1a1183a1739724bf56574ab Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 15:00:21 +0800 Subject: [PATCH 10/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E8=8E=B7=E5=8F=96=E9=98=B2?= =?UTF-8?q?=E6=8A=A4=E5=AF=B9=E8=B1=A1=E5=92=8C=E9=98=B2=E6=8A=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechAbilityImpl.java | 6 ++++-- .../ability/impl/DpTechBypassAbilityImpl.java | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 600d8535..ad23a554 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -363,8 +363,10 @@ public class DpTechAbilityImpl implements DisposeAbility { public void periodTaskRuntime() { log.debug("++++DpTech Period Task Running"); - // 更新防护对象 - getDisposeDeviceProtectObject(); + if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) { + // 定时检测防护对象 + getDisposeDeviceProtectObject(); + } // 更新心跳状态 if (timerCnt++ % DisposeConfigValue.HEART_PERIOD_OF_SECOND == 0) { diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index fa0f5298..0c5319e8 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -81,6 +81,15 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return; } + if (ret.getProtectionTargetWithStrategyForService().size() == 0) { + log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); + return; + } + + ret.getProtectionTargetWithStrategyForService().forEach(k -> { + + }); + log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); @@ -125,6 +134,11 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return; } + if (ret.getProtectionObjectDataForService().size() == 0) { + log.debug("----Finish DPTech Get All Protection Objects Succeed"); + return; + } + ret.getProtectionObjectDataForService().forEach(k -> { String objName = k.getProtectionName().getValue(); // 删除非法的防护对象 @@ -143,7 +157,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } else { DpProtectObject obj; - if (!dpBypassManager.getProtectObject().containsKey(objName)) { + if (dpBypassManager.getProtectObject().containsKey(objName)) { // 获取防护对象 obj = dpBypassManager.getProtectObject().get(objName); } else { @@ -207,8 +221,8 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { super.periodTaskRuntime(); if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) { - // 定时检测防护对象 - getDisposeDeviceProtectObject(); + // 更新防护对象与目标关联关系 + getProtectionStrategyTemplate(); } } } From 8036cc1f902a9fe65d7ba346bbc0da8e26fd1f27 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Thu, 14 Jan 2021 15:10:46 +0800 Subject: [PATCH 11/67] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E9=98=B2=E6=8A=A4=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 0c5319e8..cccc0b8d 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -165,7 +165,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { .cleanupDevices(k.getCleaningDevices().getValue()) .protectName(objName) .detectionDevices(k.getDetectionDevices().getValue()) - .ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6) + .ipType(k.getIpType() == 4 ? IpAddrType.IPV4 : IpAddrType.IPV6) .ipSegment(new Hashtable<>()) .build(); // 添加到缓存 From ea800045f2b83bb610aebfcdcd6fe49b792cb92b Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 15:13:06 +0800 Subject: [PATCH 12/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 0c5319e8..4400cb53 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -6,6 +6,7 @@ import com.dispose.common.DpTechConfigValue; import com.dispose.common.IpAddrType; import com.dispose.pojo.dto.protocol.device.ability.DpBypassManager; import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject; +import com.dispose.pojo.dto.protocol.device.ability.DpProtectionStrategyInfo; import com.dispose.pojo.entity.ServiceInfo; import com.dptech.dispose.ArrayOfProtectionObjectDataForService; import com.dptech.dispose.ArrayOfProtectionTargetWithStrategyForService; @@ -87,7 +88,28 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } ret.getProtectionTargetWithStrategyForService().forEach(k -> { + String objName = k.getProtectionTargetName().getValue(); + // 只处理CMHI相关对象和模板 + if (objName.startsWith(OBJ_PREFIX)) { + DpProtectionStrategyInfo obj; + + // 缓存中不存在改关联关系 + if (!dpBypassManager.getProtectStrategy().containsKey(objName)) { + obj = DpProtectionStrategyInfo.builder() + .protectStrategyName(k.getProtectionStrategyName().getValue()) + .protectTargetName(objName) + .build(); + dpBypassManager.getProtectStrategy().put(objName, obj); + } else { + obj = dpBypassManager.getProtectStrategy().get(objName); + + // 如果关联关系 + if (!obj.getProtectStrategyName().equals(k.getProtectionStrategyName().getValue())) { + obj.setProtectStrategyName(k.getProtectionStrategyName().getValue()); + } + } + } }); log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); From 6860e9875f43a18b2f37811a31de94f9d6b08d54 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Thu, 14 Jan 2021 17:11:41 +0800 Subject: [PATCH 13/67] =?UTF-8?q?OCT=20REM:=201.=E8=BF=AA=E6=99=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=90=AF=E5=8A=A8=E5=A4=84=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=8F=AA=E4=B8=8B=E5=8F=91=E4=B8=80=E7=A7=8D=E6=94=BB?= =?UTF-8?q?=E5=87=BB=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisposeTaskController.java | 9 ++-- .../impl/DeviceTaskManagerServiceImpl.java | 42 ++++++++----------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index 57bff311..a21267f9 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -104,8 +104,7 @@ public class DisposeTaskController { String endTime = String.valueOf(req.getDisposeTime() == -1 ? 5256000: req.getDisposeTime()); NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, Optional.ofNullable(req.getFlowDirection()).orElse(2)); - Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) - .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); + Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()}); Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); @@ -185,8 +184,7 @@ public class DisposeTaskController { Optional.ofNullable(req.getFlowDirection()) .orElse(2))) .attackType(DDoSAttackType.getTypeMaskFromAttackType( - Optional.ofNullable(req.getAttackType()) - .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()}))) + new Integer[]{DDoSAttackType.RST_FLOOD.getValue()})) .flowBandWidth(Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH)) .build(); @@ -236,8 +234,7 @@ public class DisposeTaskController { String endTime = String.valueOf(req.getDisposeTime()); NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, Optional.ofNullable(req.getFlowDirection()).orElse(2)); - Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) - .orElse(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})); + Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()}); Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index f8fa0f7a..42146c53 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -133,28 +133,24 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 设置任务状态为启动中 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); - // 遍历设备攻击类型 - for (DpTechAttackType t : DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType())) { + // 启动迪普设备,采用一种攻击类型 + DpTechAttackType attackType = DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType()).get(0); // 出方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { - // 已经启动过的任务不再重复启动 - if ((deviceTask.getExecAttackTypeOut() & t.getAttackTypeMask()) != 0) { - continue; - } // 设置启动任务攻击类型状态 deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - t.getValue()); + attackType.getValue()); // 调用迪普设备启动处置任务 ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_OUT, - t.getValue(), null); + attackType.getValue(), null); if (ret.getFirstParam() == ErrorCode.ERR_OK) { // 标志启动成功 deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - t.getValue()); + attackType.getValue()); - log.info("DPTECH_UMC setup task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_OUT, deviceTask); + log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_OUT, deviceTask); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { @@ -164,35 +160,31 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); //清除任务攻击类型启动标志 deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - t.getValue()); - log.error("DPTECH_UMC setup task {}, {} times {} error: {}", t, + attackType.getValue()); + log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask); } else { - log.error("DPTECH_UMC setup task {}, {} error {}: {}", t, + log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask); } } // 入方向 if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { - // 已经启动过的任务不再重复启动 - if ((deviceTask.getExecAttackTypeIn() & t.getAttackTypeMask()) != 0) { - continue; - } // 设置启动任务攻击类型状态 deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - t.getValue()); + attackType.getValue()); // 调用迪普设备启动处置任务 ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_IN, - t.getValue(), null); + attackType.getValue(), null); if (ret.getFirstParam() == ErrorCode.ERR_OK) { // 标志启动成功 deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - t.getValue()); + attackType.getValue()); - log.info("DPTECH_UMC setup task {}, {} succeed: {}", t, NetflowDirection.DIRECTION_IN, deviceTask); + log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_IN, deviceTask); deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { @@ -202,15 +194,15 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); //清除任务攻击类型启动标志 deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - t.getValue()); - log.error("DPTECH_UMC setup task {}, {} times {} error: {}", t, + attackType.getValue()); + log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask); } else { - log.error("DPTECH_UMC setup task {}, {} error {}: {}", t, + log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask); } } - } + // 检查需要处置的各种攻击类型任务启动状态与处置任务执行状态,判断该处置任务是否调用成功 boolean taskSetupSucceed = true; From 59583d513f15afb33c4b01723d9093b934881f17 Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Thu, 14 Jan 2021 18:01:29 +0800 Subject: [PATCH 14/67] =?UTF-8?q?OCT=20REM:=201.=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=80=89=E6=8B=A9service=E5=B1=82=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/dev/service/TemplateServiceTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java diff --git a/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java new file mode 100644 index 00000000..1ad5cc58 --- /dev/null +++ b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java @@ -0,0 +1,65 @@ +package com.dispose.test.dev.service; + +import com.dispose.service.TemplateService; +import com.dispose.test.dev.Global.InitTestEnvironment; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@Transactional +@Rollback +public class TemplateServiceTest extends InitTestEnvironment { + + @Resource + private TemplateService templateService; + + @Test + public void getTemplateTest() { + + Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME",1600L)); + Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME", (long) 1500.5)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",1500L)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",(long) 1499.5)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 100L)); + Assert.assertNull(templateService.getTemplate("GAME",-1L)); + log.info("GAME, 0L-----------template: {}", templateService.getTemplate("GAME", 0L)); + log.info("GAME, 0.9-----------template: {}", templateService.getTemplate("GAME", (long) 0.9)); + + Assert.assertEquals("DNS_Server_10G", templateService.getTemplate("DNS",1600L)); + Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1500L)); + Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1L)); + //Assert.assertEquals("Game_Server_1G", templateService.getTemplate("DNS",0L)); + Assert.assertNull(templateService.getTemplate("DNS",-1L)); + + Assert.assertEquals("WEB_Server_10G", templateService.getTemplate("WEB",1600L)); + Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1500L)); + Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1L)); + //Assert.assertEquals("Game_Server_1G", templateService.getTemplate("WEB",0L)); + Assert.assertNull(templateService.getTemplate("WEB",-1L)); + + Assert.assertEquals("General_Server_10G", templateService.getTemplate("GENERAL",1600L)); + Assert.assertEquals("General_Server_1G", templateService.getTemplate("GENERAL",1500L)); + Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",500L)); + Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",1L)); + //Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L)); + Assert.assertNull(templateService.getTemplate("GENERAL",-1L)); + + Assert.assertNull(templateService.getTemplate("ALL",100L)); + } +} From 9c908f1c10505d30c5fd39138dd95de887e0abaf Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 18:10:25 +0800 Subject: [PATCH 15/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E6=97=81=E8=B7=AF=E6=89=8B=E5=8A=A8=E7=89=B5?= =?UTF-8?q?=E5=BC=95=E6=B8=85=E6=B4=97=E5=90=AF=E5=8A=A8=EF=BC=8C=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 232 +++++++++++++++++- .../java/com/dispose/common/ErrorCode.java | 15 +- 2 files changed, 229 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index ccf9e6ae..bd26fed6 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -1,13 +1,22 @@ package com.dispose.ability.impl; +import com.dispose.common.CommonEnumHandler; import com.dispose.common.ConstValue; -import com.dispose.common.DisposeConfigValue; +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeObjectType; +import com.dispose.common.DpTechAttackType; import com.dispose.common.DpTechConfigValue; +import com.dispose.common.ErrorCode; +import com.dispose.common.Helper; import com.dispose.common.IpAddrType; +import com.dispose.common.NetflowDirection; import com.dispose.pojo.dto.protocol.device.ability.DpBypassManager; import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject; import com.dispose.pojo.dto.protocol.device.ability.DpProtectionStrategyInfo; +import com.dispose.pojo.dto.protocol.device.ability.DpTractionStrategy; import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dptech.dispose.ArrayOfBypassManualTractionStrategyForService; import com.dptech.dispose.ArrayOfProtectionObjectDataForService; import com.dptech.dispose.ArrayOfProtectionTargetWithStrategyForService; import com.dptech.dispose.NtcRequestResultInfo; @@ -15,10 +24,9 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Hashtable; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; /** @@ -29,6 +37,8 @@ import java.util.regex.Pattern; @Slf4j public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { + private final Hashtable disposeObjectCache = new Hashtable<>(); + /** * The Dispose service group. */ @@ -41,7 +51,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { /** * The All cleanup devices. */ - private final HashSet allCleanupDevices = new HashSet<>(); + private String allCleanupDevices = ""; /** * The Dp bypass manager. @@ -58,15 +68,64 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { private void initCleanupDevices() { try { log.info("++++Begging DPTech Get All Protection Devices"); - String dev = getCleanTypePort().getAllProtectDevices(); - log.info("----Finish DPTech Get All Protection Devices: {}", dev); - - Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR)); + allCleanupDevices = getCleanTypePort().getAllProtectDevices(); + log.info("----Finish DPTech Get All Protection Devices: {}", allCleanupDevices); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Devices: {}", ex.getMessage()); } } + /** + * Upgrade traction strategy. + */ + private void upgradeTractionStrategy() { + try { + log.info("++++Begging DPTech Upgrade Traction Strategy"); + + ArrayOfBypassManualTractionStrategyForService ret = + getCleanTypePort().getAllBypassManualTractionStrategyFromUMC(); + + if (ret != null && ret.getBypassManualTractionStrategyForService().size() > 0) { + ret.getBypassManualTractionStrategyForService().forEach(k -> { + String policyName = k.getPolicyName().getValue(); + // 非法名称的旁路牵引策略 + if (!policyName.startsWith(OBJ_PREFIX)) { + NtcRequestResultInfo rsp = + getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); + + if (rsp.getResultRetVal() == 0) { + log.debug("Remove Traction Strategy {} Succeed", policyName); + } else { + log.error("!!!!Remove Traction Strategy {} Error: {}", policyName, rsp.getResultInfo() + .getValue()); + } + } else { + DpTractionStrategy obj; + + if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) { + obj = dpBypassManager.getTractionStrategyName().get(policyName); + obj.setProtectName(k.getProtectName().getValue()); + obj.setIpRange(k.getIpRange().getValue()); + obj.setRunning(Boolean.parseBoolean(k.getEnabled().getValue())); + } else { + obj = DpTractionStrategy.builder() + .policyName(policyName) + .protectName(k.getProtectName().getValue()) + .ipRange(k.getIpRange().getValue()) + .running(Boolean.parseBoolean(k.getEnabled().getValue())) + .build(); + dpBypassManager.getTractionStrategyName().put(policyName, obj); + } + } + }); + } + + log.info("----Finish DPTech Upgrade Traction Strategy"); + } catch (Exception ex) { + log.error("----Exception DPTech Upgrade Traction Strategy: {}", ex.getMessage()); + } + } + /** * Gets protection strategy template. */ @@ -104,7 +163,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } else { obj = dpBypassManager.getProtectStrategy().get(objName); - // 如果关联关系 + // 如果关联关系有变动 if (!obj.getProtectStrategyName().equals(k.getProtectionStrategyName().getValue())) { obj.setProtectStrategyName(k.getProtectionStrategyName().getValue()); } @@ -113,15 +172,12 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { }); log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); - - } catch (Exception ex) { log.error("----Exception Begging DPTech Get All Protection Strategy Association Relation: {}", ex.getMessage()); } } - /** * Init device env. * @@ -187,7 +243,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { .cleanupDevices(k.getCleaningDevices().getValue()) .protectName(objName) .detectionDevices(k.getDetectionDevices().getValue()) - .ipType(k.getIpType() == 4 ? IpAddrType.IPV4 : IpAddrType.IPV6) + .ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6) .ipSegment(new Hashtable<>()) .build(); // 添加到缓存 @@ -234,6 +290,153 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } + @Override + public MulReturnType runDispose(String disposeObject, DisposeObjectType objectType, + DisposeCapacityType capType, + NetflowDirection nfDirection, + Integer attackType, + Long duration) { + ErrorCode err = ErrorCode.ERR_OK; + NtcRequestResultInfo ret; + + try { + AtomicReference protectionObject = new AtomicReference<>(""); + log.debug("++++Begging DPTech Start Cleanup Task: {}", disposeObject); + + if (capType != DisposeCapacityType.CLEANUP) { + log.error("----Error DPTech don't support dispose capacity type: {}", capType); + return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + } + + String policyName = OBJ_PREFIX + "_" + disposeObject; + + // 判断缓存中当前处置IP的旁路牵引策略是否存在, 如果存在直接删除 + if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) { + ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); + + if (ret.getResultRetVal() != 0) { + log.error("----Error DPTech Delete Old Traction Strategy Error: {}, {}", policyName, + ret.getResultInfo().getValue()); + return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); + } + } + + // 判断缓存中是否存在该处置IP对应的防护对象 + if (disposeObjectCache.containsKey(disposeObject)) { + protectionObject.set(disposeObjectCache.get(disposeObject)); + } else { + // 从设备防护对象缓存中查找当前处置IP对应的防护对象名称 + dpBypassManager.getProtectObject().values().forEach(k -> { + for (String v : k.getIpSegment().values()) { + if (Helper.ipInRange(v, disposeObject)) { + protectionObject.set(k.getProtectName()); + // 将查找到的防护对象添加到缓存中 + disposeObjectCache.put(disposeObject, k.getProtectName()); + break; + } + } + }); + } + + // 校验当前处置对象对应的防护对象名称是否正确 + if (protectionObject.get().length() == 0) { + log.error("----Error DPTech Task Not Found Protection Object: {}", disposeObject); + log.debug("!!!!DpTech UMC Protection Objects: {}", dpBypassManager.getProtectObject().values()); + return new MulReturnType<>(ErrorCode.ERR_NOSUCHUMCPROTECTOBJECT, null); + } + + log.debug("++++Begging DPTech Create Traction Strategy: {}, {}, {}", policyName, + protectionObject.get(), disposeObject); + + // 创建旁路手动牵引策略 + ret = getCleanTypePort().addBypassManualTractionStrategyForUMC(policyName, protectionObject.get(), + disposeObject); + + if (ret.getResultRetVal() != 0) { + log.error("----Error DPTech Create Traction Strategy Error: {}, {}, {}, {}", policyName, + protectionObject.get(), disposeObject, ret.getResultInfo().getValue()); + return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); + } + + log.debug("----Finish DPTech Create Traction Strategy: {}, {}, {}", policyName, + protectionObject.get(), disposeObject); + + // 启动旁路手动牵引策略 + log.debug("DpTech startBypassManualTractionStrategyForUMC request: {}, {}", policyName, disposeObject); + ret = getCleanTypePort().startBypassManualTractionStrategyForUMC(policyName, ""); + log.debug("DpTech startBypassManualTractionStrategyForUMC response: {}", ret); + + if (ret.getResultRetVal() != 0) { + err = ErrorCode.ERR_CALLDEVICE; + log.error("----Error DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, + CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), + ret.getResultInfo().getValue()); + } else { + log.debug("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, + CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), + ret.getResultInfo().getValue()); + } + } catch (Exception ex) { + err = ErrorCode.ERR_SYSTEMEXCEPTION; + log.error("----Exception DPTech Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, + CommonEnumHandler.codeOf(DpTechAttackType.class, attackType)); + } + + return new MulReturnType<>(err, null); + } + + @Override + public MulReturnType stopDispose(String disposeObject, + DisposeCapacityType capType, + NetflowDirection nfDirection, + Integer attackType, + String taskId) { + ErrorCode err = ErrorCode.ERR_OK; + + try { + log.info("++++Begging DPTech Stop Cleanup Task: {}", disposeObject); + + if (capType != DisposeCapacityType.CLEANUP) { + log.error("----Error DPTech don't support dispose capacity type: {}", capType); + return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); + } + + String policyName = OBJ_PREFIX + "_" + disposeObject; + + if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) { + log.error("----Error DPTech Stop Cleanup Task, No Such Task: {}, {}", disposeObject, policyName); + return new MulReturnType<>(ErrorCode.ERR_TASKNOTRUNNING, null); + } + + log.debug("DpTech stopBypassManualTractionStrategyForUMC request: {}", disposeObject); + NtcRequestResultInfo ret = getCleanTypePort().stopBypassManualTractionStrategyForUMC(policyName, ""); + log.debug("DpTech stopBypassManualTractionStrategyForUMC response: {}", ret); + + if (ret.getResultRetVal() != 0) { + err = ErrorCode.ERR_CALLDEVICE; + log.error("----Error DPTech Stop Cleanup Task: {}, {}", disposeObject, ret.getResultInfo().getValue()); + return new MulReturnType<>(err, null); + } + + // 删除不再使用的手动旁路牵引策略 + log.debug("DpTech delBypassManualTractionStrategyForUMC request: {}", policyName); + ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); + log.debug("DpTech delBypassManualTractionStrategyForUMC response: {}", ret); + + if (ret.getResultRetVal() != 0) { + log.error("----Error DPTech Remove Traction Strategy: {}, {}", policyName, + ret.getResultInfo().getValue()); + } + + log.info("----Finish DPTech Stop Cleanup Task Succeed: {}", disposeObject); + } catch (Exception ex) { + err = ErrorCode.ERR_SYSTEMEXCEPTION; + log.error("----Exception DPTech Stop Cleanup Task: {}, {}", disposeObject, ex.getMessage()); + } + + return new MulReturnType<>(err, null); + } + /** * Period task runtime. */ @@ -246,6 +449,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 更新防护对象与目标关联关系 getProtectionStrategyTemplate(); } + + // 清理旁路手动牵引策略 + upgradeTractionStrategy(); } } diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index 4880b744..eac55935 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -165,7 +165,7 @@ public enum ErrorCode { */ ERR_UNTRUSTTOKEN(38, "未经授权的Token"), /** - * Err unknowninterface error code. + * The Err unknowninterface. */ ERR_UNKNOWNINTERFACE(39, "未提供该接口"), /** @@ -217,19 +217,19 @@ public enum ErrorCode { */ ERR_DECRYPT_AES256(111, "AES256解密失败"), /** - * The Err no device by areaCode. + * The Err nodevice areacode. */ ERR_NODEVICE_AREACODE(112, "区域无该设备"), /** - * The Err specified IP already exists. + * The Err specifiedip exists. */ ERR_SPECIFIEDIP_EXISTS(113, "指定的IP已经存在"), /** - * The Err specified IP does not exists. + * The Err specifiedip notexists. */ ERR_SPECIFIEDIP_NOTEXISTS(114, "指定的IP地址不存在"), /** - * The Err server processing request. + * The Err server processreq. */ ERR_SERVER_PROCESSREQ(115, "服务器处理请求错误"), /** @@ -240,6 +240,11 @@ public enum ErrorCode { * The Err pengxin error. */ ERR_PENGXIN_ERROR(117, "鹏信设备返回错误"), + + /** + * The Err nosuchumcprotectobject. + */ + ERR_NOSUCHUMCPROTECTOBJECT(200, "没有找到UMC防护对象"), ; /** From 4d5b893eb1edfeb1f796737c65ef7445c8c8baa6 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 14 Jan 2021 18:11:40 +0800 Subject: [PATCH 16/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index bd26fed6..cdb74d29 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -37,6 +37,9 @@ import java.util.regex.Pattern; @Slf4j public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { + /** + * The Dispose object cache. + */ private final Hashtable disposeObjectCache = new Hashtable<>(); /** @@ -290,6 +293,17 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } + /** + * Run dispose mul return type. + * + * @param disposeObject the dispose object + * @param objectType the object type + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param duration the duration + * @return the mul return type + */ @Override public MulReturnType runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType, @@ -385,6 +399,16 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return new MulReturnType<>(err, null); } + /** + * Stop dispose mul return type. + * + * @param disposeObject the dispose object + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param taskId the task id + * @return the mul return type + */ @Override public MulReturnType stopDispose(String disposeObject, DisposeCapacityType capType, From 5d315f46899ce664bba8dca927515d66b950d252 Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Thu, 14 Jan 2021 19:31:24 +0800 Subject: [PATCH 17/67] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E6=A8=A1=E6=9D=BF=E5=8C=B9=E9=85=8D=E8=A7=84?= =?UTF-8?q?=E5=88=99=EF=BC=88=E4=BF=AE=E5=A4=8D=E5=B8=A6=E5=AE=BD=E4=B8=BA?= =?UTF-8?q?0=E5=8C=B9=E9=85=8D=E4=B8=8D=E5=88=B0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=89=202.=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E9=80=89?= =?UTF-8?q?=E6=8B=A9service=E5=B1=82=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispose/service/impl/TemplateServiceImpl.java | 7 +++++-- .../test/dev/service/TemplateServiceTest.java | 13 +++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java index a7386ee5..6857e12d 100644 --- a/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/TemplateServiceImpl.java @@ -33,9 +33,12 @@ public class TemplateServiceImpl implements TemplateService { // 判断类型是否一致 if (v.getType().equals(type)) { // 当前带宽大于当前模板最小值 - if (bandWidth > v.getBandMin()) { + if (bandWidth > v.getBandMin() || bandWidth == 0) { // 模板最大值为-1或者带宽小于等于模板最小值,返回模板名称 - if (v.getBandMax() == -1 || bandWidth <= v.getBandMax()) { + if (v.getBandMax() == -1 && bandWidth != 0) { + log.debug("Template analyze: {}, {} match {}", type, bandWidth, v); + return v.getName(); + } else if (bandWidth <= v.getBandMax() && bandWidth >= v.getBandMin()) { log.debug("Template analyze: {}, {} match {}", type, bandWidth, v); return v.getName(); } diff --git a/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java index 1ad5cc58..510a5541 100644 --- a/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java +++ b/src/test/java/com/dispose/test/dev/service/TemplateServiceTest.java @@ -32,32 +32,29 @@ public class TemplateServiceTest extends InitTestEnvironment { public void getTemplateTest() { Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME",1600L)); - Assert.assertEquals("Game_Server_10G", templateService.getTemplate("GAME", (long) 1500.5)); Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",1500L)); - Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME",(long) 1499.5)); - Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L)); Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 100L)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 1L)); + Assert.assertEquals("Game_Server_1G", templateService.getTemplate("GAME", 0L)); Assert.assertNull(templateService.getTemplate("GAME",-1L)); - log.info("GAME, 0L-----------template: {}", templateService.getTemplate("GAME", 0L)); - log.info("GAME, 0.9-----------template: {}", templateService.getTemplate("GAME", (long) 0.9)); Assert.assertEquals("DNS_Server_10G", templateService.getTemplate("DNS",1600L)); Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1500L)); Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",1L)); - //Assert.assertEquals("Game_Server_1G", templateService.getTemplate("DNS",0L)); + Assert.assertEquals("DNS_Server_1G", templateService.getTemplate("DNS",0L)); Assert.assertNull(templateService.getTemplate("DNS",-1L)); Assert.assertEquals("WEB_Server_10G", templateService.getTemplate("WEB",1600L)); Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1500L)); Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",1L)); - //Assert.assertEquals("Game_Server_1G", templateService.getTemplate("WEB",0L)); + Assert.assertEquals("WEB_Server_1G", templateService.getTemplate("WEB",0L)); Assert.assertNull(templateService.getTemplate("WEB",-1L)); Assert.assertEquals("General_Server_10G", templateService.getTemplate("GENERAL",1600L)); Assert.assertEquals("General_Server_1G", templateService.getTemplate("GENERAL",1500L)); Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",500L)); Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",1L)); - //Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L)); + Assert.assertEquals("General_Server_100M", templateService.getTemplate("GENERAL",0L)); Assert.assertNull(templateService.getTemplate("GENERAL",-1L)); Assert.assertNull(templateService.getTemplate("ALL",100L)); From 13638acb07733deb0d1dc640a81e77e18fd755f0 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 15 Jan 2021 09:35:23 +0800 Subject: [PATCH 18/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=EF=BC=8C=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1ID=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 15 ++++++++++++++- .../com/dispose/mapper/ServiceGroupMapper.java | 2 +- .../java/com/dispose/pojo/entity/ServiceInfo.java | 2 +- src/main/resources/db/schema.sql | 2 +- src/main/resources/mappers/ServiceGroup.xml | 2 +- src/main/resources/test_db/unit_test.sql | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index cdb74d29..1139b0a3 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -45,7 +45,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { /** * The Dispose service group. */ - private final Hashtable disposeServiceGroup = new Hashtable<>(); + private final Hashtable disposeServiceGroup = new Hashtable<>(); /** * The Obj prefix. @@ -65,6 +65,19 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private long timerCnt = 0; + /** + * Sync dp tech device info. + */ + private void syncDpTechDeviceInfo() { + disposeServiceGroup.values().forEach(v -> { + + }); + } + + private String getProtectObjectName(String serviceId) { + return null; + } + /** * Init cleanup devices. */ diff --git a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java index a6dad4db..a90d07aa 100644 --- a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java +++ b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java @@ -40,5 +40,5 @@ public interface ServiceGroupMapper { * @param serviceId the service id * @return the int */ - int delServiceGroupByServiceId(@Param("serviceId") Long serviceId); + int delServiceGroupByServiceId(@Param("serviceId") String serviceId); } diff --git a/src/main/java/com/dispose/pojo/entity/ServiceInfo.java b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java index 40fb81ab..73a36588 100644 --- a/src/main/java/com/dispose/pojo/entity/ServiceInfo.java +++ b/src/main/java/com/dispose/pojo/entity/ServiceInfo.java @@ -42,7 +42,7 @@ public class ServiceInfo { /** * The Service id. */ - private Long serviceId; + private String serviceId; /** * The Service type. diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 9b4f4db1..189825d4 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -135,7 +135,7 @@ DROP TABLE IF EXISTS `service_group`; CREATE TABLE `service_group` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', - `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', + `serviceId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务ID', `serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME', `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index 029a0a6a..1de535f3 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -3,7 +3,7 @@ - + diff --git a/src/main/resources/test_db/unit_test.sql b/src/main/resources/test_db/unit_test.sql index a8d2f48c..64c7cb14 100644 --- a/src/main/resources/test_db/unit_test.sql +++ b/src/main/resources/test_db/unit_test.sql @@ -211,7 +211,7 @@ DROP TABLE IF EXISTS `service_group`; CREATE TABLE `service_group` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '业务ID唯一标识符', - `serviceId` int(11) UNSIGNED NOT NULL COMMENT '业务ID', + `serviceId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务ID', `serviceType` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务类型:SERVER,WEB,DNS,GAME', `serviceBandwidth` int(11) NOT NULL COMMENT '业务带宽,单位M', `serviceIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务IP地址,逗号分割', From 771c82e282ec6a38e675d3ad523cd1e39dc3a016 Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Fri, 15 Jan 2021 10:22:55 +0800 Subject: [PATCH 19/67] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E4=B8=9A=E5=8A=A1=E6=95=B0=E6=8D=AExml?= =?UTF-8?q?=E3=80=82=202.=E6=B7=BB=E5=8A=A0=E4=B8=9A=E5=8A=A1=E4=BF=A1?= =?UTF-8?q?=E6=81=AFmapper=E5=B1=82=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mappers/ServiceGroup.xml | 2 +- .../dev/mapper/ServiceGroupMapperTest.java | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index 1de535f3..e2eb2675 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -19,7 +19,7 @@ INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp) VALUES - (#{svg.deviceId}, #{svg.serviceType}, #{svg.serviceBandwidth}, #{svg.serviceIp}) + (#{svg.serviceId}, #{svg.serviceType}, #{svg.serviceBandwidth}, #{svg.serviceIp}) diff --git a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java new file mode 100644 index 00000000..f65ecdc7 --- /dev/null +++ b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java @@ -0,0 +1,74 @@ +package com.dispose.test.dev.mapper; + +import com.dispose.mapper.ServiceGroupMapper; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.test.dev.Global.InitTestEnvironment; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +//@FixMethodOrder(MethodSorters.NAME_ASCENDING) +//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@Transactional +@Rollback +public class ServiceGroupMapperTest extends InitTestEnvironment { + /** + * The service group mapper. + */ + @Resource + private ServiceGroupMapper serviceGroupMapper; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + + /** + * A 1 add new service group. + * + * @throws JsonProcessingException the json processing exception + */ + @Test + public void a1_addServiceGroup() throws JsonProcessingException{ + List service = new ArrayList<>(); + service.add(ServiceInfo.builder() + .serviceId("100") + .serviceType("GAME") + .serviceBandwidth(1000L) + .serviceIp("192.168.100.1-192.168.100.10,192.168.100.20-192.168.100.21") + .build()); + service.add(ServiceInfo.builder() + .serviceId("101") + .serviceType("DNS") + .serviceBandwidth(2000L) + .serviceIp("192.168.101.1-192.168.101.10") + .build()); + + int num = serviceGroupMapper.addServiceGroup(service); + Assert.assertEquals(num, service.size()); + log.info("add num {}: {}", num, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(service)); + + List serviceList = serviceGroupMapper.selectAll(); + Assert.assertNotNull(serviceList); + Assert.assertNotEquals(serviceList.size(), 0); + + log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(serviceList)); + + } + + +} From afc316945bc7f7dbf84f8daded510316a6d6fbce Mon Sep 17 00:00:00 2001 From: wangyiyun Date: Fri, 15 Jan 2021 14:35:58 +0800 Subject: [PATCH 20/67] =?UTF-8?q?OCT=20REM:=201.=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E4=BF=A1=E6=81=AF=E6=9F=A5=E7=9C=8B=E3=80=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84mapper=E5=B1=82=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/mapper/ServiceGroupMapperTest.java | 91 ++++++++++++++++++- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java index f65ecdc7..a004c249 100644 --- a/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/ServiceGroupMapperTest.java @@ -23,8 +23,8 @@ import java.util.List; @Slf4j //@FixMethodOrder(MethodSorters.NAME_ASCENDING) //@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -@Transactional -@Rollback +//@Transactional +//@Rollback public class ServiceGroupMapperTest extends InitTestEnvironment { /** * The service group mapper. @@ -38,12 +38,25 @@ public class ServiceGroupMapperTest extends InitTestEnvironment { private ObjectMapper objectMapper; /** - * A 1 add new service group. + * A 1 select all. * * @throws JsonProcessingException the json processing exception */ @Test - public void a1_addServiceGroup() throws JsonProcessingException{ + public void a1_selectAllTest() throws JsonProcessingException{ + List serviceList = serviceGroupMapper.selectAll(); + //Assert.assertNotNull(serviceList); + //Assert.assertNotEquals(serviceList.size(), 0); + log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(serviceList)); + } + + /** + * A 2 add new service group. + * + * @throws JsonProcessingException the json processing exception + */ + @Test + public void a2_addServiceGroup() throws JsonProcessingException{ List service = new ArrayList<>(); service.add(ServiceInfo.builder() .serviceId("100") @@ -70,5 +83,75 @@ public class ServiceGroupMapperTest extends InitTestEnvironment { } + /** + * A 3 delete service group by id. + */ + @Test + public void a3_delServiceGroupByIdTest(){ + List service = new ArrayList<>(); + service.add(ServiceInfo.builder() + .serviceId("100") + .serviceType("GAME") + .serviceBandwidth(1000L) + .serviceIp("192.168.100.1-192.168.100.10,192.168.100.20-192.168.100.21") + .build()); + service.add(ServiceInfo.builder() + .serviceId("101") + .serviceType("DNS") + .serviceBandwidth(2000L) + .serviceIp("192.168.101.1-192.168.101.10") + .build()); + serviceGroupMapper.addServiceGroup(service); + + log.info("service number: {}", serviceGroupMapper.selectAll().size()); + serviceGroupMapper.selectAll().forEach(v -> { + int ret = serviceGroupMapper.delServiceGroupById(v.getId()); + + try { + log.info("service info: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + Assert.assertEquals(1,ret); + }); + log.info("service after delete operate: {}", serviceGroupMapper.selectAll()); + Assert.assertEquals(0,serviceGroupMapper.selectAll().size()); + } + + /** + * A 4 delete service group by service id. + */ + @Test + public void a4_delServiceGroupByServiceIdTest(){ + List service = new ArrayList<>(); + service.add(ServiceInfo.builder() + .serviceId("100") + .serviceType("GAME") + .serviceBandwidth(1000L) + .serviceIp("192.168.100.1-192.168.100.10,192.168.100.20-192.168.100.21") + .build()); + service.add(ServiceInfo.builder() + .serviceId("101") + .serviceType("DNS") + .serviceBandwidth(2000L) + .serviceIp("192.168.101.1-192.168.101.10") + .build()); + serviceGroupMapper.addServiceGroup(service); + + log.info("service number: {}", serviceGroupMapper.selectAll().size()); + serviceGroupMapper.selectAll().forEach(v -> { + int ret = serviceGroupMapper.delServiceGroupByServiceId(v.getServiceId()); + + try { + log.info("service info: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + Assert.assertEquals(1,ret); + }); + log.info("service after delete operate: {}", serviceGroupMapper.selectAll()); + Assert.assertEquals(0,serviceGroupMapper.selectAll().size()); + } } From 249451b2087e04c8c617cfd762e716886fd261f0 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 15 Jan 2021 14:43:19 +0800 Subject: [PATCH 21/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=A8=A1=E6=9D=BF=E6=96=B9=E6=B3=95=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 133 ++++++++++++++++-- src/main/java/com/dispose/common/Helper.java | 28 ++++ .../com/dispose/thread/ThreadPoolConfig.java | 9 ++ .../dev/config/TemplateConfigureTest.java | 22 +++ .../java/com/dispose/test/dev/debug/demo.java | 20 +++ 5 files changed, 198 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 1139b0a3..ec2d41b9 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -3,6 +3,7 @@ package com.dispose.ability.impl; import com.dispose.common.CommonEnumHandler; import com.dispose.common.ConstValue; import com.dispose.common.DisposeCapacityType; +import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; import com.dispose.common.DpTechAttackType; import com.dispose.common.DpTechConfigValue; @@ -23,7 +24,9 @@ import com.dptech.dispose.NtcRequestResultInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -65,17 +68,116 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private long timerCnt = 0; + private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType) { + NtcRequestResultInfo ret = getCleanTypePort() + .addProtectionObjectForUMC("", + allCleanupDevices, + objName, + ipSegment, + ipType, + 0); + + if (ret.getResultRetVal() == 0) { + log.debug("Add Protection Object {} Succeed", objName); + return ErrorCode.ERR_OK; + } else { + log.error("!!!!Add Protection Object {}, {}, {} Error: {}", objName, ipSegment, ipType, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + } + /** * Sync dp tech device info. */ private void syncDpTechDeviceInfo() { disposeServiceGroup.values().forEach(v -> { + boolean changed = false; + NtcRequestResultInfo ret; + List ipV4 = new ArrayList<>(); + List ipV6 = new ArrayList<>(); + int ipV4Idx = 1; + int ipV6Idx = 1; + // 将业务Ip根据IP地址类型进行拆分 + for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) { + if (!k.contains(":")) { + ipV4.add(ipV4Idx++ + "_" + k); + } else { + ipV6.add(ipV6Idx++ + "_" + k); + } + } + + HashMap ipSegment = new HashMap<>(2); + + if (ipV4.size() > 0) { + ipSegment.put(IpAddrType.IPV4, String.join(",", ipV4)); + } + + if (ipV6.size() > 0) { + ipSegment.put(IpAddrType.IPV6, String.join(",", ipV6)); + } + + // 检查防护对象 + for (IpAddrType t : ipSegment.keySet()) { + String protectName = getProtectObjectName(v.getServiceId(), t); + + // 防护对象存在 + if (dpBypassManager.getProtectObject().containsKey(protectName)) { + DpProtectObject dp = dpBypassManager.getProtectObject().get(protectName); + + + } else { + // 创建一个防护对象 + ret = getCleanTypePort().addProtectionObjectForUMC("", + allCleanupDevices, + protectName, + ipSegment.get(t), + IpAddrType.IPV4.equals(t) ? 0 : 1, + 0); + + if (ret.getResultRetVal() == 0) { + log.info("Add Protection Object {} Succeed", protectName); + } else { + log.error("!!!!Add Protection Object {} Error: {}", protectName, ret.getResultInfo() + .getValue()); + } + + changed = true; + } + } + + // 修改后重新从设备更新信息 + if (changed) { + getDisposeDeviceProtectObject(); + changed = false; + } }); } - private String getProtectObjectName(String serviceId) { - return null; + /** + * Gets protect object name. + * + * @param serviceId the service id + * @param ipAddrType the ip addr type + * @return the protect object name + */ + private String getProtectObjectName(String serviceId, IpAddrType ipAddrType) { + if (IpAddrType.IPV4.equals(ipAddrType) || IpAddrType.IPV6.equals(ipAddrType)) { + return OBJ_PREFIX + "_" + serviceId + "_" + ipAddrType.getDescription(); + } else { + return OBJ_PREFIX + "_" + serviceId; + } + } + + /** + * Gets traction strategy name. + * + * @param disposeIp the dispose ip + * @return the traction strategy name + */ + private String getTractionStrategyName(String disposeIp) { + return OBJ_PREFIX + "_" + disposeIp + ""; } /** @@ -147,7 +249,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private void getProtectionStrategyTemplate() { try { - log.debug("++++Begging DPTech Get All Protection Strategy Association Relation"); + log.info("++++Begging DPTech Get All Protection Strategy Association Relation"); ArrayOfProtectionTargetWithStrategyForService ret = getCleanTypePort().getAllProtectionTargetWithStrategyAssociationRelationshipForUMC(); @@ -158,7 +260,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } if (ret.getProtectionTargetWithStrategyForService().size() == 0) { - log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); + log.info("----Finish DPTech Get All Protection Strategy Association Relation"); return; } @@ -187,9 +289,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } }); - log.info("----Finish Begging DPTech Get All Protection Strategy Association Relation"); + log.info("----Finish DPTech Get All Protection Strategy Association Relation"); } catch (Exception ex) { - log.error("----Exception Begging DPTech Get All Protection Strategy Association Relation: {}", + log.error("----Exception DPTech Get All Protection Strategy Association Relation: {}", ex.getMessage()); } } @@ -220,7 +322,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { @Override public void getDisposeDeviceProtectObject() { try { - log.debug("++++Begging DPTech Get All Protection Objects"); + log.info("++++Begging DPTech Get All Protection Objects"); ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC(); if (ret == null) { @@ -300,7 +402,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } }); - log.debug("----Finish DPTech Get All Protection Objects Succeed"); + log.info("----Finish DPTech Get All Protection Objects Succeed"); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage()); } @@ -328,14 +430,14 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { try { AtomicReference protectionObject = new AtomicReference<>(""); - log.debug("++++Begging DPTech Start Cleanup Task: {}", disposeObject); + log.info("++++Begging DPTech Start Cleanup Task: {}", disposeObject); if (capType != DisposeCapacityType.CLEANUP) { log.error("----Error DPTech don't support dispose capacity type: {}", capType); return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); } - String policyName = OBJ_PREFIX + "_" + disposeObject; + String policyName = getTractionStrategyName(disposeObject); // 判断缓存中当前处置IP的旁路牵引策略是否存在, 如果存在直接删除 if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) { @@ -399,9 +501,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), ret.getResultInfo().getValue()); } else { - log.debug("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, - CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), - ret.getResultInfo().getValue()); + log.info("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, + CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), + ret.getResultInfo().getValue()); } } catch (Exception ex) { err = ErrorCode.ERR_SYSTEMEXCEPTION; @@ -438,7 +540,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); } - String policyName = OBJ_PREFIX + "_" + disposeObject; + String policyName = getTractionStrategyName(disposeObject); if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) { log.error("----Error DPTech Stop Cleanup Task, No Such Task: {}, {}", disposeObject, policyName); @@ -489,6 +591,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 清理旁路手动牵引策略 upgradeTractionStrategy(); + + // 与迪普设备同步数据 + syncDpTechDeviceInfo(); } } diff --git a/src/main/java/com/dispose/common/Helper.java b/src/main/java/com/dispose/common/Helper.java index b3e1f37c..73f98ca2 100644 --- a/src/main/java/com/dispose/common/Helper.java +++ b/src/main/java/com/dispose/common/Helper.java @@ -1,9 +1,12 @@ package com.dispose.common; +import com.dispose.config.TemplateConfigure; +import com.dispose.pojo.vo.TemplateInfo; import inet.ipaddr.AddressStringException; import inet.ipaddr.IPAddress; import inet.ipaddr.IPAddressSeqRange; import inet.ipaddr.IPAddressString; +import lombok.extern.slf4j.Slf4j; import java.io.BufferedReader; import java.io.IOException; @@ -14,6 +17,7 @@ import java.sql.Timestamp; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -21,6 +25,7 @@ import java.util.stream.Collectors; * * @author */ +@Slf4j public class Helper { /** @@ -202,4 +207,27 @@ public class Helper { return sb.toString(); } + + /** + * Gets dp template. + * + * @param type the type + * @param bandWidth the band width + * @return the dp template + */ + public static String getDpTemplate(String type, Long bandWidth) { +// Map> result = TemplateConfigure.UMC_TEMPLATE.stream() +// .collect(Collectors.groupingBy(TemplateInfo::getType)); + + + + Optional ret = TemplateConfigure.UMC_TEMPLATE.stream() + .filter(v -> v.getType().equals(type)) + .filter(v -> bandWidth > v.getBandMin() && bandWidth <= v.getBandMax()) + .findFirst() + .map(TemplateInfo::getName); + + log.info("{}", ret); + return ""; + } } diff --git a/src/main/java/com/dispose/thread/ThreadPoolConfig.java b/src/main/java/com/dispose/thread/ThreadPoolConfig.java index 7ef1fa55..3778fd22 100644 --- a/src/main/java/com/dispose/thread/ThreadPoolConfig.java +++ b/src/main/java/com/dispose/thread/ThreadPoolConfig.java @@ -40,4 +40,13 @@ public class ThreadPoolConfig { executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); return executor; } + + @Bean + public Executor dpTechTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setThreadNamePrefix("dpTechTask-"); + executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() << 1 + 1); + executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); + return executor; + } } diff --git a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java index 3051166a..59442906 100644 --- a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java +++ b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java @@ -1,6 +1,8 @@ package com.dispose.test.dev.config; +import com.dispose.common.Helper; import com.dispose.config.TemplateConfigure; +import com.dispose.service.impl.TemplateServiceImpl; import com.dispose.test.dev.Global.InitTestEnvironment; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; @@ -26,6 +28,12 @@ public class TemplateConfigureTest extends InitTestEnvironment { @Resource TemplateConfigure templateConfigure; + /** + * The Template service. + */ + @Resource + TemplateServiceImpl templateService; + /** * Template loads test. */ @@ -34,4 +42,18 @@ public class TemplateConfigureTest extends InitTestEnvironment { log.info("Load template: {}", templateConfigure.getUmcTemplate()); Assert.assertEquals(9, templateConfigure.getUmcTemplate().size()); } + + /** + * Template get test. + */ + @Test + public void templateGetTest() { + + for (String v : new String[]{"DNS", "GAME", "WEB", "GENERAL"}) { + for (Long k : new Long[]{0L, 200L, 500L, 800L, 1500L, 1600L}) { + log.info("[{}, {}] with template: {}", v, k, + Helper.getDpTemplate(v, k)); + } + } + } } diff --git a/src/test/java/com/dispose/test/dev/debug/demo.java b/src/test/java/com/dispose/test/dev/debug/demo.java index 1f251c2c..f6cdd96e 100644 --- a/src/test/java/com/dispose/test/dev/debug/demo.java +++ b/src/test/java/com/dispose/test/dev/debug/demo.java @@ -26,6 +26,7 @@ import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -608,6 +609,9 @@ public class demo { public void codeDebug() { } + /** + * Dp ip segment test. + */ @Test public void dpIpSegmentTest() { String ipSegmentString = "1_192.168.10.1-192.168.10.12,2_192.168.1.2-192.168.1.20,3_-"; @@ -625,4 +629,20 @@ public class demo { } ); } + + /** + * List to string with char test. + */ + @Test + public void listToStringWithCharTest() { + List demoList = new ArrayList<>(); + List demoList2 = new ArrayList<>(); + + demoList.add("192.168.0.1"); + demoList.add("192.168.0.2"); + demoList.add("192.168.0.24/24"); + + log.info("Result demoList: {}", String.join(",", demoList)); + log.info("Result demoList: {}", String.join(",", demoList2)); + } } From 22c0670e84bd075c5c11e13e0c72b120e566ca8f Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 15 Jan 2021 15:37:58 +0800 Subject: [PATCH 22/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0UMCc?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E3=80=81=E5=88=A0=E9=99=A4=E9=98=B2=E6=8A=A4?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B8=9A=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 114 +++++++++++++++++- src/main/java/com/dispose/common/Helper.java | 23 ++-- .../dev/config/TemplateConfigureTest.java | 1 - 3 files changed, 119 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index ec2d41b9..9d29a734 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -11,6 +11,7 @@ import com.dispose.common.ErrorCode; import com.dispose.common.Helper; import com.dispose.common.IpAddrType; import com.dispose.common.NetflowDirection; +import com.dispose.config.TemplateConfigure; import com.dispose.pojo.dto.protocol.device.ability.DpBypassManager; import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject; import com.dispose.pojo.dto.protocol.device.ability.DpProtectionStrategyInfo; @@ -68,7 +69,87 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private long timerCnt = 0; - private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType) { + /** + * Remove umc protect object error code. + * + * @param objName the obj name + * @return the error code + */ + private ErrorCode removeUMCProtectObject(String objName) { + NtcRequestResultInfo ret; + + // 更新防护策略模板和防护对象关联关系 + getProtectionStrategyTemplateAssociation(); + // 更新防护对象 + getDisposeDeviceProtectObject(); + // 更新手动旁路牵引策略 + upgradeTractionStrategy(); + + // 清理关联的旁路手动牵引策略 + for (DpTractionStrategy v : dpBypassManager.getTractionStrategyName().values()) { + // 如果防护对象关联了旁路手动牵引策略,那么删除该策略 + if (v.getProtectName().equals(objName)) { + // 如果策略正在运行,直接报错 + if (v.isRunning()) { + log.error("!!!!Remove Traction Strategy Error, It's Running: {}", v); + return ErrorCode.ERR_CALLDEVICE; + } + + ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(v.getPolicyName()); + + if (ret.getResultRetVal() == 0) { + log.debug("Remove Traction Strategy {} Succeed", v.getPolicyName()); + } else { + log.error("!!!!Remove Traction Strategy {} Error: {}", v.getPolicyName(), + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + } + } + + // 解除关联的防护模板 + for (DpProtectionStrategyInfo v : dpBypassManager.getProtectStrategy().values()) { + if (v.getProtectTargetName().equals(objName)) { + ret = getCleanTypePort().disableProtectionStrategyTemplateForUMC(objName, v.getProtectStrategyName()); + + if (ret.getResultRetVal() == 0) { + log.debug("Disable Protection Strategy Template {} Succeed", objName); + } else { + log.error("!!!!Disable Protection Strategy Template {} Error: {}", objName, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + break; + } + } + + // 删除防护对象 + ret = getCleanTypePort().deleteProtectionObjectForUMC(objName); + + if (ret.getResultRetVal() == 0) { + log.debug("Delete Protection Object {} Succeed", objName); + } else { + log.error("!!!!Delete Protection Object {} Error: {}", objName, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + + return ErrorCode.ERR_OK; + } + + /** + * Create umc portect object error code. + * + * @param objName the obj name + * @param ipSegment the ip segment + * @param ipType the ip type + * @param type the type + * @param bandWidth the band width + * @return the error code + */ + private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType, String type, + Long bandWidth) { + // 创建对象 NtcRequestResultInfo ret = getCleanTypePort() .addProtectionObjectForUMC("", allCleanupDevices, @@ -79,12 +160,35 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { if (ret.getResultRetVal() == 0) { log.debug("Add Protection Object {} Succeed", objName); - return ErrorCode.ERR_OK; + } else { log.error("!!!!Add Protection Object {}, {}, {} Error: {}", objName, ipSegment, ipType, ret.getResultInfo().getValue()); return ErrorCode.ERR_CALLDEVICE; } + + // 关联模板 + String template = Helper.getDpTemplate(type, bandWidth); + + // 未找到合适的模板 + if (TemplateConfigure.UMC_TEMPLATE.stream().noneMatch(v -> v.getName().equals(template))) { + log.error("!!!!DpTech Can't Math Template: {}, {} From {}", type, bandWidth, + TemplateConfigure.UMC_TEMPLATE); + return ErrorCode.ERR_NOSUCHTYPE; + } + + // UMC关联模板 + ret = getCleanTypePort().linkProtectionStrategyTemplateForUMC(objName, template); + + if (ret.getResultRetVal() == 0) { + log.debug("{} Link Protection Strategy Template {} Succeed", objName, template); + } else { + log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, template, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + + return ErrorCode.ERR_OK; } /** @@ -245,9 +349,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } /** - * Gets protection strategy template. + * Gets protection strategy template association. */ - private void getProtectionStrategyTemplate() { + private void getProtectionStrategyTemplateAssociation() { try { log.info("++++Begging DPTech Get All Protection Strategy Association Relation"); @@ -586,7 +690,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) { // 更新防护对象与目标关联关系 - getProtectionStrategyTemplate(); + getProtectionStrategyTemplateAssociation(); } // 清理旁路手动牵引策略 diff --git a/src/main/java/com/dispose/common/Helper.java b/src/main/java/com/dispose/common/Helper.java index 73f98ca2..48d27a94 100644 --- a/src/main/java/com/dispose/common/Helper.java +++ b/src/main/java/com/dispose/common/Helper.java @@ -31,7 +31,7 @@ public class Helper { /** * Instantiates a new Helper. */ - private Helper () { + private Helper() { throw new AssertionError("Instantiating utility class."); } @@ -160,7 +160,8 @@ public class Helper { } else if (addr.isIPv6() && ipV6All.equals(rangeIp)) { return true; } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // 处理CIDR格式 if (rangeIp.contains(cidrSplit)) { @@ -182,7 +183,8 @@ public class Helper { addr = new IPAddressString(ipAddr).toAddress(); IPAddressSeqRange range = lower.toSequentialRange(upper); return range.contains(addr); - } catch (AddressStringException ignored) {} + } catch (AddressStringException ignored) { + } return false; } @@ -216,18 +218,13 @@ public class Helper { * @return the dp template */ public static String getDpTemplate(String type, Long bandWidth) { -// Map> result = TemplateConfigure.UMC_TEMPLATE.stream() -// .collect(Collectors.groupingBy(TemplateInfo::getType)); - - - Optional ret = TemplateConfigure.UMC_TEMPLATE.stream() .filter(v -> v.getType().equals(type)) - .filter(v -> bandWidth > v.getBandMin() && bandWidth <= v.getBandMax()) - .findFirst() - .map(TemplateInfo::getName); + .filter(v -> (bandWidth == 0 && v.getBandMin() == 0) + || (bandWidth > v.getBandMin() && (bandWidth <= v.getBandMax() || v.getBandMax() == -1L))) + .map(TemplateInfo::getName) + .findFirst(); - log.info("{}", ret); - return ""; + return ret.orElse(""); } } diff --git a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java index 59442906..d126ee74 100644 --- a/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java +++ b/src/test/java/com/dispose/test/dev/config/TemplateConfigureTest.java @@ -48,7 +48,6 @@ public class TemplateConfigureTest extends InitTestEnvironment { */ @Test public void templateGetTest() { - for (String v : new String[]{"DNS", "GAME", "WEB", "GENERAL"}) { for (Long k : new Long[]{0L, 200L, 500L, 800L, 1500L, 1600L}) { log.info("[{}, {}] with template: {}", v, k, From 39513c00a3b98030cd5eb3b8f55375742bc8f0dd Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 15 Jan 2021 17:09:05 +0800 Subject: [PATCH 23/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E5=AF=B9=E8=B1=A1=E5=92=8CUMC=E9=98=B2?= =?UTF-8?q?=E6=8A=A4=E5=AF=B9=E8=B1=A1=E5=90=8C=E6=AD=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 172 +++++++++++++----- .../java/com/dispose/test/dev/debug/demo.java | 21 +++ 2 files changed, 146 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 9d29a734..a896bfc7 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -69,6 +69,18 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private long timerCnt = 0; + /** + * Upgrade device bypass info. + */ + private void upgradeDeviceBypassInfo() { + // 更新防护策略模板和防护对象关联关系 + getProtectionStrategyTemplateAssociation(); + // 更新防护对象 + getDisposeDeviceProtectObject(); + // 更新手动旁路牵引策略 + upgradeTractionStrategy(); + } + /** * Remove umc protect object error code. * @@ -78,12 +90,8 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { private ErrorCode removeUMCProtectObject(String objName) { NtcRequestResultInfo ret; - // 更新防护策略模板和防护对象关联关系 - getProtectionStrategyTemplateAssociation(); - // 更新防护对象 - getDisposeDeviceProtectObject(); - // 更新手动旁路牵引策略 - upgradeTractionStrategy(); + // 修改前同步更新设备信息 + upgradeDeviceBypassInfo(); // 清理关联的旁路手动牵引策略 for (DpTractionStrategy v : dpBypassManager.getTractionStrategyName().values()) { @@ -138,17 +146,15 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } /** - * Create umc portect object error code. + * Create protect object error code. * * @param objName the obj name * @param ipSegment the ip segment * @param ipType the ip type - * @param type the type - * @param bandWidth the band width + * @param template the template * @return the error code */ - private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType, String type, - Long bandWidth) { + private ErrorCode createProtectObject(String objName, String ipSegment, int ipType, String template) { // 创建对象 NtcRequestResultInfo ret = getCleanTypePort() .addProtectionObjectForUMC("", @@ -167,20 +173,10 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return ErrorCode.ERR_CALLDEVICE; } - // 关联模板 - String template = Helper.getDpTemplate(type, bandWidth); - - // 未找到合适的模板 - if (TemplateConfigure.UMC_TEMPLATE.stream().noneMatch(v -> v.getName().equals(template))) { - log.error("!!!!DpTech Can't Math Template: {}, {} From {}", type, bandWidth, - TemplateConfigure.UMC_TEMPLATE); - return ErrorCode.ERR_NOSUCHTYPE; - } - // UMC关联模板 - ret = getCleanTypePort().linkProtectionStrategyTemplateForUMC(objName, template); + ErrorCode err = associationProtectionTemplate(objName, template, null); - if (ret.getResultRetVal() == 0) { + if (err == ErrorCode.ERR_OK) { log.debug("{} Link Protection Strategy Template {} Succeed", objName, template); } else { log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, template, @@ -188,6 +184,51 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return ErrorCode.ERR_CALLDEVICE; } + // 修改设备后同步更新信息 + upgradeDeviceBypassInfo(); + return ErrorCode.ERR_OK; + } + + /** + * Association protection template error code. + * + * @param objName the obj name + * @param newTemplate the new template + * @param oldTemplate the old template + * @return the error code + */ + private ErrorCode associationProtectionTemplate(String objName, String newTemplate, String oldTemplate) { + NtcRequestResultInfo ret; + + // 如果关联了旧的防护模板,先解除关联 + if (oldTemplate != null + && TemplateConfigure.UMC_TEMPLATE.stream().anyMatch(m -> m.getName().equals(oldTemplate))) { + ret = getCleanTypePort().disableProtectionStrategyTemplateForUMC(objName, oldTemplate); + + if (ret.getResultRetVal() == 0) { + log.debug("Disable Protection Strategy Template {} Succeed", objName); + } else { + log.error("!!!!Disable Protection Strategy Template {} Error: {}", objName, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + + // 更新防护策略模板和防护对象关联关系 + getProtectionStrategyTemplateAssociation(); + return ErrorCode.ERR_OK; + } + + // UMC关联模板 + ret = getCleanTypePort().linkProtectionStrategyTemplateForUMC(objName, newTemplate); + + if (ret.getResultRetVal() == 0) { + log.debug("{} Link Protection Strategy Template {} Succeed", objName, newTemplate); + } else { + log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, newTemplate, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + return ErrorCode.ERR_OK; } @@ -196,12 +237,21 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private void syncDpTechDeviceInfo() { disposeServiceGroup.values().forEach(v -> { - boolean changed = false; - NtcRequestResultInfo ret; + ErrorCode err; List ipV4 = new ArrayList<>(); List ipV6 = new ArrayList<>(); int ipV4Idx = 1; int ipV6Idx = 1; + + String template = Helper.getDpTemplate(v.getServiceType(), v.getServiceBandwidth()); + + // 未找到合适的模板 + if (TemplateConfigure.UMC_TEMPLATE.stream().noneMatch(m -> m.getName().equals(template))) { + log.error("!!!!{} Can't Math Template: {}, {} From {}", v.getServiceId(), v.getServiceType(), + v.getServiceBandwidth(), TemplateConfigure.UMC_TEMPLATE); + return; + } + // 将业务Ip根据IP地址类型进行拆分 for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) { if (!k.contains(":")) { @@ -229,33 +279,61 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { if (dpBypassManager.getProtectObject().containsKey(protectName)) { DpProtectObject dp = dpBypassManager.getProtectObject().get(protectName); - - } else { - // 创建一个防护对象 - ret = getCleanTypePort().addProtectionObjectForUMC("", - allCleanupDevices, - protectName, - ipSegment.get(t), - IpAddrType.IPV4.equals(t) ? 0 : 1, - 0); - - if (ret.getResultRetVal() == 0) { - log.info("Add Protection Object {} Succeed", protectName); + // 判断关联模板是否正确 + if (dpBypassManager.getProtectStrategy().containsKey(protectName)) { + // 已经关联防护模板 + String temp = dpBypassManager.getProtectStrategy().get(protectName).getProtectStrategyName(); + // 如果关联模板有变更 + if (!temp.equals(template)) { + // 重新关联防护模板 + associationProtectionTemplate(protectName, template, temp); + } } else { - log.error("!!!!Add Protection Object {} Error: {}", protectName, ret.getResultInfo() - .getValue()); + // 关联一个新的防护模板 + associationProtectionTemplate(protectName, template, null); } - changed = true; + boolean upgradeIpSegment = false; + + // 判断防护IP段是否有变化 + if (IpAddrType.IPV4.equals(t)) { + if (ipV4.size() != dp.getIpSegment().values().size() + || !ipV4.containsAll(dp.getIpSegment().values()) + || dp.getIpSegment().values().containsAll(ipV4)) { + upgradeIpSegment = true; + } + } else if (IpAddrType.IPV6.equals(t)) { + if (ipV6.size() != dp.getIpSegment().values().size() + || !ipV4.containsAll(dp.getIpSegment().values()) + || dp.getIpSegment().values().containsAll(ipV6)) { + upgradeIpSegment = true; + } + } + + if (upgradeIpSegment) { + removeUMCProtectObject(protectName); + err = createProtectObject(protectName, + ipSegment.get(t), + IpAddrType.IPV4.equals(t) ? 0 : 1, + template); + if (err == ErrorCode.ERR_OK) { + log.debug("Add Protection Object {} Succeed", protectName); + } else { + log.error("!!!!Add Protection Object {} Error: {}", protectName, err.getMsg()); + } + } + } else { + err = createProtectObject(protectName, + ipSegment.get(t), + IpAddrType.IPV4.equals(t) ? 0 : 1, + template); + if (err == ErrorCode.ERR_OK) { + log.debug("Add Protection Object {} Succeed", protectName); + } else { + log.error("!!!!Add Protection Object {} Error: {}", protectName, err.getMsg()); + } } } - - // 修改后重新从设备更新信息 - if (changed) { - getDisposeDeviceProtectObject(); - changed = false; - } - }); } diff --git a/src/test/java/com/dispose/test/dev/debug/demo.java b/src/test/java/com/dispose/test/dev/debug/demo.java index f6cdd96e..c4d42a7a 100644 --- a/src/test/java/com/dispose/test/dev/debug/demo.java +++ b/src/test/java/com/dispose/test/dev/debug/demo.java @@ -28,6 +28,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -637,12 +638,32 @@ public class demo { public void listToStringWithCharTest() { List demoList = new ArrayList<>(); List demoList2 = new ArrayList<>(); + Hashtable tmpTable = new Hashtable<>(); + Hashtable tmpTable2 = new Hashtable<>(); demoList.add("192.168.0.1"); demoList.add("192.168.0.2"); demoList.add("192.168.0.24/24"); + demoList2.add("192.168.0.2"); + demoList2.add("192.168.0.1"); + demoList2.add("192.168.0.24/24"); + //demoList2.add("192.168.0.24/23"); + + tmpTable.put("1", "192.168.0.1"); + tmpTable.put("2", "192.168.0.2"); + tmpTable.put("3", "192.168.0.3"); + + tmpTable2.put("2", "192.168.0.2"); + tmpTable2.put("1", "192.168.0.1"); + tmpTable2.put("3", "192.168.0.3"); + log.info("Result demoList: {}", String.join(",", demoList)); log.info("Result demoList: {}", String.join(",", demoList2)); + + log.info("demoList difference demoList2: {}", demoList2.containsAll(demoList)); + log.info("demoList2 difference demoList1: {}", demoList.containsAll(demoList2)); + log.info("demoList2 difference demoList1: {}", demoList.equals(demoList2)); + log.info("tmpTable difference tmpTable: {}", tmpTable.equals(tmpTable2)); } } From c3a3b90e50585abdca7ae225c20de49be50e10ef Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Sat, 16 Jan 2021 15:02:39 +0800 Subject: [PATCH 24/67] =?UTF-8?q?OCT=20REM:=201.=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=202.=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=ADIPV6?= =?UTF-8?q?=E6=AE=B5=E6=98=AF=E5=90=A6=E5=8F=98=E5=8C=96=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index a896bfc7..2db46e3c 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -117,6 +117,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 解除关联的防护模板 for (DpProtectionStrategyInfo v : dpBypassManager.getProtectStrategy().values()) { + // 如果防护对象关联了防护策略模板,那么解除该防护策略模板 if (v.getProtectTargetName().equals(objName)) { ret = getCleanTypePort().disableProtectionStrategyTemplateForUMC(objName, v.getProtectStrategyName()); @@ -304,7 +305,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } else if (IpAddrType.IPV6.equals(t)) { if (ipV6.size() != dp.getIpSegment().values().size() - || !ipV4.containsAll(dp.getIpSegment().values()) + || !ipV6.containsAll(dp.getIpSegment().values()) || dp.getIpSegment().values().containsAll(ipV6)) { upgradeIpSegment = true; } From 89a1d7f2973d73bef3416c92d065fd3c7ad68472 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Mon, 18 Jan 2021 14:38:30 +0800 Subject: [PATCH 25/67] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E6=8B=86=E5=88=86IP?= =?UTF-8?q?=E7=9A=84=E5=AD=98=E5=82=A8=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispose/ability/impl/DpTechBypassAbilityImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 2db46e3c..5aa597ac 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -255,10 +255,16 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 将业务Ip根据IP地址类型进行拆分 for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) { + String ipValue = k.replaceAll("\\d+_", ""); + if (!k.contains(":")) { - ipV4.add(ipV4Idx++ + "_" + k); + if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) { + ipV4.add(ipV4Idx++ + "_" + ipValue); + } } else { - ipV6.add(ipV6Idx++ + "_" + k); + if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) { + ipV6.add(ipV6Idx++ + "_" + ipValue); + } } } From 69d1ee7409f23c44353b2b83803ad4a9ec48b308 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 14:44:11 +0800 Subject: [PATCH 26/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E6=B8=85=E6=B4=97=E5=A4=84=E7=BD=AE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 356 +++++++++++++----- .../java/com/dispose/common/ErrorCode.java | 10 + 2 files changed, 280 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 2db46e3c..2ae035af 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -30,7 +30,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; /** @@ -82,12 +81,34 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } /** - * Remove umc protect object error code. + * Upgrade protect object error code. + * + * @param objName the obj name + * @param ipSegment the ip segment + * @param ipType the ip type + * @param template the template + * @return the error code + */ + private ErrorCode upgradeProtectObject(String objName, String ipSegment, int ipType, String template) { + ErrorCode err = removeProtectObject(objName); + + if (err != ErrorCode.ERR_OK) { + return err; + } + + err = createProtectObject(objName, ipSegment, ipType, template); + + return err; + } + + + /** + * Remove protect object error code. * * @param objName the obj name * @return the error code */ - private ErrorCode removeUMCProtectObject(String objName) { + private ErrorCode removeProtectObject(String objName) { NtcRequestResultInfo ret; // 修改前同步更新设备信息 @@ -143,6 +164,13 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return ErrorCode.ERR_CALLDEVICE; } + // 清理缓存中的对象 + for(String v : disposeObjectCache.keySet()) { + if(disposeObjectCache.get(v).equals(objName)) { + disposeObjectCache.remove(v); + } + } + return ErrorCode.ERR_OK; } @@ -156,6 +184,11 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { * @return the error code */ private ErrorCode createProtectObject(String objName, String ipSegment, int ipType, String template) { + // 检查防护对象是否已经存在 + if (dpBypassManager.getProtectObject().containsKey(objName)) { + return ErrorCode.ERR_PROTECTOBJECTEXISTS; + } + // 创建对象 NtcRequestResultInfo ret = getCleanTypePort() .addProtectionObjectForUMC("", @@ -190,6 +223,144 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return ErrorCode.ERR_OK; } + /** + * Create traction strategy error code. + * + * @param objName the obj name + * @param disposeObject the dispose object + * @return the error code + */ + private ErrorCode createTractionStrategy(String objName, String disposeObject) { + NtcRequestResultInfo ret; + ErrorCode err; + + log.debug("++++Begging Create Traction Strategy: {}, {}", objName, disposeObject); + + // 获取旁路手动牵引策略名 + String tractionName = getTractionStrategyName(objName, disposeObject); + + // 删除旧的策略 + err = removeTractionStrategy(tractionName); + + if (err != ErrorCode.ERR_OK) { + return err; + } + + // 创建旁路手动牵引策略 + ret = getCleanTypePort().addBypassManualTractionStrategyForUMC(tractionName, + objName, + disposeObject); + if (ret.getResultRetVal() == 0) { + log.debug("----Finish Create Traction Strategy {} Succeed", tractionName); + return ErrorCode.ERR_OK; + } else { + log.error("----Create Traction Strategy Error: {}, {}, {}, {}", tractionName, + objName, disposeObject, ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + } + + /** + * Start traction strategy error code. + * + * @param objName the obj name + * @param disposeObject the dispose object + * @return the error code + */ + private ErrorCode startTractionStrategy(String objName, String disposeObject) { + NtcRequestResultInfo ret; + ErrorCode err = ErrorCode.ERR_OK; + + log.info("++++Begging Start Traction Strategy: {}, {}", objName, disposeObject); + + // 获取旁路手动牵引策略名 + String policyName = getTractionStrategyName(objName, disposeObject); + + // 启动旁路手动牵引策略 + log.debug("DpTech startBypassManualTractionStrategyForUMC request: {}, {}", policyName, disposeObject); + ret = getCleanTypePort().startBypassManualTractionStrategyForUMC(policyName, ""); + log.debug("DpTech startBypassManualTractionStrategyForUMC response: {}", ret); + + if (ret.getResultRetVal() != 0) { + err = ErrorCode.ERR_CALLDEVICE; + log.error("----Error Start Traction Strategy: {}, {}, {}", objName, disposeObject, + ret.getResultInfo().getValue()); + } else { + log.info("----Finish Start Traction Strategy: {}, {}", objName, disposeObject); + } + + return err; + } + + /** + * Stop traction strategy error code. + * + * @param objName the obj name + * @param disposeObject the dispose object + * @return the error code + */ + private ErrorCode stopTractionStrategy(String objName, String disposeObject) { + NtcRequestResultInfo ret; + + log.info("++++Begging Stop Traction Strategy: {}, {}", objName, disposeObject); + + // 获取旁路手动牵引策略名 + String policyName = getTractionStrategyName(objName, disposeObject); + + // 判断缓存中是否有该防护策略 + if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) { + log.error("----Error Stop Traction Strategy, No Such Traction Strategy: {}, {}", disposeObject, policyName); + return ErrorCode.ERR_NOSUCHPROTECTSTRATEGY; + } + + // 停止旁路手动牵引策略 + log.debug("DpTech stopBypassManualTractionStrategyForUMC request: {}", disposeObject); + ret = getCleanTypePort().stopBypassManualTractionStrategyForUMC(policyName, ""); + log.debug("DpTech stopBypassManualTractionStrategyForUMC response: {}", ret); + + if (ret.getResultRetVal() != 0) { + log.error("----Error DPTech Stop Cleanup Task: {}, {}", disposeObject, ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + + return ErrorCode.ERR_OK; + } + + /** + * Remove traction strategy error code. + * + * @param tractionName the traction name + * @return the error code + */ + private ErrorCode removeTractionStrategy(String tractionName) { + NtcRequestResultInfo ret; + + // 判断旁路手动牵引策略是否存在 + if (dpBypassManager.getTractionStrategyName().containsKey(tractionName)) { + DpTractionStrategy ts = dpBypassManager.getTractionStrategyName().get(tractionName); + + // 如果正在运行,删除失败 + if (ts.isRunning()) { + log.error("!!!!Remove Traction Strategy Error, It's Running: {}", tractionName); + return ErrorCode.ERR_TRACTIONSTRATEGYRUNNING; + } else { + // 删除策略 + ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(tractionName); + + if (ret.getResultRetVal() == 0) { + log.debug("Remove Traction Strategy {} Succeed", tractionName); + return ErrorCode.ERR_OK; + } else { + log.error("!!!!Remove Traction Strategy {} Error: {}", tractionName, + ret.getResultInfo().getValue()); + return ErrorCode.ERR_CALLDEVICE; + } + } + } + + return ErrorCode.ERR_OK; + } + /** * Association protection template error code. * @@ -237,6 +408,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { * Sync dp tech device info. */ private void syncDpTechDeviceInfo() { + // 处置平台数据同步到UMC disposeServiceGroup.values().forEach(v -> { ErrorCode err; List ipV4 = new ArrayList<>(); @@ -311,12 +483,12 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } + // 更新防护对象 if (upgradeIpSegment) { - removeUMCProtectObject(protectName); - err = createProtectObject(protectName, - ipSegment.get(t), - IpAddrType.IPV4.equals(t) ? 0 : 1, - template); + err = upgradeProtectObject(protectName, + ipSegment.get(t), + IpAddrType.IPV4.equals(t) ? 0 : 1, + template); if (err == ErrorCode.ERR_OK) { log.debug("Add Protection Object {} Succeed", protectName); } else { @@ -336,6 +508,24 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } }); + + // UMC 同步到处置平台 + dpBypassManager.getProtectObject().values().forEach(v -> { + String serviceId = v.getProtectName() + .replace(OBJ_PREFIX + "_", "") + .replace("_" + IpAddrType.IPV4.getDescription(), "") + .replace("_" + IpAddrType.IPV6.getDescription(), ""); + + // UMC上面存在对象已经失效 + if (disposeServiceGroup.values().stream().noneMatch(k -> serviceId.equals(k.getServiceId()))) { + log.debug("++++Remove UMC Unused Protect Object: {}", v.getProtectName()); + ErrorCode err = removeProtectObject(v.getProtectName()); + + if (err != ErrorCode.ERR_OK) { + log.error("!!!!Remove Protect Object Error: {}", v.getProtectName()); + } + } + }); } /** @@ -356,11 +546,12 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { /** * Gets traction strategy name. * + * @param objName the obj name * @param disposeIp the dispose ip * @return the traction strategy name */ - private String getTractionStrategyName(String disposeIp) { - return OBJ_PREFIX + "_" + disposeIp + ""; + private String getTractionStrategyName(String objName, String disposeIp) { + return OBJ_PREFIX + "_" + disposeIp + "_" + objName; } /** @@ -608,11 +799,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { NetflowDirection nfDirection, Integer attackType, Long duration) { - ErrorCode err = ErrorCode.ERR_OK; - NtcRequestResultInfo ret; - try { - AtomicReference protectionObject = new AtomicReference<>(""); + ErrorCode err; + String protectObjName = ""; log.info("++++Begging DPTech Start Cleanup Task: {}", disposeObject); if (capType != DisposeCapacityType.CLEANUP) { @@ -620,81 +809,57 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); } - String policyName = getTractionStrategyName(disposeObject); - - // 判断缓存中当前处置IP的旁路牵引策略是否存在, 如果存在直接删除 - if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) { - ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); - - if (ret.getResultRetVal() != 0) { - log.error("----Error DPTech Delete Old Traction Strategy Error: {}, {}", policyName, - ret.getResultInfo().getValue()); - return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); - } - } - // 判断缓存中是否存在该处置IP对应的防护对象 if (disposeObjectCache.containsKey(disposeObject)) { - protectionObject.set(disposeObjectCache.get(disposeObject)); + protectObjName = disposeObjectCache.get(disposeObject); } else { // 从设备防护对象缓存中查找当前处置IP对应的防护对象名称 - dpBypassManager.getProtectObject().values().forEach(k -> { + for (DpProtectObject k : dpBypassManager.getProtectObject().values()) { for (String v : k.getIpSegment().values()) { if (Helper.ipInRange(v, disposeObject)) { - protectionObject.set(k.getProtectName()); + protectObjName = k.getProtectName(); // 将查找到的防护对象添加到缓存中 disposeObjectCache.put(disposeObject, k.getProtectName()); break; } } - }); + } } // 校验当前处置对象对应的防护对象名称是否正确 - if (protectionObject.get().length() == 0) { + if (protectObjName.length() == 0) { log.error("----Error DPTech Task Not Found Protection Object: {}", disposeObject); log.debug("!!!!DpTech UMC Protection Objects: {}", dpBypassManager.getProtectObject().values()); return new MulReturnType<>(ErrorCode.ERR_NOSUCHUMCPROTECTOBJECT, null); } - log.debug("++++Begging DPTech Create Traction Strategy: {}, {}, {}", policyName, - protectionObject.get(), disposeObject); + // 为当前处置IP创建旁路手动牵引策略 + err = createTractionStrategy(protectObjName, disposeObject); - // 创建旁路手动牵引策略 - ret = getCleanTypePort().addBypassManualTractionStrategyForUMC(policyName, protectionObject.get(), - disposeObject); - - if (ret.getResultRetVal() != 0) { - log.error("----Error DPTech Create Traction Strategy Error: {}, {}, {}, {}", policyName, - protectionObject.get(), disposeObject, ret.getResultInfo().getValue()); + if (err != ErrorCode.ERR_OK) { + log.error("----Error DPTech Start Cleanup Task, Create Traction Strategy Error: {}, {}, {}", + protectObjName, disposeObject, err); return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); } - log.debug("----Finish DPTech Create Traction Strategy: {}, {}, {}", policyName, - protectionObject.get(), disposeObject); - // 启动旁路手动牵引策略 - log.debug("DpTech startBypassManualTractionStrategyForUMC request: {}, {}", policyName, disposeObject); - ret = getCleanTypePort().startBypassManualTractionStrategyForUMC(policyName, ""); - log.debug("DpTech startBypassManualTractionStrategyForUMC response: {}", ret); + err = startTractionStrategy(protectObjName, disposeObject); - if (ret.getResultRetVal() != 0) { - err = ErrorCode.ERR_CALLDEVICE; - log.error("----Error DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, - CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), - ret.getResultInfo().getValue()); - } else { - log.info("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection, - CommonEnumHandler.codeOf(DpTechAttackType.class, attackType), - ret.getResultInfo().getValue()); + if (err != ErrorCode.ERR_OK) { + log.error("----Error DPTech Start Cleanup Task, Start Traction Strategy Error: {}, {}, {}", + protectObjName, disposeObject, err); + return new MulReturnType<>(ErrorCode.ERR_CALLDEVICE, null); } + + log.info("----Finish DPTech Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, + CommonEnumHandler.codeOf(DpTechAttackType.class, attackType)); + + return new MulReturnType<>(ErrorCode.ERR_OK, null); } catch (Exception ex) { - err = ErrorCode.ERR_SYSTEMEXCEPTION; log.error("----Exception DPTech Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, CommonEnumHandler.codeOf(DpTechAttackType.class, attackType)); + return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } - - return new MulReturnType<>(err, null); } /** @@ -713,9 +878,8 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { NetflowDirection nfDirection, Integer attackType, String taskId) { - ErrorCode err = ErrorCode.ERR_OK; - try { + ErrorCode err; log.info("++++Begging DPTech Stop Cleanup Task: {}", disposeObject); if (capType != DisposeCapacityType.CLEANUP) { @@ -723,40 +887,37 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null); } - String policyName = getTractionStrategyName(disposeObject); - - if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) { - log.error("----Error DPTech Stop Cleanup Task, No Such Task: {}, {}", disposeObject, policyName); + // 判断缓存中是否存在该处置IP对应的防护对象 + if (!disposeObjectCache.containsKey(disposeObject)) { + log.error("----Error DPTech Not Found Cache Protection Object: {}", disposeObject); return new MulReturnType<>(ErrorCode.ERR_TASKNOTRUNNING, null); - } + } else { + String protectObjName = disposeObjectCache.get(disposeObject); - log.debug("DpTech stopBypassManualTractionStrategyForUMC request: {}", disposeObject); - NtcRequestResultInfo ret = getCleanTypePort().stopBypassManualTractionStrategyForUMC(policyName, ""); - log.debug("DpTech stopBypassManualTractionStrategyForUMC response: {}", ret); + err = stopTractionStrategy(protectObjName, disposeObject); - if (ret.getResultRetVal() != 0) { - err = ErrorCode.ERR_CALLDEVICE; - log.error("----Error DPTech Stop Cleanup Task: {}, {}", disposeObject, ret.getResultInfo().getValue()); - return new MulReturnType<>(err, null); - } + if (err != ErrorCode.ERR_OK) { + log.error("----Error DPTech Stop Cleanup Task, Stop Traction Strategy Error: {}, {}", disposeObject, + err); + return new MulReturnType<>(err, null); + } - // 删除不再使用的手动旁路牵引策略 - log.debug("DpTech delBypassManualTractionStrategyForUMC request: {}", policyName); - ret = getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); - log.debug("DpTech delBypassManualTractionStrategyForUMC response: {}", ret); + err = removeTractionStrategy(getTractionStrategyName(protectObjName, disposeObject)); - if (ret.getResultRetVal() != 0) { - log.error("----Error DPTech Remove Traction Strategy: {}, {}", policyName, - ret.getResultInfo().getValue()); + if (err != ErrorCode.ERR_OK) { + log.error("----Error DPTech Stop Cleanup Task, Clean Traction Strategy Error: {}, {}", + disposeObject, err); + } } log.info("----Finish DPTech Stop Cleanup Task Succeed: {}", disposeObject); + return new MulReturnType<>(ErrorCode.ERR_OK, null); } catch (Exception ex) { - err = ErrorCode.ERR_SYSTEMEXCEPTION; log.error("----Exception DPTech Stop Cleanup Task: {}, {}", disposeObject, ex.getMessage()); + return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); } - return new MulReturnType<>(err, null); + } /** @@ -766,15 +927,12 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { public void periodTaskRuntime() { synchronized (this) { super.periodTaskRuntime(); - if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) { // 更新防护对象与目标关联关系 getProtectionStrategyTemplateAssociation(); } - // 清理旁路手动牵引策略 upgradeTractionStrategy(); - // 与迪普设备同步数据 syncDpTechDeviceInfo(); } @@ -798,4 +956,30 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } } } + + /** + * Is carry protect ip boolean. + * + * @param ipAddr the ip addr + * @return the boolean + */ + @Override + public boolean isCarryProtectIp(String ipAddr) { + // 判断缓存中是否存在该处置IP对应的防护对象 + if (disposeObjectCache.containsKey(ipAddr)) { + return true; + } else { + // 从设备防护对象缓存中查找当前处置IP对应的防护对象名称 + for (DpProtectObject k : dpBypassManager.getProtectObject().values()) { + for (String v : k.getIpSegment().values()) { + if (Helper.ipInRange(v, ipAddr)) { + // 将查找到的防护对象添加到缓存中 + disposeObjectCache.put(k.getProtectName(), k.getProtectName()); + return true; + } + } + } + } + return false; + } } diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index eac55935..df067baa 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -245,6 +245,16 @@ public enum ErrorCode { * The Err nosuchumcprotectobject. */ ERR_NOSUCHUMCPROTECTOBJECT(200, "没有找到UMC防护对象"), + + /** + * Err protectobjectexists error code. + */ + ERR_PROTECTOBJECTEXISTS(201, "该防护对象已经存在"), + + ERR_TRACTIONSTRATEGYRUNNING(201, "该防护策略正在运行"), + + ERR_NOSUCHPROTECTSTRATEGY(202, "没有该防护策略"), + ; /** From 04cdb57e8f1fef2715a8d8bc00364c99d2307833 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 14:48:32 +0800 Subject: [PATCH 27/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=BF=9D=E5=AD=98IP=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispose/ability/impl/DpTechBypassAbilityImpl.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index ef9f2da9..2ae035af 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -427,16 +427,10 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 将业务Ip根据IP地址类型进行拆分 for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) { - String ipValue = k.replaceAll("\\d+_", ""); - if (!k.contains(":")) { - if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) { - ipV4.add(ipV4Idx++ + "_" + ipValue); - } + ipV4.add(ipV4Idx++ + "_" + k); } else { - if (Pattern.matches(ConstValue.ipAddrSegmentReg(), ipValue)) { - ipV6.add(ipV6Idx++ + "_" + ipValue); - } + ipV6.add(ipV6Idx++ + "_" + k); } } From 54d9f4eed7e7d4ddc98c69fd68fbd9243956c741 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 14:58:15 +0800 Subject: [PATCH 28/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E6=97=81=E8=B7=AF=E6=89=8B=E5=8A=A8=E7=89=B5?= =?UTF-8?q?=E5=BC=95=E4=BB=BB=E5=8A=A1=E5=90=AF=E5=8A=A8=E3=80=81=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E4=B8=9A=E5=8A=A1=202.=20=E5=A2=9E=E5=8A=A0=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E5=B9=B3=E5=8F=B0=E4=B8=9A=E5=8A=A1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=90=8C=E6=AD=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DeviceTaskManagerServiceImpl.java | 10 +++++-- .../impl/DisposeAbilityRouterServiceImpl.java | 28 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 42146c53..8cedb229 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -523,10 +523,13 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 启动新任务 switch (ai.getDev().getDeviceType()) { case DPTECH_UMC: - case DPTECH_BYPASS_UMC: dpTechDeviceTaskRun(ai, v, task); break; + case DPTECH_BYPASS_UMC: + restfulDeviceTaskRun(ai, v, task, DisposeDeviceType.DPTECH_BYPASS_UMC); + break; + case HAOHAN_PLATFORM: restfulDeviceTaskRun(ai, v, task, DisposeDeviceType.HAOHAN_PLATFORM); break; @@ -597,10 +600,13 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { switch (ai.getDev().getDeviceType()) { case DPTECH_UMC: - case DPTECH_BYPASS_UMC: dpTechDeviceTaskStop(ai, v, task); break; + case DPTECH_BYPASS_UMC: + restfulDeviceTaskStop(ai, v, task, DisposeDeviceType.DPTECH_BYPASS_UMC); + break; + case HAOHAN_PLATFORM: restfulDeviceTaskStop(ai, v, task, DisposeDeviceType.HAOHAN_PLATFORM); break; diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index c2fd1f9f..103c4423 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -81,9 +81,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ @Override public AbilityInfo getAbilityDevice(Long id) { DisposeDevice dev = disposeDeviceManager.getAllNormalDisposeDevices().parallelStream() - .filter(v -> v.getId().equals(id)) - .findAny() - .orElse(null); + .filter(v -> v.getId().equals(id)) + .findAny() + .orElse(null); if (dev != null) { return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort())); @@ -147,10 +147,10 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ // 缓存处置设备到Hash表中 disposeAbilityMap.put(addr, AbilityInfo.builder() - .db(db) - .dev(dev) - .linkStatus(false) - .build()); + .db(db) + .dev(dev) + .linkStatus(false) + .build()); return ErrorCode.ERR_OK; } @@ -167,18 +167,18 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ public ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType) { if (getAllAbilityDevices().stream() - .noneMatch(f -> deviceId == -1 || f.getDev().getId().equals(deviceId))) { + .noneMatch(f -> deviceId == -1 || f.getDev().getId().equals(deviceId))) { return ErrorCode.ERR_NOSUCHDEVICE; } if (getAllAbilityDevices().stream() - .noneMatch(c -> c.getDev().getDevCapacity().stream() - .anyMatch(m -> m.getCapacityType() == capacityType))) { + .noneMatch(c -> c.getDev().getDevCapacity().stream() + .anyMatch(m -> m.getCapacityType() == capacityType))) { return ErrorCode.ERR_NOSUCHTYPE; } if (getAllAbilityDevices().stream() - .noneMatch(c -> c.getDb().isCarryProtectIp(disposeIp))) { + .noneMatch(c -> c.getDb().isCarryProtectIp(disposeIp))) { return ErrorCode.ERR_IPNODEVICE; } @@ -192,7 +192,11 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ @Async("deviceTaskExecutor") @Scheduled(fixedDelay = 1000) public void runPeriodTask() { - getAllAbilityDevices().forEach(v -> v.getDb().periodTaskRuntime()); + getAllAbilityDevices().forEach(v -> { + v.getDb().periodTaskRuntime(); + // 同步最新处置平台业务信息到设备 + v.getDb().upgradeServiceGroup(serviceGroupMapper.selectAll()); + }); } /** From 3906539c0aae98f42625d6e4c2ae897ff6e09f19 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 16:38:30 +0800 Subject: [PATCH 29/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/common/ErrorCode.java | 25 ++- .../controller/UserBusinessController.java | 177 ++++++++++++++++++ .../dispose/manager/UserBusinessManager.java | 27 +++ .../manager/impl/UserBusinessManagerImpl.java | 57 ++++++ .../dispose/mapper/ServiceGroupMapper.java | 8 + .../device/business/AddUserSvrReq.java | 33 ++++ .../device/business/AddUserSvrRsp.java | 26 +++ .../device/business/BusinessIdArray.java | 28 +++ .../protocol/device/business/UserSvrInfo.java | 43 +++++ .../protocol/device/business/UserSvrRsp.java | 27 +++ .../service/UserBusinessManagerService.java | 38 ++++ .../impl/UserBusinessManagerServiceImpl.java | 93 +++++++++ .../dispose/validation/group/ValidGroups.java | 8 + src/main/resources/mappers/ServiceGroup.xml | 6 + 14 files changed, 595 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/dispose/controller/UserBusinessController.java create mode 100644 src/main/java/com/dispose/manager/UserBusinessManager.java create mode 100644 src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java create mode 100644 src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java create mode 100644 src/main/java/com/dispose/service/UserBusinessManagerService.java create mode 100644 src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index df067baa..f7112dc2 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -247,14 +247,37 @@ public enum ErrorCode { ERR_NOSUCHUMCPROTECTOBJECT(200, "没有找到UMC防护对象"), /** - * Err protectobjectexists error code. + * The Err protectobjectexists. */ ERR_PROTECTOBJECTEXISTS(201, "该防护对象已经存在"), + /** + * The Err tractionstrategyrunning. + */ ERR_TRACTIONSTRATEGYRUNNING(201, "该防护策略正在运行"), + /** + * The Err nosuchprotectstrategy. + */ ERR_NOSUCHPROTECTSTRATEGY(202, "没有该防护策略"), + + /** + * The Err businessexists. + */ + ERR_BUSINESSEXISTS(300, "该业务已经存在"), + + /** + * Err businessnotexists error code. + */ + ERR_BUSINESSNOTEXISTS(301, "该业务不存在"), + + /** + * Err addbusiness error code. + */ + ERR_ADDBUSINESS(302, "添加客户业务失败"), + + ERR_DELBUSINESS(303, "删除客户业务失败"), ; /** diff --git a/src/main/java/com/dispose/controller/UserBusinessController.java b/src/main/java/com/dispose/controller/UserBusinessController.java new file mode 100644 index 00000000..f9c34ad4 --- /dev/null +++ b/src/main/java/com/dispose/controller/UserBusinessController.java @@ -0,0 +1,177 @@ +package com.dispose.controller; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.device.business.AddUserSvrReq; +import com.dispose.pojo.dto.protocol.device.business.AddUserSvrRsp; +import com.dispose.pojo.dto.protocol.device.business.BusinessIdArray; +import com.dispose.pojo.dto.protocol.device.business.UserSvrInfo; +import com.dispose.pojo.dto.protocol.device.business.UserSvrRsp; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.security.annotation.Decryption; +import com.dispose.security.annotation.Encryption; +import com.dispose.service.UserBusinessManagerService; +import com.dispose.validation.group.ValidGroups; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business controller. + * + * @author + */ +@Controller +@RequestMapping(value = "/business") +@Slf4j +@Api(value = "抗DDoS处置平台客户业务管理接口", tags = "抗DDoS处置平台客户业务管理接口") +@Component +@Validated +@Encryption +@Decryption +public class UserBusinessController { + /** + * The User business manager service. + */ + @Resource + private UserBusinessManagerService userBusinessManagerService; + + /** + * Add user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @PutMapping("/manage") + @ResponseBody + @ApiOperation("添加客户业务信息") + public ProtocolRespDTO addUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + List svrList = new ArrayList<>(); + + // 参数转换 + for (UserSvrInfo v : mr.getMsgContent().getItems()) { + svrList.add(ServiceInfo.builder() + .serviceId(v.getBusinessId()) + .serviceType(v.getBusinessType()) + .serviceBandwidth((long) Math.ceil(Double.parseDouble(v.getBusinessBandwidth()))) + .serviceIp(v.getBusinessIp()) + .build()); + } + + // 添加业务 + List> ret = userBusinessManagerService.addUserBusiness(svrList); + + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + // 处理放回值 + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } + + /** + * Del user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @DeleteMapping("/manage") + @ResponseBody + @ApiOperation("删除客户业务信息") + public ProtocolRespDTO delUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + // 删除业务 + List> ret = userBusinessManagerService.delUserBusiness(mr.getMsgContent() + .getBusinessId()); + + // 处理放回值 + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } + + /** + * Upgrade user business protocol resp dto. + * + * @param mr the mr + * @return the protocol resp dto + */ + @PostMapping("/updateBusiness") + @ResponseBody + @ApiOperation("更新客户业务信息") + public ProtocolRespDTO upgradeUserBusiness( + @Validated(ValidGroups.AddUserInfoValid.class) + @RequestBody ProtocolReqDTO mr) { + List svrList = new ArrayList<>(); + + // 参数转换 + for (UserSvrInfo v : mr.getMsgContent().getItems()) { + svrList.add(ServiceInfo.builder() + .serviceId(v.getBusinessId()) + .serviceType(v.getBusinessType()) + .serviceBandwidth((long) Math.ceil(Double.parseDouble(v.getBusinessBandwidth()))) + .serviceIp(v.getBusinessIp()) + .build()); + } + + // 更新业务 + List> ret = userBusinessManagerService.upgradeUserBusiness(svrList); + + AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() + .items(new ArrayList<>()) + .build(); + + // 处理放回值 + ret.forEach(v -> { + UserSvrRsp rsp = UserSvrRsp.builder() + .businessId(v.getSecondParam()) + .build(); + + rsp.setStatus(v.getFirstParam().getCode()); + rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); + rspInfo.getItems().add(rsp); + }); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } +} diff --git a/src/main/java/com/dispose/manager/UserBusinessManager.java b/src/main/java/com/dispose/manager/UserBusinessManager.java new file mode 100644 index 00000000..f65d5893 --- /dev/null +++ b/src/main/java/com/dispose/manager/UserBusinessManager.java @@ -0,0 +1,27 @@ +package com.dispose.manager; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.entity.ServiceInfo; + +/** + * The interface User business manager. + * + * @author + */ +public interface UserBusinessManager { + /** + * Add user business error code. + * + * @param svrInfo the svr info + * @return the error code + */ + ErrorCode addUserBusiness(ServiceInfo svrInfo); + + /** + * Del user business error code. + * + * @param svrId the svr id + * @return the error code + */ + ErrorCode delUserBusiness(String svrId); +} diff --git a/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java new file mode 100644 index 00000000..903d8d52 --- /dev/null +++ b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java @@ -0,0 +1,57 @@ +package com.dispose.manager.impl; + +import com.dispose.common.ErrorCode; +import com.dispose.manager.UserBusinessManager; +import com.dispose.mapper.ServiceGroupMapper; +import com.dispose.pojo.entity.ServiceInfo; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business manager. + * + * @author + */ +public class UserBusinessManagerImpl implements UserBusinessManager { + /** + * The Service group mapper. + */ + @Resource + private ServiceGroupMapper serviceGroupMapper; + + /** + * Add user business error code. + * + * @param svrInfo the svr info + * @return the error code + */ + @Override + public ErrorCode addUserBusiness(ServiceInfo svrInfo) { + + if (serviceGroupMapper.selectByServiceId(svrInfo.getServiceId()) != null) { + return ErrorCode.ERR_BUSINESSEXISTS; + } + + List svrList = new ArrayList<>(); + svrList.add(svrInfo); + + return serviceGroupMapper.addServiceGroup(svrList) != 1 ? ErrorCode.ERR_ADDBUSINESS : ErrorCode.ERR_OK; + } + + /** + * Del user business error code. + * + * @param svrId the svr id + * @return the error code + */ + @Override + public ErrorCode delUserBusiness(String svrId) { + if (serviceGroupMapper.selectByServiceId(svrId) == null) { + return ErrorCode.ERR_BUSINESSNOTEXISTS; + } + + return serviceGroupMapper.delServiceGroupByServiceId(svrId) != 1 ? ErrorCode.ERR_DELBUSINESS : ErrorCode.ERR_OK; + } +} diff --git a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java index a90d07aa..5f518812 100644 --- a/src/main/java/com/dispose/mapper/ServiceGroupMapper.java +++ b/src/main/java/com/dispose/mapper/ServiceGroupMapper.java @@ -18,6 +18,14 @@ public interface ServiceGroupMapper { */ List selectAll(); + /** + * Select by service id service info. + * + * @param serviceId the service id + * @return the service info + */ + ServiceInfo selectByServiceId(@Param("serviceId") String serviceId); + /** * Add service group int. * diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java new file mode 100644 index 00000000..9e5d256a --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrReq.java @@ -0,0 +1,33 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * The type Add user svr req. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AddUserSvrReq { + /** + * The Items. + */ + @NotNull(message = "items 设备列表不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Size(min = 1, message = "items 至少需要有一个元素", groups = ValidGroups.AddUserInfoValid.class) + @Valid + private List items; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java new file mode 100644 index 00000000..054377b6 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/AddUserSvrRsp.java @@ -0,0 +1,26 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * The type Add user svr rsp. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AddUserSvrRsp { + /** + * The Items. + */ + private List items; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java new file mode 100644 index 00000000..017a6c8f --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/BusinessIdArray.java @@ -0,0 +1,28 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * The type Business id array. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BusinessIdArray { + /** + * The Business id. + */ + @NotNull(message = "businessId 字段不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Size(min = 1, message = "businessId 字段必须指定明确编号", groups = ValidGroups.AddUserInfoValid.class) + private String[] businessId; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java new file mode 100644 index 00000000..f05ab975 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java @@ -0,0 +1,43 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +/** + * The type User svr info. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class UserSvrInfo { + /** + * The Business id. + */ + @NotBlank(message = "businessId 客户业务ID能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessId; + /** + * The Business type. + */ + @NotBlank(message = "businessType 客户业务类型不能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessType; + /** + * The Business ip. + */ + @JsonProperty("businessIP") + @NotBlank(message = "businessIp 业务IP地址段不能为空", groups = ValidGroups.UpgradeDeviceValid.class) + private String businessIp; + /** + * The Business bandwidth. + */ + @NotBlank(message = "businessBandwidth 客户业务带宽不能为空", groups = ValidGroups.AddUserInfoValid.class) + private String businessBandwidth; +} diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java new file mode 100644 index 00000000..511f77f3 --- /dev/null +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrRsp.java @@ -0,0 +1,27 @@ +package com.dispose.pojo.dto.protocol.device.business; + +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * The type User svr rsp. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonPropertyOrder({"businessId", "status", "message"}) +public class UserSvrRsp extends BaseRespStatus { + /** + * The Business id. + */ + private String businessId; +} diff --git a/src/main/java/com/dispose/service/UserBusinessManagerService.java b/src/main/java/com/dispose/service/UserBusinessManagerService.java new file mode 100644 index 00000000..419f6cab --- /dev/null +++ b/src/main/java/com/dispose/service/UserBusinessManagerService.java @@ -0,0 +1,38 @@ +package com.dispose.service; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; + +import java.util.List; + +/** + * The interface User business manager service. + * + * @author + */ +public interface UserBusinessManagerService { + /** + * Add user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + List> addUserBusiness(List svrInfoList); + + /** + * Upgrade user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + List> upgradeUserBusiness(List svrInfoList); + + /** + * Del user business list. + * + * @param svrId the svr id + * @return the list + */ + List> delUserBusiness(String[] svrId); +} diff --git a/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java new file mode 100644 index 00000000..9d69a69f --- /dev/null +++ b/src/main/java/com/dispose/service/impl/UserBusinessManagerServiceImpl.java @@ -0,0 +1,93 @@ +package com.dispose.service.impl; + +import com.dispose.common.ErrorCode; +import com.dispose.manager.UserBusinessManager; +import com.dispose.pojo.entity.ServiceInfo; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.UserBusinessManagerService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * The type User business manager service. + * + * @author + */ +@Service +@Slf4j +public class UserBusinessManagerServiceImpl implements UserBusinessManagerService { + /** + * The User business manager. + */ + @Resource + private UserBusinessManager userBusinessManager; + + /** + * Add user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + @Override + public List> addUserBusiness(List svrInfoList) { + List> rsp = new ArrayList<>(); + + for (ServiceInfo v : svrInfoList) { + rsp.add(new MulReturnType<>( + userBusinessManager.addUserBusiness(v), + v.getServiceId() + )); + } + + return rsp; + } + + /** + * Upgrade user business list. + * + * @param svrInfoList the svr info list + * @return the list + */ + @Override + public List> upgradeUserBusiness(List svrInfoList) { + + List> rsp = new ArrayList<>(); + + for (ServiceInfo v : svrInfoList) { + // 删除旧业务 + userBusinessManager.delUserBusiness(v.getServiceId()); + + // 添加新业务 + rsp.add(new MulReturnType<>( + userBusinessManager.addUserBusiness(v), + v.getServiceId() + )); + } + + return rsp; + } + + /** + * Del user business list. + * + * @param svrId the svr id + * @return the list + */ + @Override + public List> delUserBusiness(String[] svrId) { + List> rsp = new ArrayList<>(); + + for (String v : svrId) { + rsp.add(new MulReturnType<>( + userBusinessManager.delUserBusiness(v), + v + )); + } + + return rsp; + } +} diff --git a/src/main/java/com/dispose/validation/group/ValidGroups.java b/src/main/java/com/dispose/validation/group/ValidGroups.java index 353c8223..b0ab2fcc 100644 --- a/src/main/java/com/dispose/validation/group/ValidGroups.java +++ b/src/main/java/com/dispose/validation/group/ValidGroups.java @@ -101,4 +101,12 @@ public interface ValidGroups { */ interface GetDevVerReqValid extends ProtocolCommonValid { } + + /** + * The interface Add device valid. + * + * @author + */ + interface AddUserInfoValid extends ProtocolCommonValid { + } } diff --git a/src/main/resources/mappers/ServiceGroup.xml b/src/main/resources/mappers/ServiceGroup.xml index e2eb2675..930ef68c 100644 --- a/src/main/resources/mappers/ServiceGroup.xml +++ b/src/main/resources/mappers/ServiceGroup.xml @@ -14,6 +14,12 @@ FROM service_group + + INSERT IGNORE INTO service_group(serviceId, serviceType, serviceBandwidth, serviceIp) From dae44b609ee51ad362418fdc2c880e23641cc973 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 16:39:09 +0800 Subject: [PATCH 30/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/controller/UserBusinessController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dispose/controller/UserBusinessController.java b/src/main/java/com/dispose/controller/UserBusinessController.java index f9c34ad4..e24653a7 100644 --- a/src/main/java/com/dispose/controller/UserBusinessController.java +++ b/src/main/java/com/dispose/controller/UserBusinessController.java @@ -82,7 +82,7 @@ public class UserBusinessController { .items(new ArrayList<>()) .build(); - // 处理放回值 + // 处理反回值 ret.forEach(v -> { UserSvrRsp rsp = UserSvrRsp.builder() .businessId(v.getSecondParam()) @@ -112,7 +112,7 @@ public class UserBusinessController { List> ret = userBusinessManagerService.delUserBusiness(mr.getMsgContent() .getBusinessId()); - // 处理放回值 + // 处理反回值 AddUserSvrRsp rspInfo = AddUserSvrRsp.builder() .items(new ArrayList<>()) .build(); @@ -161,7 +161,7 @@ public class UserBusinessController { .items(new ArrayList<>()) .build(); - // 处理放回值 + // 处理反回值 ret.forEach(v -> { UserSvrRsp rsp = UserSvrRsp.builder() .businessId(v.getSecondParam()) From 26283fe135c653c988a04cce3c03af2b6b7fdf57 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 16:55:18 +0800 Subject: [PATCH 31/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E4=B8=A4?= =?UTF-8?q?=E7=A7=8D=E6=B8=85=E6=B4=97=E6=A8=A1=E5=BC=8F=202.=20=E8=BF=AA?= =?UTF-8?q?=E6=99=AE=E6=97=81=E8=B7=AF=E6=89=8B=E5=8A=A8=E7=89=B5=E5=BC=95?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=94=AF=E6=8C=81=E8=AE=BE=E5=A4=87=E5=B0=B1?= =?UTF-8?q?=E7=BB=AA=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/ability/DisposeAbility.java | 8 +++++ .../ability/impl/DpTechAbilityImpl.java | 12 +++++++ .../ability/impl/DpTechBypassAbilityImpl.java | 32 +++++++++++++++++-- .../ability/impl/HaoHanAbilityImpl.java | 10 ++++++ .../ability/impl/HuaWeiAbilityImpl.java | 10 ++++++ .../ability/impl/PengXinAbilityImpl.java | 10 ++++++ .../ability/impl/VirtualAbilityImpl.java | 10 ++++++ .../impl/DeviceTaskManagerServiceImpl.java | 4 +++ 8 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index 58b68cc9..122d562f 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -101,6 +101,14 @@ public interface DisposeAbility { */ boolean isCarryProtectIp(String ipAddr); + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + boolean isCarryAttackType(Long attackType); + /** * Period task runtime. */ diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index ad23a554..513b0afe 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -2,6 +2,7 @@ package com.dispose.ability.impl; import com.dispose.ability.DisposeAbility; import com.dispose.common.CommonEnumHandler; +import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; @@ -395,4 +396,15 @@ public class DpTechAbilityImpl implements DisposeAbility { public void upgradeServiceGroup(List svrList) { } + + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return !DDoSAttackType.maskToDdosAttackType(attackType).contains(DDoSAttackType.NONE_ATTACKS); + } } diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 2ae035af..a470ea2d 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -2,6 +2,7 @@ package com.dispose.ability.impl; import com.dispose.common.CommonEnumHandler; import com.dispose.common.ConstValue; +import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeConfigValue; import com.dispose.common.DisposeObjectType; @@ -165,8 +166,8 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } // 清理缓存中的对象 - for(String v : disposeObjectCache.keySet()) { - if(disposeObjectCache.get(v).equals(objName)) { + for (String v : disposeObjectCache.keySet()) { + if (disposeObjectCache.get(v).equals(objName)) { disposeObjectCache.remove(v); } } @@ -982,4 +983,31 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } return false; } + + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return DDoSAttackType.maskToDdosAttackType(attackType).contains(DDoSAttackType.NONE_ATTACKS); + } + + /** + * Device ready boolean. + * + * @return the boolean + */ + @Override + public boolean deviceReady() { + if (disposeServiceGroup.keySet().size() == 0 + || dpBypassManager.getProtectObject().keySet().size() == 0 + || dpBypassManager.getProtectStrategy().keySet().size() == 0) { + return false; + } + + return super.deviceReady(); + } } diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index f41d45fe..e4d14067 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -278,6 +278,16 @@ public class HaoHanAbilityImpl implements DisposeAbility { */ @Override public void upgradeServiceGroup(List svrList) { + } + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return true; } } diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java index 09400234..cd321169 100644 --- a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -389,7 +389,17 @@ public class HuaWeiAbilityImpl implements DisposeAbility { */ @Override public void upgradeServiceGroup(List svrList) { + } + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return true; } } diff --git a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java index bb2c6b0d..6e8e13d0 100644 --- a/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/PengXinAbilityImpl.java @@ -537,6 +537,16 @@ public class PengXinAbilityImpl implements DisposeAbility { */ @Override public void upgradeServiceGroup(List svrList) { + } + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return true; } } diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index 852244a8..34832aca 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -171,6 +171,16 @@ public class VirtualAbilityImpl implements DisposeAbility { */ @Override public void upgradeServiceGroup(List svrList) { + } + /** + * Is carry attack type boolean. + * + * @param attackType the attack type + * @return the boolean + */ + @Override + public boolean isCarryAttackType(Long attackType) { + return true; } } diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 8cedb229..eb225254 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -475,6 +475,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { .getDisposeCapacity())) // 当前设备是否支持处置该IP .filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject())) + // 判断当前攻击类型是否支持 + .filter(c -> c.getDb().isCarryAttackType(v.getAttackType())) + // 判断设备是否就绪 + .filter(c -> c.getDb().deviceReady()) .forEach(d -> { log.info("Add dispose task for device: {}", d.getDev()); From ad0929e168d13b3e51e67434b6e344b29668f5a9 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 17:14:59 +0800 Subject: [PATCH 32/67] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=AD=A3Manag?= =?UTF-8?q?er=E7=BB=84=E4=BB=B6=E4=B8=8D=E8=83=BD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98=202.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=83=A8=E5=88=86log=E6=97=A5=E5=BF=97=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 24 +++++++++---------- .../manager/impl/UserBusinessManagerImpl.java | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index a470ea2d..654d9c8a 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -272,7 +272,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { NtcRequestResultInfo ret; ErrorCode err = ErrorCode.ERR_OK; - log.info("++++Begging Start Traction Strategy: {}, {}", objName, disposeObject); + log.debug("++++Begging Start Traction Strategy: {}, {}", objName, disposeObject); // 获取旁路手动牵引策略名 String policyName = getTractionStrategyName(objName, disposeObject); @@ -287,7 +287,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { log.error("----Error Start Traction Strategy: {}, {}, {}", objName, disposeObject, ret.getResultInfo().getValue()); } else { - log.info("----Finish Start Traction Strategy: {}, {}", objName, disposeObject); + log.debug("----Finish Start Traction Strategy: {}, {}", objName, disposeObject); } return err; @@ -303,7 +303,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { private ErrorCode stopTractionStrategy(String objName, String disposeObject) { NtcRequestResultInfo ret; - log.info("++++Begging Stop Traction Strategy: {}, {}", objName, disposeObject); + log.debug("++++Begging Stop Traction Strategy: {}, {}", objName, disposeObject); // 获取旁路手动牵引策略名 String policyName = getTractionStrategyName(objName, disposeObject); @@ -560,9 +560,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private void initCleanupDevices() { try { - log.info("++++Begging DPTech Get All Protection Devices"); + log.debug("++++Begging DPTech Get All Protection Devices"); allCleanupDevices = getCleanTypePort().getAllProtectDevices(); - log.info("----Finish DPTech Get All Protection Devices: {}", allCleanupDevices); + log.debug("----Finish DPTech Get All Protection Devices: {}", allCleanupDevices); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Devices: {}", ex.getMessage()); } @@ -573,7 +573,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private void upgradeTractionStrategy() { try { - log.info("++++Begging DPTech Upgrade Traction Strategy"); + log.debug("++++Begging DPTech Upgrade Traction Strategy"); ArrayOfBypassManualTractionStrategyForService ret = getCleanTypePort().getAllBypassManualTractionStrategyFromUMC(); @@ -613,7 +613,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { }); } - log.info("----Finish DPTech Upgrade Traction Strategy"); + log.debug("----Finish DPTech Upgrade Traction Strategy"); } catch (Exception ex) { log.error("----Exception DPTech Upgrade Traction Strategy: {}", ex.getMessage()); } @@ -624,7 +624,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private void getProtectionStrategyTemplateAssociation() { try { - log.info("++++Begging DPTech Get All Protection Strategy Association Relation"); + log.debug("++++Begging DPTech Get All Protection Strategy Association Relation"); ArrayOfProtectionTargetWithStrategyForService ret = getCleanTypePort().getAllProtectionTargetWithStrategyAssociationRelationshipForUMC(); @@ -635,7 +635,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } if (ret.getProtectionTargetWithStrategyForService().size() == 0) { - log.info("----Finish DPTech Get All Protection Strategy Association Relation"); + log.debug("----Finish DPTech Get All Protection Strategy Association Relation"); return; } @@ -664,7 +664,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } }); - log.info("----Finish DPTech Get All Protection Strategy Association Relation"); + log.debug("----Finish DPTech Get All Protection Strategy Association Relation"); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Strategy Association Relation: {}", ex.getMessage()); @@ -697,7 +697,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { @Override public void getDisposeDeviceProtectObject() { try { - log.info("++++Begging DPTech Get All Protection Objects"); + log.debug("++++Begging DPTech Get All Protection Objects"); ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC(); if (ret == null) { @@ -777,7 +777,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { } }); - log.info("----Finish DPTech Get All Protection Objects Succeed"); + log.debug("----Finish DPTech Get All Protection Objects Succeed"); } catch (Exception ex) { log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage()); } diff --git a/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java index 903d8d52..c8ee5401 100644 --- a/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/UserBusinessManagerImpl.java @@ -4,6 +4,7 @@ import com.dispose.common.ErrorCode; import com.dispose.manager.UserBusinessManager; import com.dispose.mapper.ServiceGroupMapper; import com.dispose.pojo.entity.ServiceInfo; +import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; @@ -14,6 +15,7 @@ import java.util.List; * * @author */ +@Component public class UserBusinessManagerImpl implements UserBusinessManager { /** * The Service group mapper. From a670d67fc8fadcebe395b0313a4d66cd0e2e27be Mon Sep 17 00:00:00 2001 From: HuangXin Date: Mon, 18 Jan 2021 18:23:02 +0800 Subject: [PATCH 33/67] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E5=AF=B9=E6=AF=94IP?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=9A=E5=8A=A1=E7=AE=A1=E7=90=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=82=E6=95=B0=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 30 ++++++++++++++----- .../java/com/dispose/common/ConstValue.java | 10 +++++++ .../controller/UserBusinessController.java | 3 +- .../protocol/device/business/UserSvrInfo.java | 12 +++++++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 654d9c8a..a7081cf2 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * The type Dp tech bypass ability. @@ -141,6 +142,12 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { for (DpProtectionStrategyInfo v : dpBypassManager.getProtectStrategy().values()) { // 如果防护对象关联了防护策略模板,那么解除该防护策略模板 if (v.getProtectTargetName().equals(objName)) { + + // 没有关联模板的防护对象 + if (v.getProtectStrategyName().length() == 0) { + break; + } + ret = getCleanTypePort().disableProtectionStrategyTemplateForUMC(objName, v.getProtectStrategyName()); if (ret.getResultRetVal() == 0) { @@ -471,15 +478,21 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 判断防护IP段是否有变化 if (IpAddrType.IPV4.equals(t)) { - if (ipV4.size() != dp.getIpSegment().values().size() - || !ipV4.containsAll(dp.getIpSegment().values()) - || dp.getIpSegment().values().containsAll(ipV4)) { - upgradeIpSegment = true; + if (ipV4.size() != dp.getIpSegment().values().size()) { + List ipList = + ipV4.stream().map(k -> k.replaceAll("\\d+_", "")).collect(Collectors.toList()); + + if (!ipList.containsAll(dp.getIpSegment().values()) + || !dp.getIpSegment().values().containsAll(ipList)) { + upgradeIpSegment = true; + } } } else if (IpAddrType.IPV6.equals(t)) { - if (ipV6.size() != dp.getIpSegment().values().size() - || !ipV6.containsAll(dp.getIpSegment().values()) - || dp.getIpSegment().values().containsAll(ipV6)) { + List ipList = + ipV6.stream().map(k -> k.replaceAll("\\d+_", "")).collect(Collectors.toList()); + + if (!ipList.containsAll(dp.getIpSegment().values()) + || !dp.getIpSegment().values().containsAll(ipList)) { upgradeIpSegment = true; } } @@ -689,6 +702,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // 获取所有检测设备 initCleanupDevices(); + + // 更新设备信息 + upgradeDeviceBypassInfo(); } /** diff --git a/src/main/java/com/dispose/common/ConstValue.java b/src/main/java/com/dispose/common/ConstValue.java index 2ea8f1e9..38c3ae18 100644 --- a/src/main/java/com/dispose/common/ConstValue.java +++ b/src/main/java/com/dispose/common/ConstValue.java @@ -79,6 +79,16 @@ public class ConstValue { public static final String IP_PORT_REG = "^[1-9]$|(^[1-9][0-9]$)|(^[1-9][0-9][0-9]$)|(^[1-9][0-9][0-9][0-9]$)|" + "(^[1-6][0-5][0-5][0-3][0-5]$)"; + /** + * The constant BUSINESS_TYPE. + */ + public static final String BUSINESS_TYPE = "^(GENERAL)|(WEB)|(DNS)|(GAME)$"; + + /** + * The constant NUM_TYPE. + */ + public static final String NUMBER_TYPE = "^[0-9]+([.]{1}[0-9]+){0,1}$"; + /** * The type Protocol. * diff --git a/src/main/java/com/dispose/controller/UserBusinessController.java b/src/main/java/com/dispose/controller/UserBusinessController.java index e24653a7..becf552d 100644 --- a/src/main/java/com/dispose/controller/UserBusinessController.java +++ b/src/main/java/com/dispose/controller/UserBusinessController.java @@ -17,6 +17,7 @@ import com.dispose.validation.group.ValidGroups; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; @@ -71,7 +72,7 @@ public class UserBusinessController { .serviceId(v.getBusinessId()) .serviceType(v.getBusinessType()) .serviceBandwidth((long) Math.ceil(Double.parseDouble(v.getBusinessBandwidth()))) - .serviceIp(v.getBusinessIp()) + .serviceIp(StringUtils.deleteWhitespace(v.getBusinessIp())) .build()); } diff --git a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java index f05ab975..d74b8f62 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/device/business/UserSvrInfo.java @@ -1,6 +1,8 @@ package com.dispose.pojo.dto.protocol.device.business; +import com.dispose.common.ConstValue; import com.dispose.validation.group.ValidGroups; +import com.dispose.validation.valids.ValidIpSegment; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; @@ -8,6 +10,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; /** * The type User svr info. @@ -28,16 +31,23 @@ public class UserSvrInfo { * The Business type. */ @NotBlank(message = "businessType 客户业务类型不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Pattern(regexp = ConstValue.BUSINESS_TYPE, + message = "businessType 未知业务类型, [GENERAL, WEB, DNS, GAME]", + groups = ValidGroups.AddUserInfoValid.class) private String businessType; /** * The Business ip. */ @JsonProperty("businessIP") - @NotBlank(message = "businessIp 业务IP地址段不能为空", groups = ValidGroups.UpgradeDeviceValid.class) + @ValidIpSegment(message = "businessIp Ip地址格式错误", groups = ValidGroups.AddUserInfoValid.class) + @NotBlank(message = "businessIp 业务IP地址段不能为空", groups = ValidGroups.AddUserInfoValid.class) private String businessIp; /** * The Business bandwidth. */ @NotBlank(message = "businessBandwidth 客户业务带宽不能为空", groups = ValidGroups.AddUserInfoValid.class) + @Pattern(regexp = ConstValue.NUMBER_TYPE, + message = "businessBandwidth 只能为数字", + groups = ValidGroups.AddUserInfoValid.class) private String businessBandwidth; } From 4f8e64b7e0e634ebd937bc65f9f8d9043fc90df6 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 19 Jan 2021 09:03:32 +0800 Subject: [PATCH 34/67] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0Sprin?= =?UTF-8?q?gBoot=E6=A1=86=E6=9E=B6=E5=88=B0=E6=9C=80=E6=96=B0=E7=9A=842.3.?= =?UTF-8?q?8=E5=8F=91=E5=B8=83=E7=89=88=E6=9C=AC=202.=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E4=B8=BA2.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b04080de..51b18b10 100644 --- a/pom.xml +++ b/pom.xml @@ -8,17 +8,17 @@ Greenwich.SR3 2.1.3.Final UTF-8 - 2.3.4.RELEASE + 2.3.8.RELEASE org.springframework.boot spring-boot-starter-parent - 2.3.4.RELEASE + 2.3.8.RELEASE com.dispose phoenix_ddos_handle - 2.0.3 + 2.0.5 phoenix_ddos_handle Dispose Platform From 20c56c79ba72a2442af6e6f3c2faef87c4fc1a27 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 19 Jan 2021 09:44:58 +0800 Subject: [PATCH 35/67] =?UTF-8?q?OCT=20REM:=201.=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechBypassAbilityImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index a7081cf2..9fcd638b 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -55,7 +55,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { /** * The Obj prefix. */ - private final String OBJ_PREFIX = "CMHI"; + private final String objectPrefix = "CMHI"; /** * The All cleanup devices. */ @@ -526,7 +526,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { // UMC 同步到处置平台 dpBypassManager.getProtectObject().values().forEach(v -> { String serviceId = v.getProtectName() - .replace(OBJ_PREFIX + "_", "") + .replace(objectPrefix + "_", "") .replace("_" + IpAddrType.IPV4.getDescription(), "") .replace("_" + IpAddrType.IPV6.getDescription(), ""); @@ -551,9 +551,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { */ private String getProtectObjectName(String serviceId, IpAddrType ipAddrType) { if (IpAddrType.IPV4.equals(ipAddrType) || IpAddrType.IPV6.equals(ipAddrType)) { - return OBJ_PREFIX + "_" + serviceId + "_" + ipAddrType.getDescription(); + return objectPrefix + "_" + serviceId + "_" + ipAddrType.getDescription(); } else { - return OBJ_PREFIX + "_" + serviceId; + return objectPrefix + "_" + serviceId; } } @@ -565,7 +565,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { * @return the traction strategy name */ private String getTractionStrategyName(String objName, String disposeIp) { - return OBJ_PREFIX + "_" + disposeIp + "_" + objName; + return objectPrefix + "_" + disposeIp + "_" + objName; } /** @@ -595,7 +595,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { ret.getBypassManualTractionStrategyForService().forEach(k -> { String policyName = k.getPolicyName().getValue(); // 非法名称的旁路牵引策略 - if (!policyName.startsWith(OBJ_PREFIX)) { + if (!policyName.startsWith(objectPrefix)) { NtcRequestResultInfo rsp = getCleanTypePort().delBypassManualTractionStrategyForUMC(policyName); @@ -656,7 +656,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { String objName = k.getProtectionTargetName().getValue(); // 只处理CMHI相关对象和模板 - if (objName.startsWith(OBJ_PREFIX)) { + if (objName.startsWith(objectPrefix)) { DpProtectionStrategyInfo obj; // 缓存中不存在改关联关系 @@ -729,7 +729,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { ret.getProtectionObjectDataForService().forEach(k -> { String objName = k.getProtectionName().getValue(); // 删除非法的防护对象 - if (!objName.startsWith(OBJ_PREFIX)) { + if (!objName.startsWith(objectPrefix)) { log.error("!!!!Found Unexpect Protection Object [{}, {}], Deleted it.", objName, k.getIpSegment().getValue()); @@ -991,7 +991,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { for (String v : k.getIpSegment().values()) { if (Helper.ipInRange(v, ipAddr)) { // 将查找到的防护对象添加到缓存中 - disposeObjectCache.put(k.getProtectName(), k.getProtectName()); + disposeObjectCache.put(ipAddr, k.getProtectName()); return true; } } From 3159e791247bffc6f7ee42f0f5c83b95f4bfa556 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Tue, 19 Jan 2021 10:13:06 +0800 Subject: [PATCH 36/67] =?UTF-8?q?OCT=20REM:=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3=E5=85=A5?= =?UTF-8?q?=E5=8F=82=E6=94=BB=E5=87=BB=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E4=BC=A0=E6=94=BB=E5=87=BB=E7=B1=BB=E5=9E=8B=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=97=A0=E6=94=BB=E5=87=BB=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/controller/DisposeTaskController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index a21267f9..f0591291 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -104,7 +104,8 @@ public class DisposeTaskController { String endTime = String.valueOf(req.getDisposeTime() == -1 ? 5256000: req.getDisposeTime()); NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, Optional.ofNullable(req.getFlowDirection()).orElse(2)); - Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()}); + Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) + .orElse(new Integer[]{DDoSAttackType.NONE_ATTACKS.getValue()})); Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); @@ -184,7 +185,8 @@ public class DisposeTaskController { Optional.ofNullable(req.getFlowDirection()) .orElse(2))) .attackType(DDoSAttackType.getTypeMaskFromAttackType( - new Integer[]{DDoSAttackType.RST_FLOOD.getValue()})) + Optional.ofNullable(req.getAttackType()) + .orElse(new Integer[]{DDoSAttackType.NONE_ATTACKS.getValue()}))) .flowBandWidth(Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH)) .build(); @@ -234,7 +236,8 @@ public class DisposeTaskController { String endTime = String.valueOf(req.getDisposeTime()); NetflowDirection netDir = CommonEnumHandler.codeOf(NetflowDirection.class, Optional.ofNullable(req.getFlowDirection()).orElse(2)); - Long attackType = DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.RST_FLOOD.getValue()}); + Long attackType = DDoSAttackType.getTypeMaskFromAttackType(Optional.ofNullable(req.getAttackType()) + .orElse(new Integer[]{DDoSAttackType.NONE_ATTACKS.getValue()})); Integer flowBand = Optional.ofNullable(req.getFlowBandwidth()) .orElse(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH); From 0e91b3a064c529572f1d2462ba87eae46d4aa1d3 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 19 Jan 2021 10:20:05 +0800 Subject: [PATCH 37/67] =?UTF-8?q?OCT=20REM:=201.=20=E8=BF=AA=E6=99=AE?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=85=BC=E5=AE=B9=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E8=81=94=E5=8A=A8=E4=B8=8E=E6=97=81=E8=B7=AF=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E7=89=B5=E5=BC=95=E4=B8=A4=E7=A7=8D=E6=B8=85=E6=B4=97=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ability/impl/DpTechAbilityImpl.java | 2 +- .../ability/impl/DpTechBypassAbilityImpl.java | 13 +- .../impl/DeviceTaskManagerServiceImpl.java | 125 +++++++++--------- 3 files changed, 77 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 513b0afe..015b1283 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -275,7 +275,7 @@ public class DpTechAbilityImpl implements DisposeAbility { */ @Override public Long toDeviceAttackType(Long ddosAttackTypeMask) { - return DpTechAttackType.formDdosAttackTypeMaks(ddosAttackTypeMask); + return DpTechAttackType.getTypeMaskFromAttackType(new DpTechAttackType[] {DpTechAttackType.UDP_FLOOD}); } /** diff --git a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java index 9fcd638b..fbd1752a 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechBypassAbilityImpl.java @@ -53,7 +53,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { private final Hashtable disposeServiceGroup = new Hashtable<>(); /** - * The Obj prefix. + * The Object prefix. */ private final String objectPrefix = "CMHI"; /** @@ -1026,4 +1026,15 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl { return super.deviceReady(); } + + /** + * To device attack type long. + * + * @param ddosAttackTypeMask the ddos attack type mask + * @return the long + */ + @Override + public Long toDeviceAttackType(Long ddosAttackTypeMask) { + return DpTechAttackType.getTypeMaskFromAttackType(new DpTechAttackType[] {DpTechAttackType.AUTO_ATTACK_TYPE}); + } } diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index eb225254..f11e1814 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -135,73 +135,75 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 启动迪普设备,采用一种攻击类型 DpTechAttackType attackType = DpTechAttackType.maskToDdosAttackType(deviceTask.getTaskAttackType()).get(0); - // 出方向 - if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { - // 设置启动任务攻击类型状态 - deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - attackType.getValue()); - // 调用迪普设备启动处置任务 - ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), - disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_OUT, - attackType.getValue(), null); + // 出方向 + if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_IN) { + // 设置启动任务攻击类型状态 + deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, + attackType.getValue()); + // 调用迪普设备启动处置任务 + ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), + disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_OUT, + attackType.getValue(), null); - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - // 标志启动成功 - deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - attackType.getValue()); + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + // 标志启动成功 + deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, + attackType.getValue()); - log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_OUT, deviceTask); + log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_OUT, + deviceTask); - deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); - } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { - // 设置该任务为新任务,待下次重试启动 - // 记录任务出错重试次数 - deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); - deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); - //清除任务攻击类型启动标志 - deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, - attackType.getValue()); - log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, - NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask); - } else { - log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, - NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask); - } + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); + } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { + // 设置该任务为新任务,待下次重试启动 + // 记录任务出错重试次数 + deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); + //清除任务攻击类型启动标志 + deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT, + attackType.getValue()); + log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, + NetflowDirection.DIRECTION_OUT, deviceTask.getErrRetry(), deviceTask); + } else { + log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, + NetflowDirection.DIRECTION_OUT, ret.getFirstParam(), deviceTask); } + } - // 入方向 - if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { - // 设置启动任务攻击类型状态 - deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - attackType.getValue()); - // 调用迪普设备启动处置任务 - ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), - disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_IN, - attackType.getValue(), null); + // 入方向 + if (disposeTask.getFlowDirection() != NetflowDirection.DIRECTION_OUT) { + // 设置启动任务攻击类型状态 + deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, + attackType.getValue()); + // 调用迪普设备启动处置任务 + ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(), + disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_IN, + attackType.getValue(), null); - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - // 标志启动成功 - deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - attackType.getValue()); + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + // 标志启动成功 + deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, + attackType.getValue()); - log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_IN, deviceTask); + log.info("DPTECH_UMC setup task {}, {} succeed: {}", attackType, NetflowDirection.DIRECTION_IN, + deviceTask); - deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); - } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { - // 设置该任务为新任务,待下次重试启动 - // 记录任务出错重试次数 - deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); - deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); - //清除任务攻击类型启动标志 - deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, - attackType.getValue()); - log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, - NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask); - } else { - log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, - NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask); - } + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), 0); + } else if (deviceTask.getErrRetry() < DisposeConfigValue.CALL_ERROR_RETRY_TIMES * 10) { + // 设置该任务为新任务,待下次重试启动 + // 记录任务出错重试次数 + deviceTask.setErrRetry(deviceTask.getErrRetry() + 1); + deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), deviceTask.getErrRetry()); + //清除任务攻击类型启动标志 + deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN, + attackType.getValue()); + log.error("DPTECH_UMC setup task {}, {} times {} error: {}", attackType, + NetflowDirection.DIRECTION_IN, deviceTask.getErrRetry(), deviceTask); + } else { + log.error("DPTECH_UMC setup task {}, {} error {}: {}", attackType, + NetflowDirection.DIRECTION_IN, ret.getFirstParam(), deviceTask); } + } // 检查需要处置的各种攻击类型任务启动状态与处置任务执行状态,判断该处置任务是否调用成功 @@ -482,9 +484,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { .forEach(d -> { log.info("Add dispose task for device: {}", d.getDev()); - if (!deviceTaskManager.addDisposeDeviceTaskInfo(v.getId(), d.getDev().getId(), - d.getDb() - .toDeviceAttackType(v.getAttackType()))) { + if (!deviceTaskManager + .addDisposeDeviceTaskInfo(v.getId(), + d.getDev().getId(), + d.getDb().toDeviceAttackType(v.getAttackType()))) { log.error("Add task {} to device {} error", v, d); } }); From bf512cab01104da0c963a08fc9e12697f5dc55f7 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 19 Jan 2021 10:43:41 +0800 Subject: [PATCH 38/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=BD=AE=E8=AE=BE=E5=A4=87=E6=B7=BB=E5=8A=A0=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E4=BB=BB=E5=8A=A1=E5=A4=B1=E8=B4=A5=E5=90=8E=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispose/manager/DeviceTaskManager.java | 9 +++++++++ .../manager/impl/DeviceTaskManagerImpl.java | 20 +++++++++++++++---- .../impl/DeviceTaskManagerServiceImpl.java | 9 +++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/dispose/manager/DeviceTaskManager.java b/src/main/java/com/dispose/manager/DeviceTaskManager.java index 1e9f555b..c247935a 100644 --- a/src/main/java/com/dispose/manager/DeviceTaskManager.java +++ b/src/main/java/com/dispose/manager/DeviceTaskManager.java @@ -136,6 +136,15 @@ public interface DeviceTaskManager { */ DeviceTask getTaskById(Long id); + /** + * Device task created boolean. + * + * @param taskId the task id + * @param devId the dev id + * @return the boolean + */ + boolean deviceTaskCreated(Long taskId, Long devId); + /** * Gets peng xin task. * diff --git a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java index 608040c6..0247aae3 100644 --- a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java @@ -25,6 +25,18 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { @Resource private DeviceTaskMapper deviceTaskMapper; + /** + * Device task created boolean. + * + * @param taskId the task id + * @param devId the dev id + * @return the boolean + */ + @Override + public boolean deviceTaskCreated(Long taskId, Long devId) { + return deviceTaskMapper.getTaskByDetails(taskId, devId).size() != 0; + } + /** * Add dispose device task info boolean. * @@ -80,11 +92,11 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { } /** - * Change dispose device task info dev status long. + * Change dispose device task info dev status int. * * @param id the id * @param devStatus the dev status - * @return the long + * @return the int */ @Override public int changeDisposeDeviceTaskInfoDevStatus(Long id, Long devStatus) { @@ -297,9 +309,9 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { } /** - * Gets PengXin device task info. + * Get peng xin task list. * - * @return the minId task info. + * @return the list */ @Override public 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 f11e1814..0116645f 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -462,7 +462,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } // 对新建的任务,创建对应处置设备任务信息 - for (DisposeTask v : disposeTaskManager.getNewDisposeTasks()) { + for (DisposeTask v : disposeTaskManager.getExpiredTasks()) { // 设置任务状态, 开始创建任务 disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_STARTING); @@ -482,8 +482,13 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { // 判断设备是否就绪 .filter(c -> c.getDb().deviceReady()) .forEach(d -> { - log.info("Add dispose task for device: {}", d.getDev()); + // 检查当前设备是否已经创建了该任务 + if (deviceTaskManager.deviceTaskCreated(v.getId(), + d.getDev().getId())) { + return; + } + log.info("Add dispose task for device: {}", d.getDev()); if (!deviceTaskManager .addDisposeDeviceTaskInfo(v.getId(), d.getDev().getId(), From a738c4f13ebe2b53eb9309895317283f4b6fa528 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 19 Jan 2021 11:23:30 +0800 Subject: [PATCH 39/67] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=BA=E8=BF=87=E6=9C=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dispose/manager/DisposeTaskManager.java | 7 +++++++ .../dispose/manager/impl/DisposeTaskManagerImpl.java | 10 ++++++++++ .../java/com/dispose/mapper/DisposeTaskMapper.java | 7 +++++++ .../service/impl/DeviceTaskManagerServiceImpl.java | 2 +- src/main/resources/mappers/DisposeTask.xml | 9 +++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dispose/manager/DisposeTaskManager.java b/src/main/java/com/dispose/manager/DisposeTaskManager.java index 63dd59fe..ca42b368 100644 --- a/src/main/java/com/dispose/manager/DisposeTaskManager.java +++ b/src/main/java/com/dispose/manager/DisposeTaskManager.java @@ -41,6 +41,13 @@ public interface DisposeTaskManager { */ List getExpiredTasks(); + /** + * Gets un expired tasks. + * + * @return the un expired tasks + */ + List getUnExpiredTasks(); + /** * Gets new dispose tasks. * diff --git a/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java index c76b1598..b5703a08 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java @@ -88,6 +88,16 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { return disposeTaskMapper.getExpiredTasks(); } + /** + * Gets un expired tasks. + * + * @return the un expired tasks + */ + @Override + public List getUnExpiredTasks() { + return disposeTaskMapper.getUnExpiredTasks(); + } + /** * Gets new dispose tasks. * diff --git a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java index d6a07442..2beda504 100644 --- a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java +++ b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java @@ -104,4 +104,11 @@ public interface DisposeTaskMapper { * @return the expired tasks */ List getExpiredTasks(); + + /** + * Gets un expired tasks. + * + * @return the un expired tasks + */ + List getUnExpiredTasks(); } diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 0116645f..d62fc05e 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -462,7 +462,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } // 对新建的任务,创建对应处置设备任务信息 - for (DisposeTask v : disposeTaskManager.getExpiredTasks()) { + for (DisposeTask v : disposeTaskManager.getUnExpiredTasks()) { // 设置任务状态, 开始创建任务 disposeTaskManager.changeDisposeTaskStatus(v.getId(), DisposeTaskStatus.TASK_STARTING); diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml index 4990f035..31be363d 100644 --- a/src/main/resources/mappers/DisposeTask.xml +++ b/src/main/resources/mappers/DisposeTask.xml @@ -139,6 +139,15 @@ WHERE currentStatus = ${@com.dispose.common.DisposeTaskStatus@TASK_NEW.getValue()} + +