use of org.opendaylight.netvirt.elan.l2gw.jobs.DisAssociateHwvtepFromElanJob in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method disAssociateHwvtepsFromElan.
private void disAssociateHwvtepsFromElan(String elanName, L2gatewayConnection input) {
Integer defaultVlan = input.getSegmentId();
List<L2GatewayDevice> l2Devices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
List<Devices> l2gwDevicesToBeDeleted = new ArrayList<>();
for (L2GatewayDevice elanL2gwDevice : l2Devices) {
if (elanL2gwDevice.getL2GatewayIds().contains(input.getKey().getUuid())) {
l2gwDevicesToBeDeleted.addAll(elanL2gwDevice.getDevicesForL2gwConnectionId(input.getKey().getUuid()));
}
}
if (l2gwDevicesToBeDeleted.isEmpty()) {
// delete logical switch
Uuid l2GatewayId = input.getL2gatewayId();
L2gateway l2Gateway = L2GatewayConnectionUtils.getNeutronL2gateway(broker, l2GatewayId);
if (l2Gateway == null) {
LOG.error("Failed to find the l2gateway for the connection {}", input.getUuid());
return;
} else {
l2gwDevicesToBeDeleted.addAll(l2Gateway.getDevices());
}
}
for (Devices l2Device : l2gwDevicesToBeDeleted) {
String l2DeviceName = l2Device.getDeviceName();
L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(l2DeviceName);
String hwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
boolean isLastL2GwConnDeleted = false;
L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
if (elanL2GwDevice != null && isLastL2GwConnBeingDeleted(elanL2GwDevice)) {
// Delete L2 Gateway device from 'ElanL2GwDevice' cache
LOG.debug("Elan L2Gw Conn cache removed for id {}", hwvtepNodeId);
ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
isLastL2GwConnDeleted = true;
} else {
Uuid l2GwConnId = input.getKey().getUuid();
LOG.debug("Elan L2Gw Conn cache with id {} is being referred by other L2Gw Conns; so only " + "L2 Gw Conn {} reference is removed", hwvtepNodeId, l2GwConnId);
if (elanL2GwDevice != null) {
elanL2GwDevice.removeL2GatewayId(l2GwConnId);
} else {
isLastL2GwConnDeleted = true;
}
}
DisAssociateHwvtepFromElanJob disAssociateHwvtepToElanJob = new DisAssociateHwvtepFromElanJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils, elanL2GwDevice, elanName, () -> elanInstanceCache.get(elanName).orNull(), l2Device, defaultVlan, hwvtepNodeId, isLastL2GwConnDeleted);
elanClusterUtils.runOnlyInOwnerNode(disAssociateHwvtepToElanJob.getJobKey(), "remove l2gw connection job", disAssociateHwvtepToElanJob);
}
}
Aggregations