use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method removeAdjacencyforExtraRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
for (Routes route : routeList) {
if (route != null && route.getNexthop() != null && route.getDestination() != null) {
boolean isLockAcquired = false;
String nextHop = String.valueOf(route.getNexthop().getValue());
String destination = String.valueOf(route.getDestination().getValue());
String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(), nextHop);
if (infName == null) {
LOG.error("Unable to find VPN NextHop interface to remove extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
// Proceed to remove the next extra-route
continue;
}
LOG.trace("Removing extra route for destination {} on vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination)).build();
try {
// Looking for existing prefix in MDSAL database
Optional<Adjacency> adjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
boolean updateNextHops = false;
List<String> nextHopList = new ArrayList<>();
if (adjacency.isPresent()) {
List<String> nhListRead = adjacency.get().getNextHopIpList();
if (nhListRead.size() > 1) {
// ECMP case
for (String nextHopRead : nhListRead) {
if (nextHopRead.equals(nextHop)) {
updateNextHops = true;
} else {
nextHopList.add(nextHopRead);
}
}
}
}
isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
if (updateNextHops) {
// An update must be done, not including the current next hop
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
Adjacency newAdj = new AdjacencyBuilder(adjacency.get()).setIpAddress(destination).setNextHopIpList(nextHopList).setKey(new AdjacencyKey(destination)).build();
Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Collections.singletonList(newAdj)).build();
VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(infName)).addAugmentation(Adjacencies.class, erAdjs).build();
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} else {
// Remove the whole route
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
LOG.trace("extra route {} deleted successfully", route);
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("exception in deleting extra route with destination {} for interface {}", destination, infName, e);
} finally {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
}
} else {
LOG.error("Incorrect input received for extra route: {}", route);
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method removeFromSubnetNode.
protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId, Uuid vpnId, Uuid portId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
try {
synchronized (subnetId.getValue().intern()) {
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
if (routerId != null) {
builder.setRouterId(null);
}
if (networkId != null) {
builder.setNetworkId(null);
}
if (vpnId != null) {
builder.setVpnId(null);
}
builder.setInternetVpnId(null);
if (portId != null && builder.getPortList() != null) {
List<Uuid> portList = builder.getPortList();
portList.remove(portId);
builder.setPortList(portList);
}
subnetmap = builder.build();
LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} else {
LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removal from subnetmap failed for node: {}", subnetId.getValue());
}
return subnetmap;
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method updateSubnetNodeWithFixedIp.
protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId, Uuid routerInterfacePortId, String fixedIp, String routerIntfMacAddress, Uuid vpnId) {
Subnetmap subnetmap = null;
SubnetmapBuilder builder = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
try {
synchronized (subnetId.getValue().intern()) {
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
builder = new SubnetmapBuilder(sn.get());
LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}", subnetId.getValue());
} else {
LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ", subnetId.getValue());
return;
}
builder.setRouterId(routerId);
builder.setRouterInterfacePortId(routerInterfacePortId);
builder.setRouterIntfMacAddress(routerIntfMacAddress);
builder.setRouterInterfaceFixedIp(fixedIp);
if (vpnId != null) {
builder.setVpnId(vpnId);
}
subnetmap = builder.build();
LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("WithRouterFixedIP: subnet map for Router FixedIp failed for node {}", subnetId.getValue(), e);
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnMaps.
private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
VpnMapBuilder builder;
boolean isLockAcquired = false;
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().setKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
}
if (name != null) {
builder.setName(name);
}
if (tenantId != null) {
builder.setTenantId(tenantId);
}
if (router != null) {
builder.setRouterId(router);
}
if (networks != null) {
List<Uuid> nwList = builder.getNetworkIds();
if (nwList == null) {
nwList = new ArrayList<>();
}
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
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 (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
boolean isLockAcquired = false;
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 (ReadFailedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
try {
// remove entire node in case of internal VPN
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("removing vpnMaps node: {} ", vpnId);
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
return;
}
vpnMapBuilder.setRouterId(null);
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try {
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
} finally {
if (isLockAcquired) {
vpnLock.unlock(vpnId);
}
}
} else {
LOG.error("VPN : {} not found", vpnId.getValue());
}
LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
Aggregations