use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers 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.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers 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.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers in project netvirt by opendaylight.
the class TestBuilders method buildManagers.
public static List<Managers> buildManagers() {
ManagersBuilder builder1 = new ManagersBuilder();
builder1.setKey(new ManagersKey(new Uri("test")));
List<ManagerOtherConfigs> otherConfigses = new ArrayList<>();
otherConfigses.add(buildOtherConfig("ha_enabled", "true"));
otherConfigses.add(buildOtherConfig("ha_id", "switchxyz"));
builder1.setManagerOtherConfigs(otherConfigses);
List<Managers> managers = new ArrayList<>();
managers.add(builder1.build());
return managers;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers in project netvirt by opendaylight.
the class HAOpClusteredListener method addToHACacheIfBecameHAChild.
/**
* If Normal non-ha node changes to HA node , its added to HA cache.
*
* @param childPath HA child path which got converted to HA node
* @param updatedChildNode updated Child node
* @param beforeChildNode non-ha node before updated to HA node
*/
public static void addToHACacheIfBecameHAChild(InstanceIdentifier<Node> childPath, Node updatedChildNode, Node beforeChildNode) {
HwvtepGlobalAugmentation updatedAugmentaion = updatedChildNode.getAugmentation(HwvtepGlobalAugmentation.class);
HwvtepGlobalAugmentation beforeAugmentaion = null;
if (beforeChildNode != null) {
beforeAugmentaion = beforeChildNode.getAugmentation(HwvtepGlobalAugmentation.class);
}
List<Managers> up = null;
List<Managers> be = null;
if (updatedAugmentaion != null) {
up = updatedAugmentaion.getManagers();
}
if (beforeAugmentaion != null) {
be = beforeAugmentaion.getManagers();
}
if (up != null) {
if (be != null) {
if (up.size() > 0) {
if (be.size() > 0) {
Managers m1 = up.get(0);
Managers m2 = be.get(0);
if (!m1.equals(m2)) {
LOG.trace("Manager entry updated for node {} ", updatedChildNode.getNodeId().getValue());
addToCacheIfHAChildNode(childPath, updatedChildNode);
}
}
}
}
// TODO handle unhaed case
}
}
Aggregations