use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnMapsNode.
private void deleteVpnMapsNode(Uuid vpnId) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
LOG.debug("removing vpnMaps node: {} ", vpnId.getValue());
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Delete vpnMaps node failed for vpn : {} ", vpnId.getValue());
}
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronBgpvpnChangeListener method update.
@Override
public void update(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn original, Bgpvpn update) {
LOG.trace("Update Bgpvpn : key: {}, value={}", identifier, update);
if (Objects.equals(original, update)) {
return;
}
String vpnName = update.getUuid().getValue();
if (!isBgpvpnTypeL3(update.getType())) {
LOG.warn("BGPVPN type for VPN {} is not L3", vpnName);
return;
}
boolean rdIrtErtStringsValid = true;
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getRouteDistinguishers().stream().anyMatch(rdStr -> rdStr.contains(" ")));
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getImportTargets().stream().anyMatch(irtStr -> irtStr.contains(" ")));
rdIrtErtStringsValid = rdIrtErtStringsValid && !(update.getExportTargets().stream().anyMatch(ertStr -> ertStr.contains(" ")));
if (!rdIrtErtStringsValid) {
LOG.error("Error encountered for BGPVPN {} with RD {} as RD/iRT/eRT contains whitespace characters", vpnName, update.getRouteDistinguishers());
return;
}
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Update VPN: update failed for vpn : {} due to failure in acquiring lock", vpnName);
return;
}
handleVpnInstanceUpdate(original.getUuid().getValue(), original.getRouteDistinguishers(), update.getRouteDistinguishers());
// TODO: Currently handling routers and networks for backward compatibility. Below logic needs to be
// removed once updated to latest BGPVPN API's.
Uuid vpnId = update.getUuid();
List<Uuid> oldNetworks = new ArrayList<>(original.getNetworks());
List<Uuid> newNetworks = new ArrayList<>(update.getNetworks());
handleNetworksUpdate(vpnId, oldNetworks, newNetworks);
List<Uuid> oldRouters = original.getRouters();
List<Uuid> newRouters = update.getRouters();
handleRoutersUpdate(vpnId, oldRouters, newRouters);
} catch (UnsupportedOperationException e) {
LOG.error("Error while processing Update Bgpvpn.", e);
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronBgpvpnChangeListener method remove.
@Override
public void remove(InstanceIdentifier<Bgpvpn> identifier, Bgpvpn input) {
LOG.trace("Removing Bgpvpn : key: {}, value={}", identifier, input);
Uuid vpnId = input.getUuid();
String vpnName = vpnId.getValue();
if (!isBgpvpnTypeL3(input.getType())) {
LOG.warn("BGPVPN type for VPN {} is not L3", vpnName);
return;
}
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Remove BGPVPN: remove bgpvpn failed for vpn : {} due to failure in acquiring lock", vpnName);
return;
}
neutronBgpvpnUtils.getUnProcessedRoutersMap().remove(input.getUuid());
neutronBgpvpnUtils.getUnProcessedNetworksMap().remove(input.getUuid());
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("Failed to handle BGPVPN Remove for VPN {} as that VPN is not configured" + " yet as a VPN Instance", vpnName);
return;
}
nvpnManager.removeVpn(input.getUuid());
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronBgpvpnRouterAssociationChangeListener method remove.
@Override
public void remove(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
LOG.trace("Removing Bgpvpn router association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid routerId = input.getRouterId();
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Remove router association: remove association failed for vpn : {} and routerId: {} due" + " to failure in acquiring lock", vpnName, routerId.getValue());
return;
}
neutronBgpvpnUtils.removeUnProcessedRouter(vpnId, routerId);
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
nvpnManager.dissociateRouterFromVpn(vpnId, routerId);
}
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronBgpvpnRouterAssociationChangeListener method add.
@Override
public void add(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
LOG.trace("Adding Bgpvpn router association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid routerId = input.getRouterId();
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Add router association: add association failed for vpn : {} and routerId: {} due to " + "failure in acquiring lock", vpnName, routerId.getValue());
return;
}
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
if (validateRouteInfo(routerId, vpnId)) {
nvpnManager.associateRouterToVpn(vpnId, routerId);
}
} else {
neutronBgpvpnUtils.addUnProcessedRouter(vpnId, routerId);
}
}
}
Aggregations