Search in sources :

Example 1 with ELAN_EOS_DELAY

use of org.opendaylight.netvirt.elan.utils.ElanConstants.ELAN_EOS_DELAY in project netvirt by opendaylight.

the class ElanInstanceEntityOwnershipListener method ownershipChanged.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void ownershipChanged(EntityOwnershipChange ownershipChange) {
    LOG.info("Entity Ownership changed for the entity: {}", ownershipChange);
    if (!ownershipChange.getState().isOwner()) {
        if (ft != null) {
            ft.cancel(false);
            ft = null;
        }
        return;
    }
    if (!ownershipChange.getState().wasOwner() && ownershipChange.getState().isOwner()) {
        if (ft != null) {
            ft.cancel(false);
            ft = null;
        }
        ft = scheduler.getScheduledExecutorService().schedule(() -> {
            try {
                // check if i'm the owner
                if (ownershipChange.getState().isOwner()) {
                    LOG.info("Elan Entity owner is: {}", ownershipChange);
                    txRunner.callWithNewReadOnlyTransactionAndClose(CONFIGURATION, tx -> {
                        l2GatewayConnectionListener.loadL2GwConnectionCache(tx);
                    });
                    InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfacesInstanceIdentifier = InstanceIdentifier.builder(ElanDpnInterfaces.class).build();
                    txRunner.callWithNewReadOnlyTransactionAndClose(OPERATIONAL, tx -> {
                        Optional<ElanDpnInterfaces> optional = Optional.empty();
                        try {
                            optional = tx.read(elanDpnInterfacesInstanceIdentifier).get();
                        } catch (ExecutionException | InterruptedException e) {
                            LOG.error("Exception While reading ElanDpnInterfaces", e);
                        }
                        if (optional.isPresent() && optional.get().getElanDpnInterfacesList() != null) {
                            LOG.debug("Found elan dpn interfaces list");
                            optional.get().nonnullElanDpnInterfacesList().values().forEach(elanDpnInterfacesList -> {
                                List<DpnInterfaces> dpnInterfaces = new ArrayList<>(elanDpnInterfacesList.nonnullDpnInterfaces().values());
                                InstanceIdentifier<ElanDpnInterfacesList> parentIid = InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanDpnInterfacesList.getElanInstanceName())).build();
                                for (DpnInterfaces dpnInterface : dpnInterfaces) {
                                    LOG.debug("Found elan dpn interfaces");
                                    elanDpnInterfaceClusteredListener.add(parentIid.child(DpnInterfaces.class, dpnInterface.key()), dpnInterface);
                                }
                            });
                        }
                    });
                } else {
                    LOG.info("Not the owner for Elan entity {}", ownershipChange);
                }
                ft = null;
            } catch (Exception e) {
                LOG.error("Failed to read mdsal ", e);
            }
        }, ELAN_EOS_DELAY, TimeUnit.MINUTES);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) HwvtepSouthboundConstants(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants) ELAN_EOS_DELAY(org.opendaylight.netvirt.elan.utils.ElanConstants.ELAN_EOS_DELAY) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) DpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces) Singleton(javax.inject.Singleton) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ElanDpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces) ElanDpnInterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList) ElanDpnInterfacesListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey) EntityOwnershipListener(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener) ResourceBatchingManager(org.opendaylight.genius.utils.batching.ResourceBatchingManager) Logger(org.slf4j.Logger) Scheduler(org.opendaylight.netvirt.elan.utils.Scheduler) ElanDpnInterfaceClusteredListener(org.opendaylight.netvirt.elan.internal.ElanDpnInterfaceClusteredListener) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(java.util.Optional) EntityOwnershipChange(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Optional(java.util.Optional) DpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces) ElanDpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ArrayList(java.util.ArrayList) ElanDpnInterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList) List(java.util.List) ElanDpnInterfacesListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey) ExecutionException(java.util.concurrent.ExecutionException) ElanDpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 ResourceBatchingManager (org.opendaylight.genius.utils.batching.ResourceBatchingManager)1 HwvtepSouthboundConstants (org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants)1 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)1 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)1 OPERATIONAL (org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL)1 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)1 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)1 EntityOwnershipChange (org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange)1 EntityOwnershipListener (org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener)1 EntityOwnershipService (org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService)1 ElanDpnInterfaceClusteredListener (org.opendaylight.netvirt.elan.internal.ElanDpnInterfaceClusteredListener)1 ELAN_EOS_DELAY (org.opendaylight.netvirt.elan.utils.ElanConstants.ELAN_EOS_DELAY)1