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);
}
}
Aggregations