*/
package org.opendaylight.netvirt.elan.l2gw.ha.listeners;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
-import com.google.common.base.Optional;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
import org.opendaylight.infrautils.metrics.MetricProvider;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
import org.opendaylight.netvirt.elan.l2gw.ha.handlers.HAEventHandler;
import org.opendaylight.netvirt.elan.l2gw.ha.handlers.IHAEventHandler;
import org.opendaylight.netvirt.elan.l2gw.ha.handlers.NodeCopier;
+import org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayServiceRecoveryHandler;
+import org.opendaylight.serviceutils.srm.RecoverableListener;
+import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class HAConfigNodeListener extends HwvtepNodeBaseListener {
+public class HAConfigNodeListener extends HwvtepNodeBaseListener<Configuration> implements RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(HAConfigNodeListener.class);
@Inject
public HAConfigNodeListener(DataBroker db, HAEventHandler haEventHandler,
NodeCopier nodeCopier, HwvtepNodeHACache hwvtepNodeHACache,
- MetricProvider metricProvider) throws Exception {
- super(LogicalDatastoreType.CONFIGURATION, db, hwvtepNodeHACache, metricProvider, true);
+ MetricProvider metricProvider,
+ final L2GatewayServiceRecoveryHandler l2GatewayServiceRecoveryHandler,
+ final ServiceRecoveryRegistry serviceRecoveryRegistry) throws Exception {
+ super(CONFIGURATION, db, hwvtepNodeHACache, metricProvider, true);
this.haEventHandler = haEventHandler;
this.nodeCopier = nodeCopier;
+ serviceRecoveryRegistry.addRecoverableListener(l2GatewayServiceRecoveryHandler.buildServiceRegistryKey(), this);
+ }
+
+ @Override
+ @SuppressWarnings("all")
+ public void registerListener() {
+ try {
+ LOG.info("Registering HAConfigNodeListener");
+ registerListener(CONFIGURATION, getDataBroker());
+ } catch (Exception e) {
+ LOG.error("HA Config Node register listener error.");
+ }
+ }
+
+ public void deregisterListener() {
+ LOG.info("Deregistering HAConfigNodeListener");
+ super.close();
}
@Override
void onPsNodeAdd(InstanceIdentifier<Node> haPsPath,
Node haPSNode,
- ReadWriteTransaction tx) throws ReadFailedException {
+ TypedReadWriteTransaction<Configuration> tx)
+ throws ExecutionException, InterruptedException {
//copy the ps node data to children
String psId = haPSNode.getNodeId().getValue();
Set<InstanceIdentifier<Node>> childSwitchIds = getPSChildrenIdsForHAPSNode(psId);
String nodeId =
HwvtepHAUtil.convertToGlobalNodeId(childPsPath.firstKeyOf(Node.class).getNodeId().getValue());
InstanceIdentifier<Node> childGlobalPath = HwvtepHAUtil.convertToInstanceIdentifier(nodeId);
- nodeCopier.copyPSNode(Optional.fromNullable(haPSNode), haPsPath, childPsPath, childGlobalPath,
- LogicalDatastoreType.CONFIGURATION, tx);
+ nodeCopier.copyPSNode(Optional.ofNullable(haPSNode), haPsPath, childPsPath, childGlobalPath,
+ CONFIGURATION, tx);
}
LOG.trace("Handle config ps node add {}", psId);
}
@Override
void onPsNodeUpdate(Node haPSUpdated,
- Node haPSOriginal,
- DataObjectModification<Node> mod,
- ReadWriteTransaction tx) throws InterruptedException, ExecutionException, ReadFailedException {
+ DataObjectModification<Node> mod,
+ TypedReadWriteTransaction<Configuration> tx) {
//copy the ps node data to children
String psId = haPSUpdated.getNodeId().getValue();
Set<InstanceIdentifier<Node>> childSwitchIds = getPSChildrenIdsForHAPSNode(psId);
Node haUpdated,
Node haOriginal,
DataObjectModification<Node> mod,
- ReadWriteTransaction tx)
- throws InterruptedException, ExecutionException, ReadFailedException {
+ TypedReadWriteTransaction<Configuration> tx) {
Set<InstanceIdentifier<Node>> childNodeIds = getHwvtepNodeHACache().getChildrenForHANode(key);
for (InstanceIdentifier<Node> haChildNodeId : childNodeIds) {
haEventHandler.copyHAGlobalUpdateToChild(haChildNodeId, mod, tx);
@Override
void onPsNodeDelete(InstanceIdentifier<Node> key,
Node deletedPsNode,
- ReadWriteTransaction tx) throws ReadFailedException {
+ TypedReadWriteTransaction<Configuration> tx)
+ throws ExecutionException, InterruptedException {
//delete ps children nodes
String psId = deletedPsNode.getNodeId().getValue();
Set<InstanceIdentifier<Node>> childPsIds = getPSChildrenIdsForHAPSNode(psId);
for (InstanceIdentifier<Node> childPsId : childPsIds) {
- HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childPsId);
+ HwvtepHAUtil.deleteNodeIfPresent(tx, childPsId);
}
}
@Override
void onGlobalNodeDelete(InstanceIdentifier<Node> key,
Node haNode,
- ReadWriteTransaction tx)
- throws ReadFailedException {
+ TypedReadWriteTransaction<Configuration> tx)
+ throws ExecutionException, InterruptedException {
//delete child nodes
Set<InstanceIdentifier<Node>> children = getHwvtepNodeHACache().getChildrenForHANode(key);
for (InstanceIdentifier<Node> childId : children) {
- HwvtepHAUtil.deleteNodeIfPresent(tx, CONFIGURATION, childId);
+ HwvtepHAUtil.deleteNodeIfPresent(tx, childId);
}
HwvtepHAUtil.deletePSNodesOfNode(key, haNode, tx);
}