use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global in project netvirt by opendaylight.
the class HwvtepHAUtil method getChildNodeIdsFromManagerOtherConfig.
/**
* Returns ha child node path from ha node of config data tree.
*
* @param haGlobalConfigNodeOptional HA global node
* @return ha Child ids
*/
public static List<NodeId> getChildNodeIdsFromManagerOtherConfig(Optional<Node> haGlobalConfigNodeOptional) {
List<NodeId> childNodeIds = new ArrayList<>();
if (!haGlobalConfigNodeOptional.isPresent()) {
return childNodeIds;
}
HwvtepGlobalAugmentation augmentation = haGlobalConfigNodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null && augmentation.getManagers() != null && augmentation.getManagers().size() > 0) {
Managers managers = augmentation.getManagers().get(0);
if (null == managers.getManagerOtherConfigs()) {
return childNodeIds;
}
for (ManagerOtherConfigs otherConfigs : managers.getManagerOtherConfigs()) {
if (otherConfigs.getOtherConfigKey().equals(HA_CHILDREN)) {
String nodeIdsVal = otherConfigs.getOtherConfigValue();
if (nodeIdsVal != null) {
String[] parts = nodeIdsVal.split(",");
for (String part : parts) {
childNodeIds.add(new NodeId(part));
}
}
}
}
}
return childNodeIds;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global in project netvirt by opendaylight.
the class HwvtepHAUtil method buildManagersForHANode.
/**
* Transform child managers (Source) to HA managers using HA node path.
*
* @param childNode Child Node
* @param haGlobalCfg HA global config node
* @return Transformed managers
*/
public static List<Managers> buildManagersForHANode(Node childNode, Optional<Node> haGlobalCfg) {
Set<NodeId> nodeIds = new HashSet<>();
nodeIds.add(childNode.getNodeId());
List<NodeId> childNodeIds = getChildNodeIdsFromManagerOtherConfig(haGlobalCfg);
nodeIds.addAll(childNodeIds);
ManagersBuilder builder1 = new ManagersBuilder();
builder1.setKey(new ManagersKey(new Uri(MANAGER_KEY)));
List<ManagerOtherConfigs> otherConfigses = new ArrayList<>();
StringBuffer stringBuffer = new StringBuffer();
for (NodeId nodeId : nodeIds) {
stringBuffer.append(nodeId.getValue());
stringBuffer.append(",");
}
String children = stringBuffer.substring(0, stringBuffer.toString().length() - 1);
otherConfigses.add(getOtherConfigBuilder(HA_CHILDREN, children).build());
builder1.setManagerOtherConfigs(otherConfigses);
List<Managers> managers = new ArrayList<>();
managers.add(builder1.build());
return managers;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global in project netvirt by opendaylight.
the class HwvtepHAUtil method buildGlobalConfigForHANode.
/**
* Build HA Global node from child nodes in config data tress.
*
* @param tx Transaction
* @param childNode Child Node object
* @param haNodePath Ha node path
* @param haGlobalCfg HA global node object
*/
public static void buildGlobalConfigForHANode(ReadWriteTransaction tx, Node childNode, InstanceIdentifier<Node> haNodePath, Optional<Node> haGlobalCfg) {
NodeBuilder nodeBuilder = new NodeBuilder();
HwvtepGlobalAugmentationBuilder hwvtepGlobalBuilder = new HwvtepGlobalAugmentationBuilder();
hwvtepGlobalBuilder.setSwitches(buildSwitchesForHANode(childNode, haNodePath, haGlobalCfg));
hwvtepGlobalBuilder.setManagers(buildManagersForHANode(childNode, haGlobalCfg));
nodeBuilder.setNodeId(haNodePath.firstKeyOf(Node.class).getNodeId());
nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, hwvtepGlobalBuilder.build());
Node configHANode = nodeBuilder.build();
tx.merge(CONFIGURATION, haNodePath, configHANode, Boolean.TRUE);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global in project netvirt by opendaylight.
the class NodeConnectedHandler method copyHANodeConfigToChild.
/**
* Copy HA global node data to Child HA node of config data tree .
*
* @param srcNode Node which to be transformed
* @param childPath Path to which source node will be transformed
* @param tx Transaction
*/
private void copyHANodeConfigToChild(Node srcNode, InstanceIdentifier<Node> childPath, ReadWriteTransaction tx) {
if (srcNode == null) {
return;
}
HwvtepGlobalAugmentation src = srcNode.getAugmentation(HwvtepGlobalAugmentation.class);
if (src == null) {
return;
}
NodeBuilder nodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(childPath);
HwvtepGlobalAugmentationBuilder dstBuilder = new HwvtepGlobalAugmentationBuilder();
globalAugmentationMerger.mergeConfigData(dstBuilder, src, childPath);
globalNodeMerger.mergeConfigData(nodeBuilder, srcNode, childPath);
nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, dstBuilder.build());
Node dstNode = nodeBuilder.build();
tx.put(CONFIGURATION, childPath, dstNode, WriteTransaction.CREATE_MISSING_PARENTS);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global in project netvirt by opendaylight.
the class NodeCopier method copyGlobalNode.
@Override
public void copyGlobalNode(Optional<Node> srcGlobalNodeOptional, InstanceIdentifier<Node> srcPath, InstanceIdentifier<Node> dstPath, LogicalDatastoreType logicalDatastoreType, ReadWriteTransaction tx) throws ReadFailedException {
if (!srcGlobalNodeOptional.isPresent() && logicalDatastoreType == CONFIGURATION) {
Futures.addCallback(tx.read(logicalDatastoreType, srcPath), new FutureCallback<Optional<Node>>() {
@Override
public void onSuccess(Optional<Node> nodeOptional) {
HAJobScheduler.getInstance().submitJob(() -> {
try {
ReadWriteTransaction tx1 = new BatchedTransaction();
if (nodeOptional.isPresent()) {
copyGlobalNode(nodeOptional, srcPath, dstPath, logicalDatastoreType, tx1);
} else {
/**
* In case the Parent HA Global Node is not present and Child HA node is present
* It means that both the child are disconnected/removed hence the parent is deleted.
* @see org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener
* OnGLobalNode() delete function
* So we should delete the existing config child node as cleanup
*/
HwvtepHAUtil.deleteNodeIfPresent(tx1, logicalDatastoreType, dstPath);
}
} catch (ReadFailedException e) {
LOG.error("Failed to read source node {}", srcPath);
}
});
}
@Override
public void onFailure(Throwable throwable) {
}
});
return;
}
HwvtepGlobalAugmentation srcGlobalAugmentation = srcGlobalNodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class);
if (srcGlobalAugmentation == null) {
/**
* If Source HA Global Node is not present
* It means that both the child are disconnected/removed hence the parent is deleted.
* @see org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpNodeListener OnGLobalNode() delete function
* So we should delete the existing config child node as cleanup
*/
HwvtepHAUtil.deleteNodeIfPresent(tx, logicalDatastoreType, dstPath);
return;
}
NodeBuilder haNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(dstPath);
HwvtepGlobalAugmentationBuilder haBuilder = new HwvtepGlobalAugmentationBuilder();
Optional<Node> existingDstGlobalNodeOptional = tx.read(logicalDatastoreType, dstPath).checkedGet();
Node existingDstGlobalNode = existingDstGlobalNodeOptional.isPresent() ? existingDstGlobalNodeOptional.get() : null;
HwvtepGlobalAugmentation existingHAGlobalData = HwvtepHAUtil.getGlobalAugmentationOfNode(existingDstGlobalNode);
globalAugmentationMerger.mergeOperationalData(haBuilder, existingHAGlobalData, srcGlobalAugmentation, dstPath);
globalNodeMerger.mergeOperationalData(haNodeBuilder, existingDstGlobalNode, srcGlobalNodeOptional.get(), dstPath);
if (OPERATIONAL == logicalDatastoreType) {
haBuilder.setManagers(HwvtepHAUtil.buildManagersForHANode(srcGlobalNodeOptional.get(), existingDstGlobalNodeOptional));
// Also update the manager section in config which helps in cluster reboot scenarios
haBuilder.getManagers().stream().forEach((manager) -> {
InstanceIdentifier<Managers> managerIid = dstPath.augmentation(HwvtepGlobalAugmentation.class).child(Managers.class, manager.getKey());
tx.put(CONFIGURATION, managerIid, manager, true);
});
}
haBuilder.setDbVersion(srcGlobalAugmentation.getDbVersion());
haNodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, haBuilder.build());
Node haNode = haNodeBuilder.build();
if (OPERATIONAL == logicalDatastoreType) {
tx.merge(logicalDatastoreType, dstPath, haNode, true);
} else {
tx.put(logicalDatastoreType, dstPath, haNode, true);
}
}
Aggregations