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