REM:
1. 增加业务对象和UMC防护对象同步逻辑
This commit is contained in:
HuangXin 2021-01-15 17:09:05 +08:00
parent 22c0670e84
commit 39513c00a3
2 changed files with 146 additions and 47 deletions

View File

@ -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<String> ipV4 = new ArrayList<>();
List<String> 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;
}
});
}

View File

@ -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<String> demoList = new ArrayList<>();
List<String> demoList2 = new ArrayList<>();
Hashtable<String, String> tmpTable = new Hashtable<>();
Hashtable<String, String> 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));
}
}