Search in sources :

Example 1 with AcquireResult

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());
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 2 with AcquireResult

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);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 3 with AcquireResult

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());
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 4 with AcquireResult

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);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Example 5 with AcquireResult

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);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) AcquireResult(org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)

Aggregations

AcquireResult (org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)18 ArrayList (java.util.ArrayList)10 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 ExecutionException (java.util.concurrent.ExecutionException)9 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)7 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance)6 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)6 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies)4 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency)4 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey)4 VpnInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface)4 VpnMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)4 RouterPortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)3 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)3 AdjacenciesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder)3 AdjacencyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder)3 VpnInterfaceBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder)3 VpnInterfaceKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey)3 VpnMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapBuilder)3 RouterIds (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds)3