use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.router.to.vpn.mapping.RoutermappingKey in project netvirt by opendaylight.
the class RouterPortsListener method add.
@Override
protected void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
LOG.trace("add : key:{} value:{}", routerPorts.getKey(), routerPorts);
Optional<RouterPorts> optRouterPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optRouterPorts.isPresent()) {
RouterPorts ports = optRouterPorts.get();
String routerName = ports.getRouterId();
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
} else {
String routerName = routerPorts.getRouterId();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
}
// Check if the router is associated with any BGP VPN and update the association
String routerName = routerPorts.getRouterId();
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
if (vpnName != null) {
InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
Optional<Routermapping> optRouterMapping = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId);
if (!optRouterMapping.isPresent()) {
Long vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
Routermapping routerMapping = new RoutermappingBuilder().setKey(new RoutermappingKey(routerName)).setRouterName(routerName).setVpnName(vpnName.getValue()).setVpnId(vpnId).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId, routerMapping);
}
}
}
Aggregations