import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
-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.DataTreeModification;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
import org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener;
+import org.opendaylight.netvirt.elan.l2gw.recovery.impl.L2GatewayServiceRecoveryHandler;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
+import org.opendaylight.serviceutils.srm.RecoverableListener;
+import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
@Singleton
public class LocalUcastMacListener extends ChildListener<Node, LocalUcastMacs, String>
- implements ClusteredDataTreeChangeListener<Node> {
+ implements ClusteredDataTreeChangeListener<Node>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(LocalUcastMacListener.class);
public static final String NODE_CHECK = "physical";
final ElanL2GatewayUtils elanL2GatewayUtils,
final JobCoordinator jobCoordinator,
final ElanInstanceCache elanInstanceCache,
- final HwvtepNodeHACache hwvtepNodeHACache) {
+ final HwvtepNodeHACache hwvtepNodeHACache,
+ final L2GatewayServiceRecoveryHandler l2GatewayServiceRecoveryHandler,
+ final ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(dataBroker, false);
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.elanL2GatewayUtils = elanL2GatewayUtils;
this.jobCoordinator = jobCoordinator;
this.elanInstanceCache = elanInstanceCache;
this.hwvtepNodeHACache = hwvtepNodeHACache;
+ serviceRecoveryRegistry.addRecoverableListener(l2GatewayServiceRecoveryHandler.buildServiceRegistryKey(), this);
}
@Override
public void init() throws Exception {
ResourceBatchingManager.getInstance().registerDefaultBatchHandlers(this.dataBroker);
super.init();
+ registerListener();
+ }
+
+ @Override
+ @SuppressWarnings("all")
+ public void registerListener() {
+ try {
+ LOG.info("Registering LocalUcastMacListener");
+ registerListener(LogicalDatastoreType.OPERATIONAL, getParentWildCardPath());
+ } catch (Exception e) {
+ LOG.error("Local Ucast Mac register listener error");
+ }
+ }
+
+ public void deregisterListener() {
+ LOG.info("Deregistering LocalUcastMacListener");
+ super.close();
}
@Override
}
elanL2GwDevice.removeUcastLocalMac(macRemoved);
- ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+ ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
elanL2GatewayUtils.unInstallL2GwUcastMacFromL2gwDevices(elanName, elanL2GwDevice,
Collections.singletonList(macAddress));
elanL2GatewayUtils.unInstallL2GwUcastMacFromElanDpns(elanInstance, elanL2GwDevice,
LOG.trace("LocalUcastMacs {} added to {}", macAddress, hwvtepNodeId);
- ElanInstance elan = elanInstanceCache.get(elanName).orNull();
+ ElanInstance elan = elanInstanceCache.get(elanName).orElse(null);
if (elan == null) {
LOG.warn("Could not find ELAN for mac {} being added", macAddress);
return;
return;
}
// TODO skitt we're only using read transactions here
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
+ LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
tx -> haOpClusteredListener.onGlobalNodeAdd(nodeIid, modification.getRootNode().getDataAfter(), tx)), LOG,
"Error processing added parent");
if (!isHAChild(nodeIid)) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
+ LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.trace("On parent add {}", nodeIid);
Node operNode = modification.getRootNode().getDataAfter();
- Set<LocalUcastMacs> configMacs = getMacs(tx.read(nodeIid).get().orNull());
+ Set<LocalUcastMacs> configMacs = getMacs(tx.read(nodeIid).get().orElse(null));
Set<LocalUcastMacs> operMacs = getMacs(operNode);
Set<LocalUcastMacs> staleMacs = Sets.difference(configMacs, operMacs);
staleMacs.forEach(staleMac -> removed(getMacIid(nodeIid, staleMac), staleMac));