*/
package org.opendaylight.netvirt.elan.l2gw.ha.handlers;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
-import com.google.common.base.Optional;
import java.util.List;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.Datastore.Operational;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
import org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAJobScheduler;
import org.opendaylight.netvirt.elan.l2gw.ha.merge.GlobalAugmentationMerger;
private static final Logger LOG = LoggerFactory.getLogger(NodeConnectedHandler.class);
- GlobalAugmentationMerger globalAugmentationMerger = GlobalAugmentationMerger.getInstance();
- PSAugmentationMerger psAugmentationMerger = PSAugmentationMerger.getInstance();
- GlobalNodeMerger globalNodeMerger = GlobalNodeMerger.getInstance();
- PSNodeMerger psNodeMerger = PSNodeMerger.getInstance();
- DataBroker db;
- HwvtepHACache hwvtepHACache = HwvtepHACache.getInstance();
+ private final GlobalAugmentationMerger globalAugmentationMerger = GlobalAugmentationMerger.getInstance();
+ private final PSAugmentationMerger psAugmentationMerger = PSAugmentationMerger.getInstance();
+ private final GlobalNodeMerger globalNodeMerger = GlobalNodeMerger.getInstance();
+ private final PSNodeMerger psNodeMerger = PSNodeMerger.getInstance();
+ private final ManagedNewTransactionRunner txRunner;
+ private final HwvtepNodeHACache hwvtepNodeHACache;
- public NodeConnectedHandler(DataBroker db) {
- this.db = db;
+ public NodeConnectedHandler(final DataBroker db, final HwvtepNodeHACache hwvtepNodeHACache) {
+ this.txRunner = new ManagedNewTransactionRunnerImpl(db);
+ this.hwvtepNodeHACache = hwvtepNodeHACache;
}
/**
* @param haNodePath Ha Iid
* @param haGlobalCfg Ha Global Config Node
* @param haPSCfg Ha Physical Config Node
- * @param tx Transaction
- * @throws ReadFailedException Exception thrown if read fails
+ * @param operTx Transaction
*/
public void handleNodeConnected(Node childNode,
InstanceIdentifier<Node> childNodePath,
InstanceIdentifier<Node> haNodePath,
Optional<Node> haGlobalCfg,
Optional<Node> haPSCfg,
- ReadWriteTransaction tx)
- throws ReadFailedException {
- HwvtepHAUtil.buildGlobalConfigForHANode(tx, childNode, haNodePath, haGlobalCfg);
- copyChildOpToHA(childNode, haNodePath, tx);
- readAndCopyChildPSOpToHAPS(childNode, haNodePath, tx);
+ TypedReadWriteTransaction<Configuration> confTx,
+ TypedReadWriteTransaction<Operational> operTx)
+ throws ExecutionException, InterruptedException {
+ HwvtepHAUtil.buildGlobalConfigForHANode(confTx, childNode, haNodePath, haGlobalCfg);
+ copyChildOpToHA(childNode, haNodePath, operTx);
+ readAndCopyChildPSOpToHAPS(childNode, haNodePath, operTx);
if (haGlobalCfg.isPresent()) {
//copy ha config to newly connected child case of reconnected child
if (haPSCfg.isPresent()) {
(created in the device)
*/
HAJobScheduler.getInstance().submitJob(() -> {
- try {
- hwvtepHACache.updateConnectedNodeStatus(childNodePath);
- LOG.info("HA child reconnected handleNodeReConnected {}",
+ LoggingFutures.addErrorLogging(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, jobTx -> {
+ hwvtepNodeHACache.updateConnectedNodeStatus(childNodePath);
+ LOG.info("HA child reconnected handleNodeReConnected {}",
childNode.getNodeId().getValue());
- ReadWriteTransaction tx1 = db.newReadWriteTransaction();
- copyHAPSConfigToChildPS(haPSCfg.get(), childNodePath, tx1);
- tx1.submit().checkedGet();
- } catch (TransactionCommitFailedException e) {
- LOG.error("Failed to process ", e);
- }
+ copyHAPSConfigToChildPS(haPSCfg.get(), childNodePath, jobTx);
+ }), LOG, "Failed to process");
});
}
- copyHANodeConfigToChild(haGlobalCfg.get(), childNodePath, tx);
+ copyHANodeConfigToChild(haGlobalCfg.get(), childNodePath, confTx);
}
- deleteChildPSConfigIfHAPSConfigIsMissing(haGlobalCfg, childNode, tx);
+ deleteChildPSConfigIfHAPSConfigIsMissing(haGlobalCfg, childNode, confTx);
}
- private void deleteChildPSConfigIfHAPSConfigIsMissing(Optional<Node> haPSCfg,
- Node childNode,
- ReadWriteTransaction tx) throws ReadFailedException {
+ private static void deleteChildPSConfigIfHAPSConfigIsMissing(Optional<Node> haPSCfg,
+ Node childNode,
+ TypedReadWriteTransaction<Configuration> tx)
+ throws ExecutionException, InterruptedException {
if (haPSCfg.isPresent()) {
return;
}
LOG.info("HA ps node not present cleanup child {}" , childNode);
- HwvtepGlobalAugmentation augmentation = childNode.getAugmentation(HwvtepGlobalAugmentation.class);
+ HwvtepGlobalAugmentation augmentation = childNode.augmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null) {
List<Switches> switches = augmentation.getSwitches();
if (switches != null) {
for (Switches ps : switches) {
- HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, ps.getSwitchRef().getValue());
+ HwvtepHAUtil.deleteNodeIfPresent(tx, ps.getSwitchRef().getValue());
}
}
} else {
* @param childGlobalNode Ha Global Child node
* @param haNodePath Ha node path
* @param tx Transaction
- * @throws ReadFailedException Exception thrown if read fails
*/
void readAndCopyChildPSOpToHAPS(Node childGlobalNode,
InstanceIdentifier<Node> haNodePath,
- ReadWriteTransaction tx)
- throws ReadFailedException {
+ TypedReadWriteTransaction<Operational> tx)
+ throws ExecutionException, InterruptedException {
- if (childGlobalNode == null || childGlobalNode.getAugmentation(HwvtepGlobalAugmentation.class) == null) {
+ if (childGlobalNode == null || childGlobalNode.augmentation(HwvtepGlobalAugmentation.class) == null) {
return;
}
- List<Switches> switches = childGlobalNode.getAugmentation(HwvtepGlobalAugmentation.class).getSwitches();
+ List<Switches> switches = childGlobalNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches();
if (switches == null) {
return;
}
for (Switches ps : switches) {
- Node childPsNode = HwvtepHAUtil.readNode(tx, OPERATIONAL,
- (InstanceIdentifier<Node>) ps.getSwitchRef().getValue());
+ Node childPsNode = tx.read((InstanceIdentifier<Node>) ps.getSwitchRef().getValue()).get().orElse(null);
if (childPsNode != null) {
InstanceIdentifier<Node> haPsPath = HwvtepHAUtil.convertPsPath(childPsNode, haNodePath);
copyChildPSOpToHAPS(childPsNode, haNodePath, haPsPath, tx);
*/
private void copyHANodeConfigToChild(Node srcNode,
InstanceIdentifier<Node> childPath,
- ReadWriteTransaction tx) {
+ TypedReadWriteTransaction<Configuration> tx) {
if (srcNode == null) {
return;
}
- HwvtepGlobalAugmentation src = srcNode.getAugmentation(HwvtepGlobalAugmentation.class);
+ HwvtepGlobalAugmentation src = srcNode.augmentation(HwvtepGlobalAugmentation.class);
if (src == null) {
return;
}
globalNodeMerger.mergeConfigData(nodeBuilder, srcNode, childPath);
nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, dstBuilder.build());
Node dstNode = nodeBuilder.build();
- tx.put(CONFIGURATION, childPath, dstNode, WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(childPath, dstNode, CREATE_MISSING_PARENTS);
}
/**
* @param childNode HA Child Node
* @param haNodePath HA node path
* @param tx Transaction
- * @throws ReadFailedException Exception thrown if read fails
*/
private void copyChildOpToHA(Node childNode,
InstanceIdentifier<Node> haNodePath,
- ReadWriteTransaction tx)
- throws ReadFailedException {
+ TypedReadWriteTransaction<Operational> tx)
+ throws ExecutionException, InterruptedException {
if (childNode == null) {
return;
}
- HwvtepGlobalAugmentation childData = childNode.getAugmentation(HwvtepGlobalAugmentation.class);
+ HwvtepGlobalAugmentation childData = childNode.augmentation(HwvtepGlobalAugmentation.class);
if (childData == null) {
return;
}
NodeBuilder haNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(haNodePath);
HwvtepGlobalAugmentationBuilder haBuilder = new HwvtepGlobalAugmentationBuilder();
- Optional<Node> existingHANodeOptional = tx.read(OPERATIONAL, haNodePath).checkedGet();
+ Optional<Node> existingHANodeOptional = tx.read(haNodePath).get();
Node existingHANode = existingHANodeOptional.isPresent() ? existingHANodeOptional.get() : null;
HwvtepGlobalAugmentation existingHAData = HwvtepHAUtil.getGlobalAugmentationOfNode(existingHANode);
haBuilder.setDbVersion(childData.getDbVersion());
haNodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, haBuilder.build());
Node haNode = haNodeBuilder.build();
- tx.merge(OPERATIONAL, haNodePath, haNode, true);
+ tx.merge(haNodePath, haNode, CREATE_MISSING_PARENTS);
}
/**
*/
public void copyHAPSConfigToChildPS(Node haPsNode,
InstanceIdentifier<Node> childPath,
- ReadWriteTransaction tx) {
+ TypedReadWriteTransaction<Configuration> tx) {
InstanceIdentifier<Node> childPsPath = HwvtepHAUtil.convertPsPath(haPsNode, childPath);
NodeBuilder childPsBuilder = HwvtepHAUtil.getNodeBuilderForPath(childPsPath);
PhysicalSwitchAugmentationBuilder dstBuilder = new PhysicalSwitchAugmentationBuilder();
- PhysicalSwitchAugmentation src = haPsNode.getAugmentation(PhysicalSwitchAugmentation.class);
+ PhysicalSwitchAugmentation src = haPsNode.augmentation(PhysicalSwitchAugmentation.class);
psAugmentationMerger.mergeConfigData(dstBuilder, src, childPath);
psNodeMerger.mergeConfigData(childPsBuilder, haPsNode, childPath);
childPsBuilder.addAugmentation(PhysicalSwitchAugmentation.class, dstBuilder.build());
Node childPSNode = childPsBuilder.build();
- tx.put(CONFIGURATION, childPsPath, childPSNode, WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(childPsPath, childPSNode, CREATE_MISSING_PARENTS);
}
/**
* @param haPath HA node path
* @param haPspath Ha Physical Switch Node path
* @param tx Transaction
- * @throws ReadFailedException Exception thrown if read fails
*/
public void copyChildPSOpToHAPS(Node childPsNode,
InstanceIdentifier<Node> haPath,
InstanceIdentifier<Node> haPspath,
- ReadWriteTransaction tx)
- throws ReadFailedException {
+ TypedReadWriteTransaction<Operational> tx)
+ throws ExecutionException, InterruptedException {
NodeBuilder haPSNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(haPspath);
PhysicalSwitchAugmentationBuilder dstBuilder = new PhysicalSwitchAugmentationBuilder();
- PhysicalSwitchAugmentation src = childPsNode.getAugmentation(PhysicalSwitchAugmentation.class);
+ PhysicalSwitchAugmentation src = childPsNode.augmentation(PhysicalSwitchAugmentation.class);
- Node existingHAPSNode = HwvtepHAUtil.readNode(tx, OPERATIONAL, haPspath);
+ Node existingHAPSNode = tx.read(haPspath).get().orElse(null);
PhysicalSwitchAugmentation existingHAPSAugumentation =
HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(existingHAPSNode);
haPSNodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, dstBuilder.build());
Node haPsNode = haPSNodeBuilder.build();
- tx.merge(OPERATIONAL, haPspath, haPsNode, true);
+ tx.merge(haPspath, haPsNode, CREATE_MISSING_PARENTS);
}
}