Search in sources :

Example 66 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method removePortOpDataEntry.

public PortOpDataEntry removePortOpDataEntry(String intfName, Uuid subnetId) {
    // Remove PortOpData and return out
    InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
    PortOpDataEntry portOpEntry = null;
    Optional<PortOpDataEntry> optionalPortOp = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
    if (!optionalPortOp.isPresent()) {
        LOG.info("removePortOpDataEntry: Cannot delete, portOp for port {} is not available in datastore", intfName);
        return null;
    } else {
        portOpEntry = optionalPortOp.get();
        List<Uuid> listSubnet = portOpEntry.getSubnetIds();
        if (listSubnet == null) {
            listSubnet = new ArrayList<>();
        }
        if (subnetId != null && listSubnet.contains(subnetId)) {
            listSubnet.remove(subnetId);
        }
        if (listSubnet.isEmpty() || subnetId == null) {
            MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
            LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
        } else {
            try {
                PortOpDataEntryBuilder portOpBuilder = null;
                portOpBuilder = new PortOpDataEntryBuilder(portOpEntry);
                portOpBuilder.setSubnetIds(listSubnet);
                SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier, portOpEntry);
                LOG.info("removePortOpDataEntry: Updated PortOpData entry for port {} with removing subnetId {}", intfName, subnetId.getValue());
            } catch (TransactionCommitFailedException ex) {
                LOG.error("removePortOpDataEntry failed: Updated PortOpData entry for port {}" + " with removing subnetId {}", intfName, subnetId.getValue());
            }
            return null;
        }
    }
    return portOpEntry;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PortOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryBuilder) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) PortOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey)

Example 67 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class SubnetOpDpnManager method addPortOpDataEntry.

public void addPortOpDataEntry(String intfName, Uuid subnetId, BigInteger dpnId) {
    try {
        // Add to PortOpData as well.
        PortOpDataEntryBuilder portOpBuilder = null;
        PortOpDataEntry portOpEntry = null;
        InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
        Optional<PortOpDataEntry> optionalPortOp = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
        if (!optionalPortOp.isPresent()) {
            // Create PortOpDataEntry only if not present
            portOpBuilder = new PortOpDataEntryBuilder().setKey(new PortOpDataEntryKey(intfName)).setPortId(intfName);
            List<Uuid> listSubnet = new ArrayList<>();
            listSubnet.add(subnetId);
            portOpBuilder.setSubnetIds(listSubnet);
        } else {
            List<Uuid> listSubnet = optionalPortOp.get().getSubnetIds();
            portOpBuilder = new PortOpDataEntryBuilder(optionalPortOp.get());
            if (listSubnet == null) {
                listSubnet = new ArrayList<>();
            }
            if (!listSubnet.contains(subnetId)) {
                listSubnet.add(subnetId);
            }
            portOpBuilder.setSubnetIds(listSubnet);
        }
        if (dpnId != null && !dpnId.equals(BigInteger.ZERO)) {
            portOpBuilder.setDpnId(dpnId);
        }
        portOpEntry = portOpBuilder.build();
        SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier, portOpEntry);
        LOG.info("addPortOpDataEntry: Created PortOpData entry for port {} with DPNId {} subnetId {}", intfName, dpnId, subnetId.getValue());
    } catch (TransactionCommitFailedException ex) {
        LOG.error("addPortOpDataEntry: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PortOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryBuilder) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) PortOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey) ArrayList(java.util.ArrayList)

Example 68 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class WeightedCentralizedSwitchScheduler method releaseCentralizedSwitch.

@Override
public boolean releaseCentralizedSwitch(Routers router) {
    String routerName = router.getRouterName();
    BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    deleteFromDpnMaps(routerName, router.getSubnetIds(), primarySwitchId);
    try {
        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName));
        switchWeightsMap.put(primarySwitchId, switchWeightsMap.get(primarySwitchId) - 1);
    } catch (TransactionCommitFailedException e) {
        return false;
    }
    return true;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) BigInteger(java.math.BigInteger)

Example 69 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class WeightedCentralizedSwitchScheduler method scheduleCentralizedSwitch.

@Override
public boolean scheduleCentralizedSwitch(Routers router) {
    BigInteger nextSwitchId = getSwitchWithLowestWeight();
    String routerName = router.getRouterName();
    RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder().setRouterName(routerName);
    RouterToNaptSwitch id = routerToNaptSwitchBuilder.setPrimarySwitchId(nextSwitchId).build();
    addToDpnMaps(routerName, router.getSubnetIds(), nextSwitchId);
    try {
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), id);
        switchWeightsMap.put(nextSwitchId, switchWeightsMap.get(nextSwitchId) + 1);
    } catch (TransactionCommitFailedException e) {
        LOG.error("ScheduleCentralizedSwitch failed for {}", routerName);
    }
    return true;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) BigInteger(java.math.BigInteger) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder)

Example 70 with TransactionCommitFailedException

use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.

the class VrfEntryListener method update.

@Override
// originalRoutePath is a little dicey - safest to keep the checking even if not needed.
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
protected void update(InstanceIdentifier<VrfEntry> identifier, VrfEntry original, VrfEntry update) {
    Preconditions.checkNotNull(update, "VrfEntry should not be null or empty.");
    final String rd = identifier.firstKeyOf(VrfTables.class).getRouteDistinguisher();
    LOG.debug("UPDATE: Updating Fib Entries to rd {} prefix {} route-paths {} origin {} old-origin {}", rd, update.getDestPrefix(), update.getRoutePaths(), update.getOrigin(), original.getOrigin());
    // Handle BGP Routes first
    if (RouteOrigin.value(update.getOrigin()) == RouteOrigin.BGP) {
        bgpRouteVrfEntryHandler.updateFlows(identifier, original, update, rd);
        LOG.info("UPDATE: Updated BGP advertised Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
        return;
    }
    if (RouteOrigin.value(update.getOrigin()) == RouteOrigin.STATIC) {
        List<RoutePaths> originalRoutePath = original.getRoutePaths();
        List<RoutePaths> updateRoutePath = update.getRoutePaths();
        LOG.info("UPDATE: Original route-path {} update route-path {} ", originalRoutePath, updateRoutePath);
        // Updates need to be handled for extraroute even if original vrf entry route path is null or
        // updated vrf entry route path is null. This can happen during tunnel events.
        Optional<VpnInstanceOpDataEntry> optVpnInstance = fibUtil.getVpnInstanceOpData(rd);
        List<String> usedRds = new ArrayList<>();
        if (optVpnInstance.isPresent()) {
            usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, optVpnInstance.get().getVpnId(), update.getDestPrefix());
        }
        // has nexthop , route needs to be created on remote Dpns
        if (originalRoutePath == null || originalRoutePath.isEmpty() && updateRoutePath != null && !updateRoutePath.isEmpty() && usedRds.isEmpty()) {
            // TODO(vivek): Though ugly, Not handling this code now, as each
            // tep add event will invoke flow addition
            LOG.trace("Original VRF entry NH is null for destprefix {}. And the prefix is not an extra route." + " This event is IGNORED here.", update.getDestPrefix());
            return;
        }
        // has nexthop empty'ed out, route needs to be removed from remote Dpns
        if (updateRoutePath == null || updateRoutePath.isEmpty() && originalRoutePath != null && !originalRoutePath.isEmpty() && usedRds.isEmpty()) {
            LOG.trace("Original VRF entry had valid NH for destprefix {}. And the prefix is not an extra route." + "This event is IGNORED here.", update.getDestPrefix());
            return;
        }
        // Update the used rds and vpntoextraroute containers only for the deleted nextHops.
        List<String> nextHopsRemoved = FibHelper.getNextHopListFromRoutePaths(original);
        nextHopsRemoved.removeAll(FibHelper.getNextHopListFromRoutePaths(update));
        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
        nextHopsRemoved.parallelStream().forEach(nextHopRemoved -> fibUtil.updateUsedRdAndVpnToExtraRoute(writeOperTxn, nextHopRemoved, rd, update.getDestPrefix()));
        CheckedFuture<Void, TransactionCommitFailedException> operFuture = writeOperTxn.submit();
        try {
            operFuture.get();
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Exception encountered while submitting operational future for update vrfentry {}", update, e);
        }
        createFibEntries(identifier, update);
        LOG.info("UPDATE: Updated static Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
        return;
    }
    // Handle all other routes only on a cluster reboot
    if (original.equals(update)) {
        // Reboot use-case
        createFibEntries(identifier, update);
        LOG.info("UPDATE: Updated Non-static Fib Entry with rd {} prefix {} route-paths {}", rd, update.getDestPrefix(), update.getRoutePaths());
        return;
    }
    LOG.info("UPDATE: Ignoring update for FIB entry with rd {} prefix {} route-origin {} route-paths {}", rd, update.getDestPrefix(), update.getOrigin(), update.getRoutePaths());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) ExecutionException(java.util.concurrent.ExecutionException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)117 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)32 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)21 Test (org.junit.Test)19 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)16 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)13 ArrayList (java.util.ArrayList)12 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)11 TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)9 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)9 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)8 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)8 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)8 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 Optional (com.google.common.base.Optional)6 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)6 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)6 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)6