parent
22c0670e84
commit
39513c00a3
|
@ -69,6 +69,18 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
*/
|
*/
|
||||||
private long timerCnt = 0;
|
private long timerCnt = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade device bypass info.
|
||||||
|
*/
|
||||||
|
private void upgradeDeviceBypassInfo() {
|
||||||
|
// 更新防护策略模板和防护对象关联关系
|
||||||
|
getProtectionStrategyTemplateAssociation();
|
||||||
|
// 更新防护对象
|
||||||
|
getDisposeDeviceProtectObject();
|
||||||
|
// 更新手动旁路牵引策略
|
||||||
|
upgradeTractionStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove umc protect object error code.
|
* Remove umc protect object error code.
|
||||||
*
|
*
|
||||||
|
@ -78,12 +90,8 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
private ErrorCode removeUMCProtectObject(String objName) {
|
private ErrorCode removeUMCProtectObject(String objName) {
|
||||||
NtcRequestResultInfo ret;
|
NtcRequestResultInfo ret;
|
||||||
|
|
||||||
// 更新防护策略模板和防护对象关联关系
|
// 修改前同步更新设备信息
|
||||||
getProtectionStrategyTemplateAssociation();
|
upgradeDeviceBypassInfo();
|
||||||
// 更新防护对象
|
|
||||||
getDisposeDeviceProtectObject();
|
|
||||||
// 更新手动旁路牵引策略
|
|
||||||
upgradeTractionStrategy();
|
|
||||||
|
|
||||||
// 清理关联的旁路手动牵引策略
|
// 清理关联的旁路手动牵引策略
|
||||||
for (DpTractionStrategy v : dpBypassManager.getTractionStrategyName().values()) {
|
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 objName the obj name
|
||||||
* @param ipSegment the ip segment
|
* @param ipSegment the ip segment
|
||||||
* @param ipType the ip type
|
* @param ipType the ip type
|
||||||
* @param type the type
|
* @param template the template
|
||||||
* @param bandWidth the band width
|
|
||||||
* @return the error code
|
* @return the error code
|
||||||
*/
|
*/
|
||||||
private ErrorCode createUMCPortectObject(String objName, String ipSegment, int ipType, String type,
|
private ErrorCode createProtectObject(String objName, String ipSegment, int ipType, String template) {
|
||||||
Long bandWidth) {
|
|
||||||
// 创建对象
|
// 创建对象
|
||||||
NtcRequestResultInfo ret = getCleanTypePort()
|
NtcRequestResultInfo ret = getCleanTypePort()
|
||||||
.addProtectionObjectForUMC("",
|
.addProtectionObjectForUMC("",
|
||||||
|
@ -167,20 +173,10 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
return ErrorCode.ERR_CALLDEVICE;
|
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关联模板
|
// 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);
|
log.debug("{} Link Protection Strategy Template {} Succeed", objName, template);
|
||||||
} else {
|
} else {
|
||||||
log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, template,
|
log.error("!!!!{} Link Protection Strategy Template {} Error: {}", objName, template,
|
||||||
|
@ -188,6 +184,51 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
return ErrorCode.ERR_CALLDEVICE;
|
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;
|
return ErrorCode.ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,12 +237,21 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
*/
|
*/
|
||||||
private void syncDpTechDeviceInfo() {
|
private void syncDpTechDeviceInfo() {
|
||||||
disposeServiceGroup.values().forEach(v -> {
|
disposeServiceGroup.values().forEach(v -> {
|
||||||
boolean changed = false;
|
ErrorCode err;
|
||||||
NtcRequestResultInfo ret;
|
|
||||||
List<String> ipV4 = new ArrayList<>();
|
List<String> ipV4 = new ArrayList<>();
|
||||||
List<String> ipV6 = new ArrayList<>();
|
List<String> ipV6 = new ArrayList<>();
|
||||||
int ipV4Idx = 1;
|
int ipV4Idx = 1;
|
||||||
int ipV6Idx = 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地址类型进行拆分
|
// 将业务Ip根据IP地址类型进行拆分
|
||||||
for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) {
|
for (String k : StringUtils.deleteWhitespace(v.getServiceIp()).split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||||
if (!k.contains(":")) {
|
if (!k.contains(":")) {
|
||||||
|
@ -229,33 +279,61 @@ public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||||
if (dpBypassManager.getProtectObject().containsKey(protectName)) {
|
if (dpBypassManager.getProtectObject().containsKey(protectName)) {
|
||||||
DpProtectObject dp = dpBypassManager.getProtectObject().get(protectName);
|
DpProtectObject dp = dpBypassManager.getProtectObject().get(protectName);
|
||||||
|
|
||||||
|
// 判断关联模板是否正确
|
||||||
|
if (dpBypassManager.getProtectStrategy().containsKey(protectName)) {
|
||||||
|
// 已经关联防护模板
|
||||||
|
String temp = dpBypassManager.getProtectStrategy().get(protectName).getProtectStrategyName();
|
||||||
|
// 如果关联模板有变更
|
||||||
|
if (!temp.equals(template)) {
|
||||||
|
// 重新关联防护模板
|
||||||
|
associationProtectionTemplate(protectName, template, temp);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 创建一个防护对象
|
// 关联一个新的防护模板
|
||||||
ret = getCleanTypePort().addProtectionObjectForUMC("",
|
associationProtectionTemplate(protectName, template, null);
|
||||||
allCleanupDevices,
|
}
|
||||||
protectName,
|
|
||||||
|
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),
|
ipSegment.get(t),
|
||||||
IpAddrType.IPV4.equals(t) ? 0 : 1,
|
IpAddrType.IPV4.equals(t) ? 0 : 1,
|
||||||
0);
|
template);
|
||||||
|
if (err == ErrorCode.ERR_OK) {
|
||||||
if (ret.getResultRetVal() == 0) {
|
log.debug("Add Protection Object {} Succeed", protectName);
|
||||||
log.info("Add Protection Object {} Succeed", protectName);
|
|
||||||
} else {
|
} else {
|
||||||
log.error("!!!!Add Protection Object {} Error: {}", protectName, ret.getResultInfo()
|
log.error("!!!!Add Protection Object {} Error: {}", protectName, err.getMsg());
|
||||||
.getValue());
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
changed = true;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -637,12 +638,32 @@ public class demo {
|
||||||
public void listToStringWithCharTest() {
|
public void listToStringWithCharTest() {
|
||||||
List<String> demoList = new ArrayList<>();
|
List<String> demoList = new ArrayList<>();
|
||||||
List<String> demoList2 = 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.1");
|
||||||
demoList.add("192.168.0.2");
|
demoList.add("192.168.0.2");
|
||||||
demoList.add("192.168.0.24/24");
|
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(",", demoList));
|
||||||
log.info("Result demoList: {}", String.join(",", demoList2));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue