use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project netvirt by opendaylight.
the class NeutronSubnetChangeListener method createSubnetToNetworkMapping.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
try {
InstanceIdentifier<NetworkMap> networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
Optional<NetworkMap> optionalNetworkMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
NetworkMapBuilder nwMapBuilder = null;
if (optionalNetworkMap.isPresent()) {
nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
} else {
nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
LOG.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
}
List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
if (subnetIdList == null) {
subnetIdList = new ArrayList<>();
}
subnetIdList.add(subnetId);
nwMapBuilder.setSubnetIdList(subnetIdList);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
LOG.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(), networkId.getValue());
} catch (ReadFailedException | RuntimeException e) {
LOG.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(), networkId.getValue());
}
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException 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.ReadFailedException 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.ReadFailedException 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.ReadFailedException 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);
}
}
}
Aggregations