use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method updateSubnetmapNodeWithPorts.
protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
LOG.info("updateSubnetmapNodeWithPorts : subnetId {}, subnetMapId {}", subnetId.toString(), id.toString());
try {
synchronized (subnetId.getValue().intern()) {
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
if (null != portId) {
List<Uuid> portList = builder.getPortList();
if (null == portList) {
portList = new ArrayList<>();
}
portList.add(portId);
builder.setPortList(portList);
LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}", subnetId.getValue(), portId.getValue());
}
if (null != directPortId) {
List<Uuid> directPortList = builder.getDirectPortList();
if (null == directPortList) {
directPortList = new ArrayList<>();
}
directPortList.add(directPortId);
builder.setDirectPortList(directPortList);
LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(), directPortId.getValue());
}
subnetmap = builder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} else {
LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed " + "cache ", subnetId.getValue(), portId.getValue());
unprocessedPortsMap.put(portId, subnetId);
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Updating port list of a given subnetMap failed for node: {}", subnetId.getValue(), e);
}
return subnetmap;
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInstanceNode.
private void updateVpnInstanceNode(Uuid vpnId, List<String> rd, List<String> irt, List<String> ert, VpnInstance.Type type, long l3vni, IpVersionChoice ipVersion) {
String vpnName = vpnId.getValue();
VpnInstanceBuilder builder = null;
List<VpnTarget> vpnTargetList = new ArrayList<>();
boolean isLockAcquired = false;
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
try {
Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
LOG.debug("Creating/Updating a new vpn-instance node: {} ", vpnName);
if (optionalVpn.isPresent()) {
builder = new VpnInstanceBuilder(optionalVpn.get());
LOG.debug("updating existing vpninstance node");
} else {
builder = new VpnInstanceBuilder().setKey(new VpnInstanceKey(vpnName)).setVpnInstanceName(vpnName).setType(type).setL3vni(l3vni);
}
if (irt != null && !irt.isEmpty()) {
if (ert != null && !ert.isEmpty()) {
List<String> commonRT = new ArrayList<>(irt);
commonRT.retainAll(ert);
for (String common : commonRT) {
irt.remove(common);
ert.remove(common);
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(common)).setVrfRTValue(common).setVrfRTType(VpnTarget.VrfRTType.Both).build();
vpnTargetList.add(vpnTarget);
}
}
for (String importRT : irt) {
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(importRT)).setVrfRTValue(importRT).setVrfRTType(VpnTarget.VrfRTType.ImportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
if (ert != null && !ert.isEmpty()) {
for (String exportRT : ert) {
VpnTarget vpnTarget = new VpnTargetBuilder().setKey(new VpnTargetKey(exportRT)).setVrfRTValue(exportRT).setVrfRTType(VpnTarget.VrfRTType.ExportExtcommunity).build();
vpnTargetList.add(vpnTarget);
}
}
VpnTargets vpnTargets = new VpnTargetsBuilder().setVpnTarget(vpnTargetList).build();
Ipv4FamilyBuilder ipv4vpnBuilder = new Ipv4FamilyBuilder().setVpnTargets(vpnTargets);
Ipv6FamilyBuilder ipv6vpnBuilder = new Ipv6FamilyBuilder().setVpnTargets(vpnTargets);
if (rd != null && !rd.isEmpty()) {
ipv4vpnBuilder.setRouteDistinguisher(rd);
ipv6vpnBuilder.setRouteDistinguisher(rd);
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
builder.setIpv6Family(ipv6vpnBuilder.build());
}
if (ipVersion != null && ipVersion.isIpVersionChosen(IpVersionChoice.UNDEFINED)) {
builder.setIpv4Family(ipv4vpnBuilder.build());
}
VpnInstance newVpn = builder.build();
isLockAcquired = vpnLock.tryLock(vpnId, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating vpn-instance for {} ", vpnName);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier, newVpn);
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Update VPN Instance node failed for node: {} {} {} {}", vpnName, rd, irt, ert);
} 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 updateVpnInterfaceWithExtraRouteAdjacency.
protected void updateVpnInterfaceWithExtraRouteAdjacency(Uuid vpnId, List<Routes> routeList) {
checkAlarmExtraRoutes(vpnId, routeList);
for (Routes route : routeList) {
if (route == null || route.getNexthop() == null || route.getDestination() == null) {
LOG.error("Incorrect input received for extra route. {}", route);
} else {
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.trace("Updating extra route for destination {} onto vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
boolean isLockAcquired = false;
try {
InstanceIdentifier<VpnInterface> identifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
InstanceIdentifier<Adjacency> path = identifier.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination));
Optional<Adjacency> existingAdjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
if (existingAdjacency.isPresent() && existingAdjacency.get().getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
LOG.error("The route with destination {} nextHop {} is already present as" + " a primary adjacency for interface {}. Skipping adjacency addition.", destination, nextHop, infName);
continue;
}
Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIpList(Collections.singletonList(nextHop)).setKey(new AdjacencyKey(destination)).setAdjacencyType(AdjacencyType.ExtraRoute).build();
isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, path, erAdj);
} catch (TransactionCommitFailedException e) {
LOG.error("exception in adding extra route with destination: {}, next hop: {}", destination, nextHop, e);
} catch (ReadFailedException e) {
LOG.error("Exception on reading data-store ", e);
} finally {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
}
} else {
LOG.error("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
}
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method updateSubnetNode.
protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
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("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
} else {
LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
return null;
}
if (routerId != null) {
builder.setRouterId(routerId);
}
if (vpnId != null) {
builder.setVpnId(vpnId);
}
builder.setInternetVpnId(internetvpnId);
subnetmap = builder.build();
LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
}
return subnetmap;
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException in project netvirt by opendaylight.
the class NeutronvpnManager method removePortsFromSubnetmapNode.
protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
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 (null != portId && null != builder.getPortList()) {
List<Uuid> portList = builder.getPortList();
portList.remove(portId);
builder.setPortList(portList);
LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(), subnetId.getValue());
}
if (null != directPortId && null != builder.getDirectPortList()) {
List<Uuid> directPortList = builder.getDirectPortList();
directPortList.remove(directPortId);
builder.setDirectPortList(directPortList);
LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId.getValue(), subnetId.getValue());
}
subnetmap = builder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} else {
LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removing a port from port list of a subnetmap failed for node: {}", subnetId.getValue(), e);
}
return subnetmap;
}
Aggregations