mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Remove vm from Load Balancers when vm is Expunged. Added more logging to vm expunge process
This commit is contained in:
parent
3735c91779
commit
dfaf7c4c5d
@ -25,4 +25,11 @@ import com.cloud.utils.net.Ip;
|
||||
public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
|
||||
boolean removeAllLoadBalanacers(Ip ip);
|
||||
List<LbDestination> getExistingDestinations(long lbId);
|
||||
|
||||
/**
|
||||
* Remove vm from all load balancers
|
||||
* @param vmId
|
||||
* @return true if removal is successful
|
||||
*/
|
||||
boolean removeVmFromLoadBalancers(long vmId);
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ package com.cloud.network.lb;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -219,6 +220,44 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeVmFromLoadBalancers(long instanceId) {
|
||||
boolean success = true;
|
||||
List<LoadBalancerVMMapVO> maps = _lb2VmMapDao.listByInstanceId(instanceId);
|
||||
if (maps == null || maps.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<Long, List<Long>> lbsToReconfigure = new HashMap<Long, List<Long>>();
|
||||
|
||||
//first set all existing lb mappings with Revoke state
|
||||
for (LoadBalancerVMMapVO map: maps) {
|
||||
long lbId = map.getLoadBalancerId();
|
||||
List<Long> instances = lbsToReconfigure.get(lbId);
|
||||
if (instances == null) {
|
||||
instances = new ArrayList<Long>();
|
||||
}
|
||||
instances.add(map.getInstanceId());
|
||||
lbsToReconfigure.put(lbId, instances);
|
||||
|
||||
map.setRevoke(true);
|
||||
_lb2VmMapDao.persist(map);
|
||||
s_logger.debug("Set load balancer rule for revoke: rule id " + map.getLoadBalancerId() + ", vmId " + instanceId);
|
||||
}
|
||||
|
||||
//Reapply all lbs that had the vm assigned
|
||||
if (lbsToReconfigure != null) {
|
||||
for (Map.Entry<Long, List<Long>> lb : lbsToReconfigure.entrySet()) {
|
||||
if (!removeFromLoadBalancer(lb.getKey(), lb.getValue())) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteLoadBalancerRule(long loadBalancerId, boolean apply) {
|
||||
|
||||
@ -132,6 +132,7 @@ import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.LoadBalancerVMMapDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
@ -254,6 +255,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
@Inject VirtualNetworkApplianceManager _routerMgr;
|
||||
@Inject NicDao _nicDao;
|
||||
@Inject RulesManager _rulesMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject UsageEventDao _usageEventDao;
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
@ -1603,8 +1605,21 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
try {
|
||||
vols = _volsDao.findByInstanceIdDestroyed(vmId);
|
||||
_storageMgr.destroy(vm, vols);
|
||||
|
||||
//cleanup port forwarding rules
|
||||
if (_rulesMgr.revokePortForwardingRule(vmId)) {
|
||||
s_logger.debug("Port forwarding rules are removed successfully as a part of vm id=" + vmId + " expunge");
|
||||
} else {
|
||||
s_logger.warn("Fail to remove port forwarding rules as a part of vm id=" + vmId + " expunge");
|
||||
}
|
||||
|
||||
//cleanup load balancer rules
|
||||
if (_lbMgr.removeVmFromLoadBalancers(vmId)) {
|
||||
s_logger.debug("LB rules are removed successfully as a part of vm id=" + vmId + " expunge");
|
||||
} else {
|
||||
s_logger.warn("Fail to remove lb rules as a part of vm id=" + vmId + " expunge");
|
||||
}
|
||||
|
||||
_rulesMgr.revokePortForwardingRule(vmId);
|
||||
_vmDao.remove(vm.getId());
|
||||
_networkGroupMgr.removeInstanceFromGroups(vm.getId());
|
||||
removeInstanceFromGroup(vm.getId());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user