use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronBgpvpnNetworkAssociationChangeListener method remove.
@Override
public void remove(InstanceIdentifier<BgpvpnNetworkAssociation> identifier, BgpvpnNetworkAssociation input) {
LOG.trace("Removing Bgpvpn network association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid networkId = input.getNetworkId();
List<Uuid> networks = new ArrayList<>();
networks.add(networkId);
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Remove network association: remove association failed for vpn : {} and networkId: {} due " + "to failure in acquiring lock", vpnName, networkId.getValue());
return;
}
neutronBgpvpnUtils.removeUnProcessedNetwork(vpnId, networkId);
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
List<String> errorMessages = nvpnManager.dissociateNetworksFromVpn(vpnId, networks);
if (!errorMessages.isEmpty()) {
LOG.error("BgpvpnNetworkAssociation remove: dissociate network id {} to vpn {} failed due to {}", networkId.getValue(), vpnName, errorMessages);
}
}
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnMaps.
protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId, @Nullable List<Uuid> networks) {
VpnMapBuilder builder;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
try {
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
builder = new VpnMapBuilder(optionalVpnMap.get());
} else {
builder = new VpnMapBuilder().withKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
}
if (name != null) {
builder.setName(name);
}
if (tenantId != null) {
builder.setTenantId(tenantId);
}
if (router != null) {
RouterIds vpnRouterId = new RouterIdsBuilder().setRouterId(router).build();
List<RouterIds> rtrIds = builder.getRouterIds() != null ? new ArrayList<>(builder.getRouterIds().values()) : null;
if (rtrIds == null) {
rtrIds = Collections.singletonList(vpnRouterId);
} else {
// Add vpnRouterId to rtrIds list only if update routerId is not existing in the VpnMap already
for (RouterIds routerId : rtrIds) {
if (!Objects.equals(routerId, vpnRouterId)) {
rtrIds.add(vpnRouterId);
}
}
}
builder.setRouterIds(rtrIds);
}
if (networks != null) {
List<Uuid> nwList = builder.getNetworkIds() != null ? new ArrayList<>(builder.getNetworkIds()) : new ArrayList<>();
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
}
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try (AcquireResult lock = tryInterfaceLock(infName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(infName);
}
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
LOG.debug("Updating vpn interface {} with new adjacencies", infName);
if (adjacencies == null) {
return;
}
vpnIfBuilder.addAugmentation(adjacencies);
if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames().values());
if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
} else {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ExecutionException | InterruptedException ex) {
// FIXME: why are we catching IllegalStateException here?
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap;
try {
optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
List<RouterIds> rtrIds = new ArrayList<>(vpnMap.nonnullRouterIds().values());
if (rtrIds == null) {
rtrIds = new ArrayList<>();
}
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
rtrIds.add(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("removing vpnMaps node: {} ", vpnId);
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
return;
} else if (vpnMap.getNetworkIds() == null && !routerId.equals(vpnMap.getVpnId())) {
rtrIds.remove(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
LOG.debug("Removing routerId {} in vpnMaps for the vpn {}", routerId, vpnId.getValue());
}
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds() != null ? new ArrayList<>(vpnMap.getNetworkIds()) : new ArrayList<>();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
} else {
LOG.error("VPN : {} not found", vpnId.getValue());
}
LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
use of org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceNode.
private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, boolean isL2Vpn, long l3vni, IpVersionChoice ipVersion) {
String vpnName = vpnId.getValue();
VpnInstanceBuilder builder = null;
List<VpnTarget> vpnTargetList = new ArrayList<>();
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
Optional<VpnInstance> optionalVpn;
try {
optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
return;
}
LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
if (optionalVpn.isPresent()) {
builder = new VpnInstanceBuilder(optionalVpn.get());
LOG.debug("updating existing vpninstance node");
} else {
builder = new VpnInstanceBuilder().withKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setL2vpn(isL2Vpn).setL3vni(l3vni).setBgpvpnType(VpnInstance.BgpvpnType.InternalVPN);
}
if (irt != null && !irt.isEmpty()) {
if (ert != null && !ert.isEmpty()) {
List<String> commonRT = new ArrayList<>(irt);
commonRT.retainAll(ert);
for (String common : commonRT) {
irt.remove(common);
ert.remove(common);
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
vpnTargetList.add(vpnTarget);
}
}
for (String importRT : irt) {
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(importRT)).setVrfRTValue(importRT).setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
if (ert != null && !ert.isEmpty()) {
for (String exportRT : ert) {
VpnTarget vpnTarget = new VpnTargetBuilder().withKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
if (rd != null && !rd.isEmpty()) {
builder.setRouteDistinguisher(rd).setVpnTargets(vpnTargets).setBgpvpnType(VpnInstance.BgpvpnType.BGPVPN);
}
builder.setIpAddressFamilyConfigured(VpnInstance.IpAddressFamilyConfigured.forValue(ipVersion.choice));
VpnInstance newVpn = builder.build();
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
} catch (TransactionCommitFailedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
}
}
}
Aggregations