parent
771c82e282
commit
249451b208
|
@ -3,6 +3,7 @@ package com.dispose.ability.impl;
|
||||||
import com.dispose.common.CommonEnumHandler;
|
import com.dispose.common.CommonEnumHandler;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.common.DisposeCapacityType;
|
import com.dispose.common.DisposeCapacityType;
|
||||||
|
import com.dispose.common.DisposeConfigValue;
|
||||||
import com.dispose.common.DisposeObjectType;
|
import com.dispose.common.DisposeObjectType;
|
||||||
import com.dispose.common.DpTechAttackType;
|
import com.dispose.common.DpTechAttackType;
|
||||||
import com.dispose.common.DpTechConfigValue;
|
import com.dispose.common.DpTechConfigValue;
|
||||||
|
@ -23,7 +24,9 @@ import com.dptech.dispose.NtcRequestResultInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
@ -65,17 +68,116 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
*/
|
*/
|
||||||
private long timerCnt = 0;
|
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.
|
* Sync dp tech device info.
|
||||||
*/
|
*/
|
||||||
private void syncDpTechDeviceInfo() {
|
private void syncDpTechDeviceInfo() {
|
||||||
disposeServiceGroup.values().forEach(v -> {
|
disposeServiceGroup.values().forEach(v -> {
|
||||||
|
boolean changed = false;
|
||||||
|
NtcRequestResultInfo ret;
|
||||||
|
List<String> ipV4 = new ArrayList<>();
|
||||||
|
List<String> 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<IpAddrType, String> 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() {
|
private void getProtectionStrategyTemplate() {
|
||||||
try {
|
try {
|
||||||
log.debug("++++Begging DPTech Get All Protection Strategy Association Relation");
|
log.info("++++Begging DPTech Get All Protection Strategy Association Relation");
|
||||||
|
|
||||||
ArrayOfProtectionTargetWithStrategyForService ret =
|
ArrayOfProtectionTargetWithStrategyForService ret =
|
||||||
getCleanTypePort().getAllProtectionTargetWithStrategyAssociationRelationshipForUMC();
|
getCleanTypePort().getAllProtectionTargetWithStrategyAssociationRelationshipForUMC();
|
||||||
|
@ -158,7 +260,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret.getProtectionTargetWithStrategyForService().size() == 0) {
|
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;
|
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) {
|
} 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());
|
ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +322,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
@Override
|
@Override
|
||||||
public void getDisposeDeviceProtectObject() {
|
public void getDisposeDeviceProtectObject() {
|
||||||
try {
|
try {
|
||||||
log.debug("++++Begging DPTech Get All Protection Objects");
|
log.info("++++Begging DPTech Get All Protection Objects");
|
||||||
ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC();
|
ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC();
|
||||||
|
|
||||||
if (ret == null) {
|
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) {
|
} catch (Exception ex) {
|
||||||
log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage());
|
log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -328,14 +430,14 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AtomicReference<String> protectionObject = new AtomicReference<>("");
|
AtomicReference<String> protectionObject = new AtomicReference<>("");
|
||||||
log.debug("++++Begging DPTech Start Cleanup Task: {}", disposeObject);
|
log.info("++++Begging DPTech Start Cleanup Task: {}", disposeObject);
|
||||||
|
|
||||||
if (capType != DisposeCapacityType.CLEANUP) {
|
if (capType != DisposeCapacityType.CLEANUP) {
|
||||||
log.error("----Error DPTech don't support dispose capacity type: {}", capType);
|
log.error("----Error DPTech don't support dispose capacity type: {}", capType);
|
||||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
String policyName = OBJ_PREFIX + "_" + disposeObject;
|
String policyName = getTractionStrategyName(disposeObject);
|
||||||
|
|
||||||
// 判断缓存中当前处置IP的旁路牵引策略是否存在, 如果存在直接删除
|
// 判断缓存中当前处置IP的旁路牵引策略是否存在, 如果存在直接删除
|
||||||
if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) {
|
if (dpBypassManager.getTractionStrategyName().containsKey(policyName)) {
|
||||||
|
@ -399,9 +501,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
|
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
|
||||||
ret.getResultInfo().getValue());
|
ret.getResultInfo().getValue());
|
||||||
} else {
|
} else {
|
||||||
log.debug("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
|
log.info("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
|
||||||
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
|
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
|
||||||
ret.getResultInfo().getValue());
|
ret.getResultInfo().getValue());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
err = ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||||
|
@ -438,7 +540,7 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
String policyName = OBJ_PREFIX + "_" + disposeObject;
|
String policyName = getTractionStrategyName(disposeObject);
|
||||||
|
|
||||||
if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) {
|
if (!dpBypassManager.getTractionStrategyName().containsKey(policyName)) {
|
||||||
log.error("----Error DPTech Stop Cleanup Task, No Such Task: {}, {}", disposeObject, policyName);
|
log.error("----Error DPTech Stop Cleanup Task, No Such Task: {}, {}", disposeObject, policyName);
|
||||||
|
@ -489,6 +591,9 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
|
|
||||||
// 清理旁路手动牵引策略
|
// 清理旁路手动牵引策略
|
||||||
upgradeTractionStrategy();
|
upgradeTractionStrategy();
|
||||||
|
|
||||||
|
// 与迪普设备同步数据
|
||||||
|
syncDpTechDeviceInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package com.dispose.common;
|
package com.dispose.common;
|
||||||
|
|
||||||
|
import com.dispose.config.TemplateConfigure;
|
||||||
|
import com.dispose.pojo.vo.TemplateInfo;
|
||||||
import inet.ipaddr.AddressStringException;
|
import inet.ipaddr.AddressStringException;
|
||||||
import inet.ipaddr.IPAddress;
|
import inet.ipaddr.IPAddress;
|
||||||
import inet.ipaddr.IPAddressSeqRange;
|
import inet.ipaddr.IPAddressSeqRange;
|
||||||
import inet.ipaddr.IPAddressString;
|
import inet.ipaddr.IPAddressString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -14,6 +17,7 @@ import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +25,7 @@ import java.util.stream.Collectors;
|
||||||
*
|
*
|
||||||
* @author <huangxin@cmhi.chinamoblie.com>
|
* @author <huangxin@cmhi.chinamoblie.com>
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class Helper {
|
public class Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,4 +207,27 @@ public class Helper {
|
||||||
|
|
||||||
return sb.toString();
|
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<String, List<TemplateInfo>> result = TemplateConfigure.UMC_TEMPLATE.stream()
|
||||||
|
// .collect(Collectors.groupingBy(TemplateInfo::getType));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Optional<String> 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 "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,4 +40,13 @@ public class ThreadPoolConfig {
|
||||||
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
||||||
return executor;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.dispose.test.dev.config;
|
package com.dispose.test.dev.config;
|
||||||
|
|
||||||
|
import com.dispose.common.Helper;
|
||||||
import com.dispose.config.TemplateConfigure;
|
import com.dispose.config.TemplateConfigure;
|
||||||
|
import com.dispose.service.impl.TemplateServiceImpl;
|
||||||
import com.dispose.test.dev.Global.InitTestEnvironment;
|
import com.dispose.test.dev.Global.InitTestEnvironment;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -26,6 +28,12 @@ public class TemplateConfigureTest extends InitTestEnvironment {
|
||||||
@Resource
|
@Resource
|
||||||
TemplateConfigure templateConfigure;
|
TemplateConfigure templateConfigure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Template service.
|
||||||
|
*/
|
||||||
|
@Resource
|
||||||
|
TemplateServiceImpl templateService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template loads test.
|
* Template loads test.
|
||||||
*/
|
*/
|
||||||
|
@ -34,4 +42,18 @@ public class TemplateConfigureTest extends InitTestEnvironment {
|
||||||
log.info("Load template: {}", templateConfigure.getUmcTemplate());
|
log.info("Load template: {}", templateConfigure.getUmcTemplate());
|
||||||
Assert.assertEquals(9, templateConfigure.getUmcTemplate().size());
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.lang.reflect.Modifier;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -608,6 +609,9 @@ public class demo {
|
||||||
public void codeDebug() {
|
public void codeDebug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dp ip segment test.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void dpIpSegmentTest() {
|
public void dpIpSegmentTest() {
|
||||||
String ipSegmentString = "1_192.168.10.1-192.168.10.12,2_192.168.1.2-192.168.1.20,3_-";
|
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<String> demoList = new ArrayList<>();
|
||||||
|
List<String> 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue